
//function old_changeProdImage(objattr, pf_id, imageids){
//var a_imageids=imageids.split(',')
//var origimageurl=''

//	pf_id=pf_id.toLowerCase()
//	origimageurl = document.images["imgproduct"+pf_id].src
//	origimageurl = origimageurl.toLowerCase()
	
//	document.images["imgproduct"+pf_id].src = origimageurl.substr(0, origimageurl.indexOf(pf_id))+pf_id+'_'+a_imageids[objattr.selectedIndex]+origimageurl.substr(origimageurl.length-5, 5)	//origimageurl.split(pf_id).join(pf_id + '-' + a_imageids[objattr.selectedIndex])
//	document.addprod["prodimagesuffix"+pf_id].value = a_imageids[objattr.selectedIndex]
//}


function changeProdImage(objattr, pf_id, imageids){
var a_imageids=imageids.split(',')
var origimageurl=''

	pf_id=pf_id.toLowerCase()
	origimageurl = document.images["imgproduct"+pf_id].src
	origimageurl = origimageurl.toLowerCase()

	//use thumb image name to generate colored image name
	if (origimageurl.indexOf(pf_id)==-1){	
		origimageurl=origimageurl.split('_'+document.addprod["prodimagesuffix"+pf_id].value+'m.').join('m.')
		document.images["imgproduct"+pf_id].src = origimageurl.substr(0, origimageurl.length-5)+'_'+a_imageids[objattr.selectedIndex]+origimageurl.substr(origimageurl.length-5, 5)
		document.addprod["prodimagesuffix"+pf_id].value = a_imageids[objattr.selectedIndex].toLowerCase()

	}else{
		document.images["imgproduct"+pf_id].src = origimageurl.substr(0, origimageurl.indexOf(pf_id))+pf_id+'_'+a_imageids[objattr.selectedIndex]+origimageurl.substr(origimageurl.length-5, 5)
		document.addprod["prodimagesuffix"+pf_id].value = a_imageids[objattr.selectedIndex].toLowerCase()
	}
}


function showDetailedImage(pf_id) {
var t

	t=document.images["imgproduct"+pf_id].src.toLowerCase()

	t=t.split('thumbnail').join('detailed')
	t=t.split('mediumres').join('detailed')
	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)
	t='/xp/showdetailsstock.asp?myimage=' + t
	
	MM_openBrWindow(t,'zoomwin','resizable=yes,width=550,height=375')

}

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('showimagefromurl.asp?myimage='+theURL,'','resizable=yes,width=220,height=22')
	}else{
		window.open(theURL,winName,features);
	}
}

function expand_collapse(item){
	if (GetElement("div"+item)){
		if (GetElement("div"+item).style.display=='none') {
			GetElement("div"+item).style.display = '';
			document.images["imgexpcol"+item].src="images/collapse0.gif"
		} else {
			GetElement("div"+item).style.display = 'none';
			document.images["imgexpcol"+item].src="images/expand0.gif"
		}
	}
}

function GotoHome() {
	document.preview.catgid.value = ''
	document.preview.subcatgid.value = ''
	document.preview.action = '/indexstock.asp'
	document.preview.submit()
}


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 = '/indexstock.asp'
	document.preview.submit()
}

function GoDirectToWizard(yid) {
	document.preview.AutoId.value = yid
	document.preview.action = '/xp5/'+'wizarda.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 gotoThisWizard(yurl, ycatgid, ysubcatgid, yXML, yWizardID, yHeight, yWidth, ynumcolor, ycomingsoon, yHeading, yPrintColors, yShapeId, yVarNames, yVarValues, yImage, yPopupImage, yconcode, xtermsofuse) {
	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) {
		GetElement("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] + '">'
			}
		}
		//alert(xstr)	
		GetElement("divShell").innerHTML = xstr
	}

	document.preview.action = '/xp5/'+yurl
	if (xtermsofuse){
		if (xtermsofuse==1){
			document.preview.nextlink.value = '/xp5/'+yurl
			document.preview.action = "/xp5/terms_use.asp"
		}
	}
	document.preview.submit()
}

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 validsearchstr(){
	document.productsearch.txtsearch.value=trimstr(document.productsearch.txtsearch.value)
	if (document.productsearch.txtsearch.value.length==0) {
		alert('Please enter search criteria...')
		return false
	}

	if (document.productsearch.txtsearch.value.length<=2) {	
		alert('Please enter atleast 3 characters...')
		return false
	}

	searchAllProducts(7)

	return false	//in all cases return false
}

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 no longer needed:
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 searchAllProducts(xgallery) {
	document.preview.action = '/xp/xp5_findsummary.asp?txtsearch='+document.productsearch.txtsearch.value
	document.preview.submit()
}


function showHelpAll(){
/*gallery=8 show all help pages matching search criteria*/
	document.preview.action = '/xp/xp5_findhelppages.asp?txtsearch='+document.productsearch.txtsearch.value
	document.preview.submit()
}

function showStockProdAll(){
/*gallery-9 show all stock products matching search criteria*/
	document.preview.action = '/xp/xp5_findStockProds.asp?txtsearch='+document.productsearch.txtsearch.value
	document.preview.submit()
}

function showCustomProdAll(){
/*gallery-10 show all custom products matching search criteria*/
	document.preview.action = '/xp/xp5_findCustomProds.asp?txtsearch='+document.productsearch.txtsearch.value
	document.preview.submit()

}


function searchCalib(ystr) {
	document.frmsearch.txtsearch.value=ystr;
	document.frmsearch.submit();
}

function ShowAlert(yalert) {
	alert(yalert)
}

//following functions used in bottompromo.asp

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)
//			alert(window.document[frmobj][qtyfld].value.length + '...'+qtyfld)
			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'
		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)
//alert(minqty+'....'+qtyfld+'....'+mult)

			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 trimstr(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
}
//following functions used in bottompromo.asp
