function addToStart(fnc){
  if(!window.listStart) window.listStart = new Array();
  window.listStart.push(fnc)
}

function start(){
  var ls = window.listStart;
  if(ls){
    for(i=0; i<ls.length; i++){
      fnc = ls[i];
      if(typeof(fnc) == 'function'){
        fnc();
      } else {
        eval(fnc);
      }
    }
  }
}

window.onload = start;

function update () {
	for (var i=0; i<document.quote1Form.elements.length; i++) {
		element = document.quote1Form.elements[i];

		if (element.name.substring(0,16) == "selectedCriteria") {
			eval("element.disabled='';");
		}
	}
	for (var i=0; i<document.quote1Form.elements.length; i++) {
		element = document.quote1Form.elements[i];

		if (element.name.substring(0,16) == "selectedCriteria") {
			eval("var value = element.value;");
			eval("var comp = compat['"+value+"'];");
			
			if (comp != null) {
				var pos = comp.indexOf(',', 0);
				if (pos > 0) {
					var ids = comp.split(',');
					for (var j=0; j<ids.length; j++) {
						eval("document.quote1Form['selectedCriteria("+ids[j]+")'].disabled='disabled';");
						eval("document.quote1Form['selectedCriteria("+ids[j]+")'].selectedIndex=0;");
					}
				}
				else {
					eval("document.quote1Form['selectedCriteria("+comp+")'].disabled='disabled';");
					eval("document.quote1Form['selectedCriteria("+comp+")'].selectedIndex=0;");
				}
			}
		}
	}
}

// 
function updateRightPrice(newPrice) {
	var rightPrice = document.getElementById('rightPrice');
	if ( (null!=rightPrice) && ('undefined'!= rightPrice) ) {
		rightPrice.innerHTML = ''+newPrice;
	}
}

// for personalization
function change(id) {
	var	activArray = null;
	if ( (null!=arrayPs) && (0<arrayPs.length) ) {
		activArray = new Array();
		for ( var key in arrayPs ) {
			activArray = createActivation( key, splitValue( arrayPs[""+key] ), activArray);
		}
	}
	// 
	var check = document.forms.personalizeForm["checkbox(" + id + ")"];
	if (check != 'undefined' ) {
		if ( true == check.checked ) {
			active(id,activArray,0);
		}
		else
			desactive(id,0);
	}
}

var szMax = 20;

function active(id,activArray,sz) {
	if ( szMax > sz ) {
		var inputA = document.forms.personalizeForm["checkbox(" + id + ")"];
		if (  true==isCheckbox(inputA) ) {
			inputA.checked=true;
			if ( (null!=activArray) && (null!=activArray[""+id]) ) {
				active(activArray[""+id],activArray,sz+1);
			}		
		}
	}
}

function desactive(id,sz) {
	var flagState = false;
	if ( szMax > sz ) {
		if ( true == isDeactivable(id) ) {
			if ( (null!=arrayPs) && (null!=arrayPs[""+id]) ) {
				var arrayToDeactive = splitValue(arrayPs[""+id]);
				for ( i=0; i< arrayToDeactive.length; i++ ) {
					if ( false == desactive( arrayToDeactive[i],sz+1) )
					 	flagState=true;
				}
			}
		}
		document.forms.personalizeForm["checkbox(" + id + ")"].checked=flagState;
	}
	return (!flagState);
}

function isDeactivable( id ) {
	if ( (null!=arrayTo) && (null!=arrayTo[""+id]) ) {
		var inputC = document.forms.personalizeForm["checkbox(" + id + ")"];
		if ( true==isCheckbox(inputC) ) {
			var inputTo = document.forms.personalizeForm["checkbox(" + arrayTo[""+id] + ")"];
			if ( true==isCheckbox(inputTo) ) {
				if ( false == inputTo.checked )
					return false;
			}
		}
	}
	return true;
}

function isCheckbox( inp ) {
	if ( (null!=inp) && (inp!='undefined') && (inp.type=='checkbox') )
		return true;
	return false;
}

function splitValue(value) {
	if (value != null) {
		var array =  value.split(',');
		if ( 0<array.length )
			return array;
	}
	return null;
}

function createActivation( key , array, activArray) {	
	if ( (null!=key) && (null!=array) && (0<array.length) ) {
		for (i=0;i<array.length;i++)
			activArray[""+array[i] ] = key;
	}
	return activArray;
}

// take a image of form
var arrayInput = new Array();
function imageForm() {
	if( ( 'undefined' != (typeof document.personalizeForm.elements) ) &&
				( null != document.personalizeForm.elements ) &&
				( 0 < document.personalizeForm.elements.length ) ) {
				
		elemSize = document.personalizeForm.elements.length;	
		for(i=0;i<elemSize;i++ ){
			elementName = document.personalizeForm.elements[i];		
			if ( 'hidden' != elementName.type ) {
				if ( 'checkbox' == elementName.type )
					arrayInput[elementName.name] = elementName.checked;
				else
					arrayInput[elementName.name] = elementName.value;
			}
		}
	}
}

function check(message) {
	for( var iter in arrayInput ) {
		if( 'checkbox' == document.forms.personalizeForm[iter].type ) {
			if ( document.forms.personalizeForm[iter].checked != arrayInput[iter] )
				return confirm(message);
		}
		else {
			if ( document.forms.personalizeForm[iter].value != arrayInput[iter] )
				return confirm(message);
		}
	}
	return true;
}

// set keyboard enter on form
var focusPage=true;
function submitEnterKey(e) {
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	if ( true == focusPage ) {  
		if(KeyID==13)
			submitForm();
	}
} 

function focusOff(e) {
	focusPage=false;
}
function focusOn(e) {
	focusPage=true;
}

function setDocumentAction() {
	document.onkeyup= submitEnterKey;
	document.onblur=focusOff;
	document.onclick=focusOn;
	focusPage=true;
}

addToStart(setDocumentAction);

function loadDefaultImage(img) {
	img.src= "./img/europ/spacer.gif";	
}