﻿/*
What it does:  This file has the most common functions of javascript which are used from
               almost all the pages.
               Here is a list of all the functions within this page:
                 GetElement(yid)
                 GetOpenerElement(yid)
                 round_(ynum, ydec)
                 trim_(ystr)
                 SuffixZeros(ynum, ydec)
                 setCookie_(name, value, expires, path, domain, secure)
                 getCookie_(name)
                 CenterThisWindow(xwidth, xheight, xpercent)
                 ShowPopupImage(yzoomimage)
                 debug(ystr)

Referred by:   Almost all web pages.
*/

<!-- Start: detect bonus area -->
//Save screen width and height in cookies
//window.onerror="return true";
//var xy = navigator.appVersion; 
//xz = xy.substring(0,4); 
document.cookie = "ScreenWidth=" + screen.width 
document.cookie = "ScreenHeight=" + screen.height 
//window.onerror="return false";
<!-- End: detect bonus area -->

function GetElement(yid) {
	return document.getElementById(yid);
}

function GetOpenerElement(yid) {
	return opener.document.getElementById(yid);
}

function round_(ynum, ydec) {
	var xstr = "1";
	var xnum, xinter;
	for (k=0;k<ydec;k++) {
		xstr = xstr + "0";
	}
	xnum = parseFloat(xstr);
	xinter = Math.round(ynum*xnum);
	return (xinter/xnum);
};

function trim_(ystr) {
	var xfound = false
	if (ystr.length == 0) return ""
	for (var k=0; k<ystr.length;k++) {
		if (!xfound) {
			if (ystr.charAt(k) == " ") {
			}
			else {
				ystr = ystr.substring(k, ystr.length)
				xfound = true
				break
			}
		}
	}
	if (!xfound) ystr = ""
	
	xfound = false
	if (ystr.length == 0) return ""
	for (k=ystr.length-1; k>=0;k--) {
		if (!xfound) {
			if (ystr.charAt(k) == " ") {
			}
			else {
				ystr = ystr.substring(0, k+1)
				xfound = true
				break
			}
		}
	}
	if (!xfound) ystr = ""
	return ystr
}

function SuffixZeros(ynum, ydec) {
	ynum = round_(ynum, ydec)
	ystr = ynum + ""
	if (ystr.indexOf(".") < 0) {
		ystr = ystr + "."
	}
	xpos = ystr.indexOf(".")
	xlen = ystr.length
	xst = xlen - xpos
	for (var k=xst; k<= ydec;k++) {
		ystr = ystr + "0"
	}
	return ystr;
}

function setCookie_(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) + 
		((expires) ? "; expires=" + expires.toGMTString() :"") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") + 
		((secure) ? "; secure" : "")
		if ((name + "=" + escape(value)).length <= 4000) {
			document.cookie = curCookie
		}
		else {
			document.cookie = curCookie
		}
}

function getCookie_(name) {
	var prefix = name + "="
	var cookieStartIndex = document.cookie.indexOf(prefix)
	if (cookieStartIndex < 0) {
		return '';
	}
	
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
	if (cookieEndIndex < 0) {
		cookieEndIndex = document.cookie.length
	}
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}

function CenterThisWindow(xwidth, xheight, xpercent){
	if (xpercent) {
		xwidth = screen.width * xpercent * 0.01
		xheight = screen.height * xpercent * 0.01
	}
	var xleft = (screen.width - xwidth) / 2;
	var xtop = (screen.height - xheight) / 2;
	return 'left='+xleft+', top='+xtop+', width='+xwidth+', height='+xheight;
}

function ShowPopupImage(yzoomimage, ypath) {
	xpath = ""
	if (ypath) {
		xpath = "&path=1"
	}
	var xwidth = 600
	var xheight= 500
	var xleft = (screen.width - xwidth)/2
	var xtop = (screen.height - xheight)/2
	var xwin1 = window.open('showdetails.asp?myimage=' + yzoomimage + xpath	, 'win1', 'left='+xleft+',top='+xtop+',width='+xwidth+',height='+xheight+',resizable')
}

function debug(ystr) {
	if (debugflag || xdebugon == '1') {
		alert(ystr)
	}
}

function gotoThisWizard(yurl, ycatgid, ysubcatgid, yXML, yWizardID, yHeight, yWidth, ynumcolor, ycomingsoon, yHeading, yPrintColors, yShapeId, yVarNames, yVarValues, yImage, yPopupImage, yconcode, xtermsofuse) {

	//yWizardID = yWizardID.replace(/,/,"");
	//yWizardID = yWizardID.replace(/=/,"");


	if (yurl.length==0 || yurl=='comingsoon' || ycomingsoon.toLowerCase() == 'true'){
		alert('Coming Soon')
		return
	}
	document.preview.catgid.value = ycatgid
	document.preview.subcatgid.value = ysubcatgid
	document.preview.templateXML.value = yXML
	document.preview.wizardid.value = yWizardID
	document.preview.templateH.value = yHeight
	document.preview.templateW.value = yWidth
	document.preview.numcolor.value = ynumcolor

	document.preview.printcolors.value = yPrintColors
	document.preview.designshape.value = yShapeId
	
	document.preview.ProductHeading.value=yHeading
	document.preview.Image.value=yImage
	document.preview.PopupImage.value=yPopupImage
	document.preview.InitConcode.value=yconcode

	if (yVarNames.length > 0) {
		document.all.divShell.innerHTML = ""
		aVarNames = yVarNames.split(";")
		aVarValues = yVarValues.split(";")
		var xstr = ""
		for (k=0; k<aVarNames.length; k++) {
			if (!document.preview[aVarNames[k]]) {

				xstr = xstr + '<input type="hidden" name="' + aVarNames[k] + '" value="' + aVarValues[k] + '">'
			}
		}
		document.all.divShell.innerHTML = xstr
	}
	

	document.preview.target = "_self"
	document.preview.action = yurl
	document.preview.submit()
}

function ShowMatPrices(yform, yWizardId, yCatgId, ySubCatgId, yH, yW, ynumcolor, yShapeId, yTemplateXML) {
	var xwidth=750;
	var xheight=480;
	var xleft = (screen.width - xwidth) / 2;
	var xtop = (screen.height - xheight) / 2;
	var mpwin = window.open('about:blank', 'mpwin', 'left='+xleft+',top='+xtop+',width='+xwidth+',height='+xheight+',resizable,scrollbars')
	if (document[yform].WizardId) {
		document[yform].WizardId.value = yWizardId
	}
	if (document[yform].wizardid) {
		document[yform].wizardid.value = yWizardId
	}
	
	if (yCatgId) {
		if (document[yform].CatgId) {
			document[yform].CatgId.value = yCatgId
		}
		if (document[yform].catgid) {
			document[yform].catgid.value = yCatgId
		}
	}
	
	if (ySubCatgId) {
		if (document[yform].SubCatgId) {
			document[yform].SubCatgId.value = ySubCatgId
		}
		if (document[yform].subcatgid) {
			document[yform].subcatgid.value = ySubCatgId
		}
	}

	if (yH) {
		if (document[yform].TemplateH) {
			document[yform].TemplateH.value = yH
		}
		if (document[yform].templateH) {
			document[yform].templateH.value = yH
		}
	}

	if (yW) {
		if (document[yform].TemplateW) {
			document[yform].TemplateW.value = yW
		}
		if (document[yform].templateW) {
			document[yform].templateW.value = yW
		}
	}

	if (ynumcolor) {
		if (document[yform].numcolor) {
			document[yform].numcolor.value = ynumcolor
		}
	}

	if (yShapeId) {
		if (document[yform].ShapeId) {
			document[yform].ShapeId.value = yShapeId
		}
		if (document[yform].shapeid) {
			document[yform].shapeid.value = yShapeId
		}
	}
	
	if (yTemplateXML) {
		if (document[yform].TemplateXML) {
			document[yform].TemplateXML.value = yTemplateXML
		}
		if (document[yform].templateXML) {
			document[yform].templateXML.value = yTemplateXML
		}
		if (document[yform].templatexml) {
			document[yform].templatexml.value = yTemplateXML
		}
	}
		
	document[yform].target = "mpwin"
	document[yform].action = "/xp5/material_prices.asp"
	document[yform].submit()
}

