//Variables 
var sMfgProdline = "";
var sMfgProdEqid = "";
var sMainPrentAcronym = "";
var setMfgProdEqid = "";
var setMainPrentAcronym = "";
var iKeyUsage = 0;

var message="";
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

function CleanAndShowPleaseWait(ControlName)
{
	if (document.getElementById('ShapePreview') != null)
		document.getElementById('ShapePreview').src = "HTMLPage.htm";
	if (document.getElementById(ControlName) != null)
	{
		var MfgControlName = document.getElementById(ControlName);
	    for (var count = MfgControlName.options.length-1; count >-1; count--)
	    {
	        MfgControlName.options[count] = null;
	    }
	
	    var optionItemPROD = new Option("Please wait...", "Please wait...",  false, false);
	    MfgControlName.options[0] = optionItemPROD;
	    MfgControlName.options[0].style.color = "#ff0000";
	}	
}

function populate_task_scriptMain(TaskName,webPage)
{
	document.getElementById("tdMessage").innerHTML = "<input type='image' src='../images/ASL_PlzWait.gif' style='border:0;'><font color='#FF0000'> Please Wait...</font>";
	if (TaskName == "NzLib")
	{
	    CleanAndShowPleaseWait("lbxMfgList");
		CleanAndShowPleaseWait("lbxProdLine");
		CleanAndShowPleaseWait("lbxProdNum");
	    window.setTimeout("FillMfgList('0-A',"+webPage+")", 1000);
	}
	else if (TaskName == "Mfg")
	{
		var CountProd = 0;
		for(i=document.getElementById("lbxMfgList").length-1; i>=0; i--)
        {
            if(document.getElementById("lbxMfgList").options[i].selected)
			{
				CountProd ++;
			}

			if (CountProd >= 20)
			{
				alert("You can not download more then 20 product line at a time.");
				EmptyControl("lbxProdLine");
				EmptyControl("lbxProdNum");
				document.getElementById("tdMessage").innerHTML = "<font color='#FF0000'>Ready</font>";
				document.getElementById('ShapePreview').src = "HTMLPage.htm";
				return false;
			}
		}
		
		CleanAndShowPleaseWait("lbxProdLine");
		CleanAndShowPleaseWait("lbxProdNum");

	    window.setTimeout("FillProdLine('')", 1000);
	}
	else if (TaskName == "Prod")
	{
		var CountProd = 0;
		for(i=document.getElementById("lbxProdLine").length-1; i>=0; i--)
        {
            if(document.getElementById("lbxProdLine").options[i].selected)
			{
				CountProd ++;
			}

			if (CountProd >= 20)
			{
				alert("You can not download more then 20 product line at a time.");
				EmptyControl("lbxProdNum");
				document.getElementById("tdMessage").innerHTML = "<font color='#FF0000'>Ready</font>";
				document.getElementById('ShapePreview').src = "HTMLPage.htm";
				return false;
			}
		}

		CleanAndShowPleaseWait("lbxProdNum");

	    window.setTimeout("FillProdNumber('')", 1000);
	}
	else if (TaskName == "Shape")
	{
		document.getElementById('ShapePreview').src = "PleaseWaitHTMLPage.htm";
	    window.setTimeout("ShowShapePreview('')", 1000);
	}
	else if (TaskName == "0-A" || TaskName == "B" || TaskName == "C" || TaskName == "D" || TaskName == "E" || TaskName == "F" || TaskName == "G" || TaskName == "H" || TaskName == "I" || TaskName == "J" || TaskName == "K" || TaskName == "L" || TaskName == "M" || TaskName == "N" || TaskName == "O" || TaskName == "P" || TaskName == "Q" || TaskName == "R" || TaskName == "S" || TaskName == "T" || TaskName == "U" || TaskName == "V" || TaskName == "W" || TaskName == "X" || TaskName == "Y" || TaskName == "Z")
	{
		CleanAndShowPleaseWait("lbxMfgList");
		CleanAndShowPleaseWait("lbxProdLine");
		CleanAndShowPleaseWait("lbxProdNum");
	    window.setTimeout("FillMfgList('" + TaskName + "'," + webPage + ")", 1000);
	}
}

function makeQuery(TemphiddenHref)
{
    var TempiNZClass = document.getElementById("SelectManufacturer").value;
    var TempOrderBy1 = " Order by Manufacturer Asc ";
    //var SelectCret = "Manufacturer, MfgAcronym, substring(convert(varchar,LastUpdateDate,3),4,5) LastDate"
    var SelectCret = "Manufacturer, MfgAcronym ";
    
	if(TemphiddenHref == "0-A")
	{
		var SqlQry =MfgCharExistQuery();
		if (vFileName == "cdcindex")
			var dsMfgCharExist = cdcindex.azxFillMfgListCr(SqlQry).value;
		else if (vFileName == "index")
		    var dsMfgCharExist = index.azxFillMfgListCr(SqlQry).value;

		
		if(dsMfgCharExist != null && typeof(dsMfgCharExist) == "object" && dsMfgCharExist.Tables != null)
	    {
		    if (dsMfgCharExist.Tables[0] != null)
	        {
				if (dsMfgCharExist.Tables[0].Rows[0].MfgFirstChar != "A")
				{
				    document.getElementById(dsMfgCharExist.Tables[0].Rows[0].MfgFirstChar).disabled = true;
				    TemphiddenHref = dsMfgCharExist.Tables[0].Rows[0].MfgFirstChar;
				}
			}
		}
	}

    if(TemphiddenHref == "0-A")
	{
		if((TempiNZClass == "1")||(TempiNZClass == "2")||(TempiNZClass == "3")) //For CT
		{
            quer = "Select " + SelectCret + " From Mfg Where MfgShow=1 and CloneMfg=0 and MfgAcronym is not null and MfgAcronym<>'' ";
            quer += "And (MfgAcronym in (Select MfgAcronym From MfgProdlineAndLib Where ProductionReady=1 and (LibComputer=1 or LibTelecom=1)) OR ";
            quer += "MfgAcronym in (Select Distinct LinkToMfg From MfgRelation Where MfgAcronym in (Select MfgAcronym ";
            quer += "From MfgProdlineAndLib Where ProductionReady=1 and (LibComputer=1 or LibTelecom=1)) And MfgRelationType=0))";
            quer += "and (Manufacturer like 'a%' or Manufacturer like '[0-9]%') " + TempOrderBy1 ;
		}
		else if(TempiNZClass == "4") //For AV
		{
            quer = "Select " + SelectCret + " From Mfg Where MfgShow=1 and CloneMfg=0 and MfgAcronym is not null and MfgAcronym<>'' ";
            quer += "And (MfgAcronym in (Select MfgAcronym From MfgProdlineAndLib Where ProductionReady=1 and LibAV=1) OR ";
            quer += "MfgAcronym in (Select Distinct LinkToMfg From MfgRelation Where MfgAcronym in (Select MfgAcronym ";
            quer += "From MfgProdlineAndLib Where ProductionReady=1 and LibAV=1) And MfgRelationType=0))";
            quer += "and (Manufacturer like 'a%' or Manufacturer like '[0-9]%') " + TempOrderBy1 ;
		}
		else
		{
            quer = "Select " + SelectCret + " From Mfg Where MfgShow=1 and CloneMfg=0 and MfgAcronym is not null and MfgAcronym<>'' ";
            quer += "And (MfgAcronym in (Select MfgAcronym From MfgProdlineAndLib Where ProductionReady=1) OR ";
            quer += "MfgAcronym in (Select Distinct LinkToMfg From MfgRelation Where MfgAcronym in (Select MfgAcronym ";
            quer += "From MfgProdlineAndLib Where ProductionReady=1) And MfgRelationType=0))";
            quer += "and (Manufacturer like 'a%' or Manufacturer like '[0-9]%') " + TempOrderBy1 ;
		}
	}
	else
	{
		if((TempiNZClass == "1")||(TempiNZClass == "2")||(TempiNZClass == "3")) //For CT
		{
            quer = "Select " + SelectCret + " From Mfg Where MfgShow=1 and CloneMfg=0 and MfgAcronym is not null and MfgAcronym<>'' ";
            quer += "And (MfgAcronym in (Select MfgAcronym From MfgProdlineAndLib Where ProductionReady=1 and (LibComputer=1 or LibTelecom=1)) OR ";
            quer += "MfgAcronym in (Select Distinct LinkToMfg From MfgRelation Where MfgAcronym in (Select MfgAcronym ";
            quer += "From MfgProdlineAndLib Where ProductionReady=1 and (LibComputer=1 or LibTelecom=1)) And MfgRelationType=0))";
            quer += "and Manufacturer like '" + TemphiddenHref + "%' " + TempOrderBy1;					
		}
		else if(TempiNZClass == "4") //For AV
		{
            quer = "Select " + SelectCret + " From Mfg Where MfgShow=1 and CloneMfg=0 and MfgAcronym is not null and MfgAcronym<>'' ";
            quer += "And (MfgAcronym in (Select MfgAcronym From MfgProdlineAndLib Where ProductionReady=1 and LibAV=1) OR ";
            quer += "MfgAcronym in (Select Distinct LinkToMfg From MfgRelation Where MfgAcronym in (Select MfgAcronym ";
            quer += "From MfgProdlineAndLib Where ProductionReady=1 and LibAV=1) And MfgRelationType=0))";
            quer += "and Manufacturer like '" + TemphiddenHref + "%' " + TempOrderBy1;					
		}
		else
		{
            quer = "Select " + SelectCret + " From Mfg Where MfgShow=1 and CloneMfg=0 and MfgAcronym is not null and MfgAcronym<>'' ";
            quer += "And (MfgAcronym in (Select MfgAcronym From MfgProdlineAndLib Where ProductionReady=1) OR ";
            quer += "MfgAcronym in (Select Distinct LinkToMfg From MfgRelation Where MfgAcronym in (Select MfgAcronym ";
            quer += "From MfgProdlineAndLib Where ProductionReady=1) And MfgRelationType=0))";
            quer += "and Manufacturer like '" + TemphiddenHref + "%' " + TempOrderBy1;					
		}
	}
	return quer;
}

function MfgCharExistQuery()
{
	var TmpiNZClass = document.getElementById("SelectManufacturer").value;
	var quer;
	if((TmpiNZClass == "1")||(TmpiNZClass == "2")||(TmpiNZClass == "3")) //For CT
	{
		quer = " Select distinct upper(substring(Manufacturer,1,1)) MfgFirstChar from Mfg ";
		quer += "Where MfgShow=1 and CloneMfg=0 and MfgAcronym is not null and MfgAcronym<>'' ";
        quer += "And (MfgAcronym in (Select MfgAcronym From MfgProdlineAndLib Where (LibComputer=1 or LibTelecom=1) and ProductionReady=1) OR ";
        quer += "MfgAcronym in (Select Distinct LinkToMfg From MfgRelation Where MfgAcronym in (Select MfgAcronym ";
        quer += "From MfgProdlineAndLib Where (LibComputer=1 or LibTelecom=1) and ProductionReady=1) And MfgRelationType=0))";
        quer += "and substring(Manufacturer,1,1) >= 'A' order by MfgFirstChar";

	}
	else if(TmpiNZClass == "4") //For AV
	{
		quer = " Select distinct upper(substring(Manufacturer,1,1)) MfgFirstChar from Mfg ";
		quer += "Where MfgShow=1 and CloneMfg=0 and MfgAcronym is not null and MfgAcronym<>'' ";
        quer += "And (MfgAcronym in (Select MfgAcronym From MfgProdlineAndLib Where LibAV=1 and ProductionReady=1) OR ";
        quer += "MfgAcronym in (Select Distinct LinkToMfg From MfgRelation Where MfgAcronym in (Select MfgAcronym ";
        quer += "From MfgProdlineAndLib Where LibAV=1 and ProductionReady=1) And MfgRelationType=0))";
        quer += "and substring(Manufacturer,1,1) >= 'A' order by MfgFirstChar";

	}
	else
	{
		quer = " Select distinct upper(substring(Manufacturer,1,1)) MfgFirstChar from Mfg ";
		quer += "Where MfgShow=1 and CloneMfg=0 and MfgAcronym is not null and MfgAcronym<>'' ";
        quer += "And (MfgAcronym in (Select MfgAcronym From MfgProdlineAndLib Where ProductionReady=1) OR ";
        quer += "MfgAcronym in (Select Distinct LinkToMfg From MfgRelation Where MfgAcronym in (Select MfgAcronym ";
        quer += "From MfgProdlineAndLib Where ProductionReady=1) And MfgRelationType=0))";
        quer += "and substring(Manufacturer,1,1) >= 'A' order by MfgFirstChar";
	}
	return quer;
}

function EmptyControl(CntrlName)
{
	for (var i = document.getElementById(CntrlName).options.length-1; i >= 0; i--)
	{
		document.getElementById(CntrlName).options[i] = null;
	}
}

//Fill Mfg name in lbxMfgList
function FillMfgList(stCreteria,webPage)
{
	var strLabelID;
    var strCheckCreteria;
	var SqlQry;	
	var dsMfgList;
	var dsMfgCharExist;
	var dsProdLine;
	var cntProdLine;
	var dsMfgListTotal;
	var quer;
    if (stCreteria == "0-A")
    {
        strCheckCreteria = "A";
    }
    else
    {
        strCheckCreteria = stCreteria;
    }
	SqlQry =MfgCharExistQuery();
	if (vFileName == "cdcindex")
		dsMfgCharExist = cdcindex.azxFillMfgListCr(SqlQry).value;
	else if (vFileName == "index")
	    dsMfgCharExist = index.azxFillMfgListCr(SqlQry).value;

	if(dsMfgCharExist != null && typeof(dsMfgCharExist) == "object" && dsMfgCharExist.Tables != null)
    {
	    if (dsMfgCharExist.Tables[0] != null)
        {
			DisableAllChar();	
			for (var count = 0; count < dsMfgCharExist.Tables[0].Rows.length; count++)
		    {
				document.getElementById(dsMfgCharExist.Tables[0].Rows[count].MfgFirstChar).disabled = false;			
			}
		}
		else
		{
			DisableAllChar();
		}
	}
	for (i=65; i<=90; i++)
    {
        strLabelID = String.fromCharCode(i);
        if ( strLabelID == strCheckCreteria )
        {
            document.getElementById(strLabelID).disabled = true;
        }
    }
	EmptyControl("lbxMfgList");
	if (webPage == 2)
	{
		document.getElementById("hdnLibType").value = document.getElementById("SelectManufacturer").value;								
	    document.getElementById("hdnLibChar").value = strCheckCreteria;
	    document.getElementById('ShapePreview').src = "HTMLPage.htm";
	    EmptyControl("lbxProdLine");
	    EmptyControl("lbxProdNum");
		sMfgProdEqid != "";
		document.getElementById("lbxProdNum").BACKGROUND="#000000";
		if ( iKeyUsage > 0)
		{
		    document.getElementById("imgAddtoQueue").src="../images/addtoqueue_button_disable.jpg";
		    sMfgProdEqid = "";
		}
	}
	SqlQry = makeQuery(stCreteria);
	
	if(document.getElementById("SelectManufacturer").value == "65535") //UNVERSAL
	{
		quer = "Select count(Manufacturer) as No_of_rows, convert(char(10),max(LastUpdateDate),101) as LastUpdateDate from Mfg ";
        quer += "Where MfgShow=1 and CloneMfg=0 and MfgAcronym is not null and MfgAcronym<>'' ";
        quer += "And (MfgAcronym in (Select MfgAcronym From MfgProdlineAndLib Where ProductionReady=1) OR ";
        quer += "MfgAcronym in (Select Distinct LinkToMfg From MfgRelation Where MfgAcronym in (Select MfgAcronym ";
        quer += "From MfgProdlineAndLib Where ProductionReady=1) And MfgRelationType=0))";
	}
	else if(document.getElementById("SelectManufacturer").value == "4") //For AV
	{
		quer = "Select count(Manufacturer) as No_of_rows, convert(char(10),max(LastUpdateDate),101) as LastUpdateDate  from Mfg ";
        quer += "Where MfgShow=1 and CloneMfg=0 and MfgAcronym is not null and MfgAcronym<>'' ";
        quer += "And (MfgAcronym in (Select MfgAcronym From MfgProdlineAndLib Where LibAV=1 and ProductionReady=1) OR ";
        quer += "MfgAcronym in (Select Distinct LinkToMfg From MfgRelation Where MfgAcronym in (Select MfgAcronym ";
        quer += "From MfgProdlineAndLib Where LibAV=1 and ProductionReady=1) And MfgRelationType=0))";

	}
	else if((document.getElementById("SelectManufacturer").value == "1") || (document.getElementById("SelectManufacturer").value == "2") || (document.getElementById("SelectManufacturer").value == "3")) //For CT
	{
		quer = "Select count(Manufacturer) as No_of_rows, convert(char(10),max(LastUpdateDate),101) as LastUpdateDate from Mfg ";
        quer += "Where MfgShow=1 and CloneMfg=0 and MfgAcronym is not null and MfgAcronym<>'' ";
        quer += "And (MfgAcronym in (Select MfgAcronym From MfgProdlineAndLib Where (LibComputer=1 or LibTelecom=1) and ProductionReady=1) OR ";
        quer += "MfgAcronym in (Select Distinct LinkToMfg From MfgRelation Where MfgAcronym in (Select MfgAcronym ";
        quer += "From MfgProdlineAndLib Where (LibComputer=1 or LibTelecom=1) and ProductionReady=1) And MfgRelationType=0))";

	}
	
	if (vFileName == "cdcindex")
		dsMfgListTotal = cdcindex.azxFillMfgListCr(quer).value;
	else if (vFileName == "index")
	    dsMfgListTotal = index.azxFillMfgListCr(quer).value;

	if(dsMfgListTotal != null && typeof(dsMfgListTotal) == "object" && dsMfgListTotal.Tables != null)
    {
	    if (dsMfgListTotal.Tables[0] != null)
        {
			document.getElementById("TotalManufacturer").innerHTML = " Total Manufacturers: " + dsMfgListTotal.Tables[0].Rows[0].No_of_rows + " (Last updated: " + dsMfgListTotal.Tables[0].Rows[0].LastUpdateDate + ")";
		}
	}
	
	if (vFileName == "cdcindex")
		dsMfgList = cdcindex.azxFillMfgListCr(SqlQry).value;
	else if (vFileName == "index")
	    dsMfgList = index.azxFillMfgListCr(SqlQry).value;

    if(dsMfgList != null && typeof(dsMfgList) == "object" && dsMfgList.Tables != null)
    {
	    if (dsMfgList.Tables[0] != null)
        {
	        //Add new Product Line list.
	        for (var count = 0; count < dsMfgList.Tables[0].Rows.length; count++)
	        {
		        optionItem = new Option( dsMfgList.Tables[0].Rows[count].Manufacturer, dsMfgList.Tables[0].Rows[count].MfgAcronym,  false, false);
		        document.getElementById("lbxMfgList").options[document.getElementById("lbxMfgList").length] = optionItem;
		        cntProdLine = "0";
	        }
	    }
		else
		{
			optionItem = new Option('- No Manufacturer Found -', '-nm-',  false, false);
	        document.getElementById("lbxMfgList").options[document.getElementById("lbxMfgList").length] = optionItem;
		}
	}
	else
	{
		optionItem = new Option('- No Manufacturer Found -', '-nm-',  false, false);
        document.getElementById("lbxMfgList").options[document.getElementById("lbxMfgList").length] = optionItem;
	}
	document.getElementById("tdMessage").innerHTML = "<font color='#FF0000'>Ready</font>";
}

//Fill ProductLine Based on Mfg name clicked on lbxMfgList
function FillProdLine(stMfgAvr)
{
	var dsProdLine;
	var selectedMfg;
	var selectedMfgName;
	var cntProdNum = 0;
	var EqCount=0;
	var SubscriptionNo = document.getElementById("hdnSubscriptionNo").value;
	var NZClassSelected = document.getElementById("SelectManufacturer").value;
	document.getElementById('ShapePreview').src = "HTMLPage.htm";
	EmptyControl("lbxProdLine");
	EmptyControl("lbxProdNum");
	document.getElementById("lbxProdNum").BACKGROUND="#000000";
	if(document.getElementById("lbxMfgList").selectedIndex >= 0)
	{
	    for(i=document.getElementById("lbxMfgList").length-1; i>=0; i--)
        {
            if(document.getElementById("lbxMfgList").options[i].selected)
            {
                selectedMfg = document.getElementById("lbxMfgList").options[i].value;
                selectedMfgName = document.getElementById("lbxMfgList").options[i].text.split("(")[0];
                //dsProdLine = index.azxFillProdLineList(selectedMfg).value;
				if (vFileName == "cdcindex")
				    dsProdLine = cdcindex.azxFillProdLineList(selectedMfg,SubscriptionNo,NZClassSelected).value;
                else if (vFileName == "index")
				    dsProdLine = index.azxFillProdLineList(selectedMfg,SubscriptionNo,NZClassSelected).value;

                if(dsProdLine != null && typeof(dsProdLine) == "object" && dsProdLine.Tables != null)
                {
                    if (dsProdLine.Tables[0] != null)
                    {
                        //Add new Product Line list.
                        for (var count = 0; count < dsProdLine.Tables[0].Rows.length; count++)
                        {
                            EqCount = dsProdLine.Tables[0].Rows[count].ProdNumCount
                            if (EqCount!=0)
                            {
                                //If Product line is archived then change font to gray
                                //else Dark black
                                if (dsProdLine.Tables[0].Rows[count].Archived==true)
                                {
	                                optionItem = new Option( dsProdLine.Tables[0].Rows[count].MfgProdline + '(' + dsProdLine.Tables[0].Rows[count].ProdNumCount + ')', selectedMfg + '~' + selectedMfgName + '~' + dsProdLine.Tables[0].Rows[count].MfgProdline + '~' + dsProdLine.Tables[0].Rows[count].Archived,  false, false);
	                                optionItem.style.color = "#808080";
	                                document.getElementById("lbxProdLine").options[document.getElementById("lbxProdLine").length] = optionItem;
	                                document.getElementById("lbxProdLine").options[cntProdNum].title = selectedMfgName;
                                }
                                else
                                {
	                                optionItem = new Option( dsProdLine.Tables[0].Rows[count].MfgProdline + '(' + dsProdLine.Tables[0].Rows[count].ProdNumCount + ')', selectedMfg + '~' + selectedMfgName + '~' + dsProdLine.Tables[0].Rows[count].MfgProdline + '~' + dsProdLine.Tables[0].Rows[count].Archived,  false, false);
	                                document.getElementById("lbxProdLine").options[document.getElementById("lbxProdLine").length] = optionItem;
	                                document.getElementById("lbxProdLine").options[cntProdNum].title = selectedMfgName;
                                }
                                cntProdNum++;
                            }
                        }
                    }
                }
            }
        }
	}
	document.getElementById("tdMessage").innerHTML = "<font color='#FF0000'>Ready</font>";
}

function FillProdNumber(stProdLine)
{
	var dsProdNum;
	var selectedProdLine;
	var selectedStencilsName = "";
	var selectedStencilsMfg = "";
	var cntProdNum = 0;
	sMfgProdEqid = "";
    sMainPrentAcronym = "";
	if ( iKeyUsage > 0)
	{
	    document.getElementById("imgAddtoQueue").src="../images/addtoqueue_button_disable.jpg";
	    sMfgProdEqid = "";
	}
	document.getElementById('ShapePreview').src = "HTMLPage.htm";
	EmptyControl("lbxProdNum");
	document.getElementById("lbxProdNum").BACKGROUND="#000000";

	if(document.getElementById("lbxProdLine").selectedIndex >= 0)
	{		
        for(i=document.getElementById("lbxProdLine").length-1; i>=0; i--)
        {
            if(document.getElementById("lbxProdLine").options[i].selected)
            {
	            selectedProdLine = document.getElementById("lbxProdLine").options[i].value.split('~');
                
                sMfgProdline += selectedProdLine[0] + '~' + selectedProdLine[2] + ",";
                
	            selectedStencilsName = document.getElementById("lbxProdLine").options[i].text.split("(")[0];
	            selectedStencilsMfg = selectedProdLine[1];
	            var isArchived = selectedProdLine[3];
				if (vFileName == "cdcindex")
					dsProdNum = cdcindex.azxFillProdNumList(selectedProdLine[0],selectedProdLine[2]).value;
				else if (vFileName == "index")
				    dsProdNum = index.azxFillProdNumList(selectedProdLine[0],selectedProdLine[2]).value;
                if(dsProdNum != null && typeof(dsProdNum) == "object" && dsProdNum.Tables != null)
                {
	                if (dsProdNum.Tables[0] != null)
                    {
	                    //Add new Product Number list.
	                    for (var count = 0; count < dsProdNum.Tables[0].Rows.length; count++)
	                    {
	                        if (isArchived=="true")
	                        {
		                        optionItem = new Option( dsProdNum.Tables[0].Rows[count].MfgProdNo, selectedProdLine[0]+'|'+selectedProdLine[2]+'|'+dsProdNum.Tables[0].Rows[count].MfgProdNo+'|'+dsProdNum.Tables[0].Rows[count].EQID,  false, false);
                                optionItem.style.color = "#CCCCCC";
		                        document.getElementById("lbxProdNum").options[document.getElementById("lbxProdNum").length] = optionItem;
		                        document.getElementById("lbxProdNum").options[cntProdNum].title = selectedStencilsName;
		                    }
		                    else
		                    {
		                        optionItem = new Option( dsProdNum.Tables[0].Rows[count].MfgProdNo, selectedProdLine[0]+'|'+selectedProdLine[2]+'|'+dsProdNum.Tables[0].Rows[count].MfgProdNo+'|'+dsProdNum.Tables[0].Rows[count].EQID,  false, false);
		                        document.getElementById("lbxProdNum").options[document.getElementById("lbxProdNum").length] = optionItem;
		                        document.getElementById("lbxProdNum").options[cntProdNum].title = selectedStencilsName;
		                    }
		                    
		                    if (sMfgProdEqid != "")
		                    {
		                        sMfgProdEqid = sMfgProdEqid + ",'" + dsProdNum.Tables[0].Rows[count].EQID + "'";
		                    }
		                    else
		                    {
		                        sMfgProdEqid = "'" + dsProdNum.Tables[0].Rows[count].EQID + "'";
		                        if ( iKeyUsage > 0)
		                        {
								    document.getElementById("imgAddtoQueue").src="../images/addtoqueue_button_enable.jpg";
								}
		                    }
		                    /*if (sMfgProdEqid != "")
		                    {
		                        sMfgProdEqid = sMfgProdEqid + "~" + selectedProdLine[0]+'|'+selectedProdLine[1]+'|'+dsProdNum.Tables[0].Rows[count].EQID;
		                    }
		                    else
		                    {
		                        sMfgProdEqid = selectedProdLine[0]+'|'+selectedProdLine[1]+'|'+dsProdNum.Tables[0].Rows[count].EQID;
		                    }*/
		                    if (sMainPrentAcronym != "")
		                    {
		                        sMainPrentAcronym = sMainPrentAcronym + "~" + selectedStencilsMfg+'|'+selectedStencilsName+'|'+dsProdNum.Tables[0].Rows[count].MfgProdNo;
		                    }
		                    else
		                    {
		                        sMainPrentAcronym = selectedStencilsMfg+'|'+selectedStencilsName+'|'+dsProdNum.Tables[0].Rows[count].MfgProdNo;
		                    }
							cntProdNum++;
	                    }
	                }
	            }
            }
        }
	}
	document.getElementById("tdMessage").innerHTML = "<font color='#FF0000'>Ready</font>";
}

function ShowShapePreview(stEQID)
{
    var stEQID = document.getElementById("lbxProdNum").value.split('|');


if(document.getElementById("ShowPreview").value=="1")
    {
        document.getElementById('ShapePreview').src = "shapepreviewuserinfo.aspx?imageCode="+ stEQID[3];
        //document.getElementById('ShapePreview').src = "http://www.netzoomsymbols.com/common/shapepreview.aspx?imageCode="+ stEQID[3];
    }
    else
        document.getElementById('ShapePreview').src = "ValidPage.htm";

    document.getElementById("tdMessage").innerHTML = "<font color='#FF0000'>Ready</font>";
}

function cdcAddToQueue()
{
	if (sMfgProdEqid != "")
	{
	    if (document.getElementById("hdnMfgProdEqid").value == "" && document.getElementById("hdnMainPrentAcronym").value == "")
	    {
	        document.getElementById("hdnMfgProdEqid").value = sMfgProdEqid;
	        document.getElementById("hdnMainPrentAcronym").value = sMainPrentAcronym;
	    }
	    else
	    {
	        document.getElementById("hdnMfgProdEqid").value = document.getElementById("hdnMfgProdEqid").value + ',' + sMfgProdEqid;
	        document.getElementById("hdnMainPrentAcronym").value = document.getElementById("hdnMainPrentAcronym").value + '~' + sMainPrentAcronym;
	    }
		document.getElementById("lbxProdNum").BackColor= "#C0C0FF";
	    alert("Added successfully");
		sMfgProdEqid = "";
		document.getElementById("imgAddtoQueue").src="../images/addtoqueue_button_disable.jpg";
		document.getElementById("imgCheckOut").src="../images/checkout_button_enable.jpg";
		document.getElementById("imgViewQueue").src="../images/view_queue.jpg";
	}
	
	if (sMfgProdline != "")
	{
	    document.getElementById("hdnMfgProdline").value = sMfgProdline;
	}
}

function frmSubmit(frm)
{
	if (document.getElementById("hdnMfgProdEqid").value != "")
	{
		frm.method = "Post";
		frm.action ="cdcQueue.aspx";
		frm.submit();
	}
}

function cdcViewQueue()
{
    var theForm = document.frmWebCDC;
    var EqList = theForm.hdnMfgProdEqid.value;
	if (document.getElementById("hdnMfgProdEqid").value != "")
	{
		window.open('cdcQueue.aspx?MfgProdEqid='+EqList+'&ViewState=0','popWin2','resizeable=no,scrollbars=yes,width=800,height=370,top=120,left=200');
	}
}

function ValidateSubs(frm) 
{ 
	var SubNo = remove_XS_whitespace(document.getElementById("Subscription_Number"));
	SetCookies(frm);
	if ( (SubNo.length != 20) && (SubNo.length != 25) && (SubNo.length != 29))
	{
		alert("Please enter a valid subscription number.");
		document.getElementById("Subscription_Number").focus();
		document.getElementById("Subscription_Number").select();
		return false;
	}
	else
	{
		return true;
	}
}

function checkValue(frm)
{
    var strEQID = "";
    for (counter = 0; counter < document.frmWebCDC.length; counter++)
	{
		if (document.frmWebCDC.elements[counter].type=="hidden" && document.frmWebCDC.elements[counter].id == "hdnEQID")
		{
			if (document.frmWebCDC.elements[counter-1].checked)
			{ 
			    strEQID = document.frmWebCDC.elements[counter].value.split('|')
			    if (document.getElementById("MfgProdEqidList").value == "")
			    {
			        document.getElementById("MfgProdEqidList").value = "'" + strEQID[2] + "'";
			    }
			    else
			    {
			        document.getElementById("MfgProdEqidList").value = document.getElementById("MfgProdEqidList").value + ",'" + strEQID[2] + "'";
			    }
			}
		}
	}
	var sSerialNumber = document.getElementById("hdnSubscriptionNo").value
	frm.method = "Post";
    frm.action ="Index.aspx?SubscriptionNo="+sSerialNumber;
    frm.submit();
}

function checkCDCQueue(frm)
{
    //document.getElementById("MfgProdEqidList").value = "";
    for (counter = 0; counter < document.frmWebCDC.length; counter++)
	{
		if (document.frmWebCDC.elements[counter].type=="hidden" && document.frmWebCDC.elements[counter].id == "hdnEQID")
		{
			if (document.frmWebCDC.elements[counter-1].checked)
			{ 
			    if (document.getElementById("MfgProdEqidList").value == "")
			    {
			        document.getElementById("MfgProdEqidList").value =  document.frmWebCDC.elements[counter].value; 
			    }
			    else
			    {
			        document.getElementById("MfgProdEqidList").value = document.getElementById("MfgProdEqidList").value + "~" + document.frmWebCDC.elements[counter].value;
			    }
			}
		}
	}
	if (document.getElementById("MfgProdEqidList").value != "")
	{
		frm.method = "Post";
	    frm.action ="userinfo.aspx";
	    frm.submit();
	}
}

function remove_XS_whitespace(item)
{
    var tmp = "";
    var item_length = item.value.length;
    var item_length_minus_1 = item.value.length - 1;
    for (index = 0; index < item_length; index++)
    {
        if (item.value.charAt(index) != ' ')
        {
            tmp += item.value.charAt(index);
        }
        else
        {
            if (tmp.length > 0)
            {
                if (item.value.charAt(index+1) != ' ' && index != item_length_minus_1)
                {
                    tmp += item.value.charAt(index);
                }
            }
        }
    }
    item.value = tmp;
    return tmp;
}

function checkcookiesupport()
{
    var status;
    if(navigator.cookieEnabled)
    {
        status=true;
		alert("Cookie Enabled...");
    }
    else
    {
        status=false;
		alert("Cookie Disabled...");
    }
    
    if (typeof navigator.cookieEnabled=="undefined" && !status)
    { 
	    document.cookie="wazzup"
        if(document.cookie.indexOf("wazzup")!=-1)
        {
            status=true;
			alert("Cookie defined...");
        }
        else
        {
            status=false;
			alert("Cookie Un-defined...");
        }
    }
    return status;
}

function DisableAllChar()
{
	for (i=65; i<=90; i++)
    {
        strLabelID = String.fromCharCode(i);
        document.getElementById(strLabelID).disabled = true;
    }
}