
function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function showMatSpecs(mfautoid){
var urlstr, pheight, pwidth, numcolor, catgid, subcatgid

	urlstr='/xp5/material_specs.asp?mfautoid='+mfautoid+'&sample=1'

	xleft = (screen.width - 620) / 2
	xtop = (screen.height - 480) / 2
	hwinspecs = window.open(urlstr, 'winspecs', 'left='+xleft+',top='+xtop+',width=620,height=480,resizable,scrollbars')
}

function loadthisSize(h, w){
var xobj, xdivname, showdivname
	showdivname = "size" + h + "-" + w
	if (document.getElementById("size" + h + "-" + w)) {
		xobj = document.getElementById("size" + h + "-" + w).style;
		xobj.visibility='visible';
		xobj.display='block';
	}
	for (var i=0; i<document.frmMain.radioSize.length;i++){
		xdivname = "size" + document.frmMain.radioSize[i].value.split('x').join('-')
		if (showdivname != xdivname){
			if (document.getElementById(xdivname)) {
				xobj = document.getElementById(xdivname).style;
				if (xobj) {
					xobj.visibility='hidden';
					xobj.display='none';
				}
			}
		}
	}
}


function AddToCart(yaddtocart, ydesturl, addtocartdomain) {

    if (typeof(arrConCode) != 'undefined'){
        if (arrConCode.length>0){	//for products with attributes
	        for (var i=0; i<arrQtyFields.length; i++){
		        if ( !validateColor(document.frmMain[arrQtyFields[i]], arrLIConcode[i]) ){
			        return
		        }
	        }
        }
    }

	if ( checkqtys('frmMain')) {
		var xaction = addtocartdomain+"/xp/xt_Add_DynStkProduct_Cart.asp"
		if (yaddtocart == "static") {
			xaction = addtocartdomain+"/xp/xt_Add_StockProduct_Cart.asp"
		}
		else if (yaddtocart == "semicustom") {
			xaction = addtocartdomain+ydesturl
		}
	
		document.frmMain.target = "_self"
		document.frmMain.action = xaction;
		document.frmMain.submit()
	}

}

function Customize(sku, sizecode) {

	document.frmMain.target = "_self"
	document.frmMain.action = '/xp/xp5_stockproductspecs.aspx?stdcode=' + sku + '&wpsizecode=' + sizecode;
	document.frmMain.submit()
}

function checkqtys(frmobj) {
var ttl=0, minqty, qtyfld, mult, validyn=true, allZero=true;
	//If qty field is empty then replace with 0
	for (var i=0;i<document[frmobj].elements.length;i++) {
		var e = document[frmobj].elements[i];

		qtyfld='qty'
	    if (e.name.substring(0,4) == 'pfid') {
			qtyfld=qtyfld + e.name.substring(4, e.name.length)
			
			if (window.document[frmobj][qtyfld].value.length==0) {
				window.document[frmobj][qtyfld].value=0;
			}
			if ( parseInt(window.document[frmobj][qtyfld].value)!=0 ){
				allZero	=false
			}
		}
	}

	if (allZero) {
		alert("Please enter quantities...");
		return false;
	}

	for (var i=0;i<document[frmobj].elements.length;i++) {
		var e = document[frmobj].elements[i];
		minqty='mqty'
		qtyfld='qty'
		mult='mult'
	    if (e.name.substring(0,4) == 'pfid') {
			minqty=minqty + e.name.substring(4, e.name.length)
			qtyfld=qtyfld + e.name.substring(4, e.name.length)
			mult=mult + e.name.substring(4, e.name.length)

			validyn=VldQty(window.document[frmobj][minqty], window.document[frmobj][qtyfld], window.document[frmobj][mult])
			if ( ! validyn) 
				break;	
		}
	}
	return validyn;
}

function VldQty(minqty,qtyfld, mult) {
var checkOK = "0123456789-";
var checkStr;
var ValidNum = true;
var decPoints = 0;
var allNum = "";
var allow=true
	checkStr = qtyfld.value;
  	for (i = 0;  i < checkStr.length;  i++){
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
    	if (j == checkOK.length){
      		ValidNum = false;
      		break;
    	}
    	allNum += ch;
  	}
  	if (!ValidNum) {
   		alert("Quantity entered is invalid...");
   		qtyfld.focus();
		qtyfld.select();
   		return false;
  	} else {
		if ((parseInt(qtyfld.value)<0  || parseInt(qtyfld.value)>0) && (parseInt(qtyfld.value)<parseInt(minqty.value)))	{
			qtyfld.focus()
			alert('Minimum order quantity should be ' + minqty.value)
			qtyfld.select();
			allow=false
		}

/*
		if (allow && parseInt(qtyfld.value)%parseInt(mult.value)!=0){
			qtyfld.focus()
			alert('Please enter quantity in the Multiples of ' +mult.value)
			qtyfld.select();
			allow=false
		}
*/


	}
	return allow;
}

function launchWizard(xSKU, xDesign, xOrientation, xSizeCode, xW, xH, xcolors, stocksku, spanish, wizardid, prodtype, customizedomain, xnumcol){
var launchurl

	if (prodtype.toUpperCase()=='PR'){
		launchurl='/xp5/personalize.aspx?sku='+xSKU+'&sz='+xSizeCode+'&numcol='+xnumcol
	}else{
		launchurl=customizedomain +'/xp5/wizardy.asp?ssSKU='+xSKU+'&ssDesign='+xDesign+'&ssOrientation='+xOrientation+'&ssSizeCode='+xSizeCode+'&ssW='+xW+'&ssH='+xH+'&ssColors='+xcolors+'&stocksku='+stocksku+'&spanish='+spanish+'&wizardid='+wizardid;
	}
	document.frmMain.target = "_self"
	document.frmMain.action = launchurl
	document.frmMain.submit()

}

function showHideLayers(divname,divstyle) {
// example: showHideLayers('divname')
	xobj = document.all[divname].style;
   	if (divstyle=='hide') {
		xobj.visibility='hidden';
		xobj.display='none';
	}
	else if (divstyle=='show') {
		xobj.visibility='visible';
		xobj.display='block';
	}
}

var currobj
function start(){

    currobj=document.frmMain

	if (document.forms.frmMain.radioSize){
		for (var i=0; i<document.frmMain.radioSize.length;i++){
			if (document.frmMain.radioSize[i].value=='10x14'){
				document.frmMain.radioSize[i].click()
				
			}else if (document.frmMain.radioSize[i].value=='14x10'){
				document.frmMain.radioSize[i].click()
			}
		}
	}
	DrawBorder()

    if (currobj.addersExists0){
        adderStartup()
    }

}

function showThemes(val){
	document.frmMain.ssThemesAll.value = val
	document.frmMain.target = "_self"
	document.frmMain.action = "#"
	document.frmMain.submit()
}

function DrawBorder() {
	//range of alphabets at a time such as A-C etc.
	var ssThemesAll = '<%=XMLib.SanitizeRequestQuery("ssThemesAll")%>'
	if (ssThemesAll.length <= 0) {
		ssThemesAll = "A-C"
	}
	var obj = document.getElementById('span' + ssThemesAll);
	if (obj) {
		obj.style.backgroundColor='#FFFFFF';
		obj.style.padding='0px 4px 1px 4px';
		obj.style.border = "solid #FF9900 1px";
		obj.style.fontWeight = "bold";
	}
}


//Adders
function openAdderRow(currElem, currSKU, currSizeCode){
	if(document.layers){	// Netscape 4+
		dom = document.layers[currElem].style;
	}else if(document.getElementById){	// Netscape 6+, gecko, IE 5+
		dom = document.getElementById(currElem).style;
	}else if(document.all){	// IE 4+
		dom = document.all[currElem].style;
	}else{	// Browser unknown; do nothing
		return ;
	}

    if (document.frmMain["qty"+currSKU+"-"+currSizeCode].value>0){
		try { dom.display = 'table-row'; }
		catch (e) { dom.display = 'block'; }
		dom.visibility = "visible";
    }else{
		dom.display = "none";
		dom.visibility = "hidden";
    }
}


var a_AdderObject=new Array()

function adderStartup(){

	for (var k=0; k<a_AdderObject.length; k++) {
		if (a_AdderObject[k].addergroup.toLowerCase().indexOf('checkbox')>=0 || a_AdderObject[k].addergroup.toLowerCase().indexOf('radio')>=0){
			if (a_AdderObject[k].attribute2=="1"){
				if (a_AdderObject[k].addergroup.toLowerCase().indexOf('radio')>=0){
					var curradder='adder'+a_AdderObject[k].sections.split(' ').join('_')    //??

					if (typeof(currobj[curradder])!="undefined" && currobj[curradder].length>1){
						for (var j=0; j<currobj[curradder].length; j++) {
							if (currobj[curradder][j].value==k){
								currobj[curradder][j].click()
								break;
							}
						}
					}else{
						currobj[curradder].click()
					}
				}
			}
		}
	}
}

function showQtyAmount(objradchk, yindex, sku, SizeCode, ParentSizeCode){
var imagestyle

	imagestyle=false
	if (a_AdderObject[yindex].adderimages.toLowerCase() == 'true') {
		imagestyle=true
	}
	if (!imagestyle){

		for (var k=0; k<a_AdderObject.length; k++) {
		    if (a_AdderObject[k].addergroup.toLowerCase().indexOf('radio')>=0){
			    if (objradchk.checked==true && k==yindex){
				    document.getElementById('cell1'+yindex).style["visibility"] = "visible"
				    document.getElementById('cell2'+yindex).style["visibility"] = "visible"
				    document.getElementById('itemttl'+yindex).style["visibility"] = "visible"
				    currobj['adder'+sku+ParentSizeCode+yindex].value = "1"		//adder to be added to cart
    			
				    currobj['AdderQty'+yindex].value=currobj['qty'+sku+SizeCode].value
    				
				    document.getElementById('divrate' + yindex).style.textDecoration = "none";
				    document.getElementById('divrate' + yindex).style.color = "black";

			    }else{
				    document.getElementById('cell1'+k).style["visibility"] = "hidden"
				    document.getElementById('cell2'+k).style["visibility"] = "hidden"
				    document.getElementById('itemttl'+k).style["visibility"] = "hidden"
				    currobj['adder'+sku+ParentSizeCode+k].value = ""
				    currobj['AdderQty'+yindex].value=currobj['qty'+sku+SizeCode].value
			    }
		    }else{  //				if (a_AdderObject[k].addergroup.toLowerCase().indexOf('checkbox')>=0){

			    if (k==yindex){
				    if (objradchk.checked==true){
					    document.getElementById('cell1'+yindex).style["visibility"] = "visible"
					    document.getElementById('cell2'+yindex).style["visibility"] = "visible"
					    document.getElementById('itemttl'+yindex).style["visibility"] = "visible"
    					
    				//alert('adder'+sku+ParentSizeCode+yindex+'\n'+currobj['adder'+sku+ParentSizeCode+yindex].value )
    					
					    currobj['adder'+sku+ParentSizeCode+yindex].value = "1"		//adder to be added to cart
    				    
				        currobj['AdderQty'+yindex].value=currobj['qty'+sku+ParentSizeCode].value
    					
				    }else{
					    document.getElementById('cell1'+k).style["visibility"] = "hidden"
					    document.getElementById('cell2'+k).style["visibility"] = "hidden"
					    document.getElementById('itemttl'+k).style["visibility"] = "hidden"
					    currobj['adder'+sku+ParentSizeCode+k].value = ""
				    }
			    }
		    }

		}
		//}
	}else{
   
		for (var k=0; k<a_AdderObject.length; k++) {
			//if (a_AdderObject[k].sections == xsections) {
				if (objradchk.checked==true && k==yindex){
					document.getElementById('span_'+yindex).style.display = "block"
					currobj['adder'+sku+SizeCode+yindex].value = "1"

					document.getElementById('divrate' + yindex).style.textDecoration = "none";
					document.getElementById('divrate' + yindex).style.color = "black";					
				}else{
					document.getElementById('span_'+k).style.display = "none"
					currobj['adder'+sku+SizeCode+k].value = ""
				}
			//}
		}
	}

}

function selectAdder(k, sku, SizeCode){
var xsections, i, j

	//obj='adder'+a_AdderObject[k].sections.split(' ').join('_')+sku+SizeCode
	obj='adder'+sku+SizeCode
	
	if (typeof(currobj[obj])!="undefined" && currobj[obj].length>1){
	    for (var i=0; i<currobj[obj].length; i++) {
		    if (currobj[obj][i].value==k){
		        currobj[obj][i].click()
		        break;
		    }
		}
	}else{
		if (currobj[obj].value==k){
		    
		    currobj[obj].click()
		}
	}

}

function setAdderObject(objno, adderimages, addergroup, short_decription, attribute2, attribute3, pkg){
	a_AdderObject[objno].adderimages = adderimages
	//a_AdderObject[objno].sections = sections
	a_AdderObject[objno].addergroup = addergroup
	a_AdderObject[objno].short_decription = short_decription
	a_AdderObject[objno].attribute2 = attribute2
	a_AdderObject[objno].attribute3 = attribute3
	a_AdderObject[objno].pkg = pkg
}

function AdderObject(){
	this.adderimages = 0
	//this.sections = ''
	this.addergroup = ''
	this.short_decription = ''
	this.attribute2 = ''
	this.attribute3 = ''
	this.pkg = ''
}


var origThumb=''
function changeProdImage(objattr, pf_id, imageids){
    var a_imageids=imageids.split(',')
    var origimageurl=''
    var opf_id

	opf_id=pf_id
	
	pf_id=pf_id.toLowerCase()
	origimageurl = document.images["imgproduct"+pf_id].src
	origimageurl = origimageurl.toLowerCase()

	if (origThumb.length==0){
		origThumb=origimageurl
	}

    origimageurl=origThumb
	//origimageurl=origThumb.split('/sm/').join('/md/')
	//use thumb image name to generate colored image name

	if (origimageurl.indexOf(pf_id)==-1){
		document.images["imgproduct"+pf_id].src = origimageurl.substr(0, origimageurl.length-4)+'_'+a_imageids[objattr.selectedIndex]+origimageurl.substr(origimageurl.length-4, 4)	//+origimageurl.substr(origimageurl.length-5, 5)
		document.frmMain["prodimagesuffix"+pf_id].value = a_imageids[objattr.selectedIndex]
	}else{
		document.images["imgproduct"+pf_id].src = origimageurl.substr(0, origimageurl.indexOf(pf_id))+pf_id+'_'+a_imageids[objattr.selectedIndex]+origimageurl.substr(origimageurl.length-4, 4)		//origimageurl.split(pf_id).join(pf_id + '-' + a_imageids[objattr.selectedIndex])
		document.frmMain["prodimagesuffix"+pf_id].value = a_imageids[objattr.selectedIndex]
	}


    var t
	t=document.images["imgproduct"+pf_id].src.toLowerCase()

	t=t.split('/md/').join('/lg/')
	t=t.split('/sm/').join('/lg/')
	//t=t.split('t.gif').join('.gif')
	//t=t.split('t.jpg').join('.jpg')
	//t=t.split('m.gif').join('.gif')
	//t=t.split('m.jpg').join('.jpg')

	t=t.substr(t.indexOf('/companies/'),t.length)

	document.getElementById("zoomimageimg"+opf_id).href=t
	document.getElementById("zoomimage"+opf_id).href=t
}

