function ShowShipping()
{      // open the window 
       ShipWin = window.open("/images/Shipping.JPG", "ShipWin", "width=440,height=170,scrollbars=no,menubar=no,resizable=no"); 
}

function textCounter(field, countfield,	maxlimit) {
/*
* The input parameters are: the field name;
* field that holds the number of characters remaining;
* the max. numb.	of characters.
*/ 
if (field.value.length > maxlimit) 									// if the current length is more than allowed
field.value =field.value.substring(0, maxlimit); 		// don't allow further input
else
countfield.value = maxlimit - field.value.length;		// set the display field to remaining number
} 

function SetSaturdayShippingMethod(RecipNum)
{	document.forms['ship_form'].elements['s_method'+RecipNum][3].checked=true;
}
function FormatDate(dYear,dMonth,dDate)
{	dMonth = dMonth+"";
	if (dMonth.length == 1)
	{	dMonth = "0"+dMonth;
	}
	dDate = dDate+"";
	if (dDate.length == 1)
	{	dDate = "0"+dDate;
	}
	return(dYear+"-"+dMonth+"-"+dDate);
}
function CheckZipCode(RecipNum)
{	var ShippingState = document.getElementById('s_state'+RecipNum).value;
	var ShippingZipCode = document.getElementById('s_zip'+RecipNum).value;
  
  if(ShippingState == 'IL' && ShippingZipCode.substr(0,3) == '606')
	 {	EnableMessenger(RecipNum);
	 }
	 else
	 {	DisableMessenger(RecipNum);
	 }
}
function IsValidShipDate(RequestedShipDate)
{	//Don't forget months start with 0
	var MemorialDay = new Date(2011,04,30);
	var July4  			= new Date(2011,06,04);
	var LaborDay 		= new Date(2011,08,05);
	var RetValue 		= true;
	if (RequestedShipDate.valueOf() == MemorialDay.valueOf())
	{	RetValue = false;	
	}
	if (RequestedShipDate.valueOf() == July4.valueOf())
	{	RetValue = false;	
	}
	if (RequestedShipDate.valueOf() == LaborDay.valueOf())
	{	RetValue = false;	
	}
	return RetValue;
}
function CheckCountry(RecipNum)
{			var ShippingCountry = document.getElementById('s_country'+RecipNum).value;
       if(ShippingCountry == 'United States')
       { 	//Change International Shipping Message
       		document.getElementById('IntShip'+RecipNum).innerHTML='<b>Varies by Location</b>';
         	document.getElementById('ShipState'+RecipNum).innerHTML='<font color="#FF0000">*</font>&nbsp;&nbsp;State:';
         	//Darken US shipping Options & Grey Out International Shipping 
         	document.getElementById('StandardRow'+RecipNum).style.color = 'black';
         	document.getElementById('2ndDayRow'+RecipNum).style.color = 'black';
       		document.getElementById('NextDayRow'+RecipNum).style.color = 'black';
       		EnableSaturday(RecipNum);
       		document.getElementById('InternationalRow'+RecipNum).style.color = 'lightgrey';
		 			//Enable US shipping Options & Disable International Shipping 
		 			document.forms['ship_form'].elements['s_method'+RecipNum][0].disabled=false;
		 			document.forms['ship_form'].elements['s_method'+RecipNum][1].disabled=false;
		 			document.forms['ship_form'].elements['s_method'+RecipNum][2].disabled=false;
		 			document.forms['ship_form'].elements['s_method'+RecipNum][4].disabled=true;
		 			document.getElementById('BaseShip'+RecipNum).innerHTML='<b>$ 9.95 </b> + $10.00 for Cooling Materials ';
		 			if (document.forms['ship_form'].elements['s_method'+RecipNum][4].checked==true)
		 			{		document.forms['ship_form'].elements['s_method'+RecipNum][0].checked=true;
		 			}
		 			CheckState(RecipNum);
       }
       else
       {	//Grey Out US shipping Options & Darken International Shipping 
         	document.getElementById('StandardRow'+RecipNum).style.color = 'lightgrey';
         	document.getElementById('2ndDayRow'+RecipNum).style.color = 'lightgrey';
       		document.getElementById('NextDayRow'+RecipNum).style.color = 'lightgrey';
       		DisableSaturday(RecipNum);
       		document.getElementById('InternationalRow'+RecipNum).style.color = 'black';
		 			//Enable US shipping Options & Disable International Shipping 
		 			document.forms['ship_form'].elements['s_method'+RecipNum][0].disabled=true;
		 			document.forms['ship_form'].elements['s_method'+RecipNum][1].disabled=true;
		 			document.forms['ship_form'].elements['s_method'+RecipNum][2].disabled=true;
		 			document.forms['ship_form'].elements['s_method'+RecipNum][4].disabled=false;

		 			if (document.forms['ship_form'].elements['s_method'+RecipNum][4].checked=true)
					{
       		if(ShippingCountry == 'Canada')
       		{		document.getElementById('IntShip'+RecipNum).innerHTML='<b>$39.00 + $ 1.00 per Item</b>';
       		 	 	document.getElementById('ShipState'+RecipNum).innerHTML='&nbsp;&nbsp;Province:';
       		}
       		if(ShippingCountry == 'United Kingdom')
       		{		document.getElementById('IntShip'+RecipNum).innerHTML='<b>$75.00 + $ 1.00 per Item</b>';
        		 	document.getElementById('ShipState'+RecipNum).innerHTML='&nbsp;&nbsp;';  
       		}
       		if(ShippingCountry == 'Puerto Rico')
       		{		document.getElementById('IntShip'+RecipNum).innerHTML='<b>$75.00 + $ 1.00 per Item</b>';
        	 		document.getElementById('ShipState'+RecipNum).innerHTML='&nbsp;&nbsp;'; 
	      	}	
	      	}
     		}
}

function EnableMessenger(RecipNum)
{
	document.getElementById('MessengerRow'+RecipNum).style.color = 'black';
	document.forms['ship_form'].elements['s_method'+RecipNum][5].disabled=false;
}
function DisableMessenger(RecipNum)
{		
	document.getElementById('MessengerRow'+RecipNum).style.color = 'lightgrey';
	document.forms['ship_form'].elements['s_method'+RecipNum][5].disabled=true;
}
function EnableSaturday(RecipNum)
{
	document.getElementById('SaturdayRow'+RecipNum).style.color = 'black';
	document.forms['ship_form'].elements['s_method'+RecipNum][3].disabled=false;
}
function DisableSaturday(RecipNum)
{		
	document.getElementById('SaturdayRow'+RecipNum).style.color = 'lightgrey';
	document.forms['ship_form'].elements['s_method'+RecipNum][3].disabled=true;
}
function CheckState(RecipNum)
{		var ShippingState = document.getElementById('s_state'+RecipNum).value;
		var ShippingStates = ["AL","AK","AZ","AR","CA","CO","CT","DC","DE","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","PR","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY"];
		var CoolingState=["AZ"];
		var ValidState = false;
		var AddCooling = false;
		
			for(var i=0; i<ShippingStates.length; i++) 
			{
    		if (ShippingStates[i] == ShippingState) 
    		{	
    			ValidState = true;					
    		}
  		}	
			for(var j=0; j<ShippingStates.length; j++) 
			{
    		if (CoolingState[j] == ShippingState) 
    		{	
    			AddCooling = true;		
    		}
  		}
  			
			if (ValidState == false)
			{	document.getElementById('s_state'+RecipNum).value = '';	}
			 if(ShippingState == 'IL')
			 {	CheckZipCode(RecipNum);
			 }
			 else
			 {	DisableMessenger(RecipNum);
			 }
       if(AddCooling == true)
       { 	document.getElementById('CoolingMessage'+RecipNum).innerHTML='When temperatures are in excess of 100&deg;F this package may be held until it is safe to ship.';
       }
       else
       {	
       		document.getElementById('CoolingMessage'+RecipNum).innerHTML='&nbsp;';
       }
       if(ShippingState == 'AK')
       { 	document.getElementById('StandardRow'+RecipNum).style.color = 'black';
       		document.getElementById('2ndDayRow'+RecipNum).style.color = 'lightgrey';
       		document.getElementById('NextDayRow'+RecipNum).style.color = 'lightgrey';
					DisableSaturday(RecipNum);
       		document.getElementById('InternationalRow'+RecipNum).style.color = 'lightgrey';
       		document.forms['ship_form'].elements['s_method'+RecipNum][0].checked=true;
		 			document.forms['ship_form'].elements['s_method'+RecipNum][0].disabled=false;
		 			document.forms['ship_form'].elements['s_method'+RecipNum][1].disabled=true;
		 			document.forms['ship_form'].elements['s_method'+RecipNum][2].disabled=true;
		 			document.forms['ship_form'].elements['s_method'+RecipNum][4].disabled=true;
		 			document.getElementById('BaseShip'+RecipNum).innerHTML='<b>$29.95</b>';
		 			document.getElementById('FreeShip'+RecipNum).innerHTML='&nbsp;';
       }
       else if(ShippingState == 'HI')
       { 	document.getElementById('StandardRow'+RecipNum).style.color = 'black';
       		document.getElementById('2ndDayRow'+RecipNum).style.color = 'lightgrey';
       		document.getElementById('NextDayRow'+RecipNum).style.color = 'lightgrey';
					DisableSaturday(RecipNum);
       		document.getElementById('InternationalRow'+RecipNum).style.color = 'lightgrey';
       		document.forms['ship_form'].elements['s_method'+RecipNum][0].checked=true;
		 			document.forms['ship_form'].elements['s_method'+RecipNum][0].disabled=false;
		 			document.forms['ship_form'].elements['s_method'+RecipNum][1].disabled=true;
		 			document.forms['ship_form'].elements['s_method'+RecipNum][2].disabled=true;
		 			document.forms['ship_form'].elements['s_method'+RecipNum][4].disabled=true;
		 			document.getElementById('BaseShip'+RecipNum).innerHTML='<b>$29.95 </b> + $10.00 for Cooling Materials';
		 			document.getElementById('FreeShip'+RecipNum).innerHTML='&nbsp;';
       }
       else if (ShippingState == 'PR')
       {	var RequestedShipDate = new Date(document.getElementById('s_shipon'+RecipNum).value.replace("-","/").replace("-","/"));
       		alert('Puerto Rico will be set as the Recipient Country');
       		document.getElementById('s_state'+RecipNum).value = '';
       		document.getElementById('s_country'+RecipNum).value = "Puerto Rico";
       		CheckCountry(RecipNum);
       		CheckShippingMethod('International',RequestedShipDate,RecipNum);
       }
}

function CheckShippingMethod(ShipMeth,MinDate,RecipNum)
{		
		var EarliestShipDate = new Date(MinDate.replace("-","/").replace("-","/"));
		var RequestedShipDate = new Date(document.getElementById('s_shipon'+RecipNum).value.replace("-","/").replace("-","/"));
		CheckCountry(RecipNum);
		 if (document.getElementById('s_country'+RecipNum).value != 'United States')
		 {	document.getElementById('ShipMessage'+RecipNum).innerHTML='<b>International Shipments must ship on Monday or Tuesday</b>'; 
		 		if (RequestedShipDate.getDay() > 2) 
				{	document.getElementById('s_shipon'+RecipNum).value="";
					document.getElementById('s_shipon'+RecipNum).style.borderColor="red";
					RequestedShipDate = EarliestShipDate;
        	while (RequestedShipDate.getDay() != 1) 
					{	RequestedShipDate.setDate(RequestedShipDate.getDate()+1);
					}
				}		 	 
		 }
		 else 
		 {	if(ShipMeth == 'UPS Saturday')
		 		{  document.getElementById('ShipMessage'+RecipNum).innerHTML='Saturday Deliveries must ship on Friday';
     	  	 if (RequestedShipDate.getDay() != 5) 
     	  	 {	document.getElementById('ShipMessage'+RecipNum).innerHTML='<b>Saturday Deliveries must ship on Friday</b>';
							document.getElementById('s_shipon'+RecipNum).value="";
							document.getElementById('s_shipon'+RecipNum).style.borderColor="red";
							RequestedShipDate = EarliestShipDate;
  	    	  	while (RequestedShipDate.getDay() != 5) 
							{	RequestedShipDate.setDate(RequestedShipDate.getDate()+1);
							}
						}
     		}
/*			else if (ShipMeth == 'Urgent 1 Day')
	     	{	 document.getElementById('ShipMessage'+RecipNum).innerHTML='Next Day Shipments cannot ship on Friday';
	     	   if (RequestedShipDate.getDay() == 5) 
						{	document.getElementById('ShipMessage'+RecipNum).innerHTML='<b>Next Day Shipments cannot ship on Friday</b>';
							document.getElementById('s_shipon'+RecipNum).style.borderColor="red";
							if (EarliestShipDate.getDay() == 5) 
							{	RequestedShipDate.setDate(RequestedShipDate.getDate()+3);
							}
						else
						{	RequestedShipDate = EarliestShipDate;
						}
					}
      	}
      	else if (ShipMeth == 'Express 2 Days')
      	{	document.forms['ship_form'].elements['s_method'+RecipNum][1].checked=true;
      		document.getElementById('ShipMessage'+RecipNum).innerHTML='Express  Shipments cannot ship on Thursday or Friday';
      	  if (RequestedShipDate.getDay() == 5 || RequestedShipDate.getDay() == 4) 
					{	document.getElementById('ShipMessage'+RecipNum).innerHTML='<b>Express Shipments cannot ship on Thursday or Friday</b>';
						document.getElementById('s_shipon'+RecipNum).style.borderColor="red";
				  	RequestedShipDate = EarliestShipDate;
				  	if (RequestedShipDate.getDay() == 4) 
						{	RequestedShipDate.setDate(RequestedShipDate.getDate()+4);
						}
						if (RequestedShipDate.getDay() == 5) 
						{	RequestedShipDate.setDate(RequestedShipDate.getDate()+3);
						}
					}
  	     }
  	    else if (ShipMeth == 'Standard 3-10 days')
  	    {	document.forms['ship_form'].elements['s_method'+RecipNum][0].checked=true;
  	    	document.getElementById('ShipMessage'+RecipNum).innerHTML='Standard Shipments cannot ship on Thursday or Friday';
  	      if (RequestedShipDate.getDay() == 5 || RequestedShipDate.getDay() == 4) 
					{	document.getElementById('ShipMessage'+RecipNum).innerHTML='<b>Standard Shipments cannot ship on Thursday or Friday</b>';
						document.getElementById('s_shipon'+RecipNum).style.borderColor="red";
				  	RequestedShipDate = EarliestShipDate;
				  	if (RequestedShipDate.getDay() == 4) 
						{	RequestedShipDate.setDate(RequestedShipDate.getDate()+4);
						}
						if (RequestedShipDate.getDay() == 5) 
						{	RequestedShipDate.setDate(RequestedShipDate.getDate()+3);
						}
					}
       	}
*/
     		else 
     		{	document.getElementById('ShipMessage'+RecipNum).innerHTML='';	
     		}				
     }
        if (!(IsValidShipDate(RequestedShipDate)))
				{	RequestedShipDate.setDate(RequestedShipDate.getDate()+1);
				}
       var NewDate = FormatDate(RequestedShipDate.getFullYear(),(RequestedShipDate.getMonth()+1),RequestedShipDate.getDate());
			 document.getElementById('s_shipon'+RecipNum).value=NewDate;
}
