//var dd = document.domain.substr(document.domain.indexOf('.')+1);
//document.domain = dd;
//alert(document.domain);

isCWindow = true;

function DownloadSalesDrawing(cId, cNm, catId, prodId, itmId, partId, viewId, vwUOM, logItUrl, bcVal, vwNm, isWT, lid) {
    //following code is moved to CADUtility.vb
    //var sysUnitVal = getCookieKyVal('superCookie', 'systemUnit');
    //var sysUnit = (sysUnitVal=='inch' ? 1 : (sysUnitVal=='mm' ? 0 : ''));
    //alert(logItUrl);
    //alert(document.domain);
    var domainlink = 'http://' + document.domain + "/";
    //Start :: Parin Chheda :: Issue#5691 :: PLP - CAD 2D Sales Drawing - Open in New Window
    //CADUtility.CADSales_Download(cId, cNm, catId, prodId, itmId, partId, viewId, vwUOM, logItUrl, bcVal, vwNm, isWT, CADSales_Download_CallBack, this);
    var CADSalesWin = window.open(domainlink + 'plp/htm/CADSalesDrawing.htm', '_blank', 'toolbar=no,location=no,directories=no,menubar=no,width=1024,height=800,status=yes,scrollbars=yes,resizable=yes');
    //End :: Parin Chheda :: Issue#5691 :: PLP - CAD 2D Sales Drawing - Open in New Window
    //CADSalesWin.document.write("<html><head></head><body style='background-image: url(/plp/mm/wait_mov.gif); background-repeat: no-repeat;BACKGROUND-POSITION:50% 50%'><table height='100%' width='100%'><tr><td>&nbsp;</td></tr></table></body></html>")
    //CADSalesWin.document.write("<html><head></head><body style='text-align:center'><table height='100%' width='100%' style='text-align:center'><tr><td><p style='font-size: 120%; vertical-align: middle; font-family: verdana; text-align: center'>The application will be started.</p><br><img src='/plp/mm/wait_mov.gif'/></td></tr></table></body></html>")
    CADUtility.CADSales_Download(cId, cNm, catId, prodId, itmId, partId, viewId, vwUOM, logItUrl, bcVal, vwNm, isWT,lid, CADSales_Download_CallBack, CADSalesWin);
}

  function recordOutboundLink(link, category, action,label,value) {
    _gat._getTrackerByName()._trackEvent(category, action,value);
    //setTimeout('document.location = "' + link.href + '"', 100);
    return false;
  }

function CADSales_Download_CallBack(res){
    if(res.value != null){
        if(res.value.length>1){
            //alert(res.context);
            if(res.context != null){
                //alert(res.value[0]);
                res.context.location = res.value[0];
                res.context.focus();
                    
                var logItUrl = res.value[1];
                if(logItUrl!=null && logItUrl!=''){
                    var objNm = logItUrl.substring(logItUrl.indexOf('^$')+2, logItUrl.indexOf('$^'));
                    var objNms = objNm.split('$$');

                    //Log Page Hit Event for Sales Drawings
                    var logItUrl1 = logItUrl.replace('^$'+objNm+'$^', escape(objNms[0]));
                    //alert(logItUrl1);
                    LogIt(logItUrl1);
                    //Log CAD View Event for Sales Drawings
                    var logItUrl2 = logItUrl.replace('^$'+objNm+'$^', escape(objNms[1]));
                    logItUrl2 = logItUrl2.replace('eventid=210', 'eventid=1026');

                    var moreData = null!=res.value[2] ? '&moreData='+escape(res.value[2]) : '';
                    var logItUrl2 = logItUrl2+moreData;
                    //alert(logItUrl2);
                    LogIt(logItUrl2);
                }
                
                //log WebTrax for Sales Drawing
                if(null!=res.value[2] && res.value[2]=='y'){
                    //alert(res.value[3]+'-'+location.href);
                    pageValue("vset", "I");
                    LogClickWebTraxURL("Download CAD");
                }
            }
            if (isCWindow == true) window.close();
        }
        else
            alert(window.message274 + '  ' + res.value);
    }
    else
        alert(window.message275);
}

function SendEmail_CallBack(res){
    if(res.value != null){
        if(res.value.length>1){
            //log email information
            logItUrl = res.value[1];
            //alert(logItUrl);
            LogIt(logItUrl);
            alert(window.message276+'  '+res.value[2]);
            
            //log WebTrax for email action
            var isWT = res.value[3];
            if(isWT=='y'){
                //alert(isWT+'-'+location.href);
                pageValue("vset", "I");
                LogClickWebTraxURL("Email CAD");
            }
        }
        else
            alert(res.value);
    }
    else
        alert(window.message277);
}

function GetDownloadInsert(storeId, ctlId){
    
    ToggleControls(true, ctlId);
    
    //var fm = document.forms[0];
    //alert(fm);
    
    var dlInsHtml = document.getElementById(ctlId+'DownloadInsertFragment');
    //alert(dlInsHtml.innerHTML);
    
    var dlCtl = document.getElementById(ctlId+'DownloadList');
    var dlVal = dlCtl.options[dlCtl.selectedIndex].value
    //alert(dlVal);
    
    var insCtl = document.getElementById(ctlId+'InsertList');
    var insVal = insCtl.options[insCtl.selectedIndex].value;
    //alert(insVal);
    
    var dlDir = getCookieKyVal('superCookie', 'downloadDir');
    if(null==dlDir || dlDir==''){
        dlDir='c:\\_download';
    }
    //alert(dlDir);
    
    CADUtility.GetDownloadInsertHTML(storeId,dlVal,insVal,dlDir,ctlId,GetDownloadInsert_CallBack,dlInsHtml);
    return true;
}

function GetDownloadInsert_CallBack(res){
    if(res.value != null){
        if(res.value.length>1){
            //alert(res.context);
             if(res.context != null){
                //alert(res.value[1]);
                res.context.innerHTML = res.value[1];
                //alert(res.value[2]);
                ToggleControls(false, res.value[2]);
                //check for options again
                var hasOps = hasOptions();
                //alert(hasOps);
                OnLoadInserterDownloader(hasOps);
             }
        }
        else
            alert(res.value);
    }
    else
        alert(window.message278);
        
    //var dlInsHtml = document.getElementById("DownloadInsertFragment");
    //alert(dlInsHtml.innerHTML);        
}

function ToggleControls(isDisabled, ctlId){
    disableAnchor(ctlId+'lnkDownload', isDisabled);
    disableAnchor(ctlId+'lnkInsert', isDisabled);
    disableAnchor('lnkOptions', isDisabled);
}

function validateEmail(emailStr){
    var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    str = emailStr;
    
    if(str!=null && str.match(emailRegEx)){
        return true;
    }else{
        alert(window.message279);
        return false;
    }
}
var imageLoadedForCAD;
var CadWindow;
function OpenBasicCAD(BasicCADUrl, logItUrl){
    //alert(logItUrl);
    if(logItUrl!=null && logItUrl!='')  LogIt(logItUrl); //Log Page Hit Event=1026 for CAD Publisher Popup
// START :: 07-Oct-2009 :: Graham D'cunha :: IssueId#3906 :: PLP - Full CAD Integration - CAD View Pop Up windown - Rotating Gears
//    var cadPubWin = window.open(BasicCADUrl,'View_CAD_Drawings','toolbar=no,location=no,directories=no,status=no,menubar=no,width=800,height=500,scrollbars=yes,resizable');
    var cadPubWin = window.open('','View_CAD_Drawings','toolbar=no,location=no,directories=no,status=no,menubar=no,width=800,height=500,scrollbars=yes,resizable');
      //cadPubWin.document.write("<html><head></head><body style='text-align:center' style='background-image: url(/plp/mm/wait_mov.gif);background-repeat: no-repeat;BACKGROUND-POSITION:40% 60%'><table height='100%' width='100%' style='text-align:center'><tr><td ><p style='font-size: 120%; vertical-align: middle; font-family: verdana; text-align: center'>The application will be started.</p><br></td></tr></table></body></html>")
      cadPubWin.document.write("<html><head></head><body style='text-align:center'><table height='100%' width='100%' style='text-align:center'><tr><td><p style='font-size: 120%; vertical-align: middle; font-family: verdana; text-align: center'>The application will be started.</p><br><img src='/plp/mm/wait_mov.gif'/></td></tr></table></body></html>")
      imageLoadedForCAD=BasicCADUrl;
      CadWindow =  cadPubWin ;
      setTimeout("CadWindow.location=imageLoadedForCAD;" , 1000);
       //cadPubWin.location=BasicCADUrl;
      // END :: 07-Oct-2009 :: Graham D'cunha :: IssueId#3906 :: PLP - Full CAD Integration - CAD View Pop Up windown - Rotating Gears
    cadPubWin.focus();
    return true;
}
var imageLoadedForCAD;
var CadWindow;
function OpenCADPublisher(cadPubUrl, logItUrl){
    //alert(logItUrl);
    if(logItUrl!=null && logItUrl!='')  LogIt(logItUrl); //Log Page Hit Event=210 for CAD Publisher Popup
// START :: 07-Oct-2009 :: Graham D'cunha :: IssueId#3906 :: PLP - Full CAD Integration - CAD View Pop Up windown - Rotating Gears
//    var cadPubWin = window.open(cadPubUrl,'View_CAD_Drawings','toolbar=no,location=no,directories=no,menubar=no,width=600,height=875,status=yes,scrollbars=yes,resizable=yes');
      var cadPubWin = window.open('','View_CAD_Drawings','toolbar=no,location=no,directories=no,menubar=no,width=600,height=875,status=yes,scrollbars=yes,resizable=yes');
      //cadPubWin.document.write("<html><head></head><body style='text-align:center' style='background-image: url(/plp/mm/wait_mov.gif);background-repeat: no-repeat;BACKGROUND-POSITION:40% 60%'><table height='100%' width='100%' style='text-align:center'><tr><td ><p style='font-size: 120%; vertical-align: middle; font-family: verdana; text-align: center'>The application will be started.</p><br></td></tr></table></body></html>")
      cadPubWin.document.write("<html><head></head><body style='text-align:center'><table height='100%' width='100%' style='text-align:center'><tr><td><p style='font-size: 120%; vertical-align: middle; font-family: verdana; text-align: center'>The application will be started.</p><br><img src='/plp/mm/wait_mov.gif'/></td></tr></table></body></html>")
      imageLoadedForCAD=cadPubUrl;
      CadWindow =  cadPubWin ;
      setTimeout("CadWindow.location=imageLoadedForCAD;" , 1000);
      //cadPubWin.location=cadPubUrl;
      //cadPubWin.document.write("<html><head></head><body style='text-align:center' style='background-image: url(/plp/mm/wait_mov.gif);background-repeat: no-repeat;BACKGROUND-POSITION:40% 60%'><table height='100%' width='100%' style='text-align:center'><tr><td ><p style='font-size: 120%; vertical-align: middle; font-family: verdana; text-align: center'>The application will be started.</p><br></td></tr></table></body></html>")
// END :: 07-Oct-2009 :: Graham D'cunha :: IssueId#3906 :: PLP - Full CAD Integration - CAD View Pop Up windown - Rotating Gears
    cadPubWin.focus();
    return true;
}

function OpenDynamicCAD(dynCadUrl, logItUrl, moreData){

    //alert(dynCadUrl);alert(logItUrl);alert(moreData);
    if(logItUrl!=null && logItUrl!=''){
        LogIt(logItUrl); //Log Page Hit Event for Dynamic Cad Popup
        
        //Logging for dynamic cad actions(insert/download/email) are implemented by Christian & Georgy. 
        //replace Page Hit Event Id (eventid=210) with "{0}" (eventid={0}) template from plain LogItURL.
        logItUrl = GetLogUrl(logItUrl);
        logItUrl = logItUrl.substring(logItUrl.indexOf('?')+1);
        //logItUrl = logItUrl.replace('eventid=210', 'eventid={0}');
        
        var qs = new Querystring(logItUrl);
        logItUrl = '&cId='+qs.getEsc("cid")
        logItUrl += '&appId='+qs.getEsc("applicationid");
        //logItUrl += '&eId='+qs.getEsc("eventid");
        //logItUrl += '&oId='+qs.getEsc("objectid");
        //logItUrl += '&oNm='+qs.getEsc("objectname");
        logItUrl += '&lsId='+qs.getEsc("logsession");
        //logItUrl += '&url='+qs.getEsc("url");
        //logItUrl += '&seo='+qs.getEsc("seo");
        //logItUrl += '&ref='+qs.getEsc("referrer");
        //logItUrl += '&s='+qs.getEsc("s");
        logItUrl += '&ctId='+qs.getEsc("CatalogID");
        logItUrl += '&vId='+qs.getEsc("VersionID");
        logItUrl += '&uId='+qs.getEsc("UserID");
        
        logItUrl = logItUrl+'&'+moreData;
        
        //alert(logItUrl);
        //alert(decodeURIComponent(encodeURIComponent(logItUrl)));
        //dynCadUrl = dynCadUrl.replace('PPOW_Entry.asp?', 'PPOW_Entry_Nilesh.asp?');
        //dynCadUrl = dynCadUrl.replace('PPOW_Entry.asp?', 'PPOW_Entry_CNLogger.asp?');
        dynCadUrl += logItUrl;
       
        //alert(dynCadUrl);
    }
    
    var dynCadWin = window.open(dynCadUrl,'ViewCADDrawings','toolbar=no,location=no,directories=no,status=no,menubar=no,width=900,height=500,scrollbars=yes,resizable');
    dynCadWin.focus();
    return true;
}

function getCookieKyVal(name, key) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) {
		    var ckVal = c.substring(nameEQ.length,c.length);
            var ctlCk = ckVal.split('*');
            
            for(var i=0;i<ctlCk.length;i=i+2) {
	            var d = ctlCk[i];
	            while (d.charAt(0)==' ') d = d.substring(1,d.length);
	            if(d==key){
	                return ctlCk[i+1];
	            }
            }
		}
	}
	return null;
}


function disableAnchor(objId, disable)
{
    var obj = document.getElementById(objId);
    if(obj != null){
        if(disable){
            var href = obj.getAttribute("href");
            var onclick = obj.getAttribute("onclick");
            //First we store previous value in a new attribute
            if(href && href != "" && href != null){
                obj.setAttribute('href_bak', href);
            }
            if(onclick != null){
                obj.setAttribute('onclick_back', onclick);
                obj.setAttribute('onclick', "void(0);");
            }
            obj.removeAttribute('href');
            //obj.style.color="gray";
        }
        else{
            var hrefBack = obj.getAttribute("href_bak");
            var onclickBack = obj.getAttribute("onclick_back");
            if(onclickBack !=null ){
                obj.setAttribute('onclick', onclickBack);
                obj.removeAttribute('onclick_back');
            }
            if(hrefBack !=null ){
                obj.setAttribute('href', hrefBack);
                obj.removeAttribute('href_bak');
                //obj.style.color="blue";
            }
        }
    }
    else{
        alert(objId+' is null');
    }
} 

function OnLoadInserterDownloader(hasOptions){
    var obj = document.getElementById('lnkOptions');
    //alert(hasOptions);
    if(!hasOptions){
        obj.visibility="hidden";
    }else{
        obj.visibility="none";
    }
    
}

function OpenCADSettings(cadUrl){
    var cadSetWin = window.open(cadUrl,'CAD_Options_Settings','width=485,height=500,scrollbars=1,resizable=1');
    cadSetWin.focus();
    return true;
}

function PopUpCADPub(logItUrl){
    //alert(logItUrl);
    if(logItUrl!=null && logItUrl!='')  LogIt(logItUrl);
}

function SwitchView(pgNm, ctlId, partId, vwId, uomVal, vwNm, bcVal){    
    var sForm = eval('document.'+pgNm);
    var sURL = sForm.action;
    //alert(sURL);
    /*switch(pgNm){
        case 'item':
            sURL = document.frmItemDetail.action;
            sForm = document.frmItemDetail;
            break;
        case 'cadpublisher':
            sURL = document.frmPlpMain.action;
            sForm = document.frmPlpMain;
            break;
    }*/

    sURL = sURL.replace(/&PDF=T/i, ' '); //remove download pdf querystring
    sForm.action = sURL;
    
    document.getElementById(ctlId+'PartIDTxt').value = partId;
    document.getElementById(ctlId+'ViewIDTxt').value = vwId;
    document.getElementById(ctlId+'uomValTxt').value = uomVal;
    document.getElementById(ctlId+'vwNmTxt').value = vwNm;
    document.getElementById(ctlId+'bcValTxt').value = bcVal;//unescape(encodeURI(bcVal));
    sForm.submit();
}
//******************************* CADSettings.aspx JS functions ***********************************/


// setCookie explicitly here without escape-ing the value passed in
function setCookie(name, value)
{
   var argv = setCookie.arguments;
   var argc = setCookie.arguments.length;
   var expires = (argc > 2) ? argv[2] : "Fri 30-Dec-2030 16:00:00 GMT";
   var path = (argc > 3) ? argv[3] : null;
   var domain  = (argc > 4) ? argv[4] : cookieDomain;
   var secure  = (argc > 5) ? argv[5] : false;
   /* alert( "Setting cookie:" + name + "=" +  value ); */
   document.cookie = name + "=" +   value + ((expires == null) ? "" : ("; expires=" + expires)) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null || domain == "") ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}

function addCookie(ckKey, name, value)
{
    if(ckKey==1) 
        superCookieValue += name + "*" + value + "*";
    else
        CadUserCookieValue += name + "*" + value + "*";
}

function getSuperCookieValue(ckKey)
{
    return ckKey==1 ? superCookieValue : CadUserCookieValue;
}

function saveOption(ckKey, name) {
    var control = document.forms[0].elements[ name ];
    //alert(control+'-'+name);
    if ( control != null ) {
        addCookie(ckKey, name, control.options[control.selectedIndex].value );
    }
}

function setOption(name, value) {
    var control = document.forms[0].elements[ name ];
    //alert(control+'-'+name+'-'+value);
    if ( control != null ) {
        for(var i=0; i<control.options.length; i++) {
            if(control.options[i].value==value) {
                control.selectedIndex=i; 
                break;
            }
        }
    }
}

 //Start :: Parin Chheda :: Issue#5678 :: PLP - CAD User Tracking - Custom Attributes not remembered
 function setOptionRadio(name, value)
 {
   	var control = document.forms[0].elements[name];
   	if (control != null)
   	{
   		for (var i = 0; i < control.length; i++)
   		{
   			var ctrlVal = control[i].nextSibling.data;
   			if (ctrlVal.substring(0, ctrlVal.length - 2) == value)
   			{
   			    control[i].checked = true;
   			    setHdnIsValueSelectedCtrl(name);
   				break;
   			}
   		}
   	}
 }

 function setOptionText(name, value)
 {
   	var control = document.forms[0].elements[name];
   	if (control != null)
   	{
   		for (var i = 0; i < control.options.length; i++)
   		{
   			if (control.options[i].text == value)
   			{
   			    control.selectedIndex = i;
   			    setHdnIsValueSelectedCtrl(name);
   				break;
   			}
   		}
   	}
 }

 function setList(name, values)
 {
 	var control = document.forms[0].elements[name];
 	if (control != null)
 	{
 		var i, j;
 		var flagSelected = 0;
 		var isCookied = false;
 		for (i = 0; i < control.length; i++)
 		{
 			if (control.options[i].selected)
 			{
 				flagSelected = i;
 				control.options[i].selected = false;
 				break;
 			}
 		}
 		if (values.indexOf(",") == -1)
 			values = values + ",";
 		var value = values.split(",");
 		for (j = 0; j < value.length; j++)
 		{
 			if (value[j] == "") continue;
 			for (i = 0; i < control.length; i++)
 			{
 				if (control[i].text == value[j])
 				{
 					control.options[i].selected = true;
 					isCookied = true;
 					setHdnIsValueSelectedCtrl(name);
 					break;
 				}
 			}
 		}
 		if (!isCookied)
 		{
 		    control.options[flagSelected].selected = true;
 		    setHdnIsValueSelectedCtrl(name);
 		}
 	}
}

function setHdnIsValueSelectedCtrl(name)
{
    var splitName = name.split("_");
    var sHdnIsValueSelected =  "hdnIsValueSelected_" + splitName[1] + "_" + splitName[2] + "_" + splitName[3] + "_" + splitName[4] + "_" + splitName[6];
    var HdnIsValueSelectedCtrl = document.forms[0].elements[sHdnIsValueSelected]
    if (HdnIsValueSelectedCtrl != null)
        HdnIsValueSelectedCtrl.value = "yes";
}
 //End :: Parin Chheda :: Issue#5678 :: PLP - CAD User Tracking - Custom Attributes not remembered

function saveCheckbox( name ) {
   var checkbox = document.forms[0].elements[ name ];
   if (checkbox != null)
   {
      addSuperCookie( name, checkbox.checked );
   }
}

function saveText(ckKey, name) {
    var control = document.forms[0].elements[ name ];
    //alert(control+'-'+name);
    if ( control != null ) {
        addCookie(ckKey, name, control.value);
    }
}

function setText(name, value) {
    var control = document.forms[0].elements[ name ];
    //alert(control+'-'+name+'-'+value);
    if (control != null)
    {
        control.value = value;
        setHdnIsValueSelectedCtrl(name);
    }
}

function saveCookies(cookieName) {
    switch(cookieName)
    {
        case 'superCookie':
            saveOption(1,"DL_2D");
            saveOption(1,"IL_2D");
            saveOption(1,"DL_3D");
            saveOption(1,"IL_3D");
            saveOption(1,"systemUnit");
            saveText(1,"downloadDir");
            addCookie(1,"downloadWindow", "250|200|" + document.forms[0].elements[ "downloadDir" ].value );
            setCookie(cookieName,getSuperCookieValue(1));
            break;
            
        case 'CadUserCookie':
            saveText(2,"email");
            saveText(2,"FirstName");
            saveText(2,"LastName");
            saveText(2,"Company");
            saveOption(2,"Country");
            saveText(2,"Zipcode");
            setCookie(cookieName,getSuperCookieValue(2));
            break;
    }
    return false;
}

function checkEnter(event) {
    if( event ) {
        if ( event.keyCode == 13 )
            return saveCookies();
        else
            return true;                        
    }
    return true;
}


function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) {
		    return c.substring(nameEQ.length,c.length);
		}
	}
	return null;
}

function getElementNameForProd(name, ProdID)
{
    var nameSplit = name.split('_');
    var nameWithProdID = '';
    if (ProdID.length > 0)
    {
        for (var i = 0; i < nameSplit.length; i++)
        {
            if (i == 1 && ProdID != nameSplit[i] && !isNaN(nameSplit[i]))
                nameWithProdID = nameWithProdID + ProdID + '_';
            else if (i == nameSplit.length - 1)
                nameWithProdID = nameWithProdID + nameSplit[i];
            else
                nameWithProdID = nameWithProdID + nameSplit[i] + '_';
        }
    }
    if (nameWithProdID == '')
        return name;
    return nameWithProdID;
}

function PresetCookies(cookieName) {
    var ckVal = readCookie(cookieName);
    //alert(ckVal);
    if(null==ckVal) return;

    var ProdID = '';
    if (cookieName == 'CadUserCookie' && document.getElementById('hdnProdID'))
        ProdID = document.getElementById('hdnProdID').value;
    
    var ctlCk = ckVal.split('*');
    
	for(var i=0;i<ctlCk.length;i=i+2) {
		var c = ctlCk[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		switch(c)
		{
		    case "DL_2D":
		    case "IL_2D":
		    case "DL_3D":
		    case "IL_3D":
		    case "systemUnit":
		    case "Country":
		        setOption(c, ctlCk[i+1]);
		        break;
		    case "downloadDir":
		    case "email":
		    case "FirstName":
		    case "LastName":
		    case "Company":
		    case "Zipcode":
		        setText(c, ctlCk[i+1]);
		        break;
		    //Start :: Parin Chheda :: Issue#5678 :: PLP - CAD User Tracking - Custom Attributes not remembered
		    default:
		        c = getElementNameForProd(c, ProdID);
		        var ndx, strType;
		        strType = "";
		        ndx = c.indexOf('_');
		        if (ndx > -1) strType = c.substring(0, ndx);
		        switch (strType)
		        {
		            case "drpdn":
		                setOptionText(c, ctlCk[i + 1]);
		                break;
		            case "listbox":
		                setList(c, ctlCk[i + 1]);
		                break;
		            case "radio":
		                setOptionRadio(c, ctlCk[i + 1]);
		                break;
		            case "editbox":
		                setText(c, ctlCk[i + 1]);
		                break;
		        }
		        break;
		    //End :: Parin Chheda :: Issue#5678 :: PLP - CAD User Tracking - Custom Attributes not remembered
		}
	}    
}

function deleteCookie(name){
    if(readCookie(name)){
        setCookie(name, '');
        alert(readCookie(name));
    }
}

////////////////////////////////// PARSE QUERY STRING PARAMETERS COMMON FUNCTIONS

function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object();
	this.get=Querystring_get;
	this.getEsc=Querystring_getEsc;
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length);

	if (qs.length == 0) return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=');
		var name = unescape(pair[0]);

		if (pair.length == 2)
			value = unescape(pair[1]);
		else
			value = name;
		
		this.params[name] = value;
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key];
	if (value==null) value=default_;
	
	return value;
}

function Querystring_getEsc(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key];
	if (value==null) value=default_;
	
	return encodeURIComponent(value);
}

