//++++++++++GLOBAL VARIABLES
var bn=navigator.appName;
var bv=navigator.appVersion;
var url=window.location.toString();
var qrystr="";
if(url.indexOf('?')!=-1){qrystr=url.substr(url.indexOf('?')+1);}
//++++++++++END GLOBAL VARIABLES

//++++++++++REFERENCE FUNCTIONS
function mainref(objid){
	if(document.all){obj="document.all."+objid;}
	else if(document.layers){obj="document."+objid;}
	else if(document.getElementById){obj="document.getElementById('"+objid+"')";}
	return obj;
}
function setref(lrid){
	if(document.all){objref="document.all."+lrid+".style"}
	else if(document.layers){objref="document."+lrid}
	else if(document.getElementById){objref="document.getElementById('"+lrid+"').style"}
	return objref;
}
//++++++++++END REFERENCE FUNCTIONS

//++++++++++GENERAL FUNCTIONS
if (top!=self){top.location=location;}
function changeinnerhtml(o,s){
	eval(mainref(o)).innerHTML=s;
}
function closediv(o){
	eval(mainref(o)).innerHTML="";
	eval(setref(o)).visibility="hidden";
}
function showobj(o,p){
	if(p==0){eval(setref(o)).display="block";}
	else if(p==1){eval(setref(o)).visibility="visible";}
}
function hideobj(o,p){
	if(p==0){eval(setref(o)).display="none";}
	else if(p==1){eval(setref(o)).visibility="hidden";}
}
function changesrcimg(o,imgsrc){
	eval(mainref(o)).src=imgsrc;
}
function fixdecimals(dnum){
	dnum=dnum.toString();
	if (dnum.indexOf('.')!=-1 && dnum.substr(dnum.indexOf('.')).length<3){dnum=dnum+"0";}
	else if (dnum.indexOf('.')==-1){dnum=dnum+".00";}
	return dnum;
}
function position(o,x,y){
	var obj=eval(setref(o));
	obj.left=x;obj.top=y;
}
var curposx,curposy;	//mouse position
function getcursorposition(e){
	curposx=0;curposy=0;
	var e=(!e)?window.event:e;//IE:Moz
	if(e.pageX){//Moz
	curposx=e.pageX+window.pageXOffset;
	curposy=e.pageY+window.pageYOffset;}
	else if(e.clientX){//IE
	if(document.documentElement){//IE 6+ strict mode
	curposx=e.clientX+document.documentElement.scrollLeft;
	curposy=e.clientY+document.documentElement.scrollTop;}
	else if(document.body){//Other IE
	curposx=e.clientX+document.body.scrollLeft;
	curposy=e.clientY+document.body.scrollTop;}}
	else{return false}//old browsers
}
function getpagescrollposition(){
	var hscroll,vscroll;
	if(bn=="Microsoft Internet Explorer"){
	if(document.documentElement){
	hscroll=document.documentElement.scrollLeft;vscroll=document.documentElement.scrollTop;}
	else if(document.body){
	hscroll=document.body.scrollLeft;vscroll=document.body.scrollTop;}}
	else{
	hscroll=window.pageXOffset;vscroll=window.pageYOffset;}
	return [hscroll,vscroll];
}
function scrolltoposition(x,y){
	document.body.scrollLeft=x;document.body.scrollTop=y;
}
function getobjectposition(o){
	o=eval(mainref(o));var leftpos=toppos=0;
	if(o.offsetParent){
	do{
	leftpos+=o.offsetLeft;toppos+=o.offsetTop;
	}while(o=o.offsetParent);
	return [leftpos,toppos];}
}
function getrelativeobjectposition(o1,o2){
	o1=eval(mainref(o1));o2=eval(mainref(o2));
	var leftpos=toppos=0;
	leftpos=parseInt(o1.offsetLeft)-parseInt(o2.offsetLeft);
	toppos=parseInt(o1.offsetTop)-parseInt(o2.offsetTop);
	return [Math.abs(leftpos),Math.abs(toppos)];
}
function getobjectsize(o){
	o=eval(mainref(o));var x=y=0;
	if(o!="undefined"){
	x=o.offsetWidth;y=o.offsetHeight;
	return [x,y];}
	else{return false;}
}
function setobjectsize(o,x,y){
	o=eval(setref(o));
	if(o!="undefined"){
	o.width=x;o.height=y;}
	else{alert("ERROR: Object \""+o+"\" is undefined!");}
}
//++++++++++END GENERAL FUNCTIONS

//++++++++++SPECIFIC FUNCTIONS
function editcart(l){
	var err=0;
	var options="options=";
	var item=document.item_options.item.value;
	var qty_val=document.item_options.qty_val.value;
	for(var i=0;i<document.item_options.elements.length-1;i++){
	if(document.item_options.item!=document.item_options.elements[i] && document.item_options.qty_val!=document.item_options.elements[i]){
	if(document.item_options.elements[i].selectedIndex!="undefined"){
	if(document.item_options.elements[i].options[document.item_options.elements[i].selectedIndex].value!='0'){
	options+=document.item_options.elements[i].options[document.item_options.elements[i].selectedIndex].value+",";}
	else{
	err=1;
	alert(document.item_options.elements[i].name+" was not selected");}}
	else{
	if(document.item_options.elements[i].checked){
	options+=document.item_options.elements[i].value+",";}}}}
	if(options!="options="){options=options.substr(0,options.length-1)}
	if(err==0){location.href="shoppingcart.asp?item="+item+"&"+options+"&qty_val="+qty_val+"&line="+l;}
}
function editcarttotal(){
	var st,tax,total,err=0;
	if(document.order_form.ShippingStateProvince.value!=""){
	st=document.order_form.ShippingStateProvince.value;}
	else{st=document.order_form.StateProvince.value;}
	if(st==locstate){
	tax=Math.round(parseFloat(document.order_form.Subtotal.value)*salestax*100)/100;
	total=Math.round((parseFloat(document.order_form.Subtotal.value)+tax)*100)/100;
	document.order_form.Tax.value=tax;
	document.order_form.Total.value=total;
	document.order_form.TaxAmount.value="$"+fixdecimals(tax);
	document.order_form.TotalAmount.value="$"+fixdecimals(total);}
	else{
	document.order_form.Tax.value=0;
	document.order_form.Total.value=Math.round(parseFloat(document.order_form.Subtotal.value));
	document.order_form.TaxAmount.value="$0.00";
	document.order_form.TotalAmount.value="$"+document.order_form.Subtotal.value;}
}
function shippingoptions(){
	var pc;
	if(document.order_form.ShippingPostalCode.value!=""){
	pc=document.order_form.ShippingPostalCode.value;}
	else{pc=document.order_form.PostalCode.value;}
	if(pc!="" && pc!=null){
	if(window.XMLHttpRequest){
	request=new XMLHttpRequest();}
	else if(window.ActiveXObject){
	request=new ActiveXObject("Msxml2.XMLHTTP");
	if(!request){
	request=new ActiveXObject("Microsoft.XMLHTTP");}}
	if(request){
	request.open("POST", "https://"+domname+"/getshipping.asp?"+qrystr, false);
	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	request.send("postalcode="+pc);
	if(request.readyState==4 && request.status==200){
	eval(setref("center_msg")).visibility="hidden";
	if(request.responseText=="0"){
	alert("ERROR: YOUR SESSION HAS EXPIRED!");
	location.href="http://"+domname+"/index.asp?loc=scart";}
	else{
	changeinnerhtml("shipping_options",request.responseText);}}}
	else{
	eval(setref("center_msg")).visibility="hidden";
	changeinnerhtml("shipping_options","ERROR: PLEASE TRY AGAIN!");}}
	else{
	eval(setref("center_msg")).visibility="hidden";
	changeinnerhtml("shipping_options","Pending address information....");}
}
var mrefpoint="i";		//for the document display ("s" for standard & "i" for innerHTML)
var mw=100;			//magnifier width
var mh=100;			//magnifier height
var imgboxpos,imgboxsize;	//for the "image box" position and size values
var zoomratio;			//for the zoom ratio
function magnifier(e){
	if(eval(setref("image_box"))!="undefined" && eval(setref("image_box"))!="undefined"){
	var mpos,mcurposx,mcurposy,pscroll,ieo;
	getcursorposition(e);
	pscroll=getpagescrollposition();
	if(bn=="Microsoft Internet Explorer"){ieo=-2;}	//magnifier position correction for ie and opera
	else if(bn=="Opera"){ieo=1;}
	else{ieo=2;}
	if(mrefpoint=="i"){
	mpos=getrelativeobjectposition("image_display","image_box");
	mcurposx=curposx-imgboxpos[0]+mpos[0];
	mcurposy=curposy-imgboxpos[1]+mpos[1];}
	else{
	mpos=imgboxpos;
	mcurposx=curposx;
	mcurposy=curposy;}
	if(curposx-pscroll[0]>=imgboxpos[0] && curposx-pscroll[0]<=imgboxpos[0]+mw/2 && curposy-pscroll[1]>=imgboxpos[1] && curposy-pscroll[1]<=imgboxpos[1]+mh/2){	//TOP LEFT
	position("magnifier",mpos[0]+'px',mpos[1]+'px');showzoom(0,0);}
	else if(curposx-pscroll[0]>=imgboxpos[0]+imgboxsize[0]-mw/2 && curposx-pscroll[0]<=imgboxpos[0]+imgboxsize[0] && curposy-pscroll[1]>=imgboxpos[1] && curposy-pscroll[1]<=imgboxpos[1]+mh/2){	//TOP RIGHT
	position("magnifier",mpos[0]+imgboxsize[0]-mw-ieo+'px',mpos[1]+'px');showzoom(-(imgboxsize[0]-mw)*zoomratio,0);}
	else if(curposx-pscroll[0]>=imgboxpos[0] && curposx-pscroll[0]<=imgboxpos[0]+mw/2 && curposy-pscroll[1]>=imgboxpos[1]+imgboxsize[1]-mh/2 && curposy-pscroll[1]<=imgboxpos[1]+imgboxsize[1]){	//BOTTOM LEFT
	position("magnifier",mpos[0]+'px',mpos[1]+imgboxsize[1]-mh-ieo+'px');showzoom(0,-(imgboxsize[1]-mh)*zoomratio);}
	else if(curposx-pscroll[0]>=imgboxpos[0]+imgboxsize[0]-mw/2 && curposx-pscroll[0]<=imgboxpos[0]+imgboxsize[0] && curposy-pscroll[1]>=imgboxpos[1]+imgboxsize[1]-mh/2 && curposy-pscroll[1]<=imgboxpos[1]+imgboxsize[1]){	//BOTTOM RIGHT
	position("magnifier",mpos[0]+imgboxsize[0]-mw-ieo+'px',mpos[1]+imgboxsize[1]-mh-ieo+'px');showzoom(-(imgboxsize[0]-mw)*zoomratio,-(imgboxsize[1]-mh)*zoomratio);}
	else if(curposx-pscroll[0]>imgboxpos[0]+mw/2 && curposx-pscroll[0]<imgboxpos[0]+imgboxsize[0]-mw/2 && curposy-pscroll[1]>=imgboxpos[1] && curposy-pscroll[1]<=imgboxpos[1]+mh/2){	//TOP MIDDLE
	position("magnifier",parseInt(mcurposx)-mw/2+'px',mpos[1]+'px');showzoom((2*(imgboxpos[0]-curposx)+mw)*zoomratio/2,0);}
	else if(curposx-pscroll[0]>imgboxpos[0]+mw/2 && curposx-pscroll[0]<imgboxpos[0]+imgboxsize[0]-mw/2 && curposy-pscroll[1]>=imgboxpos[1]+imgboxsize[1]-mh/2 && curposy-pscroll[1]<=imgboxpos[1]+imgboxsize[1]){	//BOTTOM MIDDLE
	position("magnifier",parseInt(mcurposx)-mw/2+'px',mpos[1]+imgboxsize[1]-mh-ieo+'px');showzoom((2*(imgboxpos[0]-curposx)+mw)*zoomratio/2,-(imgboxsize[1]-mh)*zoomratio);}
	else if(curposx-pscroll[0]>=imgboxpos[0] && curposx-pscroll[0]<=imgboxpos[0]+mw/2 && curposy-pscroll[1]>imgboxpos[1]+mh/2 && curposy-pscroll[1]<imgboxpos[1]+imgboxsize[1]-mh/2){	//LEFT MIDDLE
	position("magnifier",mpos[0]-pscroll[0]+'px',mcurposy-pscroll[1]-mh/2+'px');showzoom(0,(2*(imgboxpos[1]-curposy+pscroll[1])+mh)*zoomratio/2);}
	else if(curposx-pscroll[0]>=imgboxpos[0]+imgboxsize[0]-mw/2 && curposx-pscroll[0]<=imgboxpos[0]+imgboxsize[0] && curposy-pscroll[1]>imgboxpos[1]+mh/2 && curposy-pscroll[1]<imgboxpos[1]+imgboxsize[1]-mh/2){	//RIGHT MIDDLE
	position("magnifier",mpos[0]+imgboxsize[0]-pscroll[0]-mw-ieo+'px',mcurposy-pscroll[1]-mh/2+'px');showzoom(-(imgboxsize[0]+pscroll[0]-mw)*zoomratio,(2*(imgboxpos[1]-curposy+pscroll[1])+mh)*zoomratio/2);}
	else if(curposx-pscroll[0]>imgboxpos[0]+mw/2 && curposx-pscroll[0]<imgboxpos[0]+imgboxsize[0]-mw/2 && curposy-pscroll[1]>imgboxpos[1]+mh/2 && curposy-pscroll[1]<imgboxpos[1]+imgboxsize[1]-mh/2){	//CENTER
	position("magnifier",mcurposx-pscroll[0]-mw/2+'px',mcurposy-pscroll[1]-mh/2+'px');showzoom((2*(imgboxpos[0]-curposx+pscroll[0])+mw)*zoomratio/2,(2*(imgboxpos[1]-curposy+pscroll[1])+mh)*zoomratio/2);}}
	else{alert("YOUR BROWSER DOES NOT SUPPORT THE ZOOM FEATURE!\nPLEASE DOWNLOAD THE LATEST VERSION FIRST.");}
}
function getzoomratio(o1,o2){
	var obj1=getobjectsize(o1);var obj2=getobjectsize(o2);zoomratio=obj1[0]/obj2[0];
	if(zoomratio<1){zoomratio=obj2[0]/obj1[0];}
}
function hidemagnifier(){
	document.onmousemove=null;hideobj("magnifier");hideobj("zoom_box");resetzoom("n");
}
function resetzoom(img){
	imgboxpos=getobjectposition("image_box");imgboxsize=getobjectsize("image_box");
	if(img!="n"){eval(setref("zoom_box")).backgroundImage="url("+img+")";}
	eval(setref("zoom_box")).backgroundPosition="0px 0px";
}
function showzoom(x,y){
	eval(setref("zoom_box")).backgroundPosition=x+"px"+" "+y+"px";
}
function switchimage(img){
	eval(mainref("large_image")).src=img;eval(mainref("image_box")).src=img;resetzoom(img);
}
function runimagezoom(){
	getzoomratio("image_box","large_image");
	if(zoomratio>=1.5){
	showobj("magnifier",1);setobjectsize("magnifier",mw,mh);
	showobj("zoom_box",1);setobjectsize("zoom_box",mw*zoomratio,mh*zoomratio);
	document.onmousemove=magnifier;}
}
function largeitemimage(){
	showobj("large_item_image_div",1);
	eval(mainref("item_large_image")).src=eval(mainref("image_box")).src;
}
function tellafriend(itemcode,itemname){
	showobj("tell_friend_div",1);eval(mainref("ItemCode")).value=itemcode;
	changeinnerhtml("item_name",itemname);
}
var itemslist;
function storeitemslist(o){
	itemslist=eval(mainref(o)).innerHTML;
}
function displayitemslist(o){
	eval(mainref(o)).innerHTML=itemslist;
}
function senditemtofriend(){
	var item=eval(mainref("ItemCode")).value;
	var sender=eval(mainref("UserEmail")).value;
	var receiver=eval(mainref("FriendEmail")).value;
	var message=eval(mainref("Message")).value;
	if(window.XMLHttpRequest){request=new XMLHttpRequest();}
	else if(window.ActiveXObject){
	request=new ActiveXObject("Msxml2.XMLHTTP");
	if(!request){
	request=new ActiveXObject("Microsoft.XMLHTTP");}}
	if(request){
	request.open("POST", "http://"+domname+"/mailmngmnt.asp", false);
	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	itemstr=encodeURI("theform=tell_friend_form&itemcode="+item+"&sender="+sender+"&receiver="+receiver+"&message="+message);
	request.send(itemstr);
	if(request.readyState==4 && request.status==200){
	if(request.responseText=="0"){alert("ERROR: YOUR MESSAGE WAS NOT SENT!\nPLEASE TRY AGAIN.");}
	else if(request.responseText=="1"){alert("YOUR MESSAGE WAS SENT SUCCESSFULLY!");hideobj("tell_friend_div");}
	else{alert(request.responseText);}}}
	else{alert("ERROR: CONNECTION FAILED!\nPLEASE TRY AGAIN.");}
}
function sendenquiry(){
	var name=eval(mainref("Name")).value;
	var sender=eval(mainref("Email")).value;
	var message=eval(mainref("Message")).value;
	if(window.XMLHttpRequest){request=new XMLHttpRequest();}
	else if(window.ActiveXObject){
	request=new ActiveXObject("Msxml2.XMLHTTP");
	if(!request){
	request=new ActiveXObject("Microsoft.XMLHTTP");}}
	if(request){
	request.open("POST", "http://"+domname+"/mailmngmnt.asp", false);
	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	contactstr=encodeURI("theform=contact_form&clientname="+name+"&sender="+sender+"&message="+message);
	request.send(contactstr);
	if(request.readyState==4 && request.status==200){
	if(request.responseText=="0"){alert("ERROR: YOUR MESSAGE WAS NOT SENT!\nPLEASE TRY AGAIN.");}
	else if(request.responseText=="1"){alert("YOUR MESSAGE WAS SENT SUCCESSFULLY!");location.href="index.asp?loc=catalog";}
	else{alert(request.responseText);}}}
	else{alert("ERROR: CONNECTION FAILED!\nPLEASE TRY AGAIN.");}
}
//++++++++++END SPECIFIC FUNCTIONS