// 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_FindOffset(ELEM){ var X = 0; var Y = 0; var agt=navigator.userAgent.toLowerCase();
	if (navigator.appName=="Netscape"){ X = ELEM.offsetLeft; Y = ELEM.offsetTop;
	} else if (navigator.appName.indexOf("Microsoft")!=-1){
		if(agt.indexOf("msie 7.")!=-1 || agt.indexOf("msie 6.")!=-1){ var Node = ELEM;
			while(Node.parentNode.nodeName.toLowerCase() != "body"){ X += Node.offsetLeft; Y += Node.offsetTop; Node = Node.parentNode; }
			//X+=20;
		} else { X = ELEM.offsetLeft; Y = ELEM.offsetTop; } } return Array(X,Y); }
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);
}
var AEV_DropArry = new Array();
function AEV_setDrop(Nav,Btn,N){
	var Count = AEV_DropArry.length;
	AEV_DropArry[Count] = new Array();
	AEV_DropArry[Count][0] = Nav;
	AEV_DropArry[Count][1] = Btn;
	Nav.onmouseover = function() { AEV_runDrop(Count); t = 2; return true; }
	Nav.onmouseout = function() {	t = 1; delayHide(); return true; }
	Btn.onmouseover = function() { AEV_runDrop(Count); popMenu(N); return true; }
	Btn.onmouseout = function() { t=1; delayHide(); return true; }
}
function AEV_runDrop(N){ var Offset = AEV_FindOffset(AEV_DropArry[N][1])
	AEV_DropArry[N][0].style.left = Offset[0]+"px"; }
		
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_change_vis(checkfield,div1,div2,div3,div4){
	if(document.getElementById(checkfield).checked){
		document.getElementById(div1).style.display = "none";
		document.getElementById(div2).style.display = "block";
	} else {
		document.getElementById(div1).style.display = "block";
		document.getElementById(div2).style.display = "none";
	}	if(div3){
		document.getElementById(div3).style.display = document.getElementById(div1).style.display;
		document.getElementById(div4).style.display = document.getElementById(div2).style.display;
	}
}
<!-- AJAX State List -->
//var AEV_XMLSPList = '/xml/SPList.php';
//var AEV_XMLShipList = '/xml/ShipList.php';
function AEV_Org_Initiate(){ // Initiate the xmlHTTP gateway
	xmlHttp=AEV_GetXmlHttpObject(); // Create a new Object
	if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } // Alert people that their browswer doesn't support Ajax
}
function AEV_GetXmlHttpObject(){
	try { Gateway=new ActiveXObject("Microsoft.XMLHTTP"); Gateway.async="false"; } // Internet Explorer
	catch (e) { Gateway = new XMLHttpRequest(); } // Firefox, Opera 8.0+, Safari
	return Gateway; }
function AEV_GetState(ID,STATE,TAB,PREFIX,STYLE,FNCT){
	if(TAB != "false" && TAB != false) AEV_State_Tab = TAB; if(STATE != "false" && STATE != false) { AEV_State = STATE;
	} else if(document.getElementById(PREFIX)) {
	if(document.getElementById(PREFIX).getElementsByTagName('select').length > 0){
		var Index = document.getElementById(PREFIX).selectedIndex;
		STATE = document.getElementById(PREFIX)[Index].value;
	} else STATE = document.getElementById(PREFIX).value;
		if(TAB == '') TAB = document.getElementById(PREFIX).tabIndex;}
	AEV_Org_Initiate(); // Create a new Object
	var url = AEV_XMLSPList+"?ID="+ID; // Set URL
	xmlHttp.open('get',url); xmlHttp.onreadystatechange = function(){AEV_GetStateLoaded(ID,STATE,TAB,PREFIX,STYLE,FNCT);}; xmlHttp.send(''); }
function AEV_GetStateLoaded(ID,STATE,TAB,PREFIX,STYLE,FNCT){ // Start building Folders
	if (xmlHttp.readyState==4){ var xmlDoc=xmlHttp.responseXML.documentElement; // Get XML information
	if(xmlDoc.hasChildNodes && xmlDoc.childNodes.length > 0){
		if(TAB == "false" || TAB == false) TAB = false; if(STATE == "false" || STATE == false) STATE = '';
		HTML = '<select name="'+PREFIX+'" id="'+PREFIX+'"'+((TAB!=false)?' tabindex="'+TAB+'"':'')+STYLE+((FNCT!="")?' onchange="'+FNCT+';"':'')+'>';
		HTML += '<option value=""'+((STATE=='')?' selected="selected"':'')+'>Select</option>';
		for(var n = 0; n<xmlDoc.childNodes.length; n++){ var Node = xmlDoc.childNodes[n]; // For Each XML Node
			if(Node.nodeType==1) { HTML += '<option value="'+Node.childNodes[0].nodeValue+'"'+((STATE.toUpperCase()==Node.childNodes[0].nodeValue.toUpperCase())?' selected="selected"':'')+'>'+Node.childNodes[0].nodeValue+'</option>';
			} } HTML += '</select>';
	} else HTML = '<input name="'+PREFIX+'" type="text" id="'+PREFIX+'"'+((TAB!=false)?' tabindex="'+TAB+'"':'')+' value="'+STATE+'"'+STYLE+' />';
	document.getElementById(PREFIX+'_Box').innerHTML = HTML;} }
	
function AEV_ShipSpeed(ID){
	AEV_Org_Initiate(); // Create a new Object
	var url = AEV_XMLShipList+"?ID="+ID; // Set URL
	xmlHttp.open('get',url); xmlHttp.onreadystatechange = AEV_GetShipSpeed; xmlHttp.send(''); }
function AEV_GetShipSpeed(){ // Start building Folders
	if (xmlHttp.readyState==4){ var xmlDoc=xmlHttp.responseXML.documentElement; // Get XML information
		if(xmlDoc.hasChildNodes && xmlDoc.childNodes.length > 0){ HTML = '<select name="shipping_speed" id="shipping_speed">';
			for(var n = 0; n<xmlDoc.childNodes.length; n++){ var Node = xmlDoc.childNodes[n]; // For Each XML Node
				if(Node.nodeType==1) HTML += '<option value="'+Node.getAttribute("id")+'">'+unescape(Node.getAttribute("name"))+'</option>';
		} HTML += '</select>'; document.getElementById('BoxCartSpeed').innerHTML = HTML; } } }
<!-- END AJAX State List -->
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function AEV_encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;
   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);
      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;
      if (isNaN(chr2)) enc3 = enc4 = 64;
      else if (isNaN(chr3)) enc4 = 64;
      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   return output;
}

function AEV_decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;
   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));
      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;
      output = output + String.fromCharCode(chr1);
      if (enc3 != 64) output = output + String.fromCharCode(chr2);
      if (enc4 != 64) output = output + String.fromCharCode(chr3);
   } while (i < input.length);
   return output;
}
function AEV_change_state(prefix,value){
	if(value == "USA"){
		document.getElementById(prefix+'State_Text').style.display='none';
		document.getElementById(prefix+'State_US').style.display='block';
		document.getElementById(prefix+'State_CAN').style.display='none';
		for(var n=0; n<document.getElementById(prefix+'State_US').getElementsByTagName('select')[0].options.length; n++){
			if(document.getElementById(prefix+'State_US').getElementsByTagName('select')[0].options[n].value
				 == document.getElementById(prefix+'State_Text').getElementsByTagName('input')[0].value){
				document.getElementById(prefix+'State_US').getElementsByTagName('select')[0].options[n].selected = true; 
				break;
			}
		}
		document.getElementById(prefix+'State_Text').getElementsByTagName('input')[0].disabled=true;
		document.getElementById(prefix+'State_US').getElementsByTagName('select')[0].disabled=false;
		document.getElementById(prefix+'State_CAN').getElementsByTagName('select')[0].disabled=true;
	} else if(value == "CAN"){
		document.getElementById(prefix+'State_Text').style.display='none';
		document.getElementById(prefix+'State_US').style.display='none';
		document.getElementById(prefix+'State_CAN').style.display='block';
		for(var n=0; n<document.getElementById(prefix+'State_CAN').getElementsByTagName('select')[0].options.length; n++){
			if(document.getElementById(prefix+'State_CAN').getElementsByTagName('select')[0].options[n].value
				 == document.getElementById(prefix+'State_Text').getElementsByTagName('input')[0].value){
				document.getElementById(prefix+'State_CAN').getElementsByTagName('select')[0].options[n].selected = true; 
				break;
			}
		}
		document.getElementById(prefix+'State_Text').getElementsByTagName('input')[0].disabled=true;
		document.getElementById(prefix+'State_US').getElementsByTagName('select')[0].disabled=true;
		document.getElementById(prefix+'State_CAN').getElementsByTagName('select')[0].disabled=false;
	} else {
		document.getElementById(prefix+'State_Text').style.display='block';
		document.getElementById(prefix+'State_US').style.display='none';
		document.getElementById(prefix+'State_CAN').style.display='none';
		document.getElementById(prefix+'State_Text').getElementsByTagName('input')[0].disabled=false;
		document.getElementById(prefix+'State_US').getElementsByTagName('select')[0].disabled=true;
		document.getElementById(prefix+'State_CAN').getElementsByTagName('select')[0].disabled=true;
	}
}
function AEV_same_bill(){
	var FieldArray = new Array('First_Name','Last_Name','Company','Address','Suite_Apt','Address_2','City','State','Zip','Country');
	if(document.getElementById('Same_as_Billing').checked){
		for(var n=0;n < FieldArray.length;n++){
			if(document.getElementById('Shipping_'+FieldArray[n])){
				document.getElementById('Shipping_'+FieldArray[n]).value = document.getElementById('Billing_'+FieldArray[n]).value;
				document.getElementById('Shipping_'+FieldArray[n]).disabled = true;
			}
		}
	} else {
		for(var n=0;n < FieldArray.length;n++){
			if(document.getElementById('Shipping_'+FieldArray[n])){
				document.getElementById('Shipping_'+FieldArray[n]).disabled = false;
			}
		}
	}
	AEV_same_bill_2();
}
function AEV_same_bill_2(){
	var FieldArray = new Array('First_Name','Last_Name','Company');
	if(document.getElementById('Same_as_Billing_2').checked){
		for(var n=0;n < FieldArray.length;n++){
			if(document.getElementById(FieldArray[n])){
				document.getElementById(FieldArray[n]).value = document.getElementById('Billing_'+FieldArray[n]).value;
				document.getElementById(FieldArray[n]).disabled = true;
			}
		}
	} else {
		for(var n=0;n < FieldArray.length;n++){
			if(document.getElementById(FieldArray[n])){
				document.getElementById(FieldArray[n]).disabled = false;
			}
		}
	}
}
// 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(test.indexOf('isSelect')!=-1) ck=val; if ((val=val.value)!="") {
	if(test.indexOf('isCheck')!=-1){ if (ck == false) errors+='- '+nm+' is required.\n';
	} else if (test.indexOf('isSelect')!=-1) { if(ck.selectedIndex <= 0) errors+='- '+nm+' is required.\n';
	} else if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@'); q=val.lastIndexOf('.');
	if (p<1 || p==(val.length-1) || (q<1 || q==(val.length-1) || q<p)) 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 == '');
}