// Aevium Standard Functions copyright Aevium 2007
function AEV_new_window(url,id,width,height,toolbar,scrollbar,location,statusbar,menubar,resizable,fullscreen){
	self.moveTo(0,0);
	self.resizeTo(screen.availWidth,screen.availHeight);

	var isWin=(navigator.appVersion.indexOf("Win")!=-1)? true : false;
	var isIE=(navigator.appVersion.indexOf("MSIE")!=-1)? true : false;
	var toolbar=(toolbar == true || toolbar == null)? "yes" : "no";
	var scrollbar=(scrollbar == true || scrollbar == null)? "yes" : "no";
	var location=(location == true || location == null)? "yes" : "no";
	var statusbar=(statusbar == true || statusbar == null)? "yes" : "no";
	var menubar=(menubar == true || menubar == null)? "yes" : "no";
	var resizable=(resizable == true || resizable == null)? "yes" : "no";
	var fullscreen=(fullscreen == false || fullscreen == null)? false : true;
	
	if(fullscreen == true){
		if(isWin&&isIE){
			var fullwindow = window.open(url,id,"toolbar="+toolbar+",scrollbars="+scrollbar+",location="+location+",statusbar="+statusbar+",menubar="+menubar+",resizable="+resizable+",fullscreen=yes");
			fullwindow.focus();
		} else {
			var fullwindow = window.open(url,id,"toolbar="+toolbar+",scrollbars="+scrollbar+",location="+location+",statusbar="+statusbar+",menubar="+menubar+",resizable="+resizable+",width="+screen.availWidth+",height="+screen.availHeight);
			fullwindow.moveTo(0,0);
			fullwindow.focus();
		}
	} else {
		var fullwindow = window.open(url,id,"toolbar="+toolbar+",scrollbars="+scrollbar+",location="+location+",statusbar="+statusbar+",menubar="+menubar+",resizable="+resizable+",width="+width+",height="+height);
		fullwindow.focus();
	}
}
function AEV_center_window(){
	if (typeof(window.innerHeight) == 'number') {
		win_height = window.innerHeight;
		win_width = window.innerWidth;
	}	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			win_height = document.documentElement.clientHeight;
			win_width = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientHeight) {
				win_height = document.body.clientHeight;
				win_width = document.body.clientWidth;
			}
		}
	}
	x=(screen.width/2)-(win_width/2)-8;
	y=(screen.height/2)-(win_height/2)-8;
	window.moveTo(x,y);	
}
function AEV_size_window(width,height){
	window.resizeTo(width,height);
}
function AEV_format_currency(amount){
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}
function AEV_set_tel_number(field,code_val){
	document.getElementById(field).value = document.getElementById(code_val+'1').value+document.getElementById(code_val+'2').value+document.getElementById(code_val+'3').value;
}
function AEV_move_tel_number(field, code_val){
	if(document.getElementById(field+code_val).value.length == 3 && code_val < 3){
		document.getElementById(field+(parseInt(code_val)+1)).focus();
	}
}
function AEV_same_bill(){
	if(document.getElementById('Same_as_Billing').checked){
		document.getElementById('Shipping_First_Name').value = document.getElementById('Billing_First_Name').value;
		document.getElementById('Shipping_Last_Name').value = document.getElementById('Billing_Last_Name').value;
		document.getElementById('Shipping_Address').value = document.getElementById('Billing_Address').value;
		document.getElementById('Shipping_City').value = document.getElementById('Billing_City').value;
		document.getElementById('Shipping_State').value = document.getElementById('Billing_State').value;
		document.getElementById('Shipping_Zip').value = document.getElementById('Billing_Zip').value;
		document.getElementById('Shipping_First_Name').disabled = true;
		document.getElementById('Shipping_Last_Name').disabled = true;
		document.getElementById('Shipping_Address').disabled = true;
		document.getElementById('Shipping_City').disabled = true;
		document.getElementById('Shipping_State').disabled = true;
		document.getElementById('Shipping_Zip').disabled = true;
		if(document.getElementById('Billing_SuiteApt')){
			document.getElementById('Shipping_SuiteApt').value = document.getElementById('Billing_SuiteApt').value;
			document.getElementById('Shipping_SuiteApt').disabled = true;
		}
		if(document.getElementById('Shipping_Address_2')){
			document.getElementById('Shipping_Address_2').value = document.getElementById('Billing_Address_2').value;
			document.getElementById('Shipping_Address_2').disabled = true;
		}
		if(document.getElementById('Billing_Country')){
			document.getElementById('Shipping_Country').value = document.getElementById('Billing_Country').value;
			document.getElementById('Shipping_Country').disabled = true;
		}
	} else {
		document.getElementById('Shipping_First_Name').disabled = false;
		document.getElementById('Shipping_Last_Name').disabled = false;
		document.getElementById('Shipping_Address').disabled = false;
		document.getElementById('Shipping_City').disabled = false;
		document.getElementById('Shipping_State').disabled = false;
		document.getElementById('Shipping_Zip').disabled = false;	
		if(document.getElementById('Billing_SuiteApt')){
			document.getElementById('Shipping_SuiteApt').disabled = false;
		}
		if(document.getElementById('Shipping_Address_2')){
			document.getElementById('Shipping_Address_2').disabled = false;
		}
		if(document.getElementById('Billing_Country')){
			document.getElementById('Shipping_Country').disabled = false;
		}
	}
}
function AEV_checksame(){
	var i,p,q,nm,test,errors='',args=AEV_checksame.arguments;
	for (i=0; i<(args.length-1); i+=4) { 
		val1=MM_findObj(args[i]); subName1=args[i+1]; val2=MM_findObj(args[i+2]); subName2=args[i+3];
		nm1=val1.name;	if(subName1.length != 0)nm1 = subName1;
		nm2=val2.name;	if(subName2.length != 0)nm2 = subName2;
		if(val1.value != val2.value)errors+='- '+nm1+' does not equal '+nm2+'.\n';
	}
	if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
// Macromedia Standard Functions
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_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_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_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 MM_validateForm() { //v5.5  // Amended by Chad Serpan, chad.serpan@aevium.com
	// Added Checkbox and Radio capability and ability to pass alternative form names.
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]); subName = args[i+1];
	if(subName.length != 0)nm = subName;
	if (val) {if(val[0] && (val[0].type=="radio" || val[0].type=="checkbox")){ ck = false;
	for(z=0;z<val.length; z++){	nm=val[z].name;	
	if(subName.length != 0)nm = subName; if(val[z].checked==true)ck = true;}
	if(ck==false)errors+='- '+nm+' is required.\n';
	} else { nm=val.name;	if(subName.length != 0)nm = subName;
	if(val.type=="radio" || val.type=="checkbox") ck=val.checked;
	if ((val=val.value)!="") { if(test.indexOf('isCheck')!=-1){ 
	if (ck == false) errors+='- '+nm+' is required.\n';
	} else if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
	if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
	} else if (test!='R') { num = parseFloat(val); 
	if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
	if (test.indexOf('inRange') != -1) { p=test.indexOf(':');	min=test.substring(8,p); max=test.substring(p+1);
	if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n'; } }	
	} else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; } } } 
	if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}