//COMMON SCRIPTS
// centered pop-up script
	function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
	  if(window.screen)if(isCenter)if(isCenter=="true"){
		var myLeft = (screen.width-myWidth)/2;
		var myTop = (screen.height-myHeight)/2;
		features+=(features!='')?',':'';
		features+=',left='+myLeft+',top='+myTop;
	  }
	  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
	}	
// centered pop-up script fine'

var win=null;

//setup vars - browser, etc.(For layer stuff)
var doc;
var style;
var px;

if (isNavigator())
{
	doc = document.layers;
	style = '';
	px='';
	
}
else
{
	var doc = document.all;
	var style = '.style';
	px='px';
}
	

function showDiv(name,left,top)
{
	divobj = eval('doc.'+name+ style);	
	divobj.left = (left) + px;	
	divobj.top = (top) + px;
	divobj.visibility = 'visible';
}

function hideDiv(name)
{
	divobj = eval('doc.'+name+ style);		
	divobj.visibility = 'hidden';
}


function moveXYMenu(where,menuName)
{

	menu_object = eval('doc.'+menuName+'menu' + style);		
	menu_object.left = (menu_loc[where] + backOffsetMenu) + px;	
	menu_object.top = (menu_top[where]+backOffsetMenu)+px;
}
function isNavigator()
{
 return navigator.appName.indexOf("Netscape") !=-1;
}

function isNumber(val)
{
	return val == 0 || (val!=0 && val/val==1);
}

function load(what)
{
	document.location.href=what;
}

function appendToUrl(strname,strval)
{
	var curLoc = document.location.href;
	if (curLoc.indexOf("?")==-1)
		document.location.href = curLoc + "?"+strname+"="+strval;
	else
		document.location.href = curLoc + "&"+strname+"="+strval;	
}	

function addToUrl(strname,strval)
{
	var curLoc = document.location.href;
	if (curLoc.indexOf("?")==-1)//nothing added yet, safe to do it whithout checks.
	{
		curLoc = curLoc + "?"+strname+"="+strval;
	}
		
	else
	{
		//check for the name first.
		found = false;
		split_url = curLoc.split("?");
		qs = split_url[1];
		split_qs = qs.split("&");
		this_val = new Array();
		for (i=0;i<split_qs.length;i++)
		{
			this_val = split_qs[i].split("=");
			if (this_val[0]==strname)
			{
				//found it
				split_qs[i]=this_val[0]+"="+strval;
				found = true;
				break;
			}
		}
		
		if (found)
		{
			split_url[1] = split_qs.join("&"); 
			curLoc = split_url.join("?");
		}
		else //just put it at the end
		{
			curLoc=curLoc+"&"+strname+"="+strval;
		}

	}
	
	document.location.href=curLoc;	

}

function cleanUrl() // returns the url without any query string stuff
{
	curLoc = document.location.href.split("?");
	return curLoc[0];
	
}

function ask(qst,loc)
{
	var y = confirm(qst);
	if (y)
		document.location.href = loc;
}
	
function popUp(what,attributes)
{
	if (!win || win.closed)
		win=window.open(what,"shop",attributes);
	else
	{
		win.location.href=what;
		win.focus();
	}
}	

function isIndexed(obj,errMsg)
{
	if (obj.selectedIndex==0)
	{
		alert(errMsg);
		return false;
	}
	else
		return true;

}

function requireCheck(obj,errMsg)
{
	var ok = false;
	for (i=0;i<obj.length;i++)
	{
		if (obj[i].checked)
		{
			ok=true;
			break;
		}
	}
	
	if (!ok) alert(errMsg);
	
	return ok;
}

function requireOne(obj1,obj2,errMsg)
{
	var val1 = eval("document.forms[0]."+obj1+".value");
	var val2 = eval("document.forms[0]."+obj2+".value");
	
	if (trim(val1)=="" && trim(val2)=="")
	{
		alert(errMsg);
		return false;
	}
	else
		return true;
}
	
function isEqual(str1,str2,errMsg)
{
	if (str1=="" || str2=="" || str1!=str2)
	{
		alert(errMsg);
		return false;
	}
	else
		return true;
}

function notEmpty()
{
	var ok = true;
	var arg = notEmpty.arguments;
	
	// special processing to handle custom form (not forms[0])
	var formName = "forms[0]";
	var startIndex = 0;
	if (arg.length > 0 && arg[0] == "custom") {
		formName = arg[1];
		startIndex = 2;
	}
	
	for(i=startIndex; i<arg.length; i+=2)
	{
		var val= eval("document."+formName+"."+arg[i]+".value");
		if (trim(val)=="")
		{
			ok=false;
			alert(arg[i+1]);
			eval("document."+formName+"."+arg[i]+".focus();");
			break;
		}
	}

	
	return ok;
}



function doZip(){

  var ok = true;
  
  if(document.forms[0].bstate.value != 'Outside United States'){
      ok = notEmpty('bzip','You must enter a Zip Code');
  }
  
  return ok;

}

function checkEmail (emailStr)
{

	/* Check to see the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */
	var checkTLD=1;

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.*/

	var emailPat=/^(.+)@(.+)$/;

	//Special chars:
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the user is a quoted string ->NO RULES!
	For instance, "alexthebest"@travelatro.com is a legal e-mail address. */

	var quotedUser="(\"[^\"]*\")";

	/* The following applies for domains that are IP addresses,
	rather than symbolic names. Ex: alex@[123.124.233.4] is ok.*/

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in alex.it@travelatro.com, alex and it are words.*/


	var word="(" + atom + "|" + quotedUser + ")";


	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

		
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	//Validation:

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null)
	{

	//Address does not match the basic pattern.

		alert("Please enter in a valid email address");
		return false;
	}
	
	var user=matchArray[1];
	var domain=matchArray[2];


	for (i=0; i<user.length; i++) 
	{
	 	if (user.charCodeAt(i)>127)
		{
			alert("The username for the email entered contains invalid characters.");
			return false;
		}
    }
	for (i=0; i<domain.length; i++)
	{
		if (domain.charCodeAt(i)>127)
		{
			alert("Ths domain name for the email entered contains invalid characters.");
			return false;
		}
	}

	//Is user ok?
	if (user.match(userPat)==null)
	{

	// NO!
		alert("The username for the email entered doesn't seem to be valid.");
		return false;
	}

	//Is the ip address valid? (If used one)?

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null)
	{
		//yes.

		for (var i=1;i<=4;i++)
		{
		
			if (IPArray[i]>255) 
			{
				alert("Destination IP address for the email entered is invalid!");
				return false;
			}
		}
		return true;
	}

	// Domain NAME -is it ok?
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++)
	{
		if (domArr[i].search(atomPat)==-1)
		{
			alert("The domain name for the email entered does not seem to be valid.");
			return false;
	   }
	}


	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].toLowerCase().search(knownDomsPat)==-1) 
	{
		alert("The email address must end in a well-known domain or two letter " + "country.");
		return false;
	}

// Make sure there's a host name preceding the domain.

	if (len<2)
	{
		alert("This email address is missing a hostname!");
		return false;
	}

	// If nothing happened so far, we are cool.
	return true;
}

function checkEmailNoAlerts (emailStr)
{

	/* Check to see the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */
	var checkTLD=1;

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.*/

	var emailPat=/^(.+)@(.+)$/;

	//Special chars:
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the user is a quoted string ->NO RULES!
	For instance, "alexthebest"@travelatro.com is a legal e-mail address. */

	var quotedUser="(\"[^\"]*\")";

	/* The following applies for domains that are IP addresses,
	rather than symbolic names. Ex: alex@[123.124.233.4] is ok.*/

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in alex.it@travelatro.com, alex and it are words.*/


	var word="(" + atom + "|" + quotedUser + ")";


	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

		
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	//Validation:

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null)
	{

	//Address does not match the basic pattern.

		return false;
	}
	
	var user=matchArray[1];
	var domain=matchArray[2];


	for (i=0; i<user.length; i++) 
	{
	 	if (user.charCodeAt(i)>127)
		{
			return false;
		}
    }
	for (i=0; i<domain.length; i++)
	{
		if (domain.charCodeAt(i)>127)
		{
			return false;
		}
	}

	//Is user ok?
	if (user.match(userPat)==null)
	{

	// NO!
		return false;
	}

	//Is the ip address valid? (If used one)?

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null)
	{
		//yes.

		for (var i=1;i<=4;i++)
		{
		
			if (IPArray[i]>255) 
			{
				return false;
			}
		}
		return true;
	}

	// Domain NAME -is it ok?
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++)
	{
		if (domArr[i].search(atomPat)==-1)
		{
			return false;
	   }
	}


	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].toLowerCase().search(knownDomsPat)==-1) 
	{
		return false;
	}

// Make sure there's a host name preceding the domain.

	if (len<2)
	{
		return false;
	}

	// If nothing happened so far, we are cool.
	return true;
}


function ltrim ( s )
{
	return s.replace( /^\s*/, "" )
}

function rtrim ( s )
{
	return s.replace( /\s*$/, "" );
}

function trim ( s )
{
	return rtrim(ltrim(s));
}


function selState(formname,fname,dropdown)
{

	if (dropdown.value!='United States of America' || dropdown.value!='USA')
		eval("document."+formname+"."+fname+".selectedIndex=52");
}

function selCountry(formname,fname,dropdown)
{
	if (dropdown.value=='Outside United States' ||dropdown.value=='N/A' || dropdown.value=='NA')
		eval("document."+formname+"."+fname+".selectedIndex=0");
	else
		eval("document."+formname+"."+fname+".value='United States of America'");	
}	



//validation scripts

function validateSSN(ssn)
{
	var ok = true;
	var matchArr = ssn.match(/^(\d{3})-?\d{2}-?\d{4}$/);
	var numDashes = ssn.split('-').length - 1;
	if (matchArr == null || numDashes == 1) 
	{
		alert('Invalid SSN. Must be 9 digits or in the form NNN-NN-NNNN.');
		msg = "does not appear to be valid";
		ok = false;
	}
	else if (parseInt(matchArr[1],10)==0) 
	{
		alert("Invalid SSN: SSN's can't start with 000.");
		msg = "does not appear to be valid";
		ok = false;
	}
	
	return ok;
}


function formatSSN(obj)
{
	keyHit = (isNavigator()) ? keyStroke.which : event.keyCode;

	val = obj.value;
	
	last = val.charAt(val.length-1);
	if (last=='0' || isNumber(last))
	{
		
		if (keyHit!=8 && (val.length==3 || val.length==6) && val.charAt(val.length-1)!="-")
			obj.value = val +"-";
	
	}
	else
		obj.value=val.substring(0,val.length-1);
			
}

function skip () { this.blur(); }

function disable (field) 
{
  if (document.all || document.getElementById) 
    field.disabled = true;
  else
  {
    field.oldOnFocus = field.onfocus;
    field.onfocus = skip;
  }
}

function enable (field) 
{
  if (document.all || document.getElementById)
    field.disabled = false;
  else 
  {
    field.onfocus = field.oldOnFocus;
  }
}

function controlLen(obj,len)
{
	if (obj.value.length > len)
		obj.value = obj.value.substring(0,obj.value.length-1);
}

function isAfterToday(year,month,day,sError)
{
	 var ok = false;	 
     var cYear = eval("document.forms[0]."+year+".value");
     var cMonth = eval("(document.forms[0]."+month+".value)-1");
     var cDay = eval("document.forms[0]."+day+".value");
     var d = new Date();
     var dYear = d.getYear();
     var dMonth = d.getMonth() + 1;
     var dDay = d.getDate();
	 adate = new Date(cYear,cMonth,cDay);
	 if (adate < d)
	 {
	 	alert(sError);
		ok = false;
	 }
	 
	 else
		ok = true;
		
	 return ok;     
 }
 
 function isAfter(syear,smonth,sday,eyear,emonth,eday,sError)
 {
 	 var ok = false;	 
     var ssYear = eval("document.forms[0]."+syear+".value");
     var ssMonth = eval("(document.forms[0]."+smonth+".value)-1");
     var ssDay = eval("document.forms[0]."+sday+".value");
     var eeYear = eval("document.forms[0]."+eyear+".value");
     var eeMonth = eval("(document.forms[0]."+emonth+".value)-1");
     var eeDay = eval("document.forms[0]."+eday+".value");
	 sdate = new Date(ssYear,ssMonth,ssDay);
	 
	 edate = new Date(eeYear,eeMonth,eeDay);
	 if (sdate > edate)
	 {
	 	alert(sError);
		ok = false;
	 }
	 
	 else
		ok = true;
		
	 return ok;     
 }
 
 //forces a check box to be checked at form submition
 //if already checked, the value does not change (true)
 //if unchecked, we check it and set its value to false so it is passed along.
 function forceCheck(obj)
 {
 	var chk = obj.checked;
	if (!chk)
	{
		chk.value = 'false';
		chk.checked = true;
	}
 }
 
function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '')
}

function validateTelnr(vfld) 
{
  var tfld = trim(vfld);  
  var telnr = /^\+?[0-9 ()-]+[0-9]$/
  if (!telnr.test(tfld)) {
    return false;
  }

  var numdigits = 0;
  for (var j=0; j<tfld.length; j++)
    if (tfld.charAt(j)>='0' && tfld.charAt(j)<='9') numdigits++;

  if (numdigits<10) 
    return false;
  
  if (numdigits>14)
   return false;
  
  return true;
}



// centered pop-up script
	function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
	  if(window.screen)if(isCenter)if(isCenter=="true"){
		var myLeft = (screen.width-myWidth)/2;
		var myTop = (screen.height-myHeight)/2;
		features+=(features!='')?',':'';
		features+=',left='+myLeft+',top='+myTop;
	  }
	  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
	}	
// centered pop-up script fine'

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function RS(s)
{
	if (null!=s) 
	document.getElementById("BIG").src=s;
}

// end