
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 pkslp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=900,height=700,left = 200,top = 100');");
} 


function toggleMe(a){
  var e=document.getElementById(a);
  if(!e)return true;
  if(e.style.display=="none"){
    e.style.display="block"
  } else {
    e.style.display="none"
  }
  return true;
}
 
 
function validate(theForm)
{ 
  if (theForm.txtUserName.value == "")
  {
    alert("Please enter your login.");
    theForm.txtUserName.focus();
    return (false);
  }
  Validemail = isEmail(theForm.txtUserName.value)
  if (!Validemail)
  {
    alert("It appears that you have entered an invalid login.  Please check it.");  
    theForm.txtUserName.focus();
    return (false);
  } 
  return (true);
}
 

function emlValid2(theForm)
{ 
  if (theForm.login.value == "")
  {
    alert("Please enter your e-mail address.");
    theForm.login.focus();
    return (false);
  } 
  if (theForm.company_name.value == "")
  {
    alert("Please enter your company name.");
    theForm.company_name.focus();
    return (false);
  }    
  if (theForm.first_name.value == "")
  {
    alert("Please enter your first name.");
    theForm.first_name.focus();
    return (false);
  }  
  if (theForm.last_name.value == "")
  {
    alert("Please enter your last name.");
    theForm.last_name.focus();
    return (false);
  }  
  if (theForm.phone_number.value == "")
  {
    alert("Please enter your phone number.");
    theForm.phone_number.focus();
    return (false);
  }  
  if (theForm.show_code.value == "")
  {
    alert("Please enter your show code.");
    theForm.show_code.focus();
    return (false);
  }   
  if (theForm.booth_number.value == "")
  {
    alert("Please enter your booth number.");
    theForm.booth_number.focus();
    return (false);
  }     
  Validemail = isEmail(theForm.login.value)
  if (!Validemail)
  {
    alert("It appears that you have entered an invalid e-mail address.  Please check it.");
    theForm.login.focus();
    return (false);
  }
  if (theForm.hread.checked == false)
  {
	alert("You need to check that you have read and understand the terms of conditions.");
	theForm.hread.focus();
	return (false);
  }  
  return (true);
}




function emlValidUpdate(theForm)
{ 
  if (theForm.login.value == "")
  {
    alert("Please enter your e-mail address.");
    theForm.login.focus();
    return (false);
  } 
  if (theForm.company_name.value == "")
  {
    alert("Please enter your company name.");
    theForm.company_name.focus();
    return (false);
  }    
  if (theForm.first_name.value == "")
  {
    alert("Please enter your first name.");
    theForm.first_name.focus();
    return (false);
  }  
  if (theForm.last_name.value == "")
  {
    alert("Please enter your last name.");
    theForm.last_name.focus();
    return (false);
  }  
  if (theForm.phone_number.value == "")
  {
    alert("Please enter your phone number.");
    theForm.phone_number.focus();
    return (false);
  }  
  Validemail = isEmail(theForm.login.value)
  if (!Validemail)
  {
    alert("It appears that you have entered an invalid e-mail address.  Please check it.");
    theForm.login.focus();
    return (false);
  } 
  return (true);
}


function isEmail(string) {
    if (string.search(/^\w+(((-|_)\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
        return true;
    else
        return false;
}


function clearemail2() {
	if (document.eml1.login.value=="e-mail address?")
	{ document.eml1.login.value = "" }
}

function special_rates (URL) {
aWindow=window.open(URL, "thewindow","resizable=yes,toolbar=no,width=700,height=400,status=no,scrollbars=yes,menubar=no");
}

function special_labor_rates (URL) {
aWindow=window.open(URL, "thewindow","resizable=yes,toolbar=no,width=900,height=400,status=no,scrollbars=yes,menubar=no");
}

function lrg(URL) {
aWindow=window.open(URL, "thewindow","resizable=yes,toolbar=no,width=700,height=700,status=no,scrollbars=no,menubar=no");
}

function view_catalog_images(URL) {
aWindow=window.open(URL, "thewindow","resizable=yes,toolbar=no,width=1200,height=500,status=no,scrollbars=yes,menubar=no");
}
 

function openWin(URL) {
aWindow=window.open(URL, "thewindow","resizable=yes,toolbar=no,width=200,height=200,status=no,scrollbars=yes,menubar=no");
}

function help(URL) {
aWindow=window.open(URL, "thewindow","resizable=yes,toolbar=no,width=400,height=200,status=no,scrollbars=yes,menubar=no");
}


function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=275,left = 540,top = 412');");
}


function signup(fld,action) {	
	 
		var url = '/ajax/signup.php'; 
    
        var signupeml = $F('signupeml');   
        
        if (!signupeml) {

        	alert('Please enter in your email'); 

        } else {    
		 
			var params = 'signupeml=' + signupeml + '&action=' + action;
		 
			 
			var ajax = new Ajax.Updater(
			{success: 'signup'},
			url, 
			{method: 'get', parameters: params, onFailure: reportError}); 			     
					 
		}
 
}


function change_image(variant_id,product_id,variant_desc,letter) {	
 
		var url = '/ajax/change_image.php'; 
       
		var params = 'variant_id=' + variant_id + '&product_id=' + product_id  + '&variant_desc=' + variant_desc + '&letter=' + letter;
	  
		var ajax = new Ajax.Updater(
		{success: product_id},
		url, 
		{method: 'get', parameters: params, onFailure: reportError}); 	
		
		
}
 
 
function checkout_display(user_id,cart_identifier,zip) {	
	 
        var ship_to_zip = $F('ship_to_zip');  
        var coupon = $F('coupon'); 
        var ship_to_state = $F('ship_to_state'); 
        
        if (!ship_to_zip) {
        	alert('Please enter in your shipping zip'); 
        }    
        
        if (!ship_to_state) {
        	alert('Please enter in your state'); 
        }
         
        
        if ((ship_to_zip) && (ship_to_state)) { 
                  	 
	 	     new Ajax.Updater('checkout_display','/ajax/checkout_display.php?user_id=' + user_id + '&cart_identifier=' + cart_identifier + '&ship_to_state=' +  ship_to_state + '&coupon=' + coupon + '&ship_to_zip=' + ship_to_zip, {onLoading:function(request){$('submit').disabled=true}, onComplete:function(request){$('submit').disabled=false}, asynchronous:true, evalScripts:true});
	 
	    }
 
}  

function checkout_display_old(user_id,cart_identifier,zip) {	
	 
		var url = '/home/vipertra/ajax/checkout_display.php';
    
        var ship_to_zip = $F('ship_to_zip');  
        var coupon = $F('coupon'); 
        var ship_to_state = $F('ship_to_state'); 
        
        if (!ship_to_zip) {
        	alert('Please enter in your shipping zip'); 
        }    
        
        if (!ship_to_state) {
        	alert('Please enter in your state'); 
        }   
         
        
        if ((ship_to_zip) && (ship_to_state)) {                   
	 
			var params = 'user_id=' + user_id + '&cart_identifier=' + cart_identifier + '&ship_to_state=' +  ship_to_state + '&coupon=' + coupon + '&ship_to_zip=' + ship_to_zip;
			    
			var ajax = new Ajax.Updater(
			{success: 'checkout_display'},
			url, 
			{method: 'get', parameters: params, onFailure: reportError}); 
							     
		 		 	 
	 	}
	 	  
} 

function alert_test(var1) {
	alert(var1); 
}

function reset_checkout_display(user_id,cart_identifier) {	
	 
		var url = '/ajax/checkout_display.php'; 
        var coupon = $F('coupon'); 
       
		var params = 'user_id=' + user_id + '&cart_identifier=' + cart_identifier  + '&coupon=' + coupon;
		
	  
		var ajax = new Ajax.Updater(
		{success: 'checkout_display'},
		url, 
		{method: 'get', parameters: params, onFailure: reportError}); 			     
		 		 
 
} 
 
 
function electrical(job_number,id,electrical,electrical_div_tag) {	  	 
	 
		var url = '/ajax/electrical.php';
		var params = 'job_number=' + job_number + '&id=' + id + '&electrical=' + electrical + '&electrical_div_tag=' + electrical_div_tag; 
		   		 
		var ajax = new Ajax.Updater(
		{success: electrical_div_tag},
		url,  	
		{method: 'get', parameters: params, onFailure: reportError});  
 
} 

function add_to_cart(variant_id,product_id,size,variant_desc) {	
 
        var special_text = $F('special_text'); 	 
	 
		var url = '/add_to_cart.php';
		var params = 'variant_id=' + variant_id + '&product_id=' + product_id + '&size=' + size + '&variant_desc=' + variant_desc + '&special_text=' + special_text; 
		  		 
		var ajax = new Ajax.Updater(
		{success: 'items_in_cart'},
		url,  	
		{method: 'get', parameters: params, onFailure: reportError});  
 
} 
 

function update_items_in_cart(product_id) {	
	 
		var url = '/ajax/update_items_in_cart.php';
		var params = 'p_id=' + product_id;
 
		  
		var ajax = new Ajax.Updater(
		{success: 'items_in_cart'},
		url, 
		{method: 'get', parameters: params, onFailure: reportError}); 			 
 
}


function show_sizes(product_id,variant_desc,size_type,variant_id,clear) {	
	 
		var url = '/ajax/show_sizes.php';
		var params = 'product_id=' + product_id + '&variant_desc=' + variant_desc + '&size_type=' + size_type + '&variant_id=' + variant_id;   
 
		var ajax = new Ajax.Updater(
		{success: 'show_sizes'},
		url,   		
		{method: 'get', parameters: params, onComplete: function(request) {show_variants(product_id,variant_desc,size_type,clear);}, onFailure: reportError});	 
 
}

function show_variants(product_id,variant_desc,size_type,clear) {	
	 
		var url = '/ajax/show_variants.php';
		var params = 'product_id=' + product_id + '&variant_desc=' + variant_desc + '&size_type=' + size_type;
		
		var ajax = new Ajax.Updater(
		{success: 'show_variants'},
		url, 
		{method: 'get', parameters: params, onComplete: function(request) {deactivate_checkout_button(clear);}, onFailure: reportError});			 
 
}

function show_image (product_id,variant_desc,image_name) {	
	 
		var url = '/ajax/show_image.php';
		var params = 'product_id=' + product_id + '&variant_desc=' + variant_desc + '&image_name=' + image_name;
		
		var ajax = new Ajax.Updater(
		{success: 'mainimg'},
		url, 
		{method: 'get', parameters: params, onFailure: reportError}); 		 
 
}

function activate_checkout_button(variant_id,product_id,size,variant_desc,size_type) {	
	 
		var url = '/ajax/activate_checkout_button.php';
		var params = 'variant_id=' + variant_id + '&product_id=' + product_id + '&size=' + size + '&variant=' + variant_desc; 
	 
		var clear = 'n';  
		 
		var ajax = new Ajax.Updater(
		{success: 'activate_checkout_button'},
		url, 
		{method: 'get', parameters: params, onComplete: function(request) {show_sizes(product_id,variant_desc,size_type,variant_id,clear);}, onFailure: reportError});		 
 
} 

function deactivate_checkout_button(clear) {	

	 if (clear == 'y') {
	 
		var url = '/ajax/activate_checkout_button.php';
		var params = 'clear=' + clear; 
		 
		var ajax = new Ajax.Updater(
		{success: 'activate_checkout_button'},
		url, 
		{method: 'get', parameters: params, onFailure: reportError}); 		 

	}  
 
}

function ccnum(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=210,left = 540,top = 412');");
}
  


function reportError(request) {
	$F('mainResult') = "Error";
}


 
