var fabricDivSize;
var MainAddress="http://www.appleipadaccessories.ca/";
var version;
var dheight;
var shpelements;
var cartDivHeight;
var testArray;
var testArray2;
var shipping=0;
var shiptype="";
var shiplink="";
var qty=0;
var winW=0;
var winH=0;
var globalIndex=1*(readCookie("arrayindex"));
//alert(globalIndex);
if(globalIndex==null)
globalIndex=0;



Xoffset=350;    // modify these values to ...
Yoffset=400;    // change the popup position.

var old,skn,iex=(document.all),yyy=-1000,xxx=-1000;

var ns4=document.layers;
var ns6=document.getElementById&&!document.all;
var ie4=document.all;
var gdiv='';

function getDim(){

if (parseInt(navigator.appVersion)>3) {
 if (navigator.userAgent.indexOf("Firefox")!=-1) {
  winW = document.body.offsetWidth-4;
  winH = document.body.offsetHeight;
 }
else if (navigator.userAgent.indexOf("MSIE")!=-1) {
  winW = document.body.offsetWidth;
  winH = document.body.offsetHeight;
 }
else if (navigator.userAgent.indexOf("Chrome")!=-1) {
  winW = document.body.offsetWidth;
  winH = document.body.offsetHeight+1;
 }
else if (navigator.userAgent.indexOf("Safari")!=-1) {
  winW = document.body.offsetWidth+4;
  winH = document.body.offsetHeight+1;
 }
}

}

function popup(divname,maindivName){
gdiv=divname;
document.getElementById(divname).style.visibility="visible";
document.getElementById(maindivName).onmousemove=get_mouse;
}

function get_mouse(e){
var posx = 0;
var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
/*alert(posx);*/
if(gdiv!='')
{
	
document.getElementById(gdiv).style.left=(posx-40)+"px";
document.getElementById(gdiv).style.top=(posy-300)+"px";
}
}


function kill(divname){

document.getElementById(divname).style.visibility="hidden";

gdiv="";
}

function loadDiv(divname)
{
if(version >= 5.5)
document.getElementById(divname).style.filter="Alpha(Opacity='50')";
else
{
document.getElementById(divname).style.opacity=50/100;	
document.getElementById(divname).style.visibility="visible";
}

document.getElementById(divname).style.zIndex="100";
}

function enlargeImg(divname,divname2,imgurl){
if(version >= 5.5)
document.getElementById(divname).style.filter="Alpha(Opacity='80')";
else
document.getElementById(divname).style.opacity=80/100;	
document.getElementById(divname).style.visibility="visible";
getDim();
document.getElementById("Limage").src= imgurl;
document.getElementById(divname).style.height=winH+"px";
document.getElementById(divname).style.width=(winW+20)+"px";
setopeninnerDiv(divname2);  
 }



function setopenDiv(divname,divname2){
	
document.getElementById(divname).style.visibility="visible";

if(divname=="CartDiv")
{
getDim();
document.getElementById(divname).style.zIndex="100";
document.getElementById(divname2).style.zIndex="120";
document.getElementById(divname).style.height=winH+"px";
document.getElementById(divname).style.width=(winW+20)+"px";
document.getElementById(divname2).style.height="750px";
//document.getElementById("ShopCartList").style.height="400px";
//document.getElementById("ConfirmDiv").style.visibility="visible";
}

setopeninnerDiv(divname2);
}


/*function openDiv(divname,divname2,dim){


	if(dim<80)
	{
	
		
			dim+=10;
			
				if(version >= 5.5)
				document.getElementById(divname).style.filter="Alpha(Opacity='"+dim+"')";
				else
				document.getElementById(divname).style.opacity=dim/100;
				
				window.setTimeout("openDiv('"+divname+"','"+divname2+"',"+dim+")",50);
			
	}
	else
	{
		alert(divname2);	
		setopeninnerDiv(divname2);
	}
				
}*/

function setopeninnerDiv(divname){
if(version >= 5.5)
document.getElementById(divname).style.filter="Alpha(Opacity='95')";
else
document.getElementById(divname).style.opacity=95/100;	
document.getElementById(divname).style.visibility="visible";	
//openinnerDiv(divname,10);
}


/*function openinnerDiv(divname,dim){


	if(dim<=100)
	{
	
		
			dim+=10;
			//alert(dim);
				if(version >= 5.5)
				document.getElementById(divname).style.filter="Alpha(Opacity='"+dim+"')";
				else
				document.getElementById(divname).style.opacity=dim/100;
				
				window.setTimeout("openinnerDiv('"+divname+"',"+dim+")",50);
	}
}*/

function closeDiv(divname,divname2)
{
document.getElementById(divname).style.visibility="hidden";

document.getElementById(divname2).style.visibility="hidden";

if(divname=="CartDiv")
{
document.getElementById(divname).style.zIndex="1";
document.getElementById(divname2).style.zIndex="2";
document.getElementById(divname2).style.height="10px";
document.getElementById(divname).style.height="10px";
document.getElementById(divname).style.width="10px";
//document.getElementById("ShopCartList").style.height="10px";
//document.getElementById("ConfirmDiv").style.visibility="hidden";

}
}

function closeDiv2(divname)
{
document.getElementById(divname).style.visibility="hidden";
}

function fireAction(formName,actionURL)
{
var JavaCommand1="document."+formName+".action='"+MainAddress+"FText.php5?Director="+actionURL+"';";
//alert( JavaCommand1);
var JavaCommand3="document."+formName+".submit();";
eval(JavaCommand1);
eval(JavaCommand3);
}

function fireAction44(actionURL)
{
var agegroup=document.frmagegroup.agegroup.value;
var JavaCommand1="window.location='"+actionURL+"/Age-"+agegroup+".html';";


eval(JavaCommand1);

}

function fireCartAction(formName,actionURL)
{
var JavaCommand1="document."+formName+".action='"+MainAddress+"FText.php5?Director="+actionURL+"';";
//alert( JavaCommand1);
var JavaCommand3="document."+formName+".submit();";
eval(JavaCommand1);
eval(JavaCommand3);
setopenDiv("CartDiv","innerCartDiv");
}

function goTo(actionURL)
{
var JavaCommand1="window.location='"+MainAddress+"FText.php5?Director="+actionURL+"';";
eval(JavaCommand1);

}

function goTo2(actionURL)
{
var JavaCommand1="window.location='"+actionURL+"';";
eval(JavaCommand1);

}


function fireAction2(formName1,formName2,detail1,detail2,actionURL,divName)
{
	var JavaCommand4="document."+formName1+"."+detail1+".value;";
	if (eval(JavaCommand4)!='')
	{
	var JavaCommand1="document."+formName1+".action='FText.php5?Director="+actionURL+"';";
	var JavaCommand3="document."+formName1+".submit();";
	eval(JavaCommand1);
	eval(JavaCommand3);
	deflateDiv(divName,formName2,detail2);
	var JavaCommand2="document."+formName2+"."+detail2+".options[0].text=document."+formName1+"."+detail1+".value;";
	eval(JavaCommand2)
	var JavaCommand2="document."+formName2+"."+detail2+".options[0].value=document."+formName1+"."+detail1+".value;";
	eval(JavaCommand2)
	}
	else
	alert('Nothing was entered.');
}

function validateSearch(formName,actionURL)
{
if(document.frmSearch.wsearch.value=="")
alert("You entered nothing to search.");
else
fireAction(formName,actionURL);
}

function validateJoin(formName,actionURL)
{
var emailGood='false';
if(document.frmJoin.cjoin.value=="")
	{
		alert("Please enter a valid email address.");
		emailGood="empty";
	}
else
{
	
	for(i=0;i<=document.frmJoin.cjoin.value.length && emailGood=='false';i++)
	{
		if(document.frmJoin.cjoin.value.charAt(i)=='@')
		{
			for(j=0;j<=document.frmJoin.cjoin.value.length && emailGood=='false';j++)
			{
				if(document.frmJoin.cjoin.value.charAt(j)=='.')
				{
				emailGood='true';
				break;
				}
			}
		}
	
	}
}
	if (emailGood=='false')
	{
		alert("Email does not seem right");
	}
	else if(emailGood=="true")
	{
		fireAction(formName,actionURL);
	}
}

function validateLogin(formName,actionURL)
{
if(document.frmUserLogin.email.value=="")
alert("Please enter you email adddress.");
if(document.frmUserLogin.password.value=="")
alert("Please enter you password.");
else
fireAction(formName,actionURL);
}

function validateFP(formName,actionURL)
{
if(document.frmFP.email.value=="")
alert("Please enter you email adddress.");
else
fireAction(formName,actionURL);
}


function validateCart(frmname,divname,sindex,items,evalindex)
{
if(document.forms[frmname].quant.value=="")
alert("Please enter how many yards you want to buy.");
else
setupdateCookieArray(divname,sindex,items,evalindex);
}

function scanForm(formName,actionURL)
{
answer = checkCustomerForm();
if (answer!=false)
{
var JavaCommand1="document."+formName+".action='FText.php5?Director="+actionURL+"';"
var JavaCommand3="document."+formName+".submit();";
eval(JavaCommand1);
eval(JavaCommand3);
}
}


function checkCustomerForm()
{
//Check for Blank Text Boxes
	for(i=0;i<=25;i++)
	{
		//alert(i);
		if(!(i==3) && !(i==5) && !(i==10) && !(i==12) && !(i==20) && !(i==21) && !(i==22))
		{
		if(document.frmAddCustomer.elements[i].value=='')
		{
			document.frmAddCustomer.elements[i].focus();
			alert('Please fill in the hightlighted Box.');
			return false;
			break;
		}
		}
	}

/*var TextArray=[9];
	for(i=0;i<TextArray.length;i++)
	{
		var textlength = 10;
		if (document.frmAddCustomer.elements[TextArray[i]].value.length<textlength)
		{
			document.frmAddCustomer.elements[TextArray[i]].focus();
			alert("HightLighted Box has to have atleast "+textlength+" digits.");
			return false;
			break;
		}
	}*/

if(!(document.frmAddCustomer.password.value == document.frmAddCustomer.cpassword.value))
{
alert('Passwords do not match.');
return false;
}
//Check for certain textboxes that must be numerical
var TextArray=[17,18,19];
var ValidChars = '0123456789.';
var Char;
	for(i=0;i<TextArray.length;i++)
	{

	for(j=0;(j<=document.frmAddCustomer.elements[TextArray[i]].value.length);j++)
	{
	  Char = document.frmAddCustomer.elements[TextArray[i]].value.charAt(j);
	  if (ValidChars.indexOf(Char) == -1)
		 {
			 document.frmAddCustomer.elements[TextArray[i]].focus();
			 alert('HightLighted Box must me a number.');
			 return false;
			 break;
		 }
	 }
	}

//check for postal code is in right format (L8L8L8)
/*if(document.frmAddCustomer.postal.value.length==6)
{
	for(i=0;i<=5;i++)
	{
		if ((i % 2)==1)//if postion is odd..is a number
		{
			var ichar=document.frmAddCustomer.postal.value.charCodeAt(i);
			if((ichar<48) || (ichar>57))
			{
				document.frmAddCustomer.postal.focus();
				alert('Postal Code does not seem correct');
				return false;
				break;
			}

		}
		else //position is even
		{
			var ichar=document.frmAddCustomer.postal.value.charCodeAt(i);
			if((ichar<65) || (ichar>122))
			{
			document.frmAddCustomer.postal.focus();
			alert('Postal Code does not seem correct');
			return false;
			break;
			}

		}

	}
}
else
{
	alert('Postal code is too short');
	return false;
}*/


//Checks for the @ and . in an email address
var emailGood='false';
for(i=0;i<=document.frmAddCustomer.email.value.length && emailGood=='false';i++)
{
	if(document.frmAddCustomer.email.value.charAt(i)=='@')
	{
		for(j=0;j<=document.frmAddCustomer.email.value.length && emailGood=='false';j++)
		{
			if(document.frmAddCustomer.email.value.charAt(j)=='.')
			{
			emailGood='true';
			break;
			}
		}
	}

}
if (emailGood=='false')
{
	document.frmAddCustomer.email.focus();
	alert("Email does not seem right");
	return false;
}
 

}

function setupProv(optionName,label,dropBox)
{
document.getElementById(dropBox).innerHTML="";
sindex = window.document.frmAddCustomer.elements[optionName].options.selectedIndex;
myVal = window.document.frmAddCustomer.elements[optionName].options[sindex].value;
if(myVal=="US")
{
strState="";
document.getElementById(label).innerHTML="State:";
strState+="<select id='istate' name='istate'>";
strState+="<option value='AL'>Alabama</option>";
strState+="<option value='AK'>Alaska</option>";
strState+="<option value='AS'>American Samoa</option>";
strState+="<option value='AZ'>Arizona</option>";
strState+="<option value='AR'>Arkansas</option>";
strState+="<option value='CA'>California</option>";
strState+="<option value='CO'>Colorado</option>";
strState+="<option value='CT'>Connecticut</option>";
strState+="<option value='DE'>Delaware</option>";
strState+="<option value='DC'>District of Columbia</option>";
strState+="<option value='FL'>Florida</option>";
strState+="<option value='GA'>Georgia</option>";
strState+="<option value='GU'>Guam</option>";
strState+="<option value='HI'>Hawaii</option>";
strState+="<option value='ID'>Idaho</option>";
strState+="<option value='IL'>Illinois</option>";
strState+="<option value='IN'>Indiana</option>";
strState+="<option value='IA'>Iowa</option>";
strState+="<option value='KS'>Kansas</option>";
strState+="<option value='KY'>Kentucky</option>";
strState+="<option value='LA'>Louisiana</option>";
strState+="<option value='ME'>Maine</option>";
strState+="<option value='MD'>Maryland</option>";
strState+="<option value='MH'>Marshall Islands</option>";
strState+="<option value='MA'>Massachusetts</option>";
strState+="<option value='MI'>Michigan</option>";
strState+="<option value='MN'>Minnesota</option>";
strState+="<option value='MS'>Mississipi</option>";
strState+="<option value='MO'>Missouri</option>";
strState+="<option value='MT'>Montana</option>";
strState+="<option value='NE'>Nebraska</option>";
strState+="<option value='NV'>Nevada</option>";
strState+="<option value='NH'>New Hampshire</option>";
strState+="<option value='NJ'>New Jersey</option>";
strState+="<option value='NM'>New Mexico</option>";
strState+="<option value='NY'>New York</option>";
strState+="<option value='NC'>North Carolina</option>";
strState+="<option value='ND'>North Dakota</option>";
strState+="<option value='MP'>Northern Marianas</option>";
strState+="<option value='OH'>Ohio</option>";
strState+="<option value='OK'>Oklahoma</option>";
strState+="<option value='OR'>Oregon</option>";
strState+="<option value='PW'>Palau</option>";
strState+="<option value='PA'>Pennsylvania</option>";
strState+="<option value='PR'>Puerto Rico</option>";
strState+="<option value='RI'>Rhode Island</option>";
strState+="<option value='SC'>South Carolina</option>";
strState+="<option value='SD'>South Dakota</option>";
strState+="<option value='TN'>Tennessee</option>";
strState+="<option value='TX'>Texas</option>";
strState+="<option value='UT'>Utah</option>";
strState+="<option value='VT'>Vermont</option>";
strState+="<option value='VA'>Virginia</option>";
strState+="<option value='VI'>Virgin Islands</option>";
strState+="<option value='WA'>Washington</option>";
strState+="<option value='WV'>West Virginia</option>";
strState+="<option value='WI'>Winconsin</option>";
strState+="<option value='WY'>Wyoming</option>";
strState+="</select>";
document.getElementById(dropBox).innerHTML=strState;
}
else
{
strState="";
document.getElementById(label).innerHTML="Province:";
strState+="<select id='istate' name='istate'>";
strState+="<option value='AB'>Alberta</option>";
strState+="<option value='BC'>British Columbia</option>";
strState+="<option value='MB'>Manitoba</option>";
strState+="<option value='NB'>New Brunswick</option>";
strState+="<option value='NL'>Newfoundland and Labrador</option>";
strState+="<option value='NT'>Northwest Territories</option>";
strState+="<option value='NS'>Mova Scotia</option>";
strState+="<option value='NU'>Nunavut</option>";
strState+="<option value='ON'>Ontario</option>";
strState+="<option value='PE'>Prince Edward Island</option>";
strState+="<option value='QC'>Quebec</option>";
strState+="<option value='SK'>Saskatchewan</option>";
strState+="<option value='YT'>Yukon</option>";
strState+="</select>";
document.getElementById(dropBox).innerHTML=strState;
}
}

function setupProv2(optionName,label,dropBox)
{
document.getElementById(dropBox).innerHTML="";
sindex = window.document.frmAddCustomer.elements[optionName].options.selectedIndex;
myVal = window.document.frmAddCustomer.elements[optionName].options[sindex].value;
if(myVal=="US")
{
strState="";
document.getElementById(label).innerHTML="State:";
strState+="<select id='sistate' name='sistate'>";
strState+="<option value='AL'>Alabama</option>";
strState+="<option value='AK'>Alaska</option>";
strState+="<option value='AS'>American Samoa</option>";
strState+="<option value='AZ'>Arizona</option>";
strState+="<option value='AR'>Arkansas</option>";
strState+="<option value='CA'>California</option>";
strState+="<option value='CO'>Colorado</option>";
strState+="<option value='CT'>Connecticut</option>";
strState+="<option value='DE'>Delaware</option>";
strState+="<option value='DC'>District of Columbia</option>";
strState+="<option value='FL'>Florida</option>";
strState+="<option value='GA'>Georgia</option>";
strState+="<option value='GU'>Guam</option>";
strState+="<option value='HI'>Hawaii</option>";
strState+="<option value='ID'>Idaho</option>";
strState+="<option value='IL'>Illinois</option>";
strState+="<option value='IN'>Indiana</option>";
strState+="<option value='IA'>Iowa</option>";
strState+="<option value='KS'>Kansas</option>";
strState+="<option value='KY'>Kentucky</option>";
strState+="<option value='LA'>Louisiana</option>";
strState+="<option value='ME'>Maine</option>";
strState+="<option value='MD'>Maryland</option>";
strState+="<option value='MH'>Marshall Islands</option>";
strState+="<option value='MA'>Massachusetts</option>";
strState+="<option value='MI'>Michigan</option>";
strState+="<option value='MN'>Minnesota</option>";
strState+="<option value='MS'>Mississipi</option>";
strState+="<option value='MO'>Missouri</option>";
strState+="<option value='MT'>Montana</option>";
strState+="<option value='NE'>Nebraska</option>";
strState+="<option value='NV'>Nevada</option>";
strState+="<option value='NH'>New Hampshire</option>";
strState+="<option value='NJ'>New Jersey</option>";
strState+="<option value='NM'>New Mexico</option>";
strState+="<option value='NY'>New York</option>";
strState+="<option value='NC'>North Carolina</option>";
strState+="<option value='ND'>North Dakota</option>";
strState+="<option value='MP'>Northern Marianas</option>";
strState+="<option value='OH'>Ohio</option>";
strState+="<option value='OK'>Oklahoma</option>";
strState+="<option value='OR'>Oregon</option>";
strState+="<option value='PW'>Palau</option>";
strState+="<option value='PA'>Pennsylvania</option>";
strState+="<option value='PR'>Puerto Rico</option>";
strState+="<option value='RI'>Rhode Island</option>";
strState+="<option value='SC'>South Carolina</option>";
strState+="<option value='SD'>South Dakota</option>";
strState+="<option value='TN'>Tennessee</option>";
strState+="<option value='TX'>Texas</option>";
strState+="<option value='UT'>Utah</option>";
strState+="<option value='VT'>Vermont</option>";
strState+="<option value='VA'>Virginia</option>";
strState+="<option value='VI'>Virgin Islands</option>";
strState+="<option value='WA'>Washington</option>";
strState+="<option value='WV'>West Virginia</option>";
strState+="<option value='WI'>Winconsin</option>";
strState+="<option value='WY'>Wyoming</option>";
strState+="</select>";
document.getElementById(dropBox).innerHTML=strState;
}
else
{
strState="";
document.getElementById(label).innerHTML="Province:";
strState+="<select id='sistate' name='sistate'>";
strState+="<option value='AB'>Alberta</option>";
strState+="<option value='BC'>British Columbia</option>";
strState+="<option value='MB'>Manitoba</option>";
strState+="<option value='NB'>New Brunswick</option>";
strState+="<option value='NL'>Newfoundland and Labrador</option>";
strState+="<option value='NT'>Northwest Territories</option>";
strState+="<option value='NS'>Mova Scotia</option>";
strState+="<option value='NU'>Nunavut</option>";
strState+="<option value='ON'>Ontario</option>";
strState+="<option value='PE'>Prince Edward Island</option>";
strState+="<option value='QC'>Quebec</option>";
strState+="<option value='SK'>Saskatchewan</option>";
strState+="<option value='YT'>Yukon</option>";
strState+="</select>";
document.getElementById(dropBox).innerHTML=strState;
}
}

function cloneBill(label,dropBox)
{
if(document.getElementById("checker").checked==1)
	{
	document.getElementById("saddress").value=document.frmAddCustomer.address.value;
	document.getElementById("saddress2").value=document.frmAddCustomer.address2.value;
	document.getElementById("sicountry").value=document.frmAddCustomer.icountry.value;
	document.getElementById("sistate").value=document.frmAddCustomer.istate.value;
	document.getElementById("scity").value=document.frmAddCustomer.city.value;
	document.getElementById("spostal").value=document.frmAddCustomer.postal.value;
	//alert(document.frmAddCustomer.icountry.value);
	if(document.frmAddCustomer.icountry.value=='US')
		{
		
			document.getElementById(dropBox).innerHTML="";
			var strState="";
			document.getElementById(label).innerHTML="State:";
			strState+="<select id='sistate' name='sistate'>";
			strState+="<option value='"+document.frmAddCustomer.istate.value+"'>"+document.frmAddCustomer.istate.value+"</option>";
			strState+="<option value='AL'>Alabama</option>";
			strState+="<option value='AK'>Alaska</option>";
			strState+="<option value='AS'>American Samoa</option>";
			strState+="<option value='AZ'>Arizona</option>";
			strState+="<option value='AR'>Arkansas</option>";
			strState+="<option value='CA'>California</option>";
			strState+="<option value='CO'>Colorado</option>";
			strState+="<option value='CT'>Connecticut</option>";
			strState+="<option value='DE'>Delaware</option>";
			strState+="<option value='DC'>District of Columbia</option>";
			strState+="<option value='FL'>Florida</option>";
			strState+="<option value='GA'>Georgia</option>";
			strState+="<option value='GU'>Guam</option>";
			strState+="<option value='HI'>Hawaii</option>";
			strState+="<option value='ID'>Idaho</option>";
			strState+="<option value='IL'>Illinois</option>";
			strState+="<option value='IN'>Indiana</option>";
			strState+="<option value='IA'>Iowa</option>";
			strState+="<option value='KS'>Kansas</option>";
			strState+="<option value='KY'>Kentucky</option>";
			strState+="<option value='LA'>Louisiana</option>";
			strState+="<option value='ME'>Maine</option>";
			strState+="<option value='MD'>Maryland</option>";
			strState+="<option value='MH'>Marshall Islands</option>";
			strState+="<option value='MA'>Massachusetts</option>";
			strState+="<option value='MI'>Michigan</option>";
			strState+="<option value='MN'>Minnesota</option>";
			strState+="<option value='MS'>Mississipi</option>";
			strState+="<option value='MO'>Missouri</option>";
			strState+="<option value='MT'>Montana</option>";
			strState+="<option value='NE'>Nebraska</option>";
			strState+="<option value='NV'>Nevada</option>";
			strState+="<option value='NH'>New Hampshire</option>";
			strState+="<option value='NJ'>New Jersey</option>";
			strState+="<option value='NM'>New Mexico</option>";
			strState+="<option value='NY'>New York</option>";
			strState+="<option value='NC'>North Carolina</option>";
			strState+="<option value='ND'>North Dakota</option>";
			strState+="<option value='MP'>Northern Marianas</option>";
			strState+="<option value='OH'>Ohio</option>";
			strState+="<option value='OK'>Oklahoma</option>";
			strState+="<option value='OR'>Oregon</option>";
			strState+="<option value='PW'>Palau</option>";
			strState+="<option value='PA'>Pennsylvania</option>";
			strState+="<option value='PR'>Puerto Rico</option>";
			strState+="<option value='RI'>Rhode Island</option>";
			strState+="<option value='SC'>South Carolina</option>";
			strState+="<option value='SD'>South Dakota</option>";
			strState+="<option value='TN'>Tennessee</option>";
			strState+="<option value='TX'>Texas</option>";
			strState+="<option value='UT'>Utah</option>";
			strState+="<option value='VT'>Vermont</option>";
			strState+="<option value='VA'>Virginia</option>";
			strState+="<option value='VI'>Virgin Islands</option>";
			strState+="<option value='WA'>Washington</option>";
			strState+="<option value='WV'>West Virginia</option>";
			strState+="<option value='WI'>Winconsin</option>";
			strState+="<option value='WY'>Wyoming</option>";
			strState+="</select>";
			document.getElementById(dropBox).innerHTML=strState;
		}
		else
		{
			document.getElementById(dropBox).innerHTML="";
			strState="";
			document.getElementById(label).innerHTML="Province:";
			strState+="<select id='sistate' name='sistate'>";
			strState+="<option value='"+document.frmAddCustomer.istate.value+"'>"+document.frmAddCustomer.istate.value+"</option>";
			strState+="<option value='AB'>Alberta</option>";
			strState+="<option value='BC'>British Columbia</option>";
			strState+="<option value='MB'>Manitoba</option>";
			strState+="<option value='NB'>New Brunswick</option>";
			strState+="<option value='NL'>Newfoundland and Labrador</option>";
			strState+="<option value='NT'>Northwest Territories</option>";
			strState+="<option value='NS'>Mova Scotia</option>";
			strState+="<option value='NU'>Nunavut</option>";
			strState+="<option value='ON'>Ontario</option>";
			strState+="<option value='PE'>Prince Edward Island</option>";
			strState+="<option value='QC'>Quebec</option>";
			strState+="<option value='SK'>Saskatchewan</option>";
			strState+="<option value='YT'>Yukon</option>";
			strState+="</select>";
			document.getElementById(dropBox).innerHTML=strState;
		}
	
	}
	else
	{
	document.getElementById("saddress").value="";
	document.getElementById("saddress2").value="";
	//document.getElementById("sicountry").value="";
	//document.getElementById("sistate").value="";
	document.getElementById("scity").value="";
	document.getElementById("spostal").value="";
	}
}




function scanFabricForm(formName,actionURL)
{
answer = checkFabricForm();
if (answer!=false)
{
var JavaCommand1="document."+formName+".action='FText.php5?Director="+actionURL+"';"
var JavaCommand3="document."+formName+".submit();";
eval(JavaCommand1);
eval(JavaCommand3);
}
}


function checkFabricForm()
{
//Check for Blank Text Boxes
	/*for(i=0;i<=12;i++)
	{

		if(document.frmAddFabric.elements[i].value=='')
		{
			document.frmAddFabric.elements[i].focus();
			alert('Please fill in the hightlighted Box.');
			return false;
			break;
		}
	}*/
var TextArray=[0,6,7,9,10,11,17];
for(i=0;i<TextArray.length;i++)
	{

	for(j=0;(j<=document.frmAddFabric.elements[TextArray[i]].value.length);j++)
	{
	 
	  if (document.frmAddFabric.elements[TextArray[i]].value == "")
		 {
			document.frmAddFabric.elements[TextArray[i]].focus();
			alert('Please fill in the hightlighted Box.');
			return false;
			break;
		 }
	 }
	}


//Check for certain textboxes that must be numerical
var TextArray=[6,7,9,10,17,19];
var ValidChars = '0123456789.';
var Char;
	for(i=0;i<TextArray.length;i++)
	{

	for(j=0;(j<=document.frmAddFabric.elements[TextArray[i]].value.length);j++)
	{
	  Char = document.frmAddFabric.elements[TextArray[i]].value.charAt(j);
	  if (ValidChars.indexOf(Char) == -1)
		 {
			 document.frmAddFabric.elements[TextArray[i]].focus();
			 alert('HightLighted Box must me a number.');
			 return false;
			 break;
		 }
	 }
	}

}

function expandDiv(divName,frmName,textbox)
{
document.getElementById(divName).style.height="150px";
document.getElementById(divName).style.visibility="visible";
var JavaCommand2="document."+frmName+"."+textbox+".style.visibility='hidden';";
eval(JavaCommand2);

}

function deflateDiv(divName,frmName,textbox)
{
document.getElementById(divName).style.height="0px";
document.getElementById(divName).style.visibility="hidden";
var JavaCommand2="document."+frmName+"."+textbox+".style.visibility='visible';";
eval(JavaCommand2)
}

function deflate(divname,divHeader,height,headersize)
		{
		var dheight=document.getElementById(divname).offsetHeight-2;
			
			if(dheight<0)
			{
			dheight=40;	
			}
			
			if(dheight > 20)
			{
				dheight=dheight-20;
				//alert("deflate:"+dheight);
				document.getElementById(divname).style.height=dheight+"px";		
				window.setTimeout("deflate('"+divname+"','"+divHeader+"',"+height+","+headersize+")",15);	
			}
			else
				//alert("deflate:"+dheight);
				createCookie(divname,"close",1)	
				document.getElementById(divHeader).innerHTML="<div class='menuHeader' id='"+divHeader+"'>"+divHeader+"<div style='display:block;position:relative;background-image:url(\""+MainAddress+"pics/web/menuArrowDown.gif\");height:10px;width:10px;margin-left:"+headersize+"px;margin-top:-14px;' onclick='inflate(\""+divname+"\",\""+divHeader+"\","+height+","+headersize+")'></div></div>";
				
		}
		
function inflate(divname,divHeader,height,headersize)
		{
		var dheight=document.getElementById(divname).offsetHeight-2;
			if(dheight < (height-2))
			{
				dheight=dheight+20;
				document.getElementById(divname).style.height=dheight+"px";		
				window.setTimeout("inflate('"+divname+"','"+divHeader+"',"+height+","+headersize+")",15);
			}
			else
				eraseCookie(divname);
				document.getElementById(divHeader).innerHTML="<div class='menuHeader'>"+divHeader+"<div style='display:block;position:relative;background-image:url(\""+MainAddress+"pics/web/menuArrowUp.gif\");height:10px;width:10px;margin-left:"+headersize+"px;margin-top:-14px;' onclick='deflate(\""+divname+"\",\""+divHeader+"\","+height+","+headersize+")'></div></div>";
		}
		
function deflateDiv(divName,frmName,textbox)
{
document.getElementById(divName).style.height="0px";
document.getElementById(divName).style.visibility="hidden";
var JavaCommand2="document."+frmName+"."+textbox+".style.visibility='visible';";
eval(JavaCommand2)
}

function deflateF(divname,divHeader,headersize)
		{
		var dheight=document.getElementById(divname).offsetHeight-2;
			
			if(dheight<0)
			{
			dheight=40;	
			}
			
			if(dheight > 20)
			{
				dheight=dheight-20;
				document.getElementById(divname).style.height=dheight+"px";		
				window.setTimeout("deflateF('"+divname+"','"+divHeader+"','"+headersize+"')",15);
				
			}
			else
				createCookie(divname,"close",1)	
				document.getElementById(divHeader).innerHTML="<div class='menuHeader' id='"+divHeader+"'>"+divHeader+"<div style='display:block;position:relative;background-image:url(\""+MainAddress+"pics/web/menuArrowDown.gif\");height:17px;width:23px;margin-left:"+headersize+"px;margin-top:-18px;' onclick='inflateF(\""+divname+"\",\""+divHeader+"\",\""+headersize+"\")'></div></div>";
		}
		
function inflateF(divname,divHeader,headersize)
		{
		var dheight=document.getElementById(divname).offsetHeight-2;
		if(dheight < (fabricDivSize-2) )
			{
				dheight=dheight+20;
				document.getElementById(divname).style.height=dheight+"px";
				window.setTimeout("inflateF('"+divname+"','"+divHeader+"','"+headersize+"')",15);
			}
			else
				eraseCookie(divname);
				document.getElementById(divHeader).innerHTML="<div class='menuHeader'>"+divHeader+"<div style='display:block;position:relative;background-image:url(\""+MainAddress+"pics/web/menuArrowUp.gif\");height:17px;width:23px;margin-left:"+headersize+"px;margin-top:-18px;' onclick='deflateF(\""+divname+"\",\""+divHeader+"\",\""+headersize+"\")'></div></div>";
		}
							
function deflateFabric(divname,divHeader,height,headersize,divtext)
		{
		var dheight=document.getElementById(divname).offsetHeight-2;
			
			
			
			if(dheight > 20)
			{
				//alert("deflate:"+dheight);
				dheight=dheight-20;
				fabricDivSize=fabricDivSize-20;
				document.getElementById(divname).style.height=dheight+"px";		
				document.getElementById("FabricDiv").style.height=fabricDivSize+"px";
				window.setTimeout("deflateFabric('"+divname+"','"+divHeader+"',"+height+","+headersize+",'"+divtext+"')",15);
				
			}
			else
				//alert("deflate out:"+dheight);
				eraseCookie(divname);
				document.getElementById(divHeader).innerHTML="<a href='"+MainAddress+""+divtext+"-Fabric.html'>"+divtext+" Fabric</a><div style='display:block;position:relative;height:17px;width:23px;margin-left:175px;margin-top:-18px;cursor:pointer;' onclick='inflateFabric(\""+divname+"\",\""+divHeader+"\","+height+","+headersize+",\""+divtext+"\")'>+</div></div>";
				
		}
		
function setDivheight(divname,divHeader,height,headersize)
{
	 dheight=document.getElementById(divname).offsetHeight-2;
		
		if (dheight<0)
		{
		dheight=18;
		}
		deflate(divname,divHeader,height,headersize);
		
}		


function Fheight(divname,divHeader,height,headersize,divtext)
{
	 dheight=document.getElementById(divname).offsetHeight-2;
		
		if (dheight<0)
		{
		dheight=18;
		}
	
		inflateSFabric(divname,divHeader,height,headersize,divtext);
			
}
		
function inflateSFabric(divname,divHeader,height,headersize,divtext)
		{
		//alert("dheight:"+dheight+"\ninflate:"+height+"\n Divname:"+divname);
		if(dheight < (height-2))
			{
				dheight=dheight+20;
			
				fabricDivSize=fabricDivSize+20;
				document.getElementById("FabricDiv").style.height=fabricDivSize+"px";
				document.getElementById(divname).style.height=dheight+"px";		
				window.setTimeout("inflateSFabric(\""+divname+"\",\""+divHeader+"\","+height+","+headersize+",\""+divtext+"\")",15);
			}
			else
				
				createCookie(divname,"close",1)
				document.getElementById(divHeader).innerHTML="<a href='"+MainAddress+""+divtext+"-Fabric.html'>"+divtext+" Fabric</a><div style='display:block;position:relative;height:17px;width:23px;margin-left:175px;margin-top:-18px;cursor:pointer;' onclick='deflateFabric(\""+divname+"\",\""+divHeader+"\","+height+","+headersize+",\""+divtext+"\")'>-</div></div>";
																	
		}
		
function inflateFabric(divname,divHeader,height,headersize,divtext)
		{
		var dheight=document.getElementById(divname).offsetHeight-2;
		
		if(dheight < (height-2))
			{
				dheight=dheight+20;
				fabricDivSize=fabricDivSize+20;
				document.getElementById(divname).style.height=dheight+"px";		
				document.getElementById("FabricDiv").style.height=fabricDivSize+"px";
				window.setTimeout("inflateFabric('"+divname+"','"+divHeader+"',"+height+","+headersize+",'"+divtext+"')",15);
			}
			else
				createCookie(divname,"close",1)	
				document.getElementById(divHeader).innerHTML="<a href='"+MainAddress+""+divtext+"-Fabric.html'>"+divtext+" Fabric</a><div style='display:block;position:relative;height:17px;width:23px;margin-left:175px;margin-top:-18px;cursor:pointer;' onclick='deflateFabric(\""+divname+"\",\""+divHeader+"\","+height+","+headersize+",\""+divtext+"\")'>-</div></div>";														
		}
	
function setSCF(divname,height,width,margin,top)
		{
			document.getElementById(divname).style.visibility="visible";
			//inflateSCF(divname,height,width,margin,top);
		}
function inflateSCF(divname,height,width,margin,top)
		{
		
		var scfheight = document.getElementById(divname).offsetHeight;
		var scfwidth = document.getElementById(divname).offsetWidth;

		
		if(scfheight < height)
			{
				scfheight=scfheight+20;
				scfwidth=scfwidth+40;
				margin=margin-19;
				top=top-5;
				document.getElementById(divname).style.height=scfheight+"px";		
				document.getElementById(divname).style.width=scfwidth+"px";		
				document.getElementById(divname).style.left=margin+"px";
				document.getElementById(divname).style.top=top+"px";
				
				window.setTimeout("inflateSCF('"+divname+"',"+height+","+width+","+margin+","+top+")",10);
			}
														
		}	

function unsetSCF(divname)
		{
			
				document.getElementById(divname).style.height="14px";		
				document.getElementById(divname).style.width="0px";		
				document.getElementById(divname).style.left="200px";
				document.getElementById(divname).style.top="300px";
			    document.getElementById(divname).style.visibility="hidden";	
				if(version >= 5.5)
				document.getElementById(divname).style.filter="Alpha(Opacity='100')";
				else
				document.getElementById(divname).style.opacity=100/100;
				
		}

function deflateSCF(divname,dim)
		{
		document.getElementById(divname).style.visibility="hidden";	
		
		//unsetSCF(divname);
		
		}	

function chkQty()
{
		
			qty=0;
			for(var x=0;x<(globalIndex+1);x++)
				{
				//alert(globalIndex);
					testArray = new getCookieArray("shopCart"+x);
					if(testArray.length)
					{
						qty=qty+eval(testArray[2]);
						
					}
				}
				
				 return qty.toFixed(2);
				
}



function deflateShop(divname,divHeader,divname2,headersize)
		{
		 	xdheight=document.getElementById(divname).offsetHeight-2;
			xdheight2=document.getElementById(divname2).offsetHeight;
			//alert("deflate1:"+dheight2);
				if(dheight<0)
				{
				xdheight=150;	
				}
				//alert("deflate11:"+dheight2);
			if(xdheight > 40 && xdheight2 > 0)
			{
			
				xdheight=xdheight-45;
				xdheight2=xdheight2-45;
				//alert("deflate3:"+dheight2);
				
				document.getElementById(divname2).style.height=xdheight2+"px";		
				document.getElementById(divname).style.height=xdheight+"px";		
				window.setTimeout("deflateShop('"+divname+"','"+divHeader+"','"+divname2+"',"+headersize+")",15);
				
			}
			else
			
				//alert("deflate out:"+dheight);
				createCookie(divname,"close",1);
				document.getElementById(divHeader).innerHTML="<div class='menuHeader' id='"+divHeader+"'>Shopping Cart<div id='itemCountDiv' style='font-size:9px;display:block;position:relative;height:13px;width:55px;margin-left:100px;margin-top:-12px;'>"+globalIndex+" Item(s)</div><div style='display:block;position:relative;background-image:url(\""+MainAddress+"pics/web/menuArrowDown.gif\");height:10px;width:10px;margin-left:"+headersize+"px;margin-top:-14px;' onclick='inflateShop(\""+divname+"\",\""+divHeader+"\",\""+divname2+"\","+headersize+")'></div></div>";
			
			}
		
		
function inflateShop(divname,divHeader,divname2,headersize)
		{
		var dheight=document.getElementById(divname).offsetHeight-2;
		//alert("inflate cart:"+dheight);
			if(dheight < (cartDivHeight-2))
			{
				
				dheight=dheight+45;
				//alert("inflate:"+dheight);
				document.getElementById(divname2).style.height=(dheight-40)+"px";	
				document.getElementById(divname).style.height=dheight+"px";		
				window.setTimeout("inflateShop('"+divname+"','"+divHeader+"','"+divname2+"',"+headersize+")",15);
			}
			else
				eraseCookie(divname);	
				document.getElementById(divHeader).innerHTML="<div class='menuHeader'>Shopping Cart<div id='itemCountDiv' style='font-size:9px;display:block;position:relative;height:13px;width:55px;margin-left:100px;margin-top:-12px;'>"+globalIndex+" Item(s)</div><div style='display:block;position:relative;background-image:url(\""+MainAddress+"pics/web/menuArrowUp.gif\");height:10px;width:10px;margin-left:"+headersize+"px;margin-top:-14px;' onclick='deflateShop(\""+divname+"\",\""+divHeader+"\",\""+divname2+"\","+headersize+")'></div></div>";
		}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	//alert(name);
	createCookie(name,"",-1);
}



function setCookieArray(name){
    var alength = setCookieArray.arguments.length - 1;
	   for (var i = 0; i < alength; i++) {
        data = setCookieArray.arguments[i + 1]
        createCookie (name + i, data,1);
        }        
    }
	
	function ValidateBox(fid,fbname,swatch,category,type,pic,price)
	{
		var yards = document.frmShopCart.yards.value;
		var answer='true';
		if (yards=='')
			{
			alert('Nothing was entered');
			answer='false';
			
			}
		
		var ValidChars = '0123456789.';
		var Char;
	

	for(j=0;(j<=document.frmShopCart.yards.value.length);j++)
	{
	  Char = document.frmShopCart.yards.value.charAt(j);
	  if (ValidChars.indexOf(Char) == -1)
		 {
			 document.frmShopCart.yards.focus();
			 alert('HightLighted Box must me a number.');
			 answer='false';
			 break;
		 }
	 }
	
	if (answer=='true')
		setupCartCookie(fid,fbname,swatch,category,type,pic,price);
	}
	
	function setupCartCookie(fid,fbname,swatch,category,type,pic,price){
	var yards = document.frmShopCart.yards.value;
	var answer='true';
	for(var x=0;x<=globalIndex;x++)
				{
					testArray = new getCookieArray("shopCart"+x);					
					//alert(x);
					if(testArray.length)
						{
					if(testArray[1]==fid && testArray[4]=="Fabric")
						{
							updateCookieArray(x,"1",2)
							answer='false';
							break;
						}	
						}
				}
	if(answer=='true')
	{
	setCookieArray("shopCart"+globalIndex,fid,yards,fbname,swatch,category,type,pic,price);
	globalIndex=globalIndex+1;
	createCookie("arrayindex",globalIndex,1)
	}
	deflateSCF("ShopCartform",90);
	fillShopCart();
	
	
	}
	
	function setupCartCookie2(fid,fbname,swatch,category,type,pic,price){
	var yards = 1;
	var answer='true';
	for(var x=0;x<=globalIndex;x++)
				{
					testArray = new getCookieArray("shopCart"+x);					
					//alert(x);
					if(testArray.length)
						{
					if(testArray[1]==fid && testArray[4]=="(SWATCH)")
						{
							
							answer='false';
							break;
						}	
						}
				}
	if(answer=='true')
	{
	setCookieArray("shopCart"+globalIndex,fid,yards,fbname,swatch,category,type,pic,price);
	globalIndex=globalIndex+1;
	createCookie("arrayindex",globalIndex,1)
	document.getElementById("SwatchDivInfo").innerHTML="A "+fbname+" swatch has been added to your cart."
	document.getElementById("SwatchDiv").style.visibility="visible";
	}
	else
	{
	document.getElementById("SwatchDivInfo").innerHTML="A "+fbname+" swatch has already been added to your cart."
	document.getElementById("SwatchDiv").style.visibility="visible";
	}
	
	fillShopCart();
	
	
	}
	
	function getCookieArray(name){
		var i = 0;
        while (readCookie(name + i) != null) {
        this[i + 1] = readCookie(name + i);
        i++; this.length = i; 
        }
}


function delCookieArray(sindex,items){
		
		for(var x=0;x<items;x++)
		{
       eraseCookie("shopCart"+sindex+x);
        }
	
		
	

fillShopCart();
document.getElementById("shpname").innerHTML="";
	document.getElementById("shpprice").innerHTML="";
	document.getElementById("Gtotal").innerHTML="";
	document.getElementById("Checkout").innerHTML="<form id='ChkShp' method='POST' action='"+MainAddress+"FText.php5?Director=SetShip&qty="+chkQty()+"'><input type='submit' value='Check Shipping'></form>";
}

function delCookieArray2(){
		
		for(var y=0;y<=globalIndex;y++)
		{
		for(var x=0;x<7;x++)
		{
       eraseCookie("shopCart"+y+x);
        }
		
		//document.write(globaIndex+"\n"+x);
		}
		
	

fillShopCart();
calPP();
}


function setupdateCookieArray(divname,sindex,items,evalindex){
document.getElementById(divname).style.visibility='visible';
updateCookieArray(sindex,items,evalindex);
}
function updateCookieArray(sindex,items,evalindex){
	if(evalindex==1)
	{
	var JavaCommand1="var value=document.frmShopList"+sindex+".quant.value";
	}
	else
	{
	var JavaCommand1="var value=document.frmShopCart.yards.value";
	}
	eval(JavaCommand1);
	//alert(value);
	createCookie("shopCart"+sindex+items,value,1);        
	fillShopCart();
	document.getElementById("shpname").innerHTML="";
	document.getElementById("shpprice").innerHTML="";
	document.getElementById("Gtotal").innerHTML="";
	document.getElementById("Checkout").innerHTML="<form id='ChkShp' method='POST' action='"+MainAddress+"FText.php5?Director=SetShip&qty="+chkQty()+"'><input type='submit' value='Check Shipping'></form>";
	
	//calPP();
}
<!--New Fabric Design-->
function checkEnter(e,form1,preform1){ //e is event object passed from function invocation
var characterCode //literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
if(form1=="frmJoin")
validateJoin(form1,preform1);//submit the form
else if(form1=="frmSearch")
validateSearch(form1,preform1);//submit the form
else if(form1=="frmUserLogin")
validateLogin(form1,preform1);//submit the form
else if(form1=="frmFP")
validateFP(form1,preform1);//submit the form
return false
}
else{
return true
}

}

function ShipChoice(){
	
var tempship=document.Shpform.shipRates.options[document.Shpform.shipRates.selectedIndex].value;

var temp = new Array();
temp = tempship.split('@');
//document.getElementById("shpname").innerHTML="Method: "+temp[0];
shipping=(temp[1]*1);
shiptype=temp[0];
gTotal=subtotal+shipping;

document.getElementById("ShipDiv").style.visibility="hidden";

fillShopCart();
calPP();
}
		

function chgBack(divname,bcol,fcol)
{
document.getElementById(divname).style.backgroundColor=bcol;
document.getElementById(divname).style.color=fcol;
	
}
