//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 disableselect(e){
    return false
}
function reEnable(){
    return true
}
document.onselectstart=new Function ("return false")
if (window.sidebar){
    document.onmousedown=disableselect
    document.onclick=reEnable
}
*/

function CleanOnly(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;
	    }
	}	
}

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)
{
	if (TaskName == "NzLib")
	{
//	    CleanAndShowPleaseWait("lbxMfgList");
		CleanAndShowPleaseWait("lbxProdLine");
		CleanOnly("lbxProdNum");
	    window.setTimeout("FillMfgList('0-A',"+webPage+")", 300);
	}
	else if (TaskName == "Mfg")
	{
		var CountProd = 0;
		document.getElementById('ShapePreview').src = "HTMLPage.htm";
		CleanAndShowPleaseWait("lbxProdLine");
		CleanOnly("lbxProdNum");

	    window.setTimeout("FillProdLine('')", 300);
	}
	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('ShapePreview').src = "HTMLPage.htm";
				return false;
			}
		}

		CleanAndShowPleaseWait("lbxProdNum");

	    window.setTimeout("FillProdNumber('')", 300);
	}
	else if (TaskName == "Shape")
	{
		document.getElementById('ShapePreview').src = "PleaseWaitHTMLPage.htm";
	    window.setTimeout("ShowShapePreview('')", 300);
	}
	
	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")
	{
	    if (webPage==2)
		{
			document.getElementById("mysearch").value = "";
		    document.getElementById("MfgCount").innerHTML = "<b>Manufacturer:</b>";
		    document.getElementById("ProdlineCount").innerHTML = "<b>Product Line:</b>";

		}

		CleanAndShowPleaseWait("lbxMfgList");
		CleanOnly("lbxProdLine");
		CleanOnly("lbxProdNum");
	    window.setTimeout("FillMfgList('" + TaskName + "'," + webPage + ")", 300);
	}
	else if (TaskName == "SEARCH")
	{
	    document.getElementById("MfgCount").innerHTML = "<b>Manufacturer:</b>";
	    document.getElementById("ProdlineCount").innerHTML = "<b>Product Line:</b>";

		CleanAndShowPleaseWait("lbxMfgList");
		CleanOnly("lbxProdLine");
		CleanOnly("lbxProdNum");
	    window.setTimeout("FillSearchResult('" + TaskName + "'," + webPage + ")", 300);
	}
}

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;
	}
}

//FillSearchResult
function FillSearchResult(stCreteria,webPage)
{
	var strLabelID;
    var strCheckCreteria;
	var dsMfgList;
	var dsMfgCharExist;
	var dsProdLine;
	var cntProdLine;
	var dsMfgListTotal;
	var dsMfgListTotal;
	
	var AcronymList="";
	var SqlQuery;
	var SqlWhere;
	
    if (stCreteria == "0-A")
        strCheckCreteria = "A";
    else if (stCreteria == "SEARCH")
        strCheckCreteria = document.getElementById("mysearch").value;
    else
        strCheckCreteria = stCreteria;
    
    //GLossary
    //DisableAllChar();	
    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");
	
	document.getElementById("hdnLibType").value = document.getElementById("SelectManufacturer").value;								
    document.getElementById("hdnLibChar").value = strCheckCreteria;
    EmptyControl("lbxProdLine");
    EmptyControl("lbxProdNum");
	sMfgProdEqid != "";
	document.getElementById("lbxProdNum").BACKGROUND="#000000";
	if ( iKeyUsage > 0)
	{
	    document.getElementById("imgAddtoQueue").src="http://altima.http.internapcdn.net/altima_vitalstream_com/Web/VisioStencils.com/Images/DownloadImages/NetZoomVS_AddtoBasket_Button_Disabled.png";
	    sMfgProdEqid = "";
	}
	
    var KeywordString = document.getElementById("mysearch").value;
    var Subscription = document.getElementById("hdnSubscriptionNo").value;
	var sType = "any";
	var QryStr = document.getElementById("SEARCH").value.split('&');
    var keywords = document.getElementById("mysearch").value.split(' ');

    if (QryStr!="")
    {
        if (QryStr[2].split('=')[1]=="exact")
            sType = "all";
        else
            sType = "any";
            
        KeywordString = QryStr[1].split('=')[1];
    }
    
	//Fill Manufacturer in Listbox
	if (vFileName == "cdcindex")
		dsMfgList = cdcindex.azxFillMfgListCr(SqlQuery).value;
	else if (vFileName == "index")
	    dsMfgList = index.azxSearchMfgListCr(Subscription, KeywordString, sType, strCheckCreteria).value;

    if(dsMfgList != null && typeof(dsMfgList) == "object" && dsMfgList.Tables != null)
    {
	    if (dsMfgList.Tables[0] != null)
        {
            optionItem = new Option('- SELECT -', '-nm-',  false, false);
	        document.getElementById("lbxMfgList").options[document.getElementById("lbxMfgList").length] = optionItem;
	        
	        for (var count = 0; count < dsMfgList.Tables[0].Rows.length; count++)
	        {
	            // Create an Option object                
		        optionItem = new Option( dsMfgList.Tables[0].Rows[count].ManufacturerName, dsMfgList.Tables[0].Rows[count].MfgAcronym,  false, false);
		        document.getElementById("lbxMfgList").options[document.getElementById("lbxMfgList").length] = optionItem;
		        cntProdLine = "0";
		        
		        if (AcronymList=="")
		            AcronymList = "'" + dsMfgList.Tables[0].Rows[count].MfgAcronym + "'";
		        else
                    AcronymList += ",'" + dsMfgList.Tables[0].Rows[count].MfgAcronym + "'";
	        }
	        if (AcronymList!="undefined")
	        {
                SqlQuery = "Select convert(char(10),max(LastUpdateDate),101) as LastUpdateDate from Mfg Where MfgAcronym in ("+ AcronymList.replace("undefined,","") +")";
                dsMfgListTotal = index.azxFillMfgListCr(SqlQuery).value;
                
                //Show Manufacturer Count
                document.getElementById("MfgCount").innerHTML = "<b>Manufacturer ["+ dsMfgList.Tables[0].Rows.length +"]:</b>";
            }
            else
            {
                //Show Manufacturer Count
                document.getElementById("MfgCount").innerHTML = "<b>Manufacturer [0]:</b>";
            }
	    }
		else
		{
			optionItem = new Option('- No Manufacturer Found -', '-nm-',  false, false);
	        document.getElementById("lbxMfgList").options[document.getElementById("lbxMfgList").length] = optionItem;
	        
	        //Show Total Manufacturer
	        document.getElementById("MfgCount").innerHTML = "<b>Manufacturer:</b>";
            //document.getElementById("TotalManufacturer").innerHTML = " Total Manufacturers: 0" + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=gray>Archived shapes are in gray.</font> ";
		}
	}
	else
	{
		optionItem = new Option('- No Manufacturer Found -', '-nm-',  false, false);
        document.getElementById("lbxMfgList").options[document.getElementById("lbxMfgList").length] = optionItem;
        
        //Show Total Manufacturer
        //document.getElementById("TotalManufacturer").innerHTML = "<b>Total Manufacturers: 0" + "<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=gray>Archived shapes are in gray.</font> ";
        document.getElementById("MfgCount").innerHTML = "<b>Manufacturer:</b>";
	}
	
    //	document.getElementById("tdMessage").innerHTML = "<font color='#FF0000'>Ready</font>";
}

//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="http://altima.http.internapcdn.net/altima_vitalstream_com/Web/VisioStencils.com/Images/DownloadImages/NetZoomVS_AddtoBasket_Button_Disabled.png";
		    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)
        {
            if (webPage==2)
    			document.getElementById("TotalManufacturer").innerHTML = " Total Manufacturers: " + dsMfgListTotal.Tables[0].Rows[0].No_of_rows + "&nbsp;&nbsp;&nbsp;&nbsp;Updated: " + dsMfgListTotal.Tables[0].Rows[0].LastUpdateDate + "&nbsp;&nbsp;&nbsp;&nbsp;<font color=gray>Archived shapes are in gray. If your security does not allow applets for download management, please add only single product line to the basket.</font> ";
            else
			    document.getElementById("TotalManufacturer").innerHTML = " Total Manufacturers: " + dsMfgListTotal.Tables[0].Rows[0].No_of_rows + "&nbsp;&nbsp;&nbsp;&nbsp;Updated: " + dsMfgListTotal.Tables[0].Rows[0].LastUpdateDate + "&nbsp;&nbsp;&nbsp;&nbsp;</font> ";
		}
	}
	
	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)
        {
            if (webPage==2)
            {            
                optionItem = new Option('- SELECT -', '- SELECT -',  false, false);
	            document.getElementById("lbxMfgList").options[document.getElementById("lbxMfgList").length] = optionItem;
            }
            
	        //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";
	        }
if (webPage==2)
            { 
	        document.getElementById("MfgCount").innerHTML = "<b>Manufacturer ["+ dsMfgList.Tables[0].Rows.length +"]:</b>";
}
	    }
		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;
	}
}

//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";
	
	/* Search */
	var KeywordString = document.getElementById("mysearch").value;
    var Subscription = document.getElementById("hdnSubscriptionNo").value;
    var sType = "any";
    var QryStr = document.getElementById("SEARCH").value.split('&');
    var keywords = document.getElementById("mysearch").value.split(' ');

	 if (QryStr!="")
    {
        if (QryStr[2].split('=')[1]=="exact")
            sType = "all";
        else
            sType = "any";
    }            
	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];
                
				if (vFileName == "cdcindex")
				    dsProdLine = cdcindex.azxFillProdLineList(selectedMfg,SubscriptionNo,NZClassSelected).value;
                else if (vFileName == "index")
                {
                    if (KeywordString=="")
				        dsProdLine = index.azxFillProdLineList(selectedMfg,SubscriptionNo,NZClassSelected).value;
				    else
				        dsProdLine = index.azxSearchProdlineListCr(Subscription, KeywordString, sType, selectedMfg).value;
                }
                
                if(dsProdLine != null && typeof(dsProdLine) == "object" && dsProdLine.Tables != null)
                {
                    if (dsProdLine.Tables[0] != null)
                    {
                        optionItem = new Option( "- SELECT -", "- SELECT -",  false, false);
                        document.getElementById("lbxProdLine").options[document.getElementById("lbxProdLine").length] = optionItem;
                        document.getElementById("lbxProdLine").options[cntProdNum].title = selectedMfgName;

                        //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 (dsProdLine.Tables[0].Rows[count].Archived==true)
                                {
                                    if (KeywordString=="")
	                                    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);
	                                else
	                                    optionItem = new Option( dsProdLine.Tables[0].Rows[count].MfgProdLine + '(' + dsProdLine.Tables[0].Rows[count].KeyCount + ')', selectedMfg + '~' + selectedMfgName + '~' + dsProdLine.Tables[0].Rows[count].MfgProdLine + '~' + dsProdLine.Tables[0].Rows[count].Archived,  false, false);
                                        
                                        //optionItem = new Option( dsProdLine.Tables[0].Rows[count].MfgProdLine , 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
                                {
                                    if (KeywordString=="")
	                                    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);
	                                else
	                                    optionItem = new Option( dsProdLine.Tables[0].Rows[count].MfgProdLine + '(' + dsProdLine.Tables[0].Rows[count].KeyCount + ')', selectedMfg + '~' + selectedMfgName + '~' + dsProdLine.Tables[0].Rows[count].MfgProdLine + '~' + dsProdLine.Tables[0].Rows[count].Archived,  false, false);
	                                    
	                                    //optionItem = new Option( dsProdLine.Tables[0].Rows[count].MfgProdLine, 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("ProdlineCount").innerHTML = "<b>Product Line ["+ dsProdLine.Tables[0].Rows.length +"]:</b>";
                    }
                }
            }
        }
	}
}

function FillProdNumber(stProdLine)
{
	var dsProdNum;
	var selectedProdLine;
	var selectedStencilsName = "";
	var selectedStencilsMfg = "";
	var cntProdNum = 0;
	sMfgProdEqid = "";
    sMainPrentAcronym = "";
    
    /* Search */
	var KeywordString = document.getElementById("mysearch").value;
    var Subscription = document.getElementById("hdnSubscriptionNo").value;
    var sType = "any";
    var QryStr = document.getElementById("SEARCH").value.split('&');
    var keywords = document.getElementById("mysearch").value.split(' ');

 if (QryStr!="")
    {
        if (QryStr[2].split('=')[1]=="exact")
            sType = "all";
        else
            sType = "any";
    }
    
	if ( iKeyUsage > 0)
	{
	    document.getElementById("imgAddtoQueue").src="http://altima.http.internapcdn.net/altima_vitalstream_com/Web/VisioStencils.com/Images/DownloadImages/NetZoomVS_AddtoBasket_Button_Disabled.png";
	    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")
				{
				    if (KeywordString=="")
				        dsProdNum = index.azxFillProdNumList(selectedProdLine[0],selectedProdLine[2]).value;
				    else
				        dsProdNum = index.azxSearchProdNumListCr(Subscription, KeywordString, sType, 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 = "#808080";
		                        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="http://altima.http.internapcdn.net/altima_vitalstream_com/Web/VisioStencils.com/Images/DownloadImages/NetZoomVS_AddtoBasket_Button.png";
								}
		                    }
		                    /*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++;
	                    }
	                }
	            }
            }
        }
	}
}

function ShowShapePreview(stEQID)
{
        var stEQID = document.getElementById("lbxProdNum").value.split('|');
if (stEQID[3]!=undefined)
    document.getElementById('ShapePreview').src = "http://www.netzoomsymbols.com/common/shapepreview.aspx?imageCode="+ stEQID[3];
}

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";
	    
        if (sMfgProdline != "")
	    {
	        if (document.getElementById("hdnMfgProdline").value.split(',').length>15)
	        {
	            alert("Your update basket is limited to 15 product line downloads at a time, \nplease download the product lines in your basket, and then if you need any additional product lines, revisit the NetZoom Device Library Updates area to download additional product lines.");
	        }
	        else
	        {
	            var str = document.getElementById("hdnMfgProdline").value;
	            if (str!="" && str.indexOf(sMfgProdline)!=-1)
	            {
	                alert("Product Line already in Basket.");
	                document.getElementById("imgAddtoQueue").src="http://altima.http.internapcdn.net/altima_vitalstream_com/Web/VisioStencils.com/Images/DownloadImages/NetZoomVS_AddtoBasket_Button_Disabled.png";
	                document.getElementById("imgCheckOut").src="http://altima.http.internapcdn.net/altima_vitalstream_com/Web/VisioStencils.com/Images/DownloadImages/NetZoomVS_Download_Button.png";
	                document.getElementById("imgViewQueue").src="http://altima.http.internapcdn.net/altima_vitalstream_com/Web/VisioStencils.com/Images/DownloadImages/NetZoomVS_ViewBasket_Button.png";
	            } 
	            else
	            {
	                alert("Added successfully");
	                sMfgProdEqid = "";
	                document.getElementById("imgAddtoQueue").src="http://altima.http.internapcdn.net/altima_vitalstream_com/Web/VisioStencils.com/Images/DownloadImages/NetZoomVS_AddtoBasket_Button_Disabled.png";
	                document.getElementById("imgCheckOut").src="http://altima.http.internapcdn.net/altima_vitalstream_com/Web/VisioStencils.com/Images/DownloadImages/NetZoomVS_Download_Button.png";
	                document.getElementById("imgViewQueue").src="http://altima.http.internapcdn.net/altima_vitalstream_com/Web/VisioStencils.com/Images/DownloadImages/NetZoomVS_ViewBasket_Button.png";
    	            
	                document.getElementById("hdnMfgProdline").value += sMfgProdline;
                    var EqList = document.getElementById("hdnMfgProdEqid").value;
	                var ss = index.SaveToQueue(EqList).value;
	            }
	        }
	    }	    
	}
}

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('viewbasket.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 != "")
	if (document.getElementById("hdnMfgProdline").value == "")
	{
	    alert("Please add a product line to basket");
	}
	else
	{
		frm.method = "Post";
	    frm.action ="download.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;
    }
}
