//var shiprate = 0;
//var priorityrate = .1;
// Don't edit below this line!

// Check Browser Disabled COOKIE
try{ 
	var D=new Date(),CK="CK="+D.getTime();
	document.cookie=CK;
	if(document.cookie.indexOf(CK)==-1){ 
		document.location="cookieDisabled.php"
	}
}catch(e){}

// Browser Detection Variables
var nsbrowser=false;
var ns4browser=false;
if ((navigator.appName.indexOf("Netscape") != -1))
	nsbrowser=true;
if ((navigator.appName.indexOf("Netscape") != -1) && (parseInt(navigator.appVersion, 10) == "4"))
	ns4browser=true;
var DefColor=new Array();
var DefFabDesc=new Array();
var CheckedColor=new Array();

function addbookmark(){
var bookmarkurl="http://www.mycustomclothing.com/";
var bookmarktitle="My Custom Clothing";
if (!nsbrowser)
	window.external.AddFavorite(bookmarkurl,bookmarktitle);
else
	alert("Your browsers does not support automatically setting bookmarks.  To bookmark this site, click on the menu item Bookmarks -> Add Bookmark");
}

function emailfriend(){
var popupWin = window.open('http://www.mycustomclothing.com/extras/emailfriend.htm','emailfriend','toolbar=no,directories=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=350,height=300,left=15,top=15,screenX=15,screenY=15');
}

function callme(){
var popupWin = window.open('http://www.mycustomclothing.com/extras/callme.htm','callme','toolbar=no,directories=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=350,height=300,left=15,top=15,screenX=15,screenY=15');
}

function linktous(){
var popupWin = window.open('http://www.mycustomclothing.com/extras/linktous.htm','linktous','toolbar=no,directories=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=350,height=300,left=15,top=15,screenX=15,screenY=15');
}

function fashions(){
var popupWin = window.open('http://www.mycustomclothing.com/extras/fashiontv.htm','fashion','toolbar=no,directories=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=350,height=300,left=15,top=15,screenX=15,screenY=15');
}

function subscribe(){
var popupWin = window.open('http://www.mycustomclothing.com/extras/subscribe.htm','subscribe','toolbar=no,directories=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=770,height=700,left=15,top=15,screenX=15,screenY=15');
}

function trim(value) {
  while (value.substring(0,1) == ' ') {
    value = value.substring(1,value.length);
  }
  while (value.substring(value.length-1,value.length) == ' ') {
    value = value.substring(0,value.length-1);
  }
  return value;
}
/*
function Converter(){
	var amount=parseInt(document.forms[0].Amount.value);
	var shpr=amount*shiprate;
	if (document.forms[0].shiptype[1].checked){
		shpr=amount*(shiprate+priorityrate);
	}
	var amt=amount+shpr;
	if(isNaN(amt)){amt=1;}
	var URL="currency.php?amount="+amt+"&from="+document.forms[0].Currency.value+"&to="+document.forms[0].to.options[document.forms[0].to.options.selectedIndex].value+"";
	var popupWin = window.open(URL,'CurrencyConverter','toolbar=no,directories=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=450,height=250,left=15,top=15,screenX=15,screenY=15');
}
*/
function Converter(){
	amount=parseInt(document.forms[0].Amount.value);
	var URL="currency.php?amount="+amount+"&from="+document.forms[0].Currency.value+"&to="+document.forms[0].to.options[document.forms[0].to.options.selectedIndex].value+"";
	popupWin = window.open(URL,'CurrencyConverter','toolbar=no,directories=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=450,height=250,left=15,top=15,screenX=15,screenY=15');
}

function openWindow(url) {
 var popupWin = window.open(url,'remote','toolbar=no,directories=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+(screen.width-150)+',height='+(screen.height-220)+',left=15,top=15,screenX=15,screenY=15');
}

function GetValue(name) {
 var result = null;
 var myCookie = " " + document.cookie + ";";
 var searchName = " " + name + "=";
 var startOfCookie = myCookie.indexOf(searchName);
 var endOfCookie;
 if (startOfCookie != -1) {
  startOfCookie += searchName.length; // skip past name of cookie
  endOfCookie = myCookie.indexOf(";", startOfCookie);
  result = unescape(myCookie.substring(startOfCookie, endOfCookie));
 }
 return result;
}

function SetValue(name, value) {
var never = new Date();
never.setTime(never.getTime() + 7*24*60*60*1000); // Keep cookie for 7 days
var expString = "; expires=" + never.toGMTString();
document.cookie = name + "=" + escape(value) + expString;
}

function ClearValue(name) {
var never = new Date();
never.setTime(never.getTime() - 5*24*60*60*1000); // Set cookie date for 5 days ago
var expString = "; expires=" + never.toGMTString();
document.cookie = name + "=" + null + expString;
}

function ClearOrder(){
	/*
ClearValue("TotPrice");
ClearValue("ShipPrice");
ClearValue("Order");
ClearValue("Requests");
ClearValue("Accessories");
ClearValue("OrderID");
ClearValue("Gifts");
ClearValue("Certificates");
*/
	ClearValue("Referrers");
}

function FindSource(){
var preldImg=new Image();
preldImg.src="images/button2.gif";
var preldImg2=new Image();
preldImg2.src="images/newfab.gif";
var preldImg3=new Image();
preldImg3.src="images/addtocart.gif";
var preldImg4=new Image();
preldImg4.src="images/unchecked.gif";
var preldImg5=new Image();
preldImg5.src="images/checked.gif";
var preldImg6=new Image();
preldImg6.src="images/visited.gif";
var preldImg7=new Image();
preldImg7.src="images/winclose.gif";
var preldImg8=new Image();
preldImg8.src="images/continue.gif";
var preldImg9=new Image();
preldImg9.src="images/checkout.gif";

var RefValue=document.referrer;
	if ((RefValue != "") && (RefValue.indexOf("www.mycustomclothing.com") == -1)){
		SetValue("Referrers",RefValue);
	}
}

function SwatchLayer(laynumb,fabnum,ColorString,FabDesc,FabDetails,LargeImgString){
	var ColorChoice=new Array();
	var LargeImg=new Array();
	FabDesc=FabDesc.replace("'","");
	ColorChoice=ColorString.split(",");
	LargeImg=LargeImgString.split(",");
	DefColor[laynumb]=ColorChoice[0];
	DefFabDesc[laynumb]=FabDesc;
	CheckedColor[laynumb]=1;
	if (!ns4browser){
		document.write("<div id='fabview"+laynumb+"' style='position: absolute; z-index: 1; visibility: hidden; top: 280px; left: 115px;'>");
	}else{
		document.write("<layer name='fabview"+laynumb+"' z-index='1' top='280' left='115' visibility='hide'>");
	}
	document.write("<table border='0' cellpadding='0' cellspacing='0' bgcolor='#000000' style='margin-top:120px'><tr><td><table border='0' cellpadding='0' cellspacing='0' width='170'><tr><td align='right' bgcolor='#000000'><a href='javascript:HideSwatches("+laynumb+");'><img src='images/winclose.gif' border='0' width='16' height='14' hspace='2' vspace='2' alt='Close Palette'></a></td></tr></table><table width='170' border='0' cellpadding='3' cellspacing='2'><tr><td class='boxcenter'><div align='center'><b>"+FabDesc+"</b><br><span style='font-size:8pt;'><i>"+FabDetails+"</i></span></div>");
	document.write("<table border='0' cellpadding='0' cellspacing='2'>");
	for (i=1; i<ColorChoice.length+1; i++){
		document.write("<tr valign='top'>");
		document.write("<td><a href='javascript:location.href=&quot;#home&quot;;PlaceSwatch("+fabnum+",&quot;"+ColorChoice[i-1]+"&quot;,&quot;"+FabDesc+"&quot;);' onclick='javascript:CheckBoxes("+i+","+laynumb+");'><img name='clrbtn_"+laynumb+"_"+i+"' src='images/unchecked.gif' width='17' height='17' alt='"+ColName[ColorChoice[i-1]]+"' border='0'></a></td>");
		document.write("<td valign='bottom'><a href='javascript:location.href=&quot;#home&quot;;PlaceSwatch("+fabnum+",&quot;"+ColorChoice[i-1]+"&quot;,&quot;"+FabDesc+"&quot;);' class='extras' onclick='javascript:CheckBoxes("+i+","+laynumb+");'>"+ColName[ColorChoice[i-1]]+"</a></td>");
		document.write("<td valign='bottom'>");
		if(LargeImg[i-1]==1){
			document.write("<a href='javascript:location.href=&quot;#home&quot;;PlaceSwatch("+fabnum+",&quot;"+ColorChoice[i-1]+"&quot;,&quot;"+FabDesc+"&quot;);' class='extras' style='color:blue' onclick='javascript:CheckBoxes("+i+","+laynumb+");var myWin=window.open(\"preview-altimages.php?condition=Fabric&refcode="+fabnum+"-"+ColorChoice[i-1]+"\",\"AlternateImages\",\"toolbar=no,directories=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=700,height=600,left=15,top=15,screenX=15,screenY=15\");myWin.focus();'><img src='images/largeimg.png' border='0' width='62' height='14'></a>");
		}else{
			document.write("&nbsp;");
		}
		document.write("</td>");
		document.write("</tr>");
	}
	document.write("</table>");
	document.write("<p>Click on a color to view an image of it and add it to your order.</p></td></tr></table></td></tr></table>");
	if (!ns4browser){
		document.write("</div>");
	}else{
		document.write("</layer>");
	}
	CheckBoxes(1,laynumb);
}

function CheckBoxes(newboxno,fn){
	eval("document.clrbtn_"+fn+"_"+CheckedColor[fn]).src="images/unchecked.gif";
	eval("document.clrbtn_"+fn+"_"+newboxno).src="images/checked.gif";
	CheckedColor[fn]=newboxno;
}

function FabCheckBoxes(fn){
if (CheckedFabric != 0)
	eval("document.fab"+CheckedFabric).src="images/visited.gif";
eval("document.fab"+fn).src="images/checked.gif";
CheckedFabric=fn;
}

function HideSwatches(laynumb){
if (!ns4browser)
	document.getElementById("fabview"+laynumb).style.visibility="hidden";
else
	document.eval("fabview"+laynumb).visibility="hide";
}

function ShowSwatches(laynumb,fabnum){
	if (InView != 0){
		HideSwatches(InView);
	}
	InView=laynumb;

	if (!ns4browser){
		document.getElementById("fabview"+laynumb).style.visibility="visible";
	}else{
		document.eval("fabview"+laynumb).visibility="show";
	}
	PlaceSwatch(fabnum,DefColor[laynumb],DefFabDesc[laynumb]);
}

function PlaceSwatch(fn,cn,fd){
	//XMLRequest();
	FabricDesc=fd;
	FabricNum=fn;
	FabricColor=cn;
	/*
	http_request.open("HEAD", "images/fabrics/"+fn+"-"+cn+".jpg", false);
	http_request.send(null);
	if(http_request.status==200){
		document.swatch.src="images/fabrics/"+fn+"-"+cn+".jpg";
	}else{
		document.swatch.src="images/fabrics/file_blank.jpg";
	}
	*/
	document.swatch.src="images/fabrics/"+fn+"-"+cn+".jpg";
	document.addtocart.src="images/addtocart.gif";
	DefColor[fn]=cn;
	document.forms[0].finfo.value="Fabric: #"+fn;
	document.forms[0].cinfo.value="Color: "+ColName[cn];
	document.forms[0].Fabric_ID.value=FabricNum;
	document.forms[0].Fabric_Name.value=FabricDesc;
	document.forms[0].Color_Code.value=FabricColor;
	document.forms[0].Color_Name.value=ColName[FabricColor];
}


function check_string(str_value){
	var badChars="@~-=_%$#!&*^()/.,;:?[]{}<>+\"\'\\|";
	var noBadChars=true;
	//---loop check Chars
	for (i=0; i<str_value.length; i++){
		if(badChars.indexOf(str_value.substring(i,i+1))!=-1){
			noBadChars=false;
			break;
		}
	}
	return noBadChars;
	//--end loop check Chars
}

function OnlyValidChars(validchars,teststring){
var newstring="";
for (i=0;i<teststring.length; i++)
	if (validchars.indexOf(teststring.substring(i,i+1)) != -1)
		newstring+=teststring.substring(i,i+1);
return newstring;
}

function RemoveCharacters(FromString,CharsToGo,CharsToPut){
	if (FromString == "")
		return FromString;
var tempvar=FromString.split(CharsToGo);
FromString = tempvar[0];
for (i=1; i<tempvar.length; i++)
	FromString += CharsToPut+tempvar[i];
return FromString;
}

function AddItem(goNext){
	var allreq=new Array();
	var setnewreq="";
	//var ShopArray=new Array();
	var CountTotChars=0;
	//ShopArray=GetValue("shopnames").split("|");
	//for (i=0; i<(ShopArray.length-1); i++){
		//var snam=ShopArray[i].split("=")[0];
		//var snum=ShopArray[i].split("=")[1];
		//CountTotChars+=ShopArray[i].length+1;
		//if (snum == ShopNum)
		//	ShopName=snam;
		//}
if (FabricNum == 0)
	alert("Please choose a fabric and color first");
else{
	getreqval=GetValue("Order");
	var updatefabric=false;
	if (getreqval == null)
		getreqval="";
	CountTotChars+=getreqval.length;
	TmpValue=GetValue("Requests");
	if (TmpValue == null)
		TmpValue="";
	CountTotChars+=TmpValue.length;
	TmpValue=GetValue("Accessories");
	if (TmpValue == null)
		TmpValue="";
	CountTotChars+=TmpValue.length;
	TmpValue=GetValue("Gifts");
	if (TmpValue == null)
		TmpValue="";
	CountTotChars+=TmpValue.length;
	TmpValue=GetValue("Referrers");
	if (TmpValue == null)
		TmpValue="";
	CountTotChars+=TmpValue.length;
	// uncomment these lines to set limit to size of shopping cart
	//if(CountTotChars > 2000){
		//alert(CountTotChars+" Characters. Your Shopping Cart is Full!\n\nTo continue shopping, we recommend that you first check out.  Any remaining items you wish to purchase can be placed in an additional order which will be shipped at the same time and under the same consignment number.\n\nClick OK to continue with the checkout process.");
		//document.location="securepay.php";
		//return;
		//}
StyleName=""; // remove this line to put style name in shopping cart
	allreq=getreqval.split("~");
	for (i=0; i<(allreq.length-1); i++){
		if(allreq[i].split("|")[0] != RefID){
			setnewreq+=allreq[i]+"~";
		}
		else{
			updatefabric=true;
			setnewreq+=RefID+"|"+CatName+"|"+catID+"|"+StyleName+"|"+StyleNum+"|"+FabricDesc+"|"+FabricNum+"|"+ColName[FabricColor]+"|"+FabricColor+"|"+ItemPrice+"|1~"
		}
	}
	if (updatefabric){
		SetValue("Order",setnewreq);
	}
	else {
		SetValue("Order",setnewreq+RefID+"|"+CatName+"|"+catID+"|"+StyleName+"|"+StyleNum+"|"+FabricDesc+"|"+FabricNum+"|"+ColName[FabricColor]+"|"+FabricColor+"|"+ItemPrice+"|1~");
	}
	//if(goNext == 1)
		//history.back();
	//else
		//self.location="buyingfor.php?RefID="+RefID+"&catID="+catID+"&updateValue=0&FabricNum="+FabricNum;
		Color = ColName[FabricColor];
		//document.forms[0].submit(); 
		//self.location="buyingfor.php?RefID="+RefID+"&catID="+catID+"&updateValue=0&FabricNum="+FabricNum+"&Color="+Color;
	}
}

function RemoveItem(numb){
	var allreq=new Array();
	var setnewreq="";
	var getreqval=GetValue("Order");
if (getreqval == null)
	getreqval="";
allreq=getreqval.split("~");
for (i=0; i<(allreq.length-1) ; i++)
	if (allreq[i].split("|")[0].indexOf(numb) == -1)
		setnewreq+=allreq[i]+"~";
if (setnewreq == ""){
	ClearValue("Order");
	ClearValue("Requests");
	ClearValue("Accessories");
	ClearValue("Gifts");
	self.location.reload();
	}
else
	SetValue("Order",setnewreq);
setnewreq="";
//######### Changes for the Request cookie #####
getreqval=GetValue("Requests");
if (getreqval == null)
	getreqval="";
allreq=getreqval.split(",");
for (i=0; i<(allreq.length-1) ; i++)
	if (allreq[i] != numb)
		setnewreq+=allreq[i]+",";
if (setnewreq == "")
	ClearValue("Requests");
else
	SetValue("Requests",setnewreq);
//##############################################
setnewreq="";
getreqval=GetValue("Accessories");
if (getreqval == null)
	getreqval="";
allreq=getreqval.split("~");
for (i=0; i<(allreq.length-1) ; i++)
	if (allreq[i].split("|")[0] != numb)
		setnewreq+=allreq[i]+"~";
if (setnewreq == "")
	ClearValue("Accessories");
else
	SetValue("Accessories",setnewreq);
setnewreq="";
getreqval=GetValue("Gifts");
if (getreqval == null)
	getreqval="";
allreq=getreqval.split("~");
for (i=0; i<(allreq.length-1) ; i++)
	if (allreq[i].split("|")[0] != numb)
		setnewreq+=allreq[i]+"~";
if (setnewreq == "")
	ClearValue("Gifts");
else
	SetValue("Gifts",setnewreq);
self.location.reload();
}

function RemoveCert(CertID){
var allreq=new Array();
var setnewreq="";
var getreqval=GetValue("Certificates");
if (getreqval == null)
	getreqval="";
allreq=getreqval.split("~");
for (i=0; i<(allreq.length-1) ; i++)
	if (allreq[i].split("|")[0] != CertID)
		setnewreq+=allreq[i]+"~";
if (setnewreq == "")
	ClearValue("Certificates");
else
	SetValue("Certificates",setnewreq);
self.location.reload();
}

function SelectAccessory(acnum,acvalue){
var imgtochange="";
imgtochange="access"+acnum;

if (document.forms[0].elements[acnum-1].value == ""){
	document.images[imgtochange].src="images/checked.gif";
	document.forms[0].elements[acnum-1].value=acvalue;
}else{
	document.images[imgtochange].src="images/unchecked.gif";
	document.forms[0].elements[acnum-1].value="";
	}
}

function AddAccessories(ref,goNext){
var sprq=ref;
var allreq=new Array();
var setnewreq="";
for (i=0; i<(document.forms[0].elements.length-1); i++)
	if (document.forms[0].elements[i].value != "")
		sprq+="|"+document.forms[0].elements[i].value+"^1";
getreqval=GetValue("Accessories");
if (getreqval == null)
	getreqval="";
allreq=getreqval.split("~");
for (i=0; i<(allreq.length-1); i++)
	if(allreq[i].split("|")[0] != ref)
		setnewreq+=allreq[i]+"~";
if (sprq != ref)
	setnewreq+=sprq+"~";
SetValue("Accessories",setnewreq);
if(goNext == 1)
	history.back();
else
	self.location="continue.php?catID="+categoryID;
}

function AddGift(ref){
var ProfValue=0;
for(i=0; i<document.forms[0].BuyFor.length; i++)
	if (document.forms[0].BuyFor[i].selected)
		ProfValue=document.forms[0].BuyFor[i].value;
var allreq=new Array();
var setnewreq="";
var getreqval=GetValue("Gifts");
if (getreqval == null)
	getreqval="";
allreq=getreqval.split("~");
for (i=0; i<(allreq.length-1); i++)
	if(allreq[i].split("|")[0] != ref)
		setnewreq+=allreq[i]+"~";
if (ProfValue != 0)
	setnewreq+=ref+"|"+ProfValue+"~";
if (setnewreq == "")
	ClearValue("Gifts");
else
	SetValue("Gifts",setnewreq);
}

function AddCertificate(){
var getunique=new Date().valueOf();
	CertID="CCLGC"+parseInt(getunique/100);
getreqval=GetValue("Certificates");
if (getreqval == null)
	getreqval="";
if (document.forms[0].Visit[0].checked)
	LnkTxt=document.forms[0].Visit[0].value;
else
	LnkTxt=document.forms[0].Visit[1].value;
SetValue("Certificates",getreqval+CertID+"|"+document.forms[0].ForName.value+"|"+document.forms[0].ForEmail.value+"|"+document.forms[0].Message.value+"|"+LnkTxt+"|"+document.forms[0].CertAmt.value+"|1~");
}

function ShoppingCart(allowedit){
if (!ns4browser)
	document.write("<div id='shoppingcart' style='position: absolute; z-index: 2; visibility: hidden; top: 15px; left: 5px;'>");
else
	document.write("<layer name='shoppingcart' left='5' top='15' z-index='2' visibility='hide'>");
var TPrc=0;
document.write("<table border='0' cellspacing='2' cellpadding='0' bgcolor='#000000'><tr><td><table width='600' border='0' cellspacing='0' cellpadding='1'>");
document.write("<tr><td align='right' bgcolor='#395594'><a href='javascript:HideCart();'><img src='images/winclose.gif' width='16' height='14' alt='Close Shopping Cart' border='0'></a></td></tr>");
var OrderItems=new Array();
var CertItems=new Array();
var RequestItems=new Array();
var AccessItems=new Array();
var TotAccess=GetValue("Accessories");
var TotOrder=GetValue("Order");
var TotCerts=GetValue("Certificates");
var TotRequest=GetValue("Requests");
var TotGift=GetValue("Gifts");
if (TotAccess != null)
	AccessItems=TotAccess.split("~");
//############### Changes for database implementation of Request Cookie #########
if (TotRequest != null)
	RequestItems=TotRequest.split(",");
//###############################################################################
if (TotGift != null)
	GiftItems=TotGift.split("~");
if ((TotOrder == null) && (TotCerts == null))
	document.write("<tr><td align='center' class='evenrow'><br><br><b>Your Cart is Empty!</b><br><br><br></td></tr>");
var k=0;
var k2=0;
if (TotOrder != null){
	OrderItems=TotOrder.split("~");
	for (k=0; k<(OrderItems.length-1); k++){
		var IPrc=0;
		var ItemParts=new Array();
		ItemParts=OrderItems[k].split("|");
		IPrc=parseInt(ItemParts[9])*parseInt(ItemParts[10]);
		if (k%2 == 0)
			evenodd="evenrow";
		else
			evenodd="oddrow";
		GiftText="";
		if (TotGift != null){
			for(j=0; j<(GiftItems.length-1); j++){
				if (GiftItems[j].split("|")[0] == ItemParts[0]){
					GiftText=" <a href='#' onClick=\"javascript:window.open('popup_mid.php?mid="+GiftItems[j].split("|")[1]+"','MID','width=220,height=100')\"><span class='note'> For Profile No."+GiftItems[j].split("|")[1]+" </span> <img src='images/b_help.png' border='0' width='16' height='16' alt='Click here to view Name'></a>";
				}
			}
		}
		if((GiftText=="")&&((ItemParts[0].indexOf("-") != -1)||(ItemParts[0].substring(0,3) != "PKG")&&(ItemParts[0].substring(0,2) != "FA"))){
			GiftText="<b>* For Self *</b>";
		}
		document.write("<tr><td class='"+evenodd+"'><table border='0' cellpadding='0' cellspacing='0'><tr><td colspan='2'><b>"+ItemParts[1]+"</b> "+GiftText+"</td></tr>");
		if (ItemParts[0].indexOf("-") == -1){
			document.write("<tr valign='top'><td>&nbsp;&middot;&nbsp;Qty/Price:</td><td>"+ItemParts[10]+" @ US$ "+ItemParts[9]);
			if (allowedit == 1)
				document.write(" &nbsp;&nbsp;<a href='javascript:ChangeQuantity(&quot;"+ItemParts[0]+"&quot;,"+0+");' class='extras'> Change Quantity</a>");
			document.write("</td></tr>");
			}
		if ((ItemParts[0].substring(0,3) != "PKG")||(ItemParts[0].indexOf("-") != -1)){ // if not package offer
		document.write("<tr valign='top'><td>&nbsp;&middot;&nbsp;Style:</td><td>"+ItemParts[3]+" "+ItemParts[4]+"</td></tr>");
		document.write("<tr valign='top'><td>&nbsp;&middot;&nbsp;Fabric:</td><td>"+ItemParts[6]+"&nbsp;"+ItemParts[7]+"</td></tr>");
		document.write("<tr valign='top'><td>&nbsp;&middot;&nbsp;Requests:</td><td>");
		var ReqestText="None";
		var accessflag=0;
		//############### Changes for database implementation of Request Cookie #########
		if (TotRequest != null)
			for(j=0; j<(RequestItems.length-1); j++)
				if (RequestItems[j] == ItemParts[0])
					ReqestText="<a href='#' onClick=\"javascript:window.open('popup_request_cookie.php?req_id="+RequestItems[j]+"','mywindow','width=400,height=200,scrollbars=yes,resizable=yes')\">Click here to view</a>";
		//###############################################################################
		document.write(ReqestText+"</td></tr>");
		document.write("<tr valign='top'><td>&nbsp;&middot;&nbsp;Accessories:</td><td>");
		if (TotAccess != null){
			for(j=0; j<(AccessItems.length-1); j++)
				if (AccessItems[j].split("|")[0] == ItemParts[0])
					for (j2=1; j2<AccessItems[j].split("|").length; j2++){
						accessflag=1;
						document.write(AccessItems[j].split("|")[j2].split("^")[0]+" ("+AccessItems[j].split("|")[j2].split("^")[2]+" @ US$ "+AccessItems[j].split("|")[j2].split("^")[1]+")");
						if (allowedit == 1)
							document.write(" &nbsp;&nbsp;<a href='javascript:ChangeQuantity(&quot;"+AccessItems[j].split("|")[0]+"&quot;,"+j2+");' class='extras'> Change Quantity</a>");
						document.write("<br>");
						IPrc+=parseInt(AccessItems[j].split("|")[j2].split("^")[1]) * parseInt(AccessItems[j].split("|")[j2].split("^")[2]);
						}
			}
		if (accessflag == 0)
			document.write("None");
		document.write("</td></tr>");
		} // end of if not package offer
		if (IPrc != 0)
			document.write("</table><div align='right'><b>Total for Item: US$ "+IPrc+"&nbsp;</b></div>");
		else
			document.write("</table><div align='right'><b>&nbsp;</b></div>");
		if (allowedit == 1){
			document.write("<table width='100%'><tr align='center'>");
			if ((ItemParts[0].substring(0,3) != "PKG")&&(ItemParts[0].substring(0,2) != "FA")||(ItemParts[0].indexOf("-") != -1)){
				document.write("<td><a href='buyingfor.php?RefID="+ItemParts[0]+"&catID="+ItemParts[2]+"&styleID="+ItemParts[4]+"&updateValue=1' class='extras'>Edit Profile to use</a></td>");
				if ((ItemParts[0].substring(0,3) != "CMT")){// Remove Link For CMT Order
				document.write("<td><a href='fabrics.php?RefID="+ItemParts[0]+"&styleID="+ItemParts[4]+"&updateValue=1' class='extras'>Edit Fabric/Color</a></td>");
					}//End Remove Link For CMT Order
				document.write("<td><a href='requests.php?RefID="+ItemParts[0]+"&catID="+ItemParts[2]+"&updateValue=1' class='extras'>Edit Requests</a></td>");
				document.write("<td><a href='accessories.php?RefID="+ItemParts[0]+"&catID="+ItemParts[2]+"&updateValue=1' class='extras'>Edit Accessories</a></td>");
				}// end of if not package offer
			if (ItemParts[0].indexOf("-") != -1)
				document.write("</tr></table>");
			else
				document.write("<td><a href='javascript:RemoveItem(&quot;"+ItemParts[0]+"&quot;);' class='extras'>Remove Item</a></td></tr></table>");
			}
		document.write("</td></tr>");
		TPrc+=IPrc;
		}
	} //end if totorder is not null
if (TotCerts != null){
	CertItems=TotCerts.split("~");
	for (k2=0; k2<(CertItems.length-1); k2++){
		if ((k2+k)%2 == 0)
			evenodd="evenrow";
		else
			evenodd="oddrow";
		document.write("<tr><td class='"+evenodd+"'><table border='0' cellpadding='0' cellspacing='0'><tr><td colspan='2'><b>Gift Certificate</b></td></tr><tr><td>&nbsp;&middot;&nbsp;Amount:</td><td> US$ "+CertItems[k2].split("|")[5]+"</td></tr><tr><td>&nbsp;&middot;&nbsp;Recipient:</td><td>"+CertItems[k2].split("|")[1]+"</td></tr><tr><td>&nbsp;&middot;&nbsp;Send To:</td><td>"+CertItems[k2].split("|")[2]+"</td></tr><tr><td>&nbsp;&middot;&nbsp;Message:</td><td>"+CertItems[k2].split("|")[3]+"</td></tr><tr><td>&nbsp;&middot;&nbsp;Link to:</td><td>"+CertItems[k2].split("|")[4]+"</td></tr></table><div align='right'><b>Total for Item: US$ "+CertItems[k2].split("|")[5]+"&nbsp;</b></div>");
		if (allowedit == 1)
			document.write("<table width='100%'><tr align='center'><td><a href='javascript:RemoveCert(&quot;"+CertItems[k2].split("|")[0]+"&quot;);' class='extras'>Remove This Gift Certificate</a></td></tr></table>");
		document.write("</td></tr>");
		TPrc+=parseInt(CertItems[k2].split("|")[5]);
		}
	}
if ((TotOrder != null) || (TotCerts != null)){
	if ((k2+k)%2 == 0)
		evenodd="evenrow";
	else
		evenodd="oddrow";
	document.write("<tr><td align='right' class='"+evenodd+"'><table><tr><td><b>Sub-Total:</td><td align='right'><b>"+MoneyFormat(TPrc)+"</b></td></tr><tr><td><b>Shipping:</td><td align='right'><b>"+MoneyFormat(TPrc*shiprate)+"</b></td></tr><tr><td><img src='images/clrpix.gif' width='1' height='1' alt='' border='0'></td><td><hr></td></tr><tr><td><b>Total:</td><td align='right'><b>"+MoneyFormat(TPrc+(TPrc*shiprate))+"</b></td></tr></table></td></tr>");
	}
document.write("<tr><td align='center' bgcolor='#395594'>");
if (allowedit == 0)
	document.write("<span style='color:#ffffff;'>Click on Continue to check out. To make changes, click on your browser back button and then click the shopping cart icon on the top right.</span><br>");
if (allowedit == 1)
	document.write("<a href='securepay.php?Cart'><img src='images/checkout.gif' width='150' height='20' alt='Checkout' border='0' hspace='10'></a> &nbsp;");
document.write("<a href='#' onclick='javascript:HideCart();'><img src='images/continue.gif' width='150' height='20' alt='Close Cart and Continue Shopping' border='0' hspace='10'></a></td></tr></table></td></tr></table>");
SetValue("TotPrice",TPrc);
SetValue("ShipPrice",(TPrc*shiprate));
if (!ns4browser)
	document.write("</div>");
else
	document.write("</layer>");
}

function HideCart(){
if (!ns4browser){
	document.getElementById("shoppingcart").style.visibility="hidden";
	if (document.getElementById("formlayer"))
		document.getElementById("formlayer").style.visibility="visible";
	}
else {
	document.shoppingcart.visibility="hide";
	if (document.formlayer)
		document.formlayer.visibility="show";
	}
}

function ShowCart(){
if (!ns4browser){
	document.getElementById("shoppingcart").style.visibility="visible";
	if (document.getElementById("formlayer"))
		document.getElementById("formlayer").style.visibility="hidden";
	}
else {
	document.shoppingcart.visibility="show";
	if (document.formlayer)
		document.formlayer.visibility="hide";
	}
}

function OpenPopUpOpen(URL, wwidth, wheight) {
alert;
	window.open(URL,'infopopup','toolbar=no,directories=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width='+wwidth+',height='+wheight+',left=50,top=50,screenX=50,screenY=50');
}

function SameAddress(same){
if (same){
	document.forms[0].BillingFirstName.value=document.forms[0].FirstName.value;
	document.forms[0].BillingLastName.value=document.forms[0].LastName.value;
	document.forms[0].BillingPhone.value=document.forms[0].Phone.value;
	document.forms[0].BillingAddress.value=document.forms[0].Address.value;
	document.forms[0].BillingCity.value=document.forms[0].City.value;
	document.forms[0].BillingProvince.value=document.forms[0].Province.value;
	document.forms[0].BillingCountry.value=document.forms[0].Country.value;
	document.forms[0].BillingZip.value=document.forms[0].ZipCode.value;
	}
}

function MoneyFormat(amt){
var amtstring="US$ "+amt;
if (amtstring.indexOf(".") == -1)
	amtstring+=".00";
else{
	var cents=amtstring.split(".");
	if (cents[1].length == 1)
		cents[1]+="0";
	else
		cents[1]=cents[1].substring(0,2);
	amtstring=cents[0]+"."+cents[1];
	}
return amtstring;
}

function ChangeQuantity(itemNo,posNo){
var TotList="";
if (posNo == 0){ // It's the main item
	TotList=GetValue("Order");
	IndivItems=TotList.split("~");
	TotList="";
	for (k=0; k<(IndivItems.length-1); k++){
		var ItemParts=new Array();
		ItemParts=IndivItems[k].split("|");
		if (itemNo == ItemParts[0]){
			newQty=parseInt(prompt("You currently have "+ItemParts[10]+" "+ItemParts[1]+" at a price of $"+ItemParts[9]+" each.\nChange quantity to:",(parseInt(ItemParts[10])+1)));
			if (!(0 < newQty))
				newQty=ItemQty;	TotList+=ItemParts[0]+"|"+ItemParts[1]+"|"+ItemParts[2]+"|"+ItemParts[3]+"|"+ItemParts[4]+"|"+ItemParts[5]+"|"+ItemParts[6]+"|"+ItemParts[7]+"|"+ItemParts[8]+"|"+ItemParts[9]+"|"+newQty+"~";
			}
		else
			TotList+=IndivItems[k]+"~";
		}
	SetValue("Order",TotList);
	document.location=document.location.href;
	}
else{ // It's an accessory
	TotList=GetValue("Accessories");
	IndivItems=TotList.split("~");
	TotList="";
	for (k=0; k<(IndivItems.length-1); k++){
		var ItemParts=new Array();
		ItemParts=IndivItems[k].split("|");
		if (itemNo == ItemParts[0]){
			TotList+=ItemParts[0];
			for (j=1; j<(ItemParts.length); j++){
				if(j != posNo)
					TotList+="|"+ItemParts[j];
				else{
					var SubParts=new Array();
					SubParts=ItemParts[j].split("^");
					newQty=parseInt(prompt("You currently have "+SubParts[2]+" "+SubParts[0]+" at a price of $"+SubParts[1]+" each.\nChange quantity to:",(parseInt(SubParts[2])+1)));
					if (!(0 < newQty))
						newQty=SubParts[2];
					TotList+="|"+SubParts[0]+"^"+SubParts[1]+"^"+newQty;
					}
				}
			TotList+="~";
			}
		else
			TotList+=IndivItems[k]+"~";
		}
	SetValue("Accessories",TotList);
	document.location=document.location.href;
	}
}

function IsFormComplete(){
var x = 0;
var FormOk  = true;
while ((x < document.forms[0].elements.length) && (FormOk)){
	 if ((document.forms[0].elements[x].value == "")&&(document.forms[0].elements[x].name != "PayBy")&&(document.forms[0].elements[x].name != "ShipBy")&&(document.forms[0].elements[x].name != "Free")){
       if((document.forms[0].elements[x].name=="PhoneDay")&&(document.forms[0].PhoneDay.value=="")){alert('Please enter the Daytime Phone and try again.');}
		else if((document.forms[0].elements[x].name=="PhoneEvening")&&(document.forms[0].PhoneEvening.value=="")){alert('Please enter the Evening Phone and try again.');}
			else if((document.forms[0].elements[x].name=="BillingPhoneDay")&&(document.forms[0].BillingPhoneDay.value=="")){alert('Please enter the Billing Daytime Phone and try again.');}
				else if((document.forms[0].elements[x].name=="BillingPhoneEvening")&&(document.forms[0].BillingPhoneEvening.value=="")){alert('Please enter the Billing Evening Phone and try again.');}
					else{alert('Please enter the '+document.forms[0].elements[x].name +' and try again.');}
        document.forms[0].elements[x].focus();
        FormOk = false;
     	}
    x++;
   }
return FormOk;
}

function sendOrder(){
if (document.forms[0].Fax.value == "")
	document.forms[0].Fax.value=" ";
if (document.forms[0].BillingFax.value == "")
	document.forms[0].BillingFax.value=" ";
if (document.forms[0].PhoneMobile.value == "")
	document.forms[0].PhoneMobile.value=" ";
if (document.forms[0].BillingPhoneMobile.value == "")
	document.forms[0].BillingPhoneMobile.value=" ";
if (document.forms[0].OtherProvince.value == "")
	document.forms[0].OtherProvince.value=" ";
if (document.forms[0].BillingOtherProvince.value == "")
	document.forms[0].BillingOtherProvince.value=" ";
SetValue("email",document.forms[0].Email.value);
SetValue("realname",document.forms[0].FirstName.value+"|"+document.forms[0].LastName.value);
return IsFormComplete();
}

function MakeUniqueID(){
var getunique=new Date().valueOf();
	oid="CCL"+parseInt(getunique/100);
SetValue("OrderID",oid);
return oid;
}


function ReferrerOpenerMyacount(){
	var check_page=new Array('packageitems','cmtorder','buyingfor','wedding');//this name page
	var urlString=document.URL;
	var selectValue="";
	for(i=0;i<check_page.length;i++){
		if(urlString.indexOf(check_page[i]) !=-1){
			for(i=0;i<document.forms[0].elements.length;i++){
				if(document.forms[0].elements[i].type=="select-one"){
					selectValue+=document.forms[0].elements[i].value+"~";
				}
			}
			break;
		}
	}
	if(selectValue!=""){
		SetValue("ReferrerOpener",urlString);
		SetValue("ReferrerData",selectValue);
		SetValue("ReDirect","measurements");
	}else{
		ClearValue("ReferrerOpener");
		ClearValue("ReferrerData");
	}	
	url='mymeasurements-addprofile.php';
	window.open(url,'remote','toolbar=no,directories=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=540,height=220,left=15,top=15,screenX=15,screenY=15');
}


function GoOpener(page){
	if(window.opener && !window.opener.closed){
		if(window.opener.location==page){
			window.opener.location.reload();
		}else{
			window.opener.location=""+page+"";
		}
   }else{
		window.open(''+page+'','Customtailor','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width='+window.screen.width+',height='+window.screen.height+'');
   }
   window.close();
}


function setSelect(referrerprofiles,pageRef){
	var referrerdata=GetValue("ReferrerData");
	var referrerpage=GetValue("ReferrerOpener");
	var newOption = new Array();
	var num=0;

	if ((referrerdata != null)&&(referrerpage != null)&&(referrerpage.indexOf(pageRef)!=-1)){
		referrer_input=referrerdata.split('~');
		profiles=referrerprofiles.split('~');
		for(i=0;i<(profiles.length-1);i++){
			profileValue=profiles[i].split('^');
			newOption[i] = new Array();
			newOption[i][0] = profileValue[0];//value
			newOption[i][1] = profileValue[1];//name
			newOption[i][2] = i;//element id
		}
		for(i=0;i<document.forms[0].elements.length;i++){
			if(document.forms[0].elements[i].type=="select-one"){
				selectId=document.forms[0].elements[i].id;
				if(selectId.indexOf('BuyFor')!=-1){
					var myFormSelect = eval('document.forms[0].'+selectId);
					for(x=0;x<myFormSelect.options.length;x++){
						myFormSelect.options[x] = null;
					}
					myOption=newOption.length;
					for (ii=0;ii<myOption; ii++){
						myFormSelect.options[ii]=new Option(newOption[ii][1], newOption[ii][0], false, false);
						if(newOption[ii][0]==referrer_input[num]){
							myFormSelect.options[newOption[ii][2]].selected=true;
						}	
					}
					num++;
				}
			}
		}
	}

	ClearValue("ReferrerData");
	ClearValue("ReferrerOpener");
}

function telNo(value){
	return trim(OnlyValidChars("0123456789+ -",value));//call function from customtailor.js
}

function Validchars(value){
	return trim(OnlyValidChars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789+ -//",value));//call function from customtailor.js
}

function CheckAddressData(){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var noprob=true;
	document.Inquiry.FirstName.value=Validchars(document.Inquiry.FirstName.value);
	document.Inquiry.MiddleName.value=Validchars(document.Inquiry.MiddleName.value);
	document.Inquiry.LastName.value=Validchars(document.Inquiry.LastName.value);
	document.Inquiry.Address.value=Validchars(document.Inquiry.Address.value);
	document.Inquiry.City.value=Validchars(document.Inquiry.City.value);
	document.Inquiry.OtherProvince.value=Validchars(document.Inquiry.OtherProvince.value);
	document.Inquiry.ZipCode.value=Validchars(document.Inquiry.ZipCode.value);
	/*document.Inquiry.Contact_Department.value=Validchars(document.Inquiry.Contact_Department.value);*/
	if(document.Inquiry.FirstName.value==""){
		noprob=false;
		alert ("Please enter your Name!");
		document.Inquiry.FirstName.focus();
	}else if(document.Inquiry.LastName.value==""){
		noprob=false;
		alert ("Please enter your Last Name!");
		document.Inquiry.LastName.focus();
	}else if ((document.Inquiry.Email.value=="")||(!filter.test(document.Inquiry.Email.value))){
		noprob=false;
		alert ("Please provide an email address!");
		document.Inquiry.Email.focus();
	}else if(document.Inquiry.PhoneDay.value == ""){
		noprob=false;
		alert ("Please enter your phone number!");
		document.Inquiry.PhoneDay.focus();
	}else if(document.Inquiry.PhoneEvening.value == ""){
		noprob=false;
		alert ("Please enter your phone number!");
		document.Inquiry.PhoneEvening.focus();
	}else if(document.Inquiry.Address.value == ""){
		noprob=false;
		alert("Please enter your Address");
		document.Inquiry.Address.focus();
	}else if(document.Inquiry.City.value == ""){
		noprob=false;
		alert("Please enter your City");
		document.Inquiry.City.focus();
	}else if(document.Inquiry.Country.value == ""){
		noprob=false;
		alert("Please enter your Country");
		document.Inquiry.Country.focus();
	}else if(document.Inquiry.State.value == ""){
		noprob=false;
		alert("Please enter your State");
		document.Inquiry.State.focus();
	}else if((document.Inquiry.State.value == "Other")&&(document.Inquiry.OtherProvince.value == "")){
		noprob=false;
		alert("Please enter your State/Province");
		document.Inquiry.OtherProvince.focus();
	}else if(document.Inquiry.ZipCode.value==""){
		noprob=false;
		alert("Please enter your ZipCode");
		document.Inquiry.ZipCode.focus();
	}else if(document.Inquiry.AlternateEmail.value != ""){
		if(!filter.test(document.Inquiry.AlternateEmail.value)){
			alert("Please use a valid Alternate Email");
			document.Inquiry.AlternateEmail.focus();
			noprob=false;
		}else if(document.Inquiry.AlternateEmail.value==document.Inquiry.Email.value){
			alert("Please Change Alternate Email");
			document.Inquiry.AlternateEmail.focus();
			noprob=false;
		}
	}else{
		if(document.Inquiry.Email.value != document.Inquiry.ConfirmEmail.value){
			noprob=false;	
			document.Inquiry.ConfirmEmail.focus();		
		}	
	}	
	/*else{
		var setemail=GetValue("email");
		if ((setemail == null)&&(prompt("Please enter your email address again for verification","") != document.Inquiry.Email.value)){
			noprob=false;
			alert ("Email address does not match what you typed. Please recheck to make sure it is correct!");
			document.Inquiry.Email.focus();
		}
	}*/
	return noprob;
}
function check_string(str_value){
	var badChars="@~-=_%$#!&*^()/.,;:?[]{}<>+\"\'\\|";
	var noBadChars=true;
	for (i=0; i<str_value.length; i++){
		if(badChars.indexOf(str_value.substring(i,i+1))!=-1){
			noBadChars=false;
			break;
		}
	}
	return noBadChars;
}

/*============XMLHTTPRequest============*/
var http_request = false;
function XMLRequest(){
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
		http_request.overrideMimeType('text/html');
	 }
  } else if (window.ActiveXObject) { // IE
	 try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
  }
  if (!http_request) {
	 alert('Cannot create XMLHTTP instance');
	 return false;
  }
}

function findPos(obj) {
	var curleft = 0;
	var curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
function saveFabric(){
	var swatch=document.getElementById('swatch');
	var fabpath=swatch.src;
	var fabname;
	fabname=fabpath.substring((fabpath.lastIndexOf("/")+1),(fabpath.lastIndexOf(".")));
	if(fabname!="fab_note"){
		XMLRequest();
		http_request.onreadystatechange = saveReturn;
		http_request.open('GET', 'history.php?save=1&fabric='+fabname, true);
		http_request.send(null);
		var offset=findPos(swatch);
		document.getElementById('loading').style.top=(offset[1]+10)+'px';
		document.getElementById('loading').style.left=(offset[0]+160)+'px';
	}else{
		alert("Please choose a fabric and color then save");
	}
}
function saveStyle(id) {
	XMLRequest();
	http_request.onreadystatechange = saveReturn;
	http_request.open('GET', 'history.php?save=1&style='+id, true);
	http_request.send(null);
	e=document.getElementById('s'+id);
	var offset=findPos(e);
	document.getElementById('loading').style.top=(offset[1]+10)+'px';
	document.getElementById('loading').style.left=(offset[0]+10)+'px';
}
function save_shopping(e){//use in shopping cart
	var offset=findPos(e);
	set_visibility("save_shopping","visible");
	document.getElementById('save_shopping').style.top=(offset[1]+12)+'px';
	document.getElementById('save_shopping').style.left=(offset[0]-25)+'px';
}
function saveReturn() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			set_visibility("loading","visible");
			if(http_request.responseText==1){
				setTimeout("set_visibility('loading','hidden')",2000) ;
			}else{
				document.getElementById('loading').innerHTML = "<div style='font-family: Arial, Helvetica; text-align:center; color:#000; padding:26px 2px 2px 2px; white-space:nowrap; display:block; background-image:url(images/alert-warning.gif); background-repeat:no-repeat; background-position:top center'>Please <a href='myaccount.php' class='topmenu' style='text-decoration:underline'>login</a> your account<br>or<br><a href='myregister.php' class='topmenu' style='text-decoration:underline'>Register</a> for new account</div>";
				setTimeout("set_visibility('loading','hidden')",4500) ;
			}
		}else {
			alert('There was a problem with the request.');
		}
	}
}
function show_history(){
	e_history_save=document.getElementById('history_save');
	e_link_vs=document.getElementById('link_ViewSave');
	var offset=findPos(e_link_vs);
	e_history_save.style.top=(offset[1]+15)+'px';
	e_history_save.style.left=(offset[0]-240)+'px';
	if(e_history_save.style.visibility=="visible"){
		set_visibility("history_save","hidden");
		set_visibility("history_preview","hidden");
	}else{
		set_visibility("history_save","visible");
	}
}
function history_preview(condition){
	e_history_preview=document.getElementById('history_preview');
	e_history_save=document.getElementById('history_save');

	if(condition==1){
		XMLRequest();
		http_request.onreadystatechange = function(){
			if (http_request.readyState == 4) {
				if (http_request.status == 200) {
					document.getElementById('history_preview').innerHTML = http_request.responseText;
				}
			}
		}
		http_request.open('GET', 'history.php?preview=1', true);
		http_request.send(null);
		for(i=1;i<=3;i++){
			document.getElementById(eval("'his"+i+"'")).style.background='#eeeeee';
		}
		document.getElementById('his'+condition+'').style.background='#FFFFFF';
	}else if(condition==2){
		document.getElementById('history_preview').innerHTML = "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"1\" class=\"his_menu\"><tr><td align=\"center\" class=\"evenrow\" nowrap><a href=\"myhistory-preview.php?style=1\">My Favourite Styles</a></td><td align=\"center\" class=\"evenrow\" nowrap><a href=\"myhistory-preview.php?style=2\">Styles Ordered Before</a></td></tr></table>";
		for(i=1;i<=3;i++){
			document.getElementById(eval("'his"+i+"'")).style.background='#eeeeee';
		}
		document.getElementById('his'+condition+'').style.background='#FFFFFF';
	}else if(condition==3){
		for(i=1;i<=3;i++){
			document.getElementById(eval("'his"+i+"'")).style.background='#eeeeee';
		}
		document.getElementById('his'+condition+'').style.background='#FFFFFF';
		document.getElementById('history_preview').innerHTML = "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"1\" class=\"his_menu\"><tr><td align=\"center\" class=\"evenrow\" nowrap><a href=\"myhistory-preview.php?fabric=1\">My Favourite Fabrics</a></td><td align=\"center\" class=\"evenrow\" nowrap><a href=\"myhistory-preview.php?fabric=2\">Fabrics Ordered Before</a></td></tr></table>";
	}
	e_history_preview.style.top=e_history_save.offsetHeight-1;//set style top id history preview 
	e_history_preview.style.width=e_history_save.offsetWidth;//set style width id history preview 
	e_history_preview.style.left='0px';
	set_visibility("history_preview","visible");
}
///////////////////////////////////////////////////////###########%%%%%%%%%%%%%
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ Wednesday, April 04, 2007 $$$$$$$$$$$$$$$$$$$
///////////////////////////////////////////////////////###########%%%%%%%%%%%%%
function view_color_history(col_id,status){
	var responseColors="";
	XMLRequest();
	http_request.onreadystatechange = function(){
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				responseColors = http_request.responseText;
				if(responseColors==''){
					alert('We are sorry, this fabric is no longer in stock.');
				}else{
					color_history_li(col_id,responseColors,status);
				}
			}
		}
	}
	http_request.open('GET', 'history.php?preview_history=1&fabric='+col_id, true);
	http_request.send(null);
}
function remove_color_history(fab_id,col_id,col_name){
	value_con=confirm('Click OK to confirm delete fabric ID:'+fab_id+' color:'+col_name);
	if(value_con){
		XMLRequest();
		http_request.onreadystatechange = function(){
			if (http_request.readyState == 4) {
				if (http_request.status == 200) {
					responseColors = http_request.responseText;
					color_history_li(fab_id,responseColors,1);
				}
			}
		}
		http_request.open('GET','history.php?remove=1&fabric='+fab_id+'-'+col_id,true)
		http_request.send(null);
	}
}
function color_history_li(col_id,Colors,status){
	arr_colors=Colors.split(",");
	my_list=document.getElementById('c'+col_id);
	my_listNodes=my_list.childNodes.length;
	if(my_listNodes==0){
		for(i=0;i<arr_colors.length;i++){
			if(arr_colors[i]!=''){
				createLI=document.createElement("li");
				my_list.appendChild(createLI);

				createA1=document.createElement("a");
				createA1.setAttribute("href","javascript:openFabImgList('"+col_id+"','"+arr_colors[i]+"','"+ColName[arr_colors[i]]+"');");
				createTextA1=document.createTextNode(ColName[arr_colors[i]]);
				createA1.appendChild(createTextA1);
				createLI.appendChild(createA1);
				if(status==1){
					createA2=document.createElement("a");
					createA2.setAttribute("href","javascript:remove_color_history('"+col_id+"','"+arr_colors[i]+"','"+ColName[arr_colors[i]]+"');");
					createA2.setAttribute("style","margin-left:30px;");
					createTextA2=document.createTextNode("		[x] Remove");
					createA2.appendChild(createTextA2);
					createLI.appendChild(createA2);
				}
			}
		 }
	}else{
		for(j=0;j<my_listNodes;j++){
			my_list.removeChild(my_list.childNodes[0]);
		}
	}
}

function style_history_li(cat_id,Styles,status){
	arr_Styles=Styles.split(",");
	my_list=document.getElementById('s'+cat_id);
	my_listNodes=my_list.childNodes.length;
	if(my_listNodes==0){
		for(i=0;i<arr_Styles.length;i++){
			createLI=document.createElement("li");
			my_list.appendChild(createLI);

			createA1=document.createElement("a");
			createA1.setAttribute("href","javascript:openStyle('"+arr_Styles[i]+"');");
			createTextA1=document.createTextNode("No:"+arr_Styles[i]);
			createA1.appendChild(createTextA1);
			createLI.appendChild(createA1);
			if(status==1){
				createA2=document.createElement("a");
				createA2.setAttribute("href","javascript:remove_style_history("+cat_id+",'"+arr_Styles[i]+"');");
				createA2.setAttribute("style","margin-left:30px;");
				createTextA2=document.createTextNode("		[x] Remove");
				createA2.appendChild(createTextA2);
				createLI.appendChild(createA2);
			}
		 }
	}else{
		for(j=0;j<my_listNodes;j++){
			my_list.removeChild(my_list.childNodes[0]);
		}
	}
}
function remove_style_history(cat_id,style_id){
	value_con=confirm('Click OK to confirm delete Style ID:'+style_id);
	if(value_con){
		XMLRequest();
		http_request.onreadystatechange = function(){
			if (http_request.readyState == 4) {
				if (http_request.status == 200) {
					/*
					responseStyles = http_request.responseText;
					style_history_li(cat_id,responseStyles,1);
					ref_ele=document.getElementById('link_li'+cat_id);
					if(responseStyles.length==0){
						ref_ele.setAttribute("href","#");
					}else{
						ref_ele.setAttribute("href","javascript:style_history_li("+cat_id+",'"+responseStyles+"',1);");
					}
					*/
					document.location.reload();
				}
			}
		}
		http_request.open('GET','history.php?remove=1&style='+style_id,true)
		http_request.send(null);
	}
}

function set_visibility(e_id,value_visibility){
	document.getElementById(e_id).style.visibility=value_visibility;
	document.getElementById(e_id).onmouseover=function(){set_visibility(e_id,"visible");}
}

function fn_search(){
	var LinkLocation="";
	url_ref=location.pathname;
	correct_url=url_ref.indexOf("/customtailor/");
	if(correct_url!=-1){
		LinkLocation="../";
	}
	var search_condition=document.getElementById('search_condition').value;
	var search_text=document.getElementById('search_text').value;
	search_text=trim(search_text);
	if((search_condition!=0)&&(search_text.length>0)){
		document.location=LinkLocation+"special-search.php?c="+search_condition+"&q="+escape(search_text);
	}
}

function set_zone(new_location){
	XMLRequest();
	http_request.onreadystatechange = function(){
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				SetValue('location',new_location);
				document.location.reload();
			}
		}
	}
	http_request.open('GET','change_zone.php?location='+new_location,true)
	http_request.send(null);
}

//*********function for check all broser*************//
function keyWhat(e){
	var agt=navigator.userAgent.toLowerCase();
	   if ((navigator.appName == 'Microsoft Internet Explorer')||(agt.indexOf("opera") != -1)||(agt.indexOf("firefox") != -1)||(agt.indexOf("msie") != -1)||(agt.indexOf("netscape") != -1)||(agt.indexOf("mozilla") != -1)){
					 //For shift, ctrl and alt keys
		  if(event.keyCode == 17 ){ 
				alert("You Can't use ctrl keys on page");
						  return false;
		  }
	   }
}//end of function

function right() {
	if(window.event == undefined){
		var e = Event;
	}else{
		var e = window.event? event : e;
	}
		//alert(e);

	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1){
		alert("Sorry, you do not have permission to right click.");
		return false;
	}else  if (agt.indexOf("firefox") != -1 &&(e.which == 3 || e.which == 2)){		
		alert("Sorry, you do not have permission to right click.");
		return false;
	}else if (agt.indexOf("msie") != -1 &&(event.button == 2 || event.button == 3)){
		alert("Sorry, you do not have permission to right click.");
		return false;
	}else if (agt.indexOf("netscape") != -1 &&(e.which == 3 || e.which == 2)){
		alert("Sorry, you do not have permission to right click.");
		return false;
	}else if (agt.indexOf("mozilla") != -1 &&(e.which == 3 || e.which == 2)){ 
		alert("Sorry, you do not have permission to right click.");
		return false;
	}else if (agt.indexOf("chrome") != -1 &&(e.which == 3 || e.which == 2)){
		alert("Sorry, you do not have permission to right click.");
		return false;
	}
	return true;
}
//*********end of function for check browser************//
