// JavaScript Document
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

	function MM_swapImage() { //v3.0
	  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}

	function flagCalculate()
	{
		window.document.skuform.validate.value="1";
	}
	function changeMainImage(imagename)
	{
		document.getElementById
		window.document.mainimageform.imagename.value=imagename;
		MM_swapImage('MainImage','',imagename,1);
	}
	
	function openMainImage(imagename)
	{
		if (imagename == undefined) imagename = window.document.mainimageform.imagename.value;
		if(screen.width)
        {  // var winl = (screen.width - 400)/2;
	      //  var wint = (screen.height - 601)/2;
	       var winl = (screen.width - 400);
	        var wint = (screen.height - 601);
        }
        else
        {   winl = 0;wint =0;
        }
        if (winl < 0) winl = 0;
        if (wint < 0) wint = 0;
       	window.open('mainimage.asp?imagename=' + imagename,'','scrollbars=yes, resizable=no,locationbar=no,location=no,toolbar=no,status=no,menubar=no,top=30,left=30');
	}
	
	function openColor(hexcode,sku_image_big,sku_image_product){	
		if (sku_image_big!=""){	
			window.document.mainimageform.imagename.value=sku_image_big;
		}
		if (sku_image_product !=""){	
			MM_swapImage('MainImage','',sku_image_product,1);
		}
		
		if(screen.width){   
	        var winl = (screen.width-300)/2;
	        var wint = (screen.height-300)/2;
	    }else {   
	        winl = 0;
	        wint = 0;
	    }
	    if (winl < 0) {
	    	winl = 0;
		}
	    if (wint < 0) {
	    	wint = 0;
		}
		
		window.open('colorimage.asp?hexcode=' + hexcode,'','scrollbars=no, resizable=no,locationbar=no,location=no,toolbar=no,status=no,menubar=no,width=300,height=300,top='+wint+',left='+winl+'');
	}
	
	function openSku(sku_image_big,sku_image_product){	
		if (sku_image_big!="")
		{	
			window.document.mainimageform.imagename.value=sku_image_big;
		}
		if (sku_image_product !="")
		{	
			MM_swapImage('MainImage','',sku_image_product,1);
		}
	}
	
	function openSwatch(imagename,sku_image_big,sku_image_product)
	{	if (sku_image_big!=""){	
			window.document.mainimageform.imagename.value=sku_image_big;
		}
		if (sku_image_product !=""){	
			MM_swapImage('MainImage','',sku_image_product,1);
		}
		if(screen.width) {   
	        var winl = (screen.width-300)/2;
	        var wint = (screen.height-300)/2;
	    }else{   
	        winl = 0;
	        wint = 0;
	    }
	    if (winl < 0) {
	    	winl = 0;
		}
	    if (wint < 0) { 
	    	wint = 0;
		}
		
		window.open('colorimage.asp?imagename=' + imagename,'','scrollbars=no, resizable=no,locationbar=no,location=no,toolbar=no,status=no,menubar=no,width=300,height=300,top='+wint+',left='+winl+'');
	}
	function addtoCart()
	{
		window.document.skuform.action = "http://www.bluecacti.com/demo/retail/addtocart.asp?categoryname=Men&toplevel=Men&style%5Fno=500&level=1";
		window.document.skuform.submit();
	}
	
	function reloadPage()
	{   var pagelink;
	    var pagelink2;
	    var pagelink3;
	    var colorid;
	    var sizeid;
    	
	    pagelink="http://www.bluecacti.com/demo/retail/product.asp?categoryname=Men&toplevel=Men&style%5Fno=500&level=1&colorid=coloridvalue&sizeid=sizeidvalue"
        colorid = window.document.getElementById('color').options[window.document.getElementById('color').selectedIndex].value;
	    sizeid = window.document.getElementById('size').options[window.document.getElementById('size').selectedIndex].value;
    	
	    pagelink=pagelink.replace("coloridvalue",colorid);
	    pagelink=pagelink.replace("sizeidvalue",sizeid);
    	
	    window.document.location.href=pagelink;
	}
	
	
	function chooseSize(chosenSize)
	{   
		var same = false;
		if (window.document.mainimageform.size.value != 0)
	    {   
		    var tempSize;
	        tempSize = document.mainimageform.size.value;
	        same = (tempSize == chosenSize) ? true : false;
	        document.getElementById("size_"+tempSize).className="sizeSelect"; 
	    }
	    document.mainimageform.size.value = chosenSize;
	    document.getElementById("size_"+chosenSize).className="sizeSelectOn";
	    if (same) {
		    document.mainimageform.size.value = 0;
	    	document.getElementById("size_"+chosenSize).className="sizeSelect";
    	} 
	}
	
	
	function chooseColor(chosenColor)
	{   
		var same = false;
		if (document.mainimageform.color.value != 0)
	    {   
		    var tempColor;
	        tempColor = document.mainimageform.color.value;
	        same = (tempColor == chosenColor) ? true : false;
	        document.getElementById("color_"+tempColor).className="swatchSelect";
	    }
	    document.mainimageform.color.value = chosenColor;
	    document.getElementById("color_"+chosenColor).className ="swatchSelectOn"; 
	    if (same) {
		    document.mainimageform.color.value = 0;
	    	document.getElementById("color_"+chosenColor).className="swatchSelect";
	    }
	}
	
