/*======================================*/
function switchMenu(obj)
{
var el = document.getElementById(obj);
	if (el.style.display != "") 
	{
	el.style.display = "";
	document.getElementById("tab").innerHTML = "Hide advanced search";
	}
	else 
	{
	el.style.display = 'none';
	document.getElementById("tab").innerHTML = "Show advanced search";
	}
}
function picFrameSize(picframe,pad,finish1,whiteheight)
{
if (pad!='none')
	{
	document.getElementById(picframe).style.padding=pad;
	document.getElementById('top_left').src='img.php?f(images/'+finish1+'/frame_r2_c2.gif)+h(15)+w(15)+t(gif)+q(100)';
	//document.getElementById('top_middle').style.background='url(img.php?f(images/'+finish1+'/frame_r2_c5.gif)+h(15)+w(15)+t(gif)+q(100))';
	document.getElementById('top_middle').background='img.php?f(images/'+finish1+'/frame_r2_c5.gif)+h(15)+w(15)+t(gif)+q(100)';
	document.getElementById('top_right').src='img.php?f(images/'+finish1+'/frame_r2_c7.gif)+h(15)+w(15)+t(gif)+q(100)';
	document.getElementById('middle_left').background='img.php?f(images/'+finish1+'/frame_r4_c7.gif)+h(15)+w(15)+t(gif)+q(100)';
	document.getElementById('middle_right').background='img.php?f(images/'+finish1+'/frame_r5_c2.gif)+h(15)+w(15)+t(gif)+q(100)';
	document.getElementById('bottom_left').src='img.php?f(images/'+finish1+'/frame_r8_c2.gif)+h(15)+w(15)+t(gif)+q(100)';
	document.getElementById('bottom_middle').background='img.php?f(images/'+finish1+'/frame_r8_c4.gif)+h(15)+w(15)+t(gif)+q(100)';
	document.getElementById('bottom_right').src='img.php?f(images/'+finish1+'/frame_r8_c7.gif)+h(15)+w(15)+t(gif)+q(100)';
	//document.getElementById('frameOp').style.display='none';
	//document.getElementById('frameSizes').style.display='';
	//document.getElementById('frameLinks').style.display='';
	//document.getElementById('frameLinkTitle').style.display='';
	
	document.getElementById('bottom_middle_15').src='images/spacer.gif';
	//document.getElementById('top_middle_15').src='images/spacer.gif';
	
	document.getElementById('left_middle_15').src='images/spacer.gif';
	document.getElementById('right_middle_15').src='images/spacer.gif';
	
	}
else
	{
	document.getElementById(picframe).style.padding=0;
	document.getElementById('top_left').src='images/spacer.gif';
	document.getElementById('top_middle').background='images/spacer.gif)';
	document.getElementById('top_right').src='images/spacer.gif';
	document.getElementById('middle_left').background='images/spacer.gif';
	document.getElementById('middle_right').background='images/spacer.gif';
	document.getElementById('bottom_left').src='images/spacer.gif';
	document.getElementById('bottom_middle').background='images/spacer.gif';
	document.getElementById('bottom_right').src='images/spacer.gif';
	document.getElementById('frameOp').style.display='';
	document.getElementById('frameSizes').style.display='none';
	document.getElementById('frameLinks').style.display='none';
	document.getElementById('frameLinkTitle').style.display='none';
	
	document.getElementById('bottom_middle_15').src='images/spacer_white.gif';
	
	document.getElementById('top_middle_15').src='images/spacer_white.gif';
	
	document.getElementById('left_middle_15').src='images/spacer_white.gif';
	document.getElementById('left_middle_15').height=whiteheight;
	document.getElementById('right_middle_15').src='images/spacer_white.gif';
	document.getElementById('right_middle_15').height=whiteheight;
	
	}
}
function picFrameFinish(finish1)
{
	document.getElementById('top_left').src='img.php?f(images/'+finish1+'/frame_r2_c2.gif)+h(15)+w(15)+t(gif)+q(100)';
	document.getElementById('top_middle').background='img.php?f(images/'+finish1+'/frame_r2_c5.gif)+h(15)+w(15)+t(gif)+q(100)';
	document.getElementById('top_right').src='img.php?f(images/'+finish1+'/frame_r2_c7.gif)+h(15)+w(15)+t(gif)+q(100)';
	document.getElementById('middle_left').background='img.php?f(images/'+finish1+'/frame_r4_c7.gif)+h(15)+w(15)+t(gif)+q(100)';
	document.getElementById('middle_right').background='img.php?f(images/'+finish1+'/frame_r5_c2.gif)+h(15)+w(15)+t(gif)+q(100)';
	document.getElementById('bottom_left').src='img.php?f(images/'+finish1+'/frame_r8_c2.gif)+h(15)+w(15)+t(gif)+q(100)';
	document.getElementById('bottom_middle').background='img.php?f(images/'+finish1+'/frame_r8_c4.gif)+h(15)+w(15)+t(gif)+q(100)';
	document.getElementById('bottom_right').src='img.php?f(images/'+finish1+'/frame_r8_c7.gif)+h(15)+w(15)+t(gif)+q(100)';
}
function picCanvas(obj,option,file,type,height,width)
{
	if (option=='none')
	{
	document.getElementById(obj).src='img.php?f(images/pictures/fullsize/full_'+file+'.'+type+')+h('+height+')+w('+width+')+t('+type+')+q(100)';
	document.getElementById('frameOp').style.display='';
	document.getElementById('frameSizes').style.display='none';
	document.getElementById('frameLinks').style.display='none';
	document.getElementById('frameLinkTitle').style.display='none';
	}
	else
	{
	document.getElementById(obj).src='canvas.php?f(images/pictures/fullsize/full_'+file+'.'+type+')+h('+height+')+w('+width+')+t('+type+')+q(100)';
	//document.getElementById('frameOp').style.display='none';
	//document.getElementById('frameSizes').style.display='';
	//document.getElementById('frameLinks').style.display='';
	//document.getElementById('frameLinkTitle').style.display='';
	}
}
function getObject(name) {
   var ns4 = (document.layers) ? true : false;
   var w3c = (document.getElementById) ? true : false;
   var ie4 = (document.all) ? true : false;

   if (ns4) return eval('document.' + name);
   if (w3c) return document.getElementById(name);
   if (ie4) return eval('document.all.' + name);
   return false;
}
//loading php docs on action even
function bgPHP(url) {

   // Internet Explorer
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req = null; }
   }

   // Mozailla/Safari
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }

   // Call the processChange() function when the page has loaded
   if (req != null) {
      req.open("GET", url, true);
      req.send(null);
   }
}

/*=======================================*/


function CheckForm(form)
{
	
	var i;
	var arr;
	var str;
	var x;

	for (i=0;i<form.elements.length;i++)
	{
		if(form.elements[i].name.substr(0,4) == "CHK_")
		{			
			
			str = GetFieldValueByName(form,form.elements[i].name.substr(4));
			
			if(str != null)
			{
			
				str = Trim(str);
							
				arr = form.elements[i].value.split("|");			
				
				switch(arr[0])
				{
					case "STR":
						//check mandatory field							
						if ((str.length == 0) && (arr[3] == "True"))
						{
							alert("The field > " + arr[4] + " < must be filled in");
							return false;
						}
						
						//check min length	
						if (str.length < parseInt(arr[1]))
						{
							alert("The value in field > " + arr[4] + " < is too short");
							return false;
						}
						
						//check max length
						if (str.length > parseInt(arr[2]))
						{
							alert("The value in field > " + arr[4] + " < is too long");
							return false;
						}
						break;
											
					case "INT":
																
						//check mandatory field
						if ((str.length == 0) && (arr[3] == "True"))
						{
							alert("The field > " + arr[4] + " < must be filled in");
							return false;
						}
						
						//check sanity
						if(!(IsNumeric(str)))
						{
							alert("The value in field > " + arr[4] + " < is numeric only");
							return false;
						}
												
						//check min value
						if (arr[1] != "x")
						{
							if (parseInt(str) < parseInt(arr[1]))
							{
								alert("The value in field > " + arr[4] + " < is too small");
								return false;
							}
						}
						
						//check max length
						if (arr[2] != "x")
						{
							if (parseInt(str) > parseInt(arr[2]))
							{
								alert("The value in field > " + arr[4] + " < is too big");
								return false;
							}
						}
						
						break;
					
					case "FLOAT":
																		
						//check mandatory field
						if ((str.length == 0) && (arr[3] == "True"))
						{
							alert("The field > " + arr[4] + " < must be filled in");
							return false;
						}
						
						//check sanity
						if(!(IsNumeric(str)))
						{
							alert("The value in field > " + arr[4] + " < is numeric only");
							return false;
						}
												
						//check min value
						if (arr[1] != "x")
						{
							if (parseFloat(str) < parseFloat(arr[1]))
							{
								alert("The value in field > " + arr[4] + " < is too small");
								return false;
							}
						}
						
						//check max length
						if (arr[2] != "x")
						{
							if (parseFloat(str) > parseFloat(arr[2]))
							{
								alert("The value in field > " + arr[4] + " < is too big");
								return false;
							}
						}
						
						break;
										
										
					case "EML":
					
						//check mandatory field							
						if ((str.length == 0) && (arr[3] == "True"))
						{
							alert("The field > " + arr[4] + " < must be filled in");
							return false;
						}
						
						//check min length	
						if (str.length < parseInt(arr[1]))
						{
							alert("The value in field > " + arr[4] + " < is too short");
							return false;
						}
						
						//check max length
						if (str.length > parseInt(arr[2]))
						{
							alert("The value in field > " + arr[4] + " < is too long");
							return false;
						}
						
						//check format
						if ((str.indexOf("@",1)==-1)&&(str.length > 0)) 
						{
      						alert ("Invalid email address - please re-enter.");
      						return false;
   						}
						break;
						
					case "DATE":
						
						//check mandatory field
						if ((str.length == 0) && (arr[3] == "True"))
						{
							alert("The field > " + arr[4] + " < must be filled in");
							return false;
						}
						
						//check sanity
						if(!(IsDate(str)))
						{
							alert("The value in field > " + arr[4] + " < is not a valid date (MM/DD/YYYY)");
							return false;
						}
						
						//check min value
						if (arr[1] != "x")
						{
							if (GetDate(str) < GetDate(arr[1]))
							{
								alert("The date in field > " + arr[4] + " < is less than the minimum date");
								return false;
							}
						}
						
						//check max length
						if (arr[2] != "x")
						{
							if (GetDate(str) > GetDate(arr[2]))
							{
								alert("The value in field > " + arr[4] + " < is later than the maximum date");
								return false;
							}
						}
						
						break;
				}
			}
		}
	}
	
	return true;

}

//============================================================================================

function Replace(string,replacechar,replacewith) 
{
	var temp = "";
	var i;
	
	string = '' + string;
	splitstring = string.split(replacechar);
	for(i = 0; i < splitstring.length; i++)
	{
		if(i < (splitstring.length -1))
			temp += splitstring[i] + replacewith;
		else
			temp += splitstring[i];
	}
	return temp;
}

//============================================================================================

function GetFieldValueByName(form,name)
{
	var i;
	
	for (i=0;i<form.elements.length;i++)
	{
		if(form.elements[i].name == name)
			return (form.elements[i].value);
	}
	return null;
}

/*

======================= STANDARD HELPER FUNCTIONS BELOW =======================================

*/
function IsNumeric(str)
{
	var i;
	for(i=0;i<str.length;i++)
	{
		if(!(	((str.charAt(i) <= '9') && (str.charAt(i) >= '0')) ||
				(str.charAt(i) == ' ') || (str.charAt(i) == '.') || (str.charAt(i) == '-')))
			return(false);
	}
	return(true);
}

//============================================================================================

function IsAlphaNumeric(str)
{
	var i;
	for(i=0;i<str.length;i++)
	{
		if(!(	((str.charAt(i) <= '9') && (str.charAt(i) >= '0')) ||
				((str.charAt(i) <= 'z') && (str.charAt(i) >= 'a')) ||
				(str.charAt(i) == ' ') || (str.charAt(i) == '-') ||
				(str.charAt(i) == 'ü') || (str.charAt(i) == 'ä') ||
				(str.charAt(i) == 'ö') || (str.charAt(i) == 'Ü') ||
				(str.charAt(i) == 'Ä') || (str.charAt(i) == 'Ö') ||
				(str.charAt(i) == 'é') || (str.charAt(i) == 'ß') ||
				((str.charAt(i) <= 'Z') && (str.charAt(i) >= 'A')) ))
			return(false);
	}
	return(true);
}

//============================================================================================

function IsAlpha(str)
{
	var i;
	
	for(i=0;i<str.length;i++)
	{
		if(!(	((str.charAt(i) <= 'z') && (str.charAt(i) >= 'a')) ||
				(str.charAt(i) == ' ') || (str.charAt(i) == '-') ||
				(str.charAt(i) == 'ü') || (str.charAt(i) == 'ä') ||
				(str.charAt(i) == 'ö') || (str.charAt(i) == 'Ü') ||
				(str.charAt(i) == 'Ä') || (str.charAt(i) == 'Ö') ||
				(str.charAt(i) == 'é') || (str.charAt(i) == 'ß') ||
				((str.charAt(i) <= 'Z') && (str.charAt(i) >= 'A')) ))
			return(false);
	}
	return(true);
}

//============================================================================================

function Trim(str)
{
	//trim leding spaces
	while(true)
	{
		if(str.charAt(0) == ' ')
			str = str.substr(1);
		else
			break;
	}
	
	//trim trailing spaces
	while(true)
	{
		if(str.charAt(str.length-1) == ' ')
			str = str.substr(0,str.length-1);
		else
			break;
	}
	return(str);	
}

//============================================================================================

function IsDate(argDate)
{
	var date_split;
	var i;
	var tdate, tmonth, tyear;
	
	date_split = argDate.split('/');
	
	//check for date parts
	if(date_split.length != 3)
		return(false);
		
	//check for zero values
	for(i=0;i<date_split.length;i++)
	{
		if(parseInt(date_split[i]) == 0)
			return(false);
	}
	
	//check for 4-digit year
	if(date_split[2].length != 4)
		return(false);
		
	//check for valid date, e.g. 02/29/1997
	tdate = parseInt(date_split[1]);
	tmonth = parseInt(date_split[0]);
	tyear = parseInt(date_split[2]);
	
	var date = new Date(parseInt(date_split[2]),parseInt(date_split[0])-1,parseInt(date_split[1]));
	
	if(date.getDate() != tdate)
		return(false);
	
	if(date.getMonth() != (tmonth-1))
		return(false);
	
	if(date.getFullYear() != tyear)
		return(false);
		
	return(true);
}


function GetDate(argDate)
{
	//use IsDate() first !!!!
	
	var date_split;	
	var tdate, tmonth, tyear;
	
	date_split = argDate.split('/');
	
		
	
	tdate = parseInt(date_split[1]);
	tmonth = parseInt(date_split[0]);
	tyear = parseInt(date_split[2]);
	
	return date = new Date(parseInt(date_split[2]),parseInt(date_split[0])-1,parseInt(date_split[1]));
		
}