document.tom = 0;
document.hbh = null;
document.pp = null;
document.cp = null;
document.hbh = null;
document.stim = null;

function runSearcher(i){
	if(i.length>0){
		clearTimeout(document.stim);
		document.stim = setTimeout("returnSearch('"+i+"')",250);
	}else{hideSearcher();}
}

function hideSearcher(){
	document.stim = setTimeout("dohideSearcher()",1000);
}

function dohideSearcher(){
	$('#keyresults').hide();
}

function returnSearch(i){
	var i = escape(i);
	if(i.length>0){
		$('#simg').show();
		$.ajax({
		   type: "GET",
		   url: "load.php",
		   data: "i=returnKeyword&o=" + i,
		   success: function(msg){
				$('#simg').hide();
				$('#keyresults').show();
				$('#keyresults').html(msg);
		   }
		 });
	}
}

function exeSearch(x,o){
	$.ajax({
	   type: "GET",
	   url: "load.php",
	   data: "i=setsearch&type=" + x + "&key=" + o,
	   success: function(msg){
			location.href='order.php';
	   }
	 });
}

function clearSearch(){
	$.ajax({
	   type: "GET",
	   url: "load.php",
	   data: "i=setsearch&type=&key=",
	   success: function(msg){
			location.href='order.php';
	   }
	 });
}

function prepmenu(i){
	clearTimeout(document.tom);
	xx = $('#'+i).position().left + 50;
	yy = 235;
	$('#extendmenu').css({left:xx,top:yy}).show();
	$("#productspagemenu").hide(); $("#servicespagemenu").hide(); $("#programspagemenu").hide();
	$('#'+i+"menu").show();
}

function prepoff(){
	clearTimeout(document.tom);
	document.tom = setTimeout("closemenu()",200);
}

function closemenu(){
	$('#extendmenu').hide();
	$('#'+document.cmo).hide();
}

function extendmenu(){
	clearTimeout(document.tom);
}

function hbchtransfer(){
	if(document.hbh==null){
		//document.hbh =  document.getElementsByClassName('boxcontent'); /* DOES NOT WORK IN IE!*/
		document.hbh = new Array();
		document.hbh[0] = "b1";
		document.hbh[1] = "b2";
		document.cp = document.hbh[0]; //.id
		document.pp = 0;
		document.pc = (document.hbh.length-1);
		$('#'+document.cp).fadeIn();
		document.clc = setInterval("jumptonext()",5000);
	}
}

function jumptonext(){ 
 	$('#'+document.hbh[document.pp]).fadeOut('normal',function(){ if(document.pp==document.pc){document.pp=0;}else{document.pp++} $('#'+document.hbh[(document.pp)]).fadeIn('normal')});
 	//$('#'+document.hbh[document.pp].id).fadeOut('normal',function(){ if(document.pp==document.pc){document.pp=0;}else{document.pp++} $('#'+document.hbh[(document.pp)].id).fadeIn('normal')});
}
	
	//var pc = $('#hbch').css('marginLeft').replace(/px/,"");
	//var wc = $('#hbch').css('width').replace(/px/,"");
	//alert(pc);
	//$('#hbch').fadeOut('fast', function(){$('#hbch').animate({marginLeft: '-=450'}, 250, function(){$('#hbch').fadeIn();});} );
	
document.counter=0;

function submitForm(){
		errors = "";
		if( document.getElementById('fullname').value == "" ){errors+='-Name\n';}
		if( document.getElementById('phone').value == "" ){errors+='-Phone\n';}
		if( document.getElementById('email').value == "" ){errors+='-Email\n';}
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	   var address = document.getElementById('email').value
	   if(reg.test(address) == false) {
		  errors+='-Invalid Email\n';
	   }

		if(errors!=""){alert('The following fields are required: \r\n' + errors); return false;}
		document.pform.action = '?submit=1'; document.pform.submit();
}

function addfield(i){document.counter = document.counter+1; nfield(document.counter);}

function nfield(i){
	var newcode = '<p id="box'+i+'"><span class="labelText">Upload Documents:</span><input type="file" name="fdocument'+i+'" onchange="addfield(this.value)" onkeypress="return noenter()" onkeypress="return !(window.event.keyCode == 13 || event.which == 13)"/> <a href="javascript:remove('+i+')"><img src="images/delete.png" border="0"/></a></p>';
	$('#newfiles').append(newcode);
}

function remove(i){$('#box'+i).remove();}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

/*
Jade, eCommerce Platform - v0.6
Designed & Developed by CJPS Enterprises
Functions.js - v1.0
*/

function view(i){
	document.getElementById('overlay').style.display='block';
	$('#cart').fadeIn('fast');
	loadview(i);
}

function hide(){
	document.getElementById('overlay').style.display='none';
	$('#cart').fadeOut('fast');
	document.getElementById('mcc').style.display='none';
}

function hidet(){document.getElementById('mcc').style.display='none';}

function hidea(){document.getElementById('mca').style.display='none';}

function ieb(){alert("Please update to the latest version of Internet Explorer, the version you're currently using is no longer compatible.  You will now be redirected to the home page.  Thank you!"); window.location = "index.php";}

function repo(){
	$('#icart').css({height:$(window).height()-90});
	if($(window).scrollTop()>320){
		$('#icart').css({top:$(window).scrollTop()-230});
	}else{
		$('#icart').css({top:64});
	}
}

function firstrun(){
	javascript:view('confirmuser');
}

function copyaddress(){
	document.getElementById('baddress').value = document.getElementById('address').value;
	document.getElementById('baddress2').value = document.getElementById('address2').value;
	document.getElementById('bcity').value = document.getElementById('city').value;
	document.getElementById('bstate').value = document.getElementById('state').value;
	document.getElementById('bcountry').value = document.getElementById('country').value;
	document.getElementById('bpostalcode').value = document.getElementById('postalcode').value;
	document.getElementById('saa').style.display='none'; document.getElementById('saa2').style.display='none';
}

function clearaddress(){
	document.getElementById('baddress').value = '';
	document.getElementById('baddress2').value = '';
	document.getElementById('bcity').value = '';
	document.getElementById('bstate').value = '';
	document.getElementById('bcountry').value = '';
	document.getElementById('bpostalcode').value = '';
	document.getElementById('saa').style.display='block'; document.getElementById('saa2').style.display='block';
	document.getElementById('cb').checked=false;
}

function dorder(){ 

	var chkr = $("input[@name='ptype']:checked").val();
	if(chkr!=undefined){
	var i = document.getElementById('ppo').value;
	var subtotal = document.getElementById('a1').value;
	var taxes = document.getElementById('a2').value;
	var shipping = document.getElementById('a3').value;
	var total = document.getElementById('a4').value;
	var stype = "";

	if(chkr=="PO" && i==""){alert("Please enter your PO#"); return;}

	document.getElementById('overlay').style.display='block';
	$('#cart').fadeIn('normal');
	
	var ajaxRequest;    
	try{ajaxRequest = new XMLHttpRequest();
	} catch (e){
	try{ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try{ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e){alert("Ajax is required for this function to work!");
	return false;}}}

	ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){
		document.getElementById('cart').innerHTML = ajaxRequest.responseText;
	}}
	document.getElementById('cart').innerHTML = '<img src="images/loader.gif" class="centerloader" />';
	ajaxRequest.open("GET", "load.php?i=processorder&po=" + i + "&ptype=" + chkr + "&subtotal=" + subtotal + "&taxes=" + taxes + "&shipping=" + shipping + "&total=" + total + "&stype=" + stype);
	ajaxRequest.send(null);
	}else{alert("Please choose a method of payment.");}
}

function poswitch(){
	document.getElementById('po').style.display='block';
	document.getElementById('cpo').style.display='none';
}

function ccswitch(){
	document.getElementById('cpo').style.display='block';
	document.getElementById('po').style.display='none';
}

function unlockconfig(){
	$('#country').removeAttr('disabled');
	$('#bcountry').removeAttr('disabled');
	$('#saveb').show(); $('#upb').hide();
	op = document.getElementById('mainform').getElementsByTagName("input");
	for(x=0;x<=op.length; x++){
		$(document.getElementById(op[x].id)).attr('disabled', '');
	}
}

function hideicon(i){$('#'+i).fadeOut('normal');}
function showicon(i){$('#'+i).fadeIn('normal');}
function autohide(){setTimeout("hide()",1500);}

function loadview(i){
	var ajaxRequest;    
	try{ajaxRequest = new XMLHttpRequest();
	} catch (e){
	try{ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try{ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e){alert("Ajax is required for this function to work!");
	return false;}}}

	ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){
		document.getElementById('cart').innerHTML = ajaxRequest.responseText;
	}}
	 
	document.getElementById('cart').innerHTML = '<img src="images/loader.gif" class="centerloader" />';
	ajaxRequest.open("GET", "load.php?i=" + i);
	ajaxRequest.send(null);
}

function viewrecep(i){
	document.getElementById('overlay').style.display='block';
	$('#cart').fadeIn('normal');
	
	var ajaxRequest;    
	try{ajaxRequest = new XMLHttpRequest();
	} catch (e){
	try{ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try{ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e){alert("Ajax is required for this function to work!");
	return false;}}}

	ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){
		document.getElementById('cart').innerHTML = ajaxRequest.responseText;
	}}
	 
	document.getElementById('cart').innerHTML = '<img src="images/loader.gif" class="centerloader" />';
	ajaxRequest.open("GET", "load.php?i=recep&id=" + i);
	ajaxRequest.send(null);
}

function viewpayment(i){
	document.getElementById('overlay').style.display='block';
	$('#cart').fadeIn('normal');
	
	var ajaxRequest;    
	try{ajaxRequest = new XMLHttpRequest();
	} catch (e){
	try{ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try{ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e){alert("Ajax is required for this function to work!");
	return false;}}}

	ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){
		document.getElementById('cart').innerHTML = ajaxRequest.responseText;
	}}
	 
	document.getElementById('cart').innerHTML = '<img src="images/loader.gif" class="centerloader" />';
	ajaxRequest.open("GET", "load.php?i=viewpayment&id=" + i);
	ajaxRequest.send(null);
}

function newpass(){
	var i = prompt("Please type in the password you'd like to use. (Minimum 6 characters required)","");
	if(i!=null && i!=""){
		if(i.length >=6){
			
			var ajaxRequest;    
			try{ajaxRequest = new XMLHttpRequest();
			} catch (e){
			try{ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
			try{ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){alert("Ajax is required for this function to work!");
			return false;}}}
		
			ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){
				ioi = ajaxRequest.responseText;
				if(ioi=="SENT"){alert("Your password has been updated!");}
			}}
		
			ajaxRequest.open("GET", "load.php?i=newpassword&ip=" + i);
			ajaxRequest.send(null);
			
		}else{alert("Please type in a password (Minimum 6 characters)"); newpass();}
	}
}

function resetpsw(){
	u = document.getElementById('username').value;
	var ajaxRequest;    
	try{ajaxRequest = new XMLHttpRequest();
	} catch (e){
	try{ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try{ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e){alert("Ajax is required for this function to work!");
	return false;}}}

	ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){
		ioi = ajaxRequest.responseText;
		if(ioi=="SENT"){document.getElementById('response').innerHTML = "Your password has been reset.<br/>Please check your email for your new temporary password."; document.getElementById('rsa').disabled=true;}
		if(ioi=="FAIL"){document.getElementById('response').innerHTML = "Username does not exist.";
		document.getElementById('username').disabled=false;document.getElementById('rsb').disabled=false;
		}
	}}

	document.getElementById('username').disabled=true;
	document.getElementById('rsb').disabled=true;
	document.getElementById('response').innerHTML = 'Checking... Please wait.';
	ajaxRequest.open("GET", "load.php?i=resetpassword&username=" + u);
	ajaxRequest.send(null);
}

function login(){
	username = document.getElementById('username').value; password = document.getElementById('password').value;
	if(username!='Username'){
		var ajaxRequest;    
		try{ajaxRequest = new XMLHttpRequest();
		} catch (e){
		try{ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try{ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e){alert("Ajax is required for this function to work!");
		return false;}}}
	
		ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){
			document.getElementById('cart').innerHTML = ajaxRequest.responseText;
		}}
		 
		document.getElementById('cart').innerHTML = '<img src="images/loader.gif" class="centerloader" />';
		ajaxRequest.open("GET", "load.php?i=logingin&username="+username+"&password="+password);
		ajaxRequest.send(null);
	}else{document.getElementById('reponder').innerHTML = 'Please type in a username and password.';}
}

function pitem(i,o,d,cc){
	$('#ek').html('<a href="javascript:hide()" id="cclean"><img src="images/close.png" alt="close" border="0"/><br/>Close</a>');
	if(cc == ""){var cc = "";}
	$('#mcci').html('Item: '+d+' | Quantity: <input id="tqt" style="width:70px; height:13px; text-align:right" type="text" maxlength="7" onkeydown="if(event.keyCode==13){additem('+o+')}" /> <img id="loader" alt="loading" style="display: none; float:right" src="images/miniloader.gif"/> <input class="adbutton" id="adbutton" type="button" value="Add Item" onclick="additem('+o+','+cc+')" />');
	document.getElementById('overlay').style.display='block';
	$('#mcc').fadeIn('fast');	
	document.getElementById('tqt').focus();
}

function addctc(x,o,u){
	
	if(u==""){return;}
	
	$('#ek').html('<a href="javascript:hide()" id="cclean"><img src="images/close.png" alt="close" border="0"/><br/>Close</a>');
	$('#mcci').html('<div style="text-align:center"><img id="loader" src="images/miniloader.gif" /> Checking Product...</div>');
	document.getElementById('overlay').style.display='block';
	$('#mcc').fadeIn('fast');	
	
		$.ajax({
		   type: "GET",
		   url: "load.php",
		   data: "i=checkProduct&x=" + x + "&o=" + o + "&u=" + u,
		   success: function(msg){
				if(msg!="0"){
					$('#mcci').html('<img id="loader" src="images/miniloader.gif" /> <div style="text-align:center">Adding Item... <input id="tqt" value="'+u+'" type="hidden"/><input id="adbutton" type="button" value="Add Item" style="display:none" /></div>');
					additem(msg);
					hide();
				}	
				if(msg=="0"){$('#mcci').html('<div style="text-align:center">Product does not exist.</div>');}
		   }
		 });
}

function changeqty(i,q,d){
	$('#ek').html('<a href="javascript:hidet()" id="cclean"><img src="images/close.png" alt="close" border="0"/><br/>Close</a>');
	$('#mcci').html('New Quantity: <input id="tqt" style="width:70px; height:13px; text-align:right" type="text" maxlength="7" onkeydown="if(event.keyCode==13){alteritem('+i+')}" value="'+q+'" /> <img id="loader" alt="loading" style="display: none; float:right" src="images/miniloader.gif"/> <input class="adbutton" id="adbutton" type="button" value="Update" onclick="alteritem('+i+')" />');
	document.getElementById('overlay').style.display='block';
	$('#mcc').fadeIn('fast');
	document.getElementById('tqt').focus();
	document.getElementById('tqt').select();
}

function alteritem(i){
	if(i!=""){
		qt = document.getElementById('tqt').value;
		//if(document.getElementById('sy'+i+'lock').checked){ll=1;}else{ll=0;}
		//if(document.getElementById('sy'+i+'xn').checked){xn=1;}else{xn=0;}
		/*
		re = /[0-9]/;
		if(qt.match(re)){}else{return;}
		
		qt = Number(qt)+Number(99);
		qt = qt.toString();
		
		if(qt.length==2){qt = 100;}
		if(qt.length==3){qt = qt.substr(0,1) + "00";}
		if(qt.length==4){qt = qt.substr(0,2) + "00";}
		if(qt.length==5){qt = qt.substr(0,3) + "00";}
		if(qt.length==6){qt = qt.substr(0,4) + "00";}
		if(qt.length==7){qt = qt.substr(0,5) + "00";}
		*/
		
		var ajaxRequest;    
		try{ajaxRequest = new XMLHttpRequest();
		} catch (e){
		try{ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try{ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e){alert("Ajax is required for this function to work!");
		return false;}}}
	
		ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){
			hide();
			view('cart');
		}}
		 
		//document.getElementById('icart').innerHTML = '<img src="images/loader.gif" class="centerloader" />';
		document.getElementById('adbutton').disabled='true';
		document.getElementById('loader').style.display='block';
		ajaxRequest.open("GET", "load.php?i=alteritem&id="+i+"&qty="+qt);
		ajaxRequest.send(null);
	}
}

function additem(i,cc){
	if(i!=""){
		qt = (document.getElementById('tqt').value);
		//if(document.getElementById('sy'+i+'lock').checked){ll=1;}else{ll=0;}
		//if(document.getElementById('sy'+i+'xn').checked){xn=1;}else{xn=0;}
		/*
		re = /[0-9]/;
		if(qt.match(re)){}else{return;}
		
		qt = Number(qt)+Number(99);
		qt = qt.toString();
		
		if(qt.length==2){qt = 100;}
		if(qt.length==3){qt = qt.substr(0,1) + "00";}
		if(qt.length==4){qt = qt.substr(0,2) + "00";}
		if(qt.length==5){qt = qt.substr(0,3) + "00";}
		if(qt.length==6){qt = qt.substr(0,4) + "00";}
		if(qt.length==7){qt = qt.substr(0,5) + "00";}
		*/
		var ajaxRequest;    
		try{ajaxRequest = new XMLHttpRequest();
		} catch (e){
		try{ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try{ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e){alert("Ajax is required for this function to work!");
		return false;}}}
	
		ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){
			hide();
			document.getElementById('icart').innerHTML = ajaxRequest.responseText;
		}}
		
		 
		//document.getElementById('icart').innerHTML = '<img src="images/loader.gif" class="centerloader" />';
		document.getElementById('adbutton').disabled='true';
		document.getElementById('loader').style.display='block';
		ajaxRequest.open("GET", "load.php?i=additem&id="+i+"&qty="+qt+"&cp="+cc);
		ajaxRequest.send(null);
		
	}
}

function removeitem(a,b,c,e){
		var ajaxRequest;    
		try{ajaxRequest = new XMLHttpRequest();
		} catch (e){
		try{ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try{ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e){alert("Ajax is required for this function to work!");
		return false;}}}
	
		ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){
			document.getElementById('icart').innerHTML = ajaxRequest.responseText;
		}}
		 
		//document.getElementById('icart').innerHTML = '<img src="images/loader.gif" class="centerloader" />';
		ajaxRequest.open("GET", "load.php?i=removeitem&id="+a+"&qty="+b+"&cp="+c+"&ie="+e);
		ajaxRequest.send(null);
}

function clearcart(){
	i = confirm("Are you sure you would like to clear your cart?");
	if(i==1){
		var ajaxRequest;    
		try{ajaxRequest = new XMLHttpRequest();
		} catch (e){
		try{ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try{ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e){alert("Ajax is required for this function to work!");
		return false;}}}
	
		ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){
			document.getElementById('icart').innerHTML = ajaxRequest.responseText;
		}}
		 
		ajaxRequest.open("GET", "load.php?i=clearcart");
		ajaxRequest.send(null);
	}
}

function save(){
	ans = "";
	fn = document.getElementById('firstname').value;
	ln = document.getElementById('lastname').value;
	bn = document.getElementById('businessname').value;
	ad = document.getElementById('address').value;
	ad2 = document.getElementById('address2').value;
	cy = document.getElementById('city').value;
	st = document.getElementById('state').value;
	co = document.getElementById('country').value;
	po = document.getElementById('postalcode').value;
	bad = document.getElementById('baddress').value;
	bad2 = document.getElementById('baddress2').value;
	bcy = document.getElementById('bcity').value;
	bst = document.getElementById('bstate').value;
	bco = document.getElementById('bcountry').value;
	bpo = document.getElementById('bpostalcode').value;
	ph = document.getElementById('phone').value;
	fx = document.getElementById('fax').value;
	tx = document.getElementById('tax').value;
	
	if(fn=="" || ln==""){ans+='-Full Name\n';}
	if(ad==""||cy==""||st==""||co==""||po==""){ans+='-Full Address\n';}
	if(bad==""||bcy==""||bst==""||bco==""||bpo==""){ans+='-Full Business Address\n';}
	if(ans!=""){alert('Sorry, the following fields are required:\n' + ans); return false;}

	var ajaxRequest;    
	try{ajaxRequest = new XMLHttpRequest();
	} catch (e){
	try{ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try{ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e){alert("Ajax is required for this function to work!");
	return false;}}}

	ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){
		//document.getElementById('cart').innerHTML = ajaxRequest.responseText; 
		document.getElementById('saveb').disabled=false;
		$('#usave').toggle('normal');
	}}
	$('#usave').toggle('normal');
	document.getElementById('saveb').disabled=true;
	ajaxRequest.open("GET", "load.php?i=myaccount&update=1&fn="+fn+"&ln="+ln+"&bn="+bn+"&ad="+ad+"&ad2="+ad2+"&cy="+cy+"&st="+st+"&co="+co+"&po="+po+"&bad="+bad+"&bad2="+bad2+"&bcy="+bcy+"&bst="+bst+"&bco="+bco+"&bpo="+bpo+"&ph="+ph+"&fx="+fx+"&tx="+tx);
	ajaxRequest.send(null);
}

function register(){
	var ans = "";
	var fn = document.getElementById('firstname').value;
	var ln = document.getElementById('lastname').value;
	var bn = document.getElementById('businessname').value;
	var ad = document.getElementById('address').value;
	var ad2 = document.getElementById('address2').value;
	var cy = document.getElementById('city').value;
	var st = document.getElementById('state').value;
	var co = document.getElementById('country').value;
	var po = document.getElementById('postalcode').value;
	var bad = document.getElementById('baddress').value;
	var bad2 = document.getElementById('baddress2').value;
	var bcy = document.getElementById('bcity').value;
	var bst = document.getElementById('bstate').value;
	var bco = document.getElementById('bcountry').value;
	var bpo = document.getElementById('bpostalcode').value;
	var ph = document.getElementById('phone').value;
	var fx = document.getElementById('fax').value;
	var ema = document.getElementById('em').value;
	var ps = document.getElementById('psw').value;
	var ps2 = document.getElementById('psw2').value;
	var taxed = document.getElementById('tx').value;
	
	if(fn=="" || ln==""){ans+='-Full Name\n';}
	if(ema==""){ans+='-Email\n';}
	if(ad==""||cy==""||st==""||co==""||po==""){ans+='-Full Address\n';}
	if(bad==""||bcy==""||bst==""||bco==""||bpo==""){ans+='-Full Business Address\n';}
	if(ps==""|| ps.length <6 ){ans+='-Please type in a password (Minimum 6 characters)\n';}
	if(ps!=ps2){ans+='-Password must match reenter password.\n';}
	if(ans!=""){alert('Sorry, the following fields are required:\n' + ans); return false;}

	var ajaxRequest;    
	try{ajaxRequest = new XMLHttpRequest();
	} catch (e){
	try{ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try{ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e){alert("Ajax is required for this function to work!");
	return false;}}}

	ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){
		document.getElementById('usave').innerHTML = ajaxRequest.responseText; 
		rit = ajaxRequest.responseText;
		if(rit != "Account created, please wait..."){document.getElementById('saveb').disabled=false;}
		if(rit == "Account created, please wait..."){location.href="order.php";}
	}}
	$('#usave').show();
	document.getElementById('saveb').disabled=true;
	ajaxRequest.open("GET", "load.php?i=createaccount&new=1&fn="+fn+"&ln="+ln+"&username="+ema+"&bn="+bn+"&ad="+ad+"&ad2="+ad2+"&cy="+cy+"&st="+st+"&co="+co+"&po="+po+"&bad="+bad+"&bad2="+bad2+"&bcy="+bcy+"&bst="+bst+"&bco="+bco+"&bpo="+bpo+"&ph="+ph+"&fx="+fx+"&email="+ema+"&ps="+ps+"&tx="+taxed);
	ajaxRequest.send(null);
}

function viewsyringes(i){if(i != document.lastview){$('#syringe'+i).slideDown('slow'); $('#syringe'+document.lastview).slideUp('slow'); document.lastview = i;}}

function whatis(i){view(i);}

function makepayment(){
	var accn = $('#ccn').val();
	var acccsv = $('#cccsv').val();
	var accem = $('#ccem').val();
	var accey = $('#ccey').val();
	var atprice = $('#tprice').val();
	var aoid = $('#oid').val();
	var aupcc = $('#upcc').val();
	var aecc = $('#eCC').val();
	
	if(accn != "" && acccsv != ""){
	$('#Makement').attr('disabled','disabled');
	$.ajax({
	   type: "GET",
	   url: "load.php",
	   data: "i=ppayment&ccn="+accn+"&cccsv="+acccsv+"&ccem="+accem+"&ccey="+accey+"&tprice="+atprice+"&oid="+aoid+"&upcc="+aupcc+"&ecc="+aecc,
	   success: function(msg){
			if(msg=="Payment has processed! You can now navigate away from this page."){
			alert (msg);
			}
			else
			{
			alert(msg);
			$('#Makement').attr('disabled','');
			}
	   }
	 });
	}else{alert("All fields are required in order to make payment.");}
}

/*Depreciated
function syringetype(i){document.syringetype = i; $('#sec1').slideDown('normal'); $('#sec0').slideUp('normal');}
function syringesize(i){document.syringesize = i; $('#sec2').slideDown('normal'); $('#sec1').slideUp('normal');}
function syringeguage(i){document.syringeguage = i; $('#sec3').slideDown('normal'); $('#sec2').slideUp('normal');}
function needlelength(i){document.needlelength = i; $('#sec4').slideDown('normal'); $('#sec3').slideUp('normal');}
function qty(i){ document.qty = i; $('#sec4').slideUp('normal'); $('#sec5').slideDown('normal');
	document.getElementById('ssize').innerHTML = document.syringesize;
	document.getElementById('sguage').innerHTML = document.syringeguage;
	document.getElementById('snlength').innerHTML = document.needlelength;
	document.getElementById('sqty').innerHTML = document.qty;}
*/

function calcship(i,w){
	$('#isbutton').attr("disabled","disabled");
	$('#tpsp').html('Calculating...');
	$.ajax({
	   type: "GET",
	   url: "load.php",
	   data: "i=getShipping&s=" + i + "&m=" + w,
	   success: function(msg){
			if(msg!=""){$('#tpsp').html('$'+msg)}else{$('#tpsp').html("TBD");};
			$('#a3').val(msg);
			gettotal();
			$('#isbutton').removeAttr("disabled");
	   }
	 });
}

function gettotal(){
	var nv1 = Number($('#a1').val());
	var nv2 = Number($('#a2').val()); 
	var nv3 = Number($('#a3').val());
	var newvalue = Number(nv1+nv2+nv3);
	var newvalue = newvalue.toFixed(2);
	$('#ttop').html(newvalue);
	$('#a4').val( newvalue );
}

function getneedleinfo(i){
	imp = new Array();
	imp[1] = "Ultra fine, tri-bevel precision tip, attached needle. Needle hub color: Yellow. Latex free.<br/>Box = 100 qty. Case = 1,000 qty (10 boxes)";
	imp[2] = "Ultra fine, tri-bevel precision tip, attached needle. For use with 100U Insulin.<br/>Needle hub color: Yellow. Latex free. Box = 100 qty. Case = 1,000 qty (10 boxes)";
	
	imp[3] = "Ultra fine, tri-bevel precision tip, attached needle. Needle hub color: Red. Latex free.<br/> Box = 100 qty. Case = 1,000 qty (10 boxes)";
	imp[4] = "Ultra fine, tri-bevel precision tip, attached needle for use with 100U Insulin.<br/>Needle hub color: Red. Latex free. Box = 100 qty. Case = 1,000 qty (10 boxes)";
	
	imp[5] = "Ultra slim, tri-bevel precision tip, attached needle. Needle hub color: Gray. Latex free.<br/> Box = 100 qty. Case = 1,000 qty (10 boxes)";
	imp[6] = "Ultra slim, tri-bevel precision tip, attached needle for use with 100U Insulin.<br/>Needle hub color: Gray. Latex free. Box = 100 qty. Case = 1,000 qty (10 boxes)";
	
	imp[7] = "Ultra slim, tri-bevel precision tip, attached needle. Needle hub color: Orange. Latex free.<br/> Box = 100 qty. Case = 1,000 qty (10 boxes)";
	imp[8] = "MicroGlide, tri-bevel precision tip, attached needle. Needle hub color: Blue. Latex free.<br/> Box = 100 qty. Case = 1,000 qty (10 boxes)";
	imp[9] = "MicroGlide, tri-bevel precision tip, attached needle. Needle hub color: Black. Latex free.<br/> Box = 100 qty. Case = 1,000 qty (10 boxes)";
	imp[10] = "MicroGlide, tri-bevel precision tip, attached needle. Needle hub color: Green. Latex free.<br/> Box = 100 qty. Case = 1,000 qty (10 boxes)";

	$(document).mousemove(function(e){
   		xx = e.pageX - 20;
    	yy = e.pageY - 10;
	});
	
	

	$('#mca').css({left:xx,top:yy}).show();
	
	$('#mcca').html("<div style='font-size:11px;margin-top:-5px;text-align:center'>"+imp[i]+"</div>");
	$('#mca').fadeIn('fast');
}

function runsec(i){
	if(i!=2){
	$('#cont').attr('disabled', 'disabled');
	}else{$('#cont').attr('disabled', '');}
	$('#sec1').hide(); $('#sec2').hide();$('#sec3').hide();$('#sec4').hide();
	$('#sec'+i).show();
}
function hidesec(i){	$('#sec'+i).hide();}
function enablecontinue(){$('#cont').attr('disabled', '');}
function discont(){$('#cont').attr('disabled', 'disabled');}
function cont2(){$('#cont').attr('disabled', ''); $('#sec4').show();}

function passcon(){
	taxid = 0;
	ustype = $('#usertype').val();
	ffname = $('#ff').val();
	
	if(ustype==1 && $('#docprescription').attr('checked') == true){taxid = 0;}
	if(ustype==2){taxid = 0;}
	if(ustype==3 && $('#prof').val()==1){taxid = 1;}
	if(ustype==3 && $('#prof').val()==0){taxid = 1; ustype=4;}

	view('register');
	
	$.ajax({
	   type: "GET",
	   url: "load.php",
	   data: "i=register&ut="+ustype+"&tx="+taxid+"&ff="+ffname,
	   success: function(msg){
			$('#cart').html(msg);
	   }
	 });
}

function uploadext(){
	if( $('#taxff').val() != "" ){
		$('#smf').attr('disabled', 'disabled');
		$('#usave').html("Uploading file. Please wait...");
		$('#usave').toggle('normal');
		document.checkerr = setInterval("checkchange()",2000);
	}
}

function checkchange(){
	if(window.uploaderr.document.body.innerHTML!=""){
		clearInterval(document.checkerr);
		$('#smf').attr('disabled', '');
		$('#usave').toggle('normal');
		$('#sectors').hide('normal');
		$('#sentor').show('normal');
		$('#ff').val($.trim(window.uploaderr.document.body.innerHTML));
	}
}

function viewlargeimage(i){
	$('#largeimageview').show();
	$('#largeimageviewin').html('<img id="nimgg" src="products/'+i+'"/>');
	$('#largeimageview').css({'width':$('#nimgg').width(),'height':$('#nimgg').height(),'marginLeft':(0-($('#nimgg').width()/2)),'marginTop':(0-($('#nimgg').height()/2))});
}
