// ============================================ //
// Merchant Solutions Merchant Server Script vMS3.50
// Copyright Comtech Solutions, Salt Lake City, 2001 ALL RIGHTS RESERVED 
// This script code is available under agreement only to Registered 
// Comtech Solutions clients.
// Set Debug to "true" to verify operation with your application.
// Parameters: CSI=Part Number, Q=Quantity, 
// Common Action Settings: "View", "AddList", and ?
NewSearch = unescape(window.location.search.substring(1,window.location.search.length))
NewSearch = NewSearch.toUpperCase();
RefID = ""
k=NewSearch.indexOf("REFID=")
if (k>=0){
	j=NewSearch.indexOf("&",k+6)
	if (j>k){
		RefID = "&RefID="+NewSearch.substring(k+6,j)
	} else {
		RefID = "&RefID="+NewSearch.substring(k+6,NewSearch.length)
	}
	CRefID = "REFID="+RefID+"; path=/;"
	document.cookie = CRefID
}
RefID = getCookieData("REFID")
QMMsgID = ""
QMMsgID = getCookieData("MSGID")
var Debug=false;
var GoSecure = true
var CID;
var Action="View"
TStamp = new Date();
document.cookie = "QCOOKIE=True; path=/;"
Pth = "https://secure2.ComtechSolutions.net"
if( !GoSecure ) {Pth = "http://ComtechSolutions.net"}
//Pth = "http://b2bdev.comtechsolutions.net"
//if( !GoSecure ) {Pth = "http://b2bdev.comtechsolutions.net"}
if( !(document.cookie.indexOf("QUNIQUE") >= 0) )  
	{document.cookie = "QUNIQUE="+(Math.floor(Math.random()*100000000)+
	Math.floor(TStamp.getTime()))+"; path=/;"}
function getCookieData(label)  {
	var labelLen = label.length
	var cLen = document.cookie.length
	var i=0
	while( i < cLen ) {
		var j = i + labelLen
		if( document.cookie.substring(i,j) == label )   {
			var cEnd = document.cookie.indexOf(";",j)
			if( cEnd == -1 )  { cEnd = document.cookie.length }
			return unescape(document.cookie.substring(j+1,cEnd)) }
		i++  }
	return "" }
function ViewOrder()  {
	// This function is optional.
	location = Pth + "/QMS/ShopView.asp?CID="+CID+"&ViewMode=Cart&Back="
		+escape(window.location.href)+"&QUNIQUE="+getCookieData("QUNIQUE")+RefID+QMMsgID }
		
function InitClient(NCID,NAction,NDebug)  {
	CID = NCID;
	Action = NAction;
	Debug = NDebug;
}
	
function NewPath(ClientPath)  {
	Pth = ClientPath
}
	
function QuickAddList(frm)  {
	// This function is optional. (working sample - refundcents.com)
	// All elements of the form: "CSD=aaa;CSI=bbb;CSP=ccc;CSSH=ddd;CST=eee"
	// The only REQUIRED values are CSP and either CSD or CSI.  All CS Names must start with xOCS=
	var ext="";
	var ext="";
	var count=0;
	for( i=0; i<frm.elements.length; i++ )  {
		obj = frm.elements[i]
		if( obj.name.length > 0 )  {
			var Found = false
			if( obj.name.indexOf("OCS=") ) { 
				Found = false;
				aValue = ""
				bValue = ""
				cValue = ""
				if( obj.name.charAt(0) == "s" ) { if( !obj.options[obj.selectedIndex].defaultSelected ) { Found=true; aValue = obj.options[obj.selectedIndex].value } }
				else if( obj.name.charAt(0) == "t" ) { if (obj.value != null && obj.value != ""){ Found=true; aValue = obj.value } }
				else if (obj.name.charAt(0) == "q" ) { 
					if (obj.value != null && obj.value != ""){
						Found=true; bValue = "CSQ=" + obj.value ;
						NumOpt = parseInt(frm.elements[i+1].name.charAt(1));
						if (NumOpt>0) {
							for ( j=0; j<NumOpt; j++){
								OptObj = frm.elements[i+2+j]
								cValue = cValue + OptObj.options[OptObj.selectedIndex].value
							}
						}
					aValue = frm.elements[i+1].value + cValue + ";" + bValue
					}
				}
				else if( (obj.name.charAt(0) == "r" || obj.name.charAt(0) == "c") && obj.checked ) { Found=true; aValue = obj.value }
				if( Found )  { ext += "&Item=" + escape(obj.name.substring(obj.name.indexOf("OCS=")+4,obj.name.length) + escape(aValue) + ";")}
				}
			}
		}
	if( document.cookie.length > 0 && document.cookie.substring("QCOOKIE") )  {
		var url = Pth + "/QMS/AddItemMS.asp?CID=" + CID + "&Action=" + Action + ext;
		if( Debug ) {url += "&Debug=True"}
		location = url + "&v=QM3.00&TStamp=" + TStamp.getTime() + "&Back=" 
			+escape(window.location.href)+"&QUNIQUE="+getCookieData("QUNIQUE")+RefID+QMMsgID
		}
	else  {
		alert("Your system does not support cookies so your item cannot be ordered online.")
		}
	}
function QuickAdd(CSD,CSI,CSP,CSSH,CST,CSQ,CTRL)  {
	// This function is optional.
	ext = "&CSI=" + escape(CSI) + "&CSD=" + escape(CSD) + "&CSP="
		+ escape(CSP) + "&CSSH=" + escape(CSSH) + "&CST=" + escape(CST) + "&CTRL=" + CTRL
	if( !isNaN(CSQ) )  { ext = ext + "&Q=" + CSQ}
	if( document.cookie.length > 0 && document.cookie.substring("QCOOKIE") )  {
		var url = Pth + "/QMS/AddItemMS.asp?CID=" + CID 
			+ "&Action=" + Action + ext;
		if( Debug ) {url += "&Debug=True"}
		location = url + "&v=QM3.00&TStamp=" + TStamp.getTime() + "&Back=" 
			+escape(window.location.href)+"&QUNIQUE="+getCookieData("QUNIQUE")+RefID+QMMsgID
		}
	else  {
		alert("Your system does not support cookies so your item cannot be ordered online.")
		}
	}
function QuickAddCL(clName,CSD,CSI,CSP,CSSH,CST,CSQ,CTRL)  {
	// This function is optional. (Working sample - Demo)
	var x = clName.options[clName.selectedIndex].value.split(";")
	if( x.length >= 1 )  { CSD += x[0] }
	if( x.length >= 2 )  { CSI += x[1] }
	if( x.length >= 3 )  { CSP = x[2] }
	if( x.length >= 4 )  { CSSH = x[3] }
	if( x.length >= 5 )  { CST = x[4] }
	if( x.length >= 6 )  { CSQ = x[5] }
	QuickAdd(CSD,CSI,CSP,CSSH,CST,CSQ,CTRL)
	}
function QuickAddQ(clName,CSQ,CSD,CSI,CSP,CSSH,CST,CTRL)  {
	// Use this function if the page uses products that have a choice list of quantities 
	// and only one product is ordered at a time.  You must pass the NAME of the choice list
	// as the first parameter (i.e. document.fmData.clName - where fmData is the name of the form
	// and clName is the name of the choice list.
	if( !isNaN(clName.options[clName.selectedIndex].value) )  {CSQ=clName.options[clName.selectedIndex].value}
	QuickAdd(CSD,CSI,CSP,CSSH,CST,CSQ,CTRL)
	}
function QMAdd(xCSD,xCSI,xCSP,xCSSH,xCST,xCSQ,xCTRL)  {
	// CSQ=quantity, CSQD=default quantity, CSD=description, CSI=part number, CSP=price, CSSH=shipping and handling
	// any number of fields may follow.
	CSD = xCSD; CSI=xCSI; CSP=xCSP; CSSH=xCSSH; CST=xCST; CSQ=xCSQ; CTRL=xCTRL;
	for( i=7; i<QMAdd.arguments.length; i++ )  {
		if( !QMAddCL(QMAdd.arguments[i]) )  {return}
		}
	QuickAdd(CSD,CSI,CSP,CSSH,CST,CSQ,CTRL)
	}
function QMAddCL(clName)  {
	// This function is optional. (Working sample - Demo)
	val = clName.options[clName.selectedIndex].value;
	if( val.substring(0,6) == "PROMPT" )  {alert(val.substring(7,val.length));clName.focus();return(false)}
	var x = val.split(";")
	if( x.length >= 1 )  { CSD += x[0] }
	if( x.length >= 2 )  { CSI += x[1] }
	if( x.length >= 3 && x[2].length > 0 )  { CSP = x[2]; }
	if( x.length >= 4 && x[3].length > 0 )  { CSSH = x[3] }
	if( x.length >= 5 && x[4].length > 0 )  { CST = x[4] }
	if( x.length >= 6 && x[5].length > 0 )  { CSQ = x[5] }
	return(true)
	}