// JavaScript Document
function MM_openBrWindow(theURL,winName,features) { //v2.0
	if (theURL.toLowerCase().indexOf('showdetails')>=0){
		window.open(theURL,winName,features);
	}else if (theURL.toLowerCase().indexOf('.gif')>0 || theURL.toLowerCase().indexOf('.jpg')>0){
		window.open('/xp/showimagefromurl.asp?myimage='+theURL,'','resizable=yes,width=220,height=22')
	}else{
		window.open(theURL,winName,features);
	}
}

function LoginNow() {
	document.preview.fullpage.value="true"
	document.preview.action = "/xp5/login.asp"
	document.preview.submit()
}

function LogoutNow() {
	document.preview.fullpage.value="true"
	document.preview.logout.value="true"
	document.preview.action = "/xp/xp5_MyAccount.asp"
	document.preview.submit()
}

function GotoHome() {
	document.preview.catgid.value = ''
	document.preview.subcatgid.value = ''
	document.preview.action = '/index.aspx'
	document.preview.submit()
}

//This function is not required now. The variables are passed in url string.
function showProducts(ydeptid, ypageno) {
	if (!ypageno) {
		ypageno = 1
	}
	document.preview.wizardid.value = ydeptid
	document.preview.prodtype.value = 'S'
	document.preview.gallery.value = 5	//display stock products listing
	document.preview.action = '/xp/xp5_stocklisting.aspx?dept_id='+ydeptid+'&currentpage='+ypageno
	document.preview.submit()
}

//This function is not used. The variables should passed in url string.
function showProductDetails(deptid,stdcode) {
	document.preview.wizardid.value = deptid
	document.preview.stdcode.value = stdcode
	document.preview.prodtype.value = 'S'
	document.preview.gallery.value = 6	//display stock products listing
	document.preview.action = '/xp/xp5_stockproductspecs.aspx'
	document.preview.submit()
}

function submitEvent(gallery,xvar) {
	document.preview.gallery.value = gallery
	document.preview.manageEvent.value = xvar
	document.preview.action = '/index.aspx'
	document.preview.submit()
}

//This function is not required now. The variables are passed in url string.
function NextPage(yprodtype, ygallery, ywizardid, yproductid, yurl, yparentid) {
//alert(yprodType+'...'+ygallery+'...'+ywizardid+'...'+yproductid+'...'+yurl+'...'+yparentid)
	if (!yprodtype) {
		yprodtype = 'S'
	}
	if (!ygallery) {
		ygallery = ''
	}
	if (!ywizardid) {
		ywizardid = ''
	}
	if (!yproductid) {
		yproductid = ''
	}
	if (!yurl) {
		yurl = ''
	}
	if (!yparentid) {
		yparentid = ''
	}
	document.preview.prodtype.value = yprodtype
	document.preview.gallery.value = ygallery
	document.preview.wizardid.value = ywizardid
	document.preview.productid.value = yproductid
	document.preview.url.value = yurl
	document.preview.parentid.value = yparentid

	document.preview.catgid.value = ''
	document.preview.subcatgid.value = ''
	document.preview.action = '/index.aspx'
	document.preview.submit()
}

function updateAccount(){
	document.preview.action = '/xp/xp5_updateAccount.asp'
	document.preview.submit()
}

function gotoWizard(xurl, ProductHeading){
	if (xurl.length==0 || xurl=='comingsoon'){
		alert('Coming Soon')
		return
	}
	document.preview.ProductHeading.value=ProductHeading
	document.preview.action = '/xp5/'+xurl
	document.preview.submit()
}

function ClearWizardPreferences(yprefix) {
	setCookie(yprefix + "names", "")
	setCookie(yprefix + "values", "")
}

function setCookie(name, value, expires, path, domain, secure) {
	//path='/xp5'
	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
	}
	//document.write(unescape(document.cookie.substring(1, document.cookie.length)) + '\n\n')
	//document.write(document.cookie.substring(1, document.cookie.length))
	//alert(unescape(document.cookie.substring(1, document.cookie.length)))
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}

function validateinput(){
	document.frmsearch.txtsearch.value=trimstr(document.frmsearch.txtsearch.value)
	if (document.frmsearch.txtsearch.value.length==0) {
		alert('Please enter search criteria...')
		return false
	}
	return true
}

function searchCalib(ystr) {
	document.frmsearch.txtsearch.value=ystr;
	document.frmsearch.submit();
}

function ShowAlert(yalert) {
	alert(yalert)
}

function GoDirectToWizard(yid) {
	document.preview.AutoId.value = yid
	document.preview.action = '/xp5/'+'wizarda.asp'
	//document.preview.submit()	
}

//stock products listing and addtocart functions

function showLargeImg (imgName){
	open('/xp2/images/'+imgName,"cag" , "width=475,height=450,resizable=1,scrollbars=1,location=no");
}

function productDetails (ipfid) {
var xx
return

	xx="pf_id=" + ipfid
	open("productdetails.asp?" + xx,"cag" , "width=540,height=800,status=1,resizable=1,scrollbars=1, location=no");
}
	
function checkqtys(frmobj) {
var ttl=0, minqty, qtyfld, 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
				break;	
			}
		}
	}

	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'
	    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)
			//alert(minqty+'....'+qtyfld)
			validyn=VldQty(window.document[frmobj][minqty], window.document[frmobj][qtyfld])
			if ( ! validyn) 
				break;	
		}
	}
	return validyn;
}

function VldQty(minqty,qtyfld) {
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
		}
	}
	return allow;
}

function loadpage(list) {
	if (list.options[list.selectedIndex].value !=" ") {
		var theStr = new String(list.options[list.selectedIndex].value);
    	var xsample = theStr.substring(0,10);
		if (xsample == "javascript") {
			theStr=theStr.replace(/javascript:/, "");
			eval(theStr);
		}
		else {
			location.href=list.options[list.selectedIndex].value;
		}
	} else {
		alert('Please make a selection from the drop-down list below');
	}
}