// V1.0 2004-03-01 AH
var checkCaseColor = false;
var checkAllColor = true;
var optionScreenSurfaceMountedReversely = false;

function switchSide(type,side){
	if(type == 'electric'){
		document.getElementById(type).style.backgroundImage = "url('images/electric_"+side+".jpg')";
	}else if(type == 'elproLarge'){
		document.getElementById(type).style.backgroundImage = "url('images/elpro_"+side+".jpg')";
	}else if(type == 'decender'){
		document.getElementById(type).style.backgroundImage = "url('images/descender_"+side+".jpg')";
	}else{
		document.getElementById(type).style.backgroundImage = "url('images/manual_"+side+".jpg')";
	}
}

function showReverseMountable(value){
	if(value == 'Y'){
		document.getElementById('reverseMountable').style.display = "Block";
	}else{
		document.getElementById('reverseMountable').style.display = "None";
	}
}

function showReverseMountable(value){
	if(value == 'Y'){
		document.getElementById('reverseMountable').style.display = "Block";
	}else{
		document.getElementById('reverseMountable').style.display = "None";
	}
}

function popwin ( url, options )
{  if ( !options )
	{	// default options
		var options = 'status=no,resizable=yes,scrollbars=yes,menubar=no,toolbar=no,width=400,height=330';
	}
	
	window.open ( url, 'newwin', options );
	return true;
}


function focuson(form,object)
{
	var str = 'document.' + form + '.' + object + '.focus();';
	eval(str);
}

function changeproducts()
{

}

function splitintoarrays(arraystring, resultarray){
	//this function splits the string into arrays
	

}

function checkKey() {
  if (window.event && window.event.keyCode == 13)
		calculateValues();
	return !(window.event && window.event.keyCode == 13);
}

function checkKey2() {
  if (window.event && window.event.keyCode == 13)
		;
	return !(window.event && window.event.keyCode == 13);
}


function backtoDesign(id){
	document.location.href = 'screendesign.php?ssid=' + id;
}

function askDel(ID) {
	var MSG = "Are you sure you want to delete this item ?";
	if(confirm(MSG)) {
		document.location.href = './manage.php?task=delete&id=' + ID;
	}
}

function backtoScreenchooserGET(fabricSize){
	url = "screenchooser.php"
   	url += "?fabricSize="+fabricSize;
	document.location = url;
}

function openPDF(){
	window.open("pdf/createpdf.php",'mywindow')
}
			
function backtoScreenchooser(){
	document.location = "screenchooser.php"	
}

function  lastchanged(){
	//the last changed fieldname must be remembered
	var lastchanged = "";	
}

function calculateHeight(VAH, blackdrop, bottom){
	
	var overallheight = (VAH + blackdrop) + bottom
	overallheight = Math.round(overallheight * 100)/100
	return overallheight
} 

function calculateWidth(fabricwidth, slat){
	var overallwidth = fabricwidth + slat
	overallwidth = Math.round(overallwidth * 100)/100
	return overallwidth
} 

function calculateFabricwidth(frameleft_right , VAW){
	// c2 = a2 + b2
		//next calculate the fabric width
		var fabricwidth = (2 * frameleft_right) + VAW
		return fabricwidth
}

function calculateDiagonal(a , b){
	// c2 = a2 + b2
		var diagonal =  Math.sqrt(((a*a) + (b*b))) 
		//round it to 2 decimals 
		diagonal = Math.round(diagonal * 100)/100
		return diagonal
} 


function calculateValues(type){
	if(validateValues(type))
	{
		if(type == 'fixed'){
			var VAW = parseInt(document.formScreenchooser.VAW.value);
			var VAH = parseInt(document.formScreenchooser.VAH.value);
			
			//diagonal
			document.formScreenchooser.diagonal.value = calculateDiagonal(VAW , VAH );			
			document.getElementById('diagonalspan').innerHTML = calculateDiagonal(VAW , VAH );
		}else{
		
			//values are correct now calcuate the other values
			//alert("Other values are calculates");			
			var VAW = parseInt(document.formScreenchooser.VAW.value);
			var VAH = parseInt(document.formScreenchooser.VAH.value);
			var slat = parseInt(document.formScreenchooser.slat.value);
			//temp for border
			var border = parseInt(document.formScreenchooser.border.value);
			var bottom = parseInt(document.formScreenchooser.bottom.value);
			//send it back to the display
			
			//diagonal
			document.formScreenchooser.diagonal.value = calculateDiagonal(VAW , VAH );
			document.getElementById('diagonalspan').innerHTML = calculateDiagonal(VAW , VAH );
			
			//fabricwidth
			var frame_left_right = parseInt(document.formScreenchooser.or_frame_left_right.value);
			var fabricwidth = calculateFabricwidth(border , VAW);
			document.formScreenchooser.fabricwidth.value = fabricwidth;
			document.getElementById('fabricwidthspan').innerHTML = fabricwidth;
			
			//overall height
			
			var blackdrop = parseInt(document.formScreenchooser.blackdrop.value);
			document.formScreenchooser.overallheight.value = calculateHeight(VAH, blackdrop, bottom);
			document.getElementById('overallheightspan').innerHTML = calculateHeight(VAH, blackdrop, bottom);
			
			//overall width
			document.formScreenchooser.overallwidth.value = calculateWidth(fabricwidth, slat);
			document.getElementById('overallwidthspan').innerHTML = calculateWidth(fabricwidth, slat);
			
			// als ingevulde doekbreedte == case doekbreedte
			if (fabricwidth == parseInt(document.formScreenchooser.doekbreedte.value)) {
				document.getElementById('overalllengthcasespan').innerHTML = fabricwidth + parseInt(document.formScreenchooser.als_gelijk_doek.value);
				document.formScreenchooser.overalllengthcase.value = fabricwidth + parseInt(document.formScreenchooser.als_gelijk_doek.value);
			}
			else {
				// kleiner en groter zijn nog dezelfde dus groter pakken
				document.getElementById('overalllengthcasespan').innerHTML = fabricwidth + parseInt(document.formScreenchooser.als_groter_doek.value);
				document.formScreenchooser.overalllengthcase.value = fabricwidth + parseInt(document.formScreenchooser.als_groter_doek.value);
			}
			
			if (fabricwidth == parseInt(document.formScreenchooser.doekbreedte.value)) {
				document.getElementById('overalllengthcaseflangespan').innerHTML = fabricwidth + parseInt(document.formScreenchooser.als_gelijk_ophang.value);
				document.formScreenchooser.overalllengthcaseflange.value = fabricwidth + parseInt(document.formScreenchooser.als_gelijk_ophang.value);
			}
			else {
				document.getElementById('overalllengthcaseflangespan').innerHTML = fabricwidth + parseInt(document.formScreenchooser.als_groter_ophang.value);
				document.formScreenchooser.overalllengthcaseflange.value = fabricwidth + parseInt(document.formScreenchooser.als_groter_ophang.value);
			}
		}
	}	
}

function fillOveralLengthCase(){
	var VAW = parseInt(document.formScreenchooser.or_VAW.value);
	var border = parseInt(document.formScreenchooser.or_border.value);
	
	var fabricwidth = calculateFabricwidth(border , VAW);

	// als ingevulde doekbreedte == case doekbreedte
	if (fabricwidth == parseInt(document.formScreenchooser.doekbreedte.value)) {
		document.getElementById('oldOveralllengthcasespan').value = fabricwidth + parseInt(document.formScreenchooser.als_gelijk_doek.value);
	}
	else {
		// kleiner en groter zijn nog dezelfde dus groter pakken
		document.getElementById('oldOveralllengthcasespan').value = fabricwidth + parseInt(document.formScreenchooser.als_groter_doek.value);
	}
}

function resetValues(type){
	var MSG = "Weet u zeker dat u de waarden wilt resetten?";
	if(confirm(MSG)) {
		//set the values back to the orignal values
			document.formScreenchooser.VAW.value =  document.formScreenchooser.or_VAW.value
			document.formScreenchooser.VAH.value =  document.formScreenchooser.or_VAH.value
		if(type != 'fixed'){			
			document.formScreenchooser.border.value = document.formScreenchooser.or_frame_left_right.value
			document.formScreenchooser.bottom.value = document.formScreenchooser.or_frame_bottom.value
			document.formScreenchooser.blackdrop.value = document.formScreenchooser.or_blackdrop.value
		}
		calculateValues(type)	
	}
}

function validateValues(type){
	//the values are calculated for the screendesign
	//first check the VAH
	var VAW = parseInt(document.formScreenchooser.VAW.value);
	var VAH = parseInt(document.formScreenchooser.VAH.value);
	if(type != 'fixed'){
		var slat = parseInt(document.formScreenchooser.slat.value);
		var border = parseInt(document.formScreenchooser.border.value);
		var bottom = parseInt(document.formScreenchooser.bottom.value);
		var blackdrop = parseInt(document.formScreenchooser.blackdrop.value);
		if(document.formScreenchooser.VAW.value == "" || calculateFabricwidth(border, VAW) < parseInt(document.formScreenchooser.minimum_breedte.value) || calculateFabricwidth(border, VAW) > parseInt(document.formScreenchooser.maximum_breedte.value))
		{
			alert("Please enter a valid View Area Width. The fabric width can be max:" + document.formScreenchooser.maximum_breedte.value + " mm. or min:" + document.formScreenchooser.minimum_breedte.value + " mm.");
		}
		else
		{		if(document.formScreenchooser.VAH.value == "" || calculateHeight(VAH, blackdrop, bottom) < parseInt(document.formScreenchooser.minimum_hoogte.value) || calculateHeight(VAH, blackdrop, bottom) > parseInt(document.formScreenchooser.maximum_hoogte.value)){
					alert("Please enter a valid View Area Height.  The fabric height can be max:" + document.formScreenchooser.maximum_hoogte.value + " mm. or min:" + document.formScreenchooser.minimum_hoogte.value + " mm.")
				}
				else
				{
						
						if(document.formScreenchooser.blackdrop.value=="")
						{
							document.formScreenchooser.blackdrop.value= 0
						}
						return true				
					
				}
			
		}
		return false
	}else{
		if(document.formScreenchooser.VAW.value == "" || calculateFabricwidth(0, VAW) < parseInt(document.formScreenchooser.minimum_breedte.value) || calculateFabricwidth(0, VAW) > parseInt(document.formScreenchooser.maximum_breedte.value))
		{
			alert("Please enter a valid View Area Width. The fabric width can be max:" + document.formScreenchooser.maximum_breedte.value + " mm. or min:" + document.formScreenchooser.minimum_breedte.value + " mm.");
		}
		else
		{		
			if(document.formScreenchooser.VAH.value == "" || calculateHeight(VAH, 0, 0) < parseInt(document.formScreenchooser.minimum_hoogte.value) || calculateHeight(VAH, 0, 0) > parseInt(document.formScreenchooser.maximum_hoogte.value)){
				alert("Please enter a valid View Area Height.  The fabric height can be max:" + document.formScreenchooser.maximum_hoogte.value + " mm. or min:" + document.formScreenchooser.minimum_hoogte.value + " mm.")
			}else{
				return true;
			}			
		}
		return false
		
	}
}

function validateValuesSubmit(){
	//the values are calculated for the screendesign
	//first check the VAH
	var VAW = parseInt(document.formScreenchooser.VAW.value);
	var VAH = parseInt(document.formScreenchooser.VAH.value);
	var slat = parseInt(document.formScreenchooser.slat.value);
	var border = parseInt(document.formScreenchooser.border.value);
	var bottom = parseInt(document.formScreenchooser.bottom.value);
	var blackdrop = parseInt(document.formScreenchooser.blackdrop.value);
	if(document.formScreenchooser.VAW.value == "" || calculateFabricwidth(border, VAW) < parseInt(document.formScreenchooser.minimum_breedte.value) || calculateFabricwidth(border, VAW) > parseInt(document.formScreenchooser.maximum_breedte.value))
	{
		alert("Please enter a valid View Area Width. The fabric width can be 5.000 mm max.");
		return false;	
	}
	else
	{		
		if(document.formScreenchooser.VAH.value == "" || calculateHeight(VAH, blackdrop, bottom) < parseInt(document.formScreenchooser.minimum_hoogte.value) || calculateHeight(VAH, blackdrop, bottom) > parseInt(document.formScreenchooser.maximum_hoogte.value)){
			alert("Please enter a valid View Area Height.  The fabric height can be 6.000 mm max.")
			return false;	
		}
		else
		{
			if(document.formScreenchooser.blackdrop.value=="")
			{
				document.formScreenchooser.blackdrop.value= 0
			}
		
		return true				
				
		}		
	}
	
	
		
}

function visible(flag, object)
{
	var x = new getObj(object);
	x.style.visibility = (flag) ? 'hidden' : 'visible'
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

function visibleandfill()
{
	visible(0,'product' );
	//get the arrays of the products (article code) per productgroup from the hidden fields

}

function Change2To(ArrayName)
    {
		visible(0,'productID' );

      	document.scenarioform2.productID.length=0;
	  	for(i = 0; i < multiArray[ArrayName].length; i++){
		  	document.scenarioform2.productID.length++
		  	document.scenarioform2.productID.options[i].text = multiArray[ArrayName][i][1];
		  	document.scenarioform2.productID.options[i].value = multiArray[ArrayName][i][0];
		}
    }
	
function doLink(productID){
	//alert("screenchooser.php?productID=" + productID + "");
	window.location="step2.php?productID=" + productID;
}

function doSubmit()
{
	var selLength = document.form1.casecolorsSelected.length;
	var i;
	
	for(i=selLength-1; i>=0; i--)
	{
		document.form1.casecolorsSelected.options[i].selected = true;
	}
	
	var selLength = document.form1.fabrictypesSelected.length;
	var i;
	
	for(i=selLength-1; i>=0; i--)
	{
		document.form1.fabrictypesSelected.options[i].selected = true;
	}
	
	var selLength = document.form1.formatsSelected.length;
	var i;
	
	for(i=selLength-1; i>=0; i--)
	{
		document.form1.formatsSelected.options[i].selected = true;
	}
	
	document.form1.submit();
}

function gotopage(url,target)
{
	if ((typeof target == 'undefined')||(target=="")) window.location = url;
	else if (target == "new") window.open(url,"new",'scrollbars,resizable,maximized=yes');
//	window.open(pag,nam,'height=' + h + ',width=' + w + ',top=0,left=0,');
	else top.frames[target].location = url;
}


function gotovalue(object,target)
{
	var str = ("var url = " + object + ".value;");
	eval(str);
	if (url != "") gotopage(url,target)
}

function setvisability(object,ifvalue,url,b,target)
{
	var str = ("var value = " + object + ".value;");
	eval(str);
	if (value == "../field/field.php") var sel = ">> Velden >>";
	else if (value == "../constraint/constraint.php") var sel = ">> Constraint >>";
	else if (value == "../index/index.php") var sel = ">> Index >>";
	if (value == ifvalue) {
		var extra = "?showfieldauth=1";
		var sign = "&";
	}
	else {
		var extra = "";
		var sign = "?";
	}
	gotopage(url + extra + sign + "a=" + b + "&sel=" + sel,target);
}

function get(name)
{
	var str = ("var value = " + name + ".value;");
	eval(str);
	return value;
}

function getvariables(names,vars,url)
{
	if (typeof(vars)=="undefined") vars = "";
	var name = names.split(";");
	var count = splvars.length;
	var string = "";
	for (i=0 ; i < count ; i++)
	{
		var value = get("top.staticvars." + name[i])
		var str = ("var value = top.staticvars." + name[i] + ".value;");
		eval(str);
		if (string != "") string += "&";
		str = name[i] + "=" + value;
		string += str;
	}
	if ((vars != "") && (str != ""))
	{
		url += "?" + vars;
		if (str != "")
		{
			if (vars != "") url += "&";
			url += str;
		}
	}
	gotopage(url);
}

function set(name,value) 
{
	var str = (name + ".value=\"" + value + "\";");
	eval(str);
}

function setchecked(name,value) 
{
	var str = (name + ".checked=\"" + value + "\";");
	eval(str);
}



function setvariables(name,value,add) 
{
	if (add == 'add')
	{
		var arr1newvalue = new Array();
		var arr1prevvalue = new Array();
		var newvalue = value;
		var arrnewvalue = newvalue.split(";");
		for (i = 0 ; i < (arrnewvalue.length) ; i++)
		{
			var arrtempnewvalue = arrnewvalue[i].split(",");
			arr1newvalue[i] = arrtempnewvalue[0];
		}
		var prevvalue = get("top.staticvars." + name);
		var arrprevvalue = prevvalue.split(";");
		for (i = 0 ; i < arrprevvalue.length ; i++)
		{
			var arrtempprevvalue = arrprevvalue[i].split(",");
			arr1prevvalue[i] = arrtempprevvalue[0];
		}
		for (i = 0 ; i < arr1newvalue.length ; i++)
		{
			var donotadd = false;
			for (j = 0 ; j < arr1prevvalue.length ; j++)
			{
				if (arr1newvalue[i] == arr1prevvalue[j]) donotadd = true; //if is already present
			}
			if (!donotadd) 
			{
				if (prevvalue != "") prevvalue += ";";
				prevvalue += arrnewvalue[i];
			}
		}
		value = prevvalue;
	}
	set("top.staticvars." + name,value);
}


function list2list(src,dst,model,actiontype,removeoriginal,dosort,srcid)
{
	if ((typeof(model) == 'undefined')||(model == ""))var  model ="";
	if ((typeof(actiontype) == 'undefined')||(actiontype == "")) var actiontype = "add";
//Moves a value from one listbox to another
	if ((typeof(removeoriginal) == 'undefined')||(removeoriginal == "")) var removeoriginal = true;//if the selected values after trasfer should be deleted
	if ((typeof(dosort) == 'undefined')||(dosort == "")) var dosort = true;//if the moved value should be placed on it's alphanumeric hierarchal place
	if ((typeof(srcid) == 'undefined')||(srcid == "")) var srcid = "";
	
	if (model != "") {
		var dstold = dst;
		var srcold = src;
		eval("dst = " + dst + ";");//set destination object
		eval("src = " + src + ";");//set source object
	
		var ids = new Array();
		var values = new Array();
		var list = new Array();
		var last = 0;
		
		// get the set id's
		for (var i = 0; i < src.length ; i++) {//walk trough all selected items
			if ((src.options[i] != null)&&(src.options[i].selected)) {
				values[last] = src.options[i].value;
				ids[last] = i;
				list[last] = 'src';
				last++;
			}
		}

		var mod = model;
		//make the string model into an array
		var model2 = new Array();
		var index = new Array();
		var object = new Array();
		model = model.split("_");
		//make the object
		for (var i = 0 ; i < model.length ; i++) {
			model[i] = model[i].split(",");
			var k = 0;
			model2[i] = new Array();
			for (var j = 0 ; j < model[i].length ; j++) {
				if (model[i][j].search("<tag>") != -1) {
					model[i][j] = model[i][j].replace("<tag>","");
					model[i][j] = model[i][j].replace("</tag>","");
					index[i] = model[i][j];
				}
				else {
					model2[i][k] = model[i][j];
					k++;
				}
			}
		}
		for (var i = 0 ; i < index.length ; i++) {
			object[index[i]] = new Array();
			for (var j = 0 ; j < model2[i].length ; j++) {
				object[index[i]][j] = model2[i][j];
			}
		}
		if (actiontype == "add")
		{
			//for the object do:
			while (1) {
				var current = last;//if at the end of the loop current is last break
				for (var j = 0 ; j < values.length ; j++) {//for each existing item check if it refers to items and if so add them
					if (object[values[j]] != null) {//has references
						for (var k = 0 ; k < object[values[j]].length ; k++) {//for each reference
							var con = false;
							for (var l = 0 ; l < values.length ; l++) {//determine the values. if they already exist don't increase last (uses con)
								if (values[l] == object[values[j]][k]) {
									con = true;
									break;
								}
							}
							if (!con) {//if not found already
								values[last] = object[values[j]][k]; //update the values
								for (var l = 0 ; l < src.length ; l++) {//search the src for the value
									if (src.options[l].value == values[last]) {
										ids[last] = l;
										list[last] = 'src';
										last++;
									}
								}
								for (var l = 0 ; l < dst.length ; l++) {//search the dst for the value
									if (dst.options[l].value == values[last]) {
										ids[last] = l;
										list[last] = 'dst';
										last++;
									}
								}
							}
						}
					}
				}
				if (current == last) break;
			}
			for (var i = 0 ; i < values.length ; i++) {
				if (list[i] == 'dst') {
				}
				else {
					var len = dst.length;
					dst.options[len] = new Option(src.options[ids[i]].text);//copy the source text and value to the destination list
					dst.options[len].value = src.options[ids[i]].value;
					//if not sorted sort
					if (dosort) {
						j = 0;
						while ((len-j-1) >= 0){
							if ((dst.options[len-j-1] != null)&&((dst.options[len-j].text) < (dst.options[len-j-1].text))){
								var val = dst.options[len-j-1].value;
								var text = dst.options[len-j-1].text;
								var color = dst.options[len-j-1].style.color;
								dst.options[len-j-1].value = dst.options[len-j].value;
								dst.options[len-j-1].text = dst.options[len-j].text;
								dst.options[len-j-1].style.color = dst.options[len-j].style.color;
								dst.options[len-j].value = val;
								dst.options[len-j].text = text;
								dst.options[len-j].style.color = color;
								j++;
							}
							else break;//when no longer needs to sort
						}
					}
				}
			}
			for (var i = 0 ; i < src.length ; i++) {
				if (zzz) i--;
				var zzz = false;
				for (var j = 0 ; j < values.length ; j++) {
					if (list[j] == 'src') {
						if (src.options[i].value == values[j]) {
							src.options[i] = null;
							var zzz = true;
						}
					}
				}
			}
		}
		if (actiontype == "remove") {
			var notremoved = 0;
			var len = dst.length;//number of lines already in the destinaltion list
			for (var i = 0; i < src.length ; i++){//walk trough all selected items
				if ((src.options[i] != null)&&(src.options[i].selected)&&(src.options[i].style.color != "#999999")) {//if not null and selected
					dst.options[len] = new Option(src.options[i].text);//copy the source text and value to the destination list
					dst.options[len].value = src.options[i].value;
					//if not sorted sort
					if (dosort){
						var j = 0;
						while ((len-j-1) >= 0){
							if ((dst.options[len-j-1] != null)&&((dst.options[len-j].text) < (dst.options[len-j-1].text))){
								var val = dst.options[len-j-1].value;
								var text = dst.options[len-j-1].text;
								dst.options[len-j-1].value = dst.options[len-j].value;
								dst.options[len-j-1].text = dst.options[len-j].text;
								dst.options[len-j].value = val;
								dst.options[len-j].text = text;
								j++;
							}
							else break;//when no longer needs to sort
						}
					}
					len++;//len has increased
				}
				else if ((src.options[i].style.color == "#999999")&&(src.options[i].selected)) notremoved++;
			}
			if (notremoved > 0) alert("Er zijn " + notremoved + " geselecteerde objecten niet verwijderd omdat een ander object afhankelijk is van het object.");
			//remove all selected from the sourcelist
			if (removeoriginal) while (1) {
				var deleted = false;
				for (var i = 0; i < src.length ; i++){
					if ((src.options[i] != null)&&(src.options[i].selected)&&(src.options[i].style.color != "#999999")) {
						src.options[i] = null;
						deleted = true;
						break;
					}
				}
				if (!deleted) break
			}
		}
//		alert(object[637]);
		//retoutch the dst list in add and the src list in remove (makegrey)
		if (actiontype == "add") ls = dst;
		if (actiontype == "remove") ls = src;
		for (var i = 0 ; i < ls.length ; i++) {
			ls.options[i].style.color = "#000000";
		}
		for (var i = 0 ; i < ls.length ; i++) {
			if (object[ls.options[i].value] != null) {
				for (var j = 0 ; j < object[ls.options[i].value].length ; j++) {
					for (var k = 0 ; k < ls.length ; k++) {
//						alert (k + "  "+ ls.options[k].value +" == "+ i + "  "+ object[ls.options[i].value][j]);
						if (ls.options[k].value == object[ls.options[i].value][j]) {
							if (object[ls.options[i].value][j] != ls.options[i].value) {
								ls.options[k].style.color = "#999999";
							}
						}					
					}
				}
			}
		}
	}
	else {
		eval("dst = " + dst + ";");//set destination object
		eval("src = " + src + ";");//set source object
		
		var len = dst.length;//number of lines already in the destinaltion list
		for (var i = 0; i < src.length ; i++){//walk trough all selected items
			if ((src.options[i] != null)&&(src.options[i].selected)){//if not null and selected
				dst.options[len] = new Option(src.options[i].text);//copy the source text and value to the destination list
				dst.options[len].value = src.options[i].value;
				//if not sorted sort
				if (dosort){
					var j = 0;
					while ((len-j-1) >= 0){
						if ((dst.options[len-j-1] != null)&&((dst.options[len-j].text) < (dst.options[len-j-1].text))){
							var val = dst.options[len-j-1].value;
							var text = dst.options[len-j-1].text;
							dst.options[len-j-1].value = dst.options[len-j].value;
							dst.options[len-j-1].text = dst.options[len-j].text;
							dst.options[len-j].value = val;
							dst.options[len-j].text = text;
							j++;
						}
						else break;//when no longer needs to sort
					}
				}
				len++;//len has increased
			}
		}
		//remove all selected from the sourcelist
		if (removeoriginal) while (1){
			var deleted = false;
			for (var i = 0; i < src.length ; i++){
				if ((src.options[i] != null)&&(src.options[i].selected)) {
					src.options[i] = null;
					deleted = true;
					break;
				}
			}
			if (!deleted) break
		}
	}
}

function list2temp(object,field,sep)//sets the values of the listfield in the specified field
{
	eval ("object = " + object + ";");
	var str = "";
	for (var i = 0 ; i < object.length ; i++) if (object.options[i] != null) str = add2str(str,object.options[i].value,sep);
	set(field,str);
}

function add2str(str,sstr,sep)
{
	if (str != "") str += sep;
	str += sstr;
	return str;
}

function setstatus(text)
{
	window.defaultStatus = text;
	window.status = text;
}

function Add2Field(field,value,sep)
{
	var val = get(field);
	val = add2str(val,value,sep);
	set(field,val);
}

function alertField(field,actiontype,sep,text1,text2)
{
	
	var val = get(field);
	if (actiontype == 'count'){
		val2 = val.split(sep);
		if (val != "") alert(text1 + val2.length + text2);
	}
}

function implicitcheck(field, fields, check) {
	if (document.getElementById(field).checked == check) {
		var arrfields = fields.split(",");
		for (var i = 0 ; i < arrfields.length ; i++) {
			document.getElementById(arrfields[i]).checked = check;
		}
	}
}

function gotowithval(url, target, object, conditionfield, conditionvalue, inverse, fields, checkfields, frameset) {
	var arrfields = fields.split(";");
	var arrcheckfields = checkfields.split(";");
	cont = false;
	if (conditionfield != "") {
		var arrconditionfield = conditionfield.split(";");
		var arrconditionvalue = conditionvalue.split(";");
		var arrinverse = inverse.split(";");
		for (i = 0 ; i < arrconditionfield.length ; i++) {
			conditionfield = arrconditionfield[i];
			conditionvalue = arrconditionvalue[i];
			inverse = arrinverse[i];
			if (inverse == "") var is = "==";
			if (inverse == "i") var is = "!=";
			if (eval(object + "." + conditionfield + ".value" + is + "'" + conditionvalue + "';")) cont = true;
		}
	}
	else cont = true;
	if (cont) {
		if (!((typeof(frameset) == "undefined") || (frameset == ""))) top.switchFrameSet('mainframeset', frameset);
		var values = "";
		for (var i = 0 ; i < arrfields.length ; i++) {
			eval("var val = " + object + "." + arrfields[i] + ".value");
			if (!((val == "") || (val == "undefined"))) {
				if (values == "") values += "?";
				else values += "&";
				values += arrfields[i] + "=" + val;
			}
		}
		if (checkfields != "") {
			for (var i = 0 ; i < arrcheckfields.length ; i++) {
				var str = ("var val = " + object + "." + arrcheckfields[i] + ".checked");
				eval(str);
				if (val) {
					if (values == "") values += "?";
					else values += "&";
					values += arrcheckfields[i] + "=on";
				}
			}
		}
		gotopage(url + values,target);
	}
}

function addtofield(object, field, value) {
	eval("var val = " + object + "." + field + ".value");
	if (val == "") val = "0";
	var temp = parseInt(val);
	temp += value;
	val = parseInt(temp);
	eval(object + "." + field + ".value=" + val + ";");
}

function helpwin(id) {
	window.open('../help/helpfile.php?HelpDocID=' + id,'Help','height=500,width=400,top=100,left=' + (screen.availWidth - 450) + ',scrollbars');
}

function inputpopup(text, defval, inputfield) {
	var newval = window.prompt(text,defval)
	document.getElementById(inputfield).value = newval;
}

function inputpopup2(text, defval, inputfield, errortext) {
	var newval = window.prompt(text,defval);
	if (!newval) newval = -1;
	while ((newval <= defval)&&(newval != -1))  {
		newval = window.prompt(errortext + defval + " " + text,newval);
		if (!newval) newval = -1;
	}
	document.getElementById(inputfield).value = newval;
}

function inputpopup3(text, defval, inputfield, errortext, allok) {
	var inallok = false;
	var newval = window.prompt(text,defval);
	inallok = checkinallok(allok, newval);s
	if (!newval) newval = -1;
	while ((newval != -1)&&(!inallok))  {
		newval = window.prompt(errortext + " " + text,defval);
		if (!newval) newval = -1;
		inallok = checkinallok(allok, newval)
	}
	document.getElementById(inputfield).value = newval;
}

function checkinallok(allok, newval) {
	if (!newval) return false;
	else {
		var arrallok = allok.split(";");
		var ok = false;
		for (var i = 0 ; i < arrallok.length ; i++) {
			if (arrallok[i] == newval) ok = true;
		}
		return ok;
	}
}

function selecttypeofsubmodelversion(target) {
	var b = this.b.value;
	if (this.typeunderobject != null) var typeunderobject = this.typeunderobject.value;
	else var typeunderobject = "";
	var SelectedOverview = this.SelectedOverview.value;
	top.staticvars.SelectedOverview.value = SelectedOverview;
	if (this.oldSelectedOverview.value == "O") top.staticvars.SelectedOverviewObject.value = b;
	if (this.oldSelectedOverview.value == "D") top.staticvars.SelectedOverviewDomain.value = b;
	if (this.oldSelectedOverview.value == "S") top.staticvars.SelectedOverviewSegment.value = b;
	var str = "top.refreshframe.location = '" + target + "?a=" + b + "&typeunderobject=" + typeunderobject + "&c=" + SelectedOverview + "'";
	eval(str);
}

function list2display(field2, fieldname2, display) {
	var field = document.getElementById(field2);
	for (var i = 0 ; i < field.length ; i++) {
		if (field.options[i] != null) 
		{
			var tempvalue = field.options[i].value;
			var fieldname = fieldname2 + tempvalue;
			setdisplay(fieldname, display);
		}
	}
}

function setdisplay(field2, display) {
	var field = document.getElementById(field2);
	if (display) field.style.display = 'block';
	else field.style.display = 'none';
}

function list2temp(object,field,sep)//sets the values of the listfield in the specified field
{
	eval ("object = " + object + ";");
	var str = "";
	for (var i = 0 ; i < object.length ; i++) if (object.options[i] != null) str = add2str(str,object.options[i].value,sep);
	set(field,str);
}

function observer(oldvalue, object) {
	if (isNaN(object.value)) {
		if (oldvalue == 'recalculate')
			calculateValues();
		else
			object.value = oldvalue;
		
		return false;
	}	
	return true
}

function showTip (divName){
	document.getElementById(divName).style.visibility = 'visible';
}

function hideTip (divName){
	document.getElementById(divName).style.visibility = 'hidden';
}

function checkForm(theForm) {
	var submitForm = true;

	if (!checkRadioButton(theForm.fabrictype) && !(theForm.fabrictype.checked)) {
		//alert('Please select a fabric type');
		document.getElementById('clothtypes').style.display='block';
		submitForm = false;
	}
	else {
		document.getElementById('clothtypes').style.display='none';

		if(checkAllColor){
			if (getRadioButtonValue(theForm.casecolor) == 'other' && !(theForm.casecolor.checked)) {
				if (theForm.other_color.value == "")  {
					document.getElementById('selectCaseColorCode').style.display='block';
					document.getElementById('selectCaseColor').style.display='none';
					submitForm = false;
				}
			}
			else{
				if (!checkRadioButton(theForm.casecolor) && !(theForm.casecolor.checked)) {
					document.getElementById('selectCaseColorCode').style.display='none';
					document.getElementById('selectCaseColor').style.display='block';
					submitForm = false;
				}else{					
					document.getElementById('selectCaseColorCode').style.display='none';
					document.getElementById('selectCaseColor').style.display='none';
					
					// if screens are designer screens THESE ARE NOW OFF, IN CASE OF SHOW REWRITE CODE BELOW!!!
					if(checkCaseColor){
						if (!checkRadioButton(theForm.case_endcaps_color) && !(theForm.case_endcaps_color.checked)) {
							alert('Please select a case caps color');
							submitForm = false;				
						}
						else{
							if (!checkRadioButton(theForm.case_strip_color) && !(theForm.case_strip_color.checked)) {
								
								alert('Please select a case strip color');
								submitForm = false;				
							}
						}
					}
				}
			}
		}
	}
	
	if(optionScreenSurfaceMountedReversely){
		if(theForm.screenSurfaceMountedReversely.checked){
			// if no choice is made: show error
			if(!checkRadioButton(theForm.screenSurfaceChoises) ){
				document.getElementById('screenSurfaceNoChoise').style.display='block';
				submitForm = false;
			}else{
				document.getElementById('screenSurfaceNoChoise').style.display='none';
			}		
		}
	}
	
	if(submitForm){
		theForm.submit();
	}
}


function getRadioButtonValue(theButton) {
	// check if a radio button is selected
	var radio_choice = false;
	for (counter = 0; counter < theButton.length; counter++) {
		if (theButton[counter].checked)
			return theButton[counter].value;
	}
	return (false);
}

function checkRadioButton(theButton) {
	// check if a radio button is selected
	var radio_choice = false;
	for (counter = 0; counter < theButton.length; counter++) {
		if (theButton[counter].checked)
			return (true);
	}
	return (false);
}

/* show options of step 1 */
var showOptionsStep1 = ''
function showStep1Options(id){
	if(showOptionsStep1 != ''){
		document.getElementById(showOptionsStep1+'Content').style.display = 'none';
	}
	
	document.getElementById(id+'Content').style.display = 'block';
	showOptionsStep1 = id;
}

function checkSubmitStep1(){
  	if (window.event && window.event.keyCode == 13) {
		document.scenarioform.submit();
	}
	return !(window.event && window.event.keyCode == 13);
}

function showSubmitBtn(value){
	if(value != 0 && value != ''){
		document.getElementById('submitStep1').style.display = 'block';
	}else{
		document.getElementById('submitStep1').style.display = 'none';
	}
}

function showScreenSurfaceChoises(){
	if(document.getElementById('screenSurfaceChoises').style.display == 'block'){
		document.getElementById('screenSurfaceChoises').style.display = 'none';
	}else{
		document.getElementById('screenSurfaceChoises').style.display = 'block';
	}
}
