﻿var isShowHideoption=false,isSHtmlVisible=false,http=null,xml=null,xslGrid=null,xslDetail=null,strXml="",strXslGrid="",strXslDetail="",strXslItemDetail="", strshapeId="",strcut="",strpriceFrom="",strpriceTo="",strsizeFrom="",strsizeTo="",strcolor="",strclarity="",strpolish="",strsymmetry="",strdepth="",strtable="",strfluorescence="",strsearchtype = "", strPageNumber="1",strxmllocal="", xslDiamondDetailToolTip=null, whitespace = " \t\n\r",BroweserType = null, sortCriteria="",strsortCriteria="",strGlobalAscDesc="",strGlobalSort="", nn6=document.getElementById&&!document.all, ie=document.all, strD_ID="",strD_Type="", IsLoadedFirstTime=true, strDiamondid="",strXslDetailDisplay="";
if(navigator.appName == "Netscape"){BroweserType="FIREFOX";}if(navigator.appName == "Microsoft Internet Explorer"){BroweserType="IE";}
http = CreateRequestObject(),strtempSLeft="",strtempSTop="";
var DETPOPUPXML = "";
String.prototype.replaceAll=function(s1, s2) {return this.split(s1).join(s2)}
function GetDetailXsl()
{
    if(http!=null)
    {
        try
        {
            //SendRequest(http,"XmlData/EarringDetail.xsl","GET");
            SendRequest(http,"XmlData/EarringDetailEnhanced.xsl","GET");
            strXslDetail = GetText(http);
        }
        catch(e){AError(ex.message+"\n"+ex.source);}
    }
    else
    {
        AError("Your Browser does not support this script.");
        RedirectIt();
    }
}

function GetDetailXslDisplay()
{
    if(http!=null)
    {
        try
        {
            //SendRequest(http,"XmlData/EarringDetail.xsl","GET");
            SendRequest(http,"XmlData/EarringDetailsDisplayEnhanced.xsl","GET");
            strXslDetailDisplay = GetText(http);
        }
        catch(e){AError(ex.message+"\n"+ex.source);}
    }
    else
    {
        AError("Your Browser does not support this script.");
        RedirectIt();
    }
}

function GetStyleXsl()
{
    if(http!=null)
    {
        try
        {
            SendRequest(http,"XmlData/itemDiamondDetails.xsl","GET");
            strXslItemDetail = GetText(http);
            //Add function here to add style html into session
			uc_EarringSearchResultGrid.SetDisplayStyleHtml(strXslItemDetail,callback_SetDisplayStyleHtml);
        }catch(e){AError(ex.message+"\n"+ex.source);}
    }else{AError("Your Browser does not support this script.");RedirectIt();}
}
function callback_SetDisplayStyleHtml(res) {}
function initHttpRequest(){}
function getSearchResult(strpagenumber,sortCriteria)
{ 
    try 
    { 
        FillScroller_html();
        if(strXslDetail==null || strXslDetail.trim()=="")
		{ 
			GetDetailXsl(); 
		}
        var status=true; 
        SetHide("Chk6"); 
        SetHide("spanReport");
        SetInnerHtml("sizeError","");
		SetInnerHtml("priceError","");
        SetClassName("txtPriceFrom","bluetext"); 
        SetClassName("txtPriceTo","bluetext"); 
        SetClassName("txtSizeFrom","bluetext"); 
        SetClassName("txtSizeTo","bluetext"); 
        SetHide("topControlPanal"); 
        if (isNaN(GetCValue("txtPriceFrom"))==true) 
        { 
            SetVisible("priceErrorRow"); 
            SetInnerHtml("priceError","Please Enter Valid Price or Leave Price field blank"); 
            SetCValue("hdnFrom_Price",""); 
            SetClassName("txtPriceFrom","errorMesage"); 
            eraseCookie("MsolSearch_PriceFrom"); 
            createCookie("MsolSearch_PriceFrom",GetCValue("hdnFrom_Price"),30); 
            SetFocus("txtPriceFrom"); 
            return false; 
        } 
        else if (GetCValue("txtPriceFrom")< 0) 
        { 
            SetVisible("priceErrorRow");
            SetInnerHtml("priceError","Please Enter Valid Price or Leave Price field blank");
            SetCValue("hdnFrom_Price",""); 
            SetClassName("txtPriceFrom","errorMesage"); 
            eraseCookie("MsolSearch_PriceFrom"); 
            createCookie("MsolSearch_PriceFrom",GetCValue("hdnFrom_Price"),30); 
            SetFocus("txtPriceFrom"); 
            return false; 
        } 
        else if (isNaN(GetCValue("txtPriceTo"))==true) 
        { 
            SetVisible("priceErrorRow"); 
            SetInnerHtml("priceError","Please Enter Valid Price or Leave Price field blank"); 
            SetCValue("hdnTo_Price",""); 
            SetClassName("txtPriceTo","errorMesage"); 
            eraseCookie("MsolSearch_PriceTo"); 
            createCookie("MsolSearch_PriceTo",GetCValue("hdnTo_Price"),30); 
            SetFocus("txtPriceTo"); 
            return false; 
        } 
        else if (GetCValue("txtPriceTo")< 0) 
        { 
            SetVisible("priceErrorRow"); 
            SetInnerHtml("priceError","Please Enter Valid Price or Leave Price fields blank"); 
            SetCValue("hdnTo_Price",""); 
            SetClassName("txtPriceTo","errorMesage"); 
            eraseCookie("MsolSearch_PriceTo"); 
            createCookie("MsolSearch_PriceTo",GetCValue("hdnTo_Price"),30); 
            SetFocus("txtPriceTo");
             return false; 
        } 
        else if (isNaN(GetCValue("txtSizeFrom"))==true) 
        { 
            SetVisible("sizeErrorRow"); 
            SetInnerHtml("sizeError","Please Enter Valid Size or Leave Size fields blank"); 
            SetCValue("hdnFrom_Size",""); 
            SetClassName("txtSizeFrom","errorMesage"); 
            SetFocus("txtSizeFrom"); 
            eraseCookie("MsolSearch_SizeFrom"); 
            createCookie("MsolSearch_SizeFrom",GetCValue("hdnFrom_Size"),30); 
            return false; 
        } 
        else if(GetCValue("txtSizeFrom")< 0) 
        { 
            SetVisible("sizeErrorRow"); 
            SetInnerHtml("sizeError","Please Enter Valid Size or Leave Size fields blank"); 
            SetCValue("hdnFrom_Size",""); 
            SetClassName("txtSizeFrom","errorMesage"); 
            eraseCookie("MsolSearch_SizeFrom"); 
            createCookie("MsolSearch_SizeFrom",GetCValue("hdnFrom_Size"),30); 
            SetFocus("txtSizeFrom"); 
            return false; 
        } 
        else if (isNaN(GetCValue("txtSizeTo"))==true) 
        { 
            SetVisible("sizeErrorRow"); 
            SetInnerHtml("sizeError","Please Enter Valid Size or Leave Size fields blank"); 
            SetCValue("hdnTo_Size",""); 
            SetClassName("txtSizeTo","errorMesage"); 
            eraseCookie("MsolSearch_SizeTo"); 
            createCookie("MsolSearch_SizeTo",GetCValue("hdnTo_Size"),30); 
            SetFocus("txtSizeTo"); 
            return false; 
        } 
        else if (GetCValue("txtSizeTo")< 0) 
        { 
            SetVisible("sizeErrorRow"); 
            SetInnerHtml("sizeError","Please Enter Valid Size or Leave Size fields blank"); 
            SetClassName("txtSizeTo","errorMesage"); 
            eraseCookie("MsolSearch_SizeTo"); 
            createCookie("MsolSearch_SizeTo",GetCValue("hdnTo_Size"),30); 
            SetFocus("txtSizeTo"); 
            return false; 
        } 
        if (GetCValue("txtPriceTo")!="") 
        { 
            if(parseFloat(GetCValue("txtPriceTo"))< parseFloat(GetCValue("txtPriceFrom"))) 
            { 
                SetVisible("priceErrorRow"); 
                SetInnerHtml("priceError","Please enter smaller value in first box and larger value in second box"); 
                SetCValue("hdnTo_Price",""); 
                SetClassName("txtPriceTo","errorMesage"); 
                eraseCookie("MsolSearch_PriceTo"); 
                createCookie("MsolSearch_PriceTo",GetCValue("hdnTo_Price"),30); 
                SetFocus("txtPriceTo"); 
                return false; 
            } 
        } 
        if (GetCValue("txtSizeTo")!="") 
        { 
            if (parseInt(GetCValue("txtSizeTo"))<parseInt(GetCValue("txtSizeFrom"))) 
            { 
                SetVisible("sizeErrorRow"); 
                SetInnerHtml("sizeError","Please enter smaller size in first box and larger size in second box"); 
                SetClassName("txtSizeTo","errorMesage"); 
                eraseCookie("MsolSearch_SizeTo"); 
                createCookie("MsolSearch_SizeTo",GetCValue("hdnTo_Size"),30); 
                SetFocus("txtSizeTo"); 
                return false; 
            } 
        } 
        if(status==false) 
        { 
            return false; 
        } 
        Svisibile("Img_Ring","hidden"); 
		Sdisplay("Img_Ring","none"); 
		Svisibile("search_result","visible"); 
		Sdisplay("search_result","block"); 
		Svisibile("loose_search","hidden"); 
		Sdisplay("loose_search","none"); 
		Svisibile("diamond_detail","hidden"); 
		Sdisplay("diamond_detail","none");		
		Svisibile("item_detail","hidden"); 
		Sdisplay("item_detail","none"); 
        SetHide("tblSearchPanal"); 
        SetSrc("imgControlShape","./images/showArrow.gif"); 
        SetClassName("txtPriceFrom","bluetext"); 
        SetClassName("txtPriceTo","bluetext"); 
        SetClassName("txtSizeFrom","bluetext"); 
        SetClassName("txtSizeTo","bluetext"); 
        if(GetClassName("sizeErrorRow")=="VISIBLE") 
        { 
            SetInnerHtml("sizeError",""); 
            SetHide("sizeErrorRow"); 
        } 
        if(GetClassName("priceErrorRow")=="VISIBLE") 
        { 
            SetInnerHtml("priceError",""); 
            SetHide("priceErrorRow"); 
        } 
        SetCValue("hdnTo_Price",GetCValue("txtPriceTo")); 
        SetCValue("hdnFrom_Price",GetCValue("txtPriceFrom")) ; 
        SetCValue("hdnFrom_Size",GetCValue("txtSizeFrom")); 
        SetCValue("hdnTo_Size",GetCValue("txtSizeTo")); 
        strshapeId = GetCValue("hdnFrom_ShapeId"); 
        strcut = GetCValue("hdnFrom_Cut"); 
        strpriceFrom = GetCValue("hdnFrom_Price"); 
        strpriceTo = GetCValue("hdnTo_Price"); 
        strsizeFrom = GetCValue("hdnFrom_Size"); 
        strsizeTo = GetCValue("hdnTo_Size"); 
        strcolor = GetCValue("hdnFrom_Color"); 
        strclarity = GetCValue("hdn_Clarity");
        SetHide("spannoresult"); 
        SetVisible("tblDataGrid"); 
        SetVisible("tblInnerDataGrid"); 
        SHeightP("tblInnerDataGrid","200px"); 
        SetHide("IDDiamondDetailTable"); 
        SetHide("tblSettingStyle"); 
        SetHide("tblItemDisplay"); 
        Svisibile("imgShowLoading","visible"); 
        SetHide("extrabar"); 
        STopP("imgShowLoading",(findPosY(document.getElementById("tblDataGrid"))+70+"px")); 
        SLeftP("imgShowLoading",(findPosX(document.getElementById("tblDataGrid"))+(document.getElementById("tblDataGrid").offsetWidth/2)-55+"px")); 
        SetFocus("a_linkScroller"); 
        strPageNumber = strpagenumber; 
        strGlobalSort = ""; 
        strGlobalAscDesc = "";
        SCursor("imgTopControl","default");
		document.getElementById("imgTopControl").title="";
		SetVisible("tbl_scroller_outer");
        document.getElementById("tbl_scroller_outer").style.borderWidth = "1px";
        //document.getElementById("tbl_scroller_outer").style.borderRightWidth = "1px";
        uc_EarringSearchResultGrid.GetSearchResult(strshapeId,strcut,strpriceFrom,strpriceTo,strsizeFrom,strsizeTo,strcolor,strclarity,strPageNumber,strGlobalSort,strGlobalAscDesc,callback); 
    } 
    catch(e) { AError("getsearchresult:"+e.message+e.source); }
}

//New Function for search enhancements
function getSearchResultNew(strpagenumber,type,sortCriteria) 
{
	try
	{   
		FillScroller_html(); 
		if(strXslDetail==null || strXslDetail.trim()=="")
		{ 
			GetDetailXsl(); 
		} 
		var status=true;
		if(status==false) 
		{ 
			return false; 
		} 
		Svisibile("Img_Ring","hidden"); 
		Sdisplay("Img_Ring","none"); 
		Svisibile("buildring","hidden"); 
		Sdisplay("buildring","none"); 
		Svisibile("buildpendant","hidden"); 
		Sdisplay("buildpendant","none"); 
		Svisibile("buildsearch","hidden"); 
		Sdisplay("buildsearch","none"); 
		Svisibile("search_result","visible"); 
		Sdisplay("search_result","block"); 
		Svisibile("loose_search","hidden"); 
		Sdisplay("loose_search","none"); 
		Svisibile("diamond_detail","hidden"); 
		Sdisplay("diamond_detail","none"); 
		Svisibile("setting","hidden"); 
		Sdisplay("setting","none"); 
		Svisibile("item_detail","hidden"); 
		Sdisplay("item_detail","none"); 
		SetSrc("imgControlShape","./images/showArrow.gif"); 
		SetHide("tblSearchPanal"); 
		SetSrc("imgControlShape","./images/showArrow.gif"); 
		SetSrc("img3","./images/closeArrow.gif"); 
		SetHide("extrabar"); 
		SetHide("tblSettingStylePanal"); 
		SetClassName("txtPriceFrom","bluetext"); 
		SetClassName("txtPriceTo","bluetext"); 		

		if(GetClassName("priceErrorRow")=="VISIBLE") 
		{ 
			SetInnerHtml("priceError",""); 
			SetHide("priceErrorRow"); 
		}
		
		strcut = ""; 		
		strshapeId = GetCValue("ctl00_CPHSearch_hdnFrom_ShapeId");
		strpriceFrom = GetCValue("ctl00_CPHSearch_hdnFrom_Price"); 
		strpriceTo = GetCValue("ctl00_CPHSearch_hdnTo_Price"); 
		
		strsizeFrom = ""; 
		strsizeTo = ""; 
		strcolor = ""; 
		strclarity = ""; 
		strpolish = "";
		strsymmetry = "";
		strdepth = "";
		strtable = "";
		strfluorescence = "";
		
		SetHide("spannoresult"); 
		SetVisible("tblDataGrid"); 
		SetVisible("tblInnerDataGrid");
		SetVisible("tblInnerDataGridNonUpselling"); 
		SHeightP("tblInnerDataGrid","200px"); 
		SetHide("IDDiamondDetailTable"); 
		SetHide("tblSettingStyle"); 
		SetHide("tblItemDisplay"); 
		Svisibile("imgShowLoading","visible");
		STopP("imgShowLoading",(findPosY(document.getElementById("tblDataGrid"))+70+"px")); 
		SLeftP("imgShowLoading",(findPosX(document.getElementById("tblDataGrid"))+(document.getElementById("tblDataGrid").offsetWidth/2)-55+"px")); 
		SetFocus("a_linkScroller");		
		strPageNumber = strpagenumber; 
		//Check what you have to send here
		strsearchtype = GetCValue("SearchGrid1_hdnSearchType");
		strGlobalSort = ""; 
		strGlobalAscDesc = "";		
		var strGloabalPagging = 10;		
		//setTimeout('uc_EarringSearchResultGrid.GetSearchResult(strshapeId,strcut,strpriceFrom,strpriceTo,strsizeFrom,strsizeTo,strcolor,strclarity,strpolish,strsymmetry,strdepth,strtable,strfluorescence,strPageNumber,strGloabalPagging,strsearchtype,strGlobalSort,strGlobalAscDesc,callback)',0); 
		uc_EarringSearchResultGrid.GetSearchResult(strshapeId,strcut,strpriceFrom,strpriceTo,strsizeFrom,strsizeTo,strcolor,strclarity,strPageNumber,strGlobalSort,strGlobalAscDesc,callback); 
		//setTimeout('uc_SearchResultGrid.GetSearchResult_NonUpselling(strshapeId,strcut,strpriceFrom,strpriceTo,strsizeFrom,strsizeTo,strcolor,strclarity,strpolish,strsymmetry,strdepth,strtable,strfluorescence,strPageNumber,strGloabalPagging,strsearchtype,strGlobalSort,strGlobalAscDesc,callback_scroller_GetSearchResult_NonUpselling)',5);;
	} 
	catch(e) 
	{ 
		AError("getSearchResult:"+e.message); 
	} 
}

function callback(res)
{ 
    try 
    { 
        var arr="", strtemp=null; arr = res.value; 
        if(typeof(arr)=="object" && arr.length>0) 
        { 
            strXml = arr[0];
            strxmllocal = arr[0]; 
            document.getElementById("copy").innerHTML = arr[1]; 
            if(strXml.trim()!="") 
            { 
                strScrollerPriceFrom = (parseFloat(arr[3])).toFixed(2); 
                strScrollerPriceTo = (parseFloat(arr[4])).toFixed(2); 
                arrPrice[0] = (parseFloat(arr[3])).toFixed(2); 
                arrPrice[1] = (parseFloat(arr[4])).toFixed(2); 
                strScrollerShape = arr[8]; 
                strScrollerSizeFrom = (parseFloat(arr[5])).toFixed(2); 
                strScrollerSizeTo = (parseFloat(arr[6])).toFixed(2); 
                SetPagging(arr[2],arr[7]); 
                SetCValue("VScrollerShapeId",strScrollerShape); 
				SetCValue("VScrollerCut",GetCValue("hdnFrom_Cut")); 
				SetCValue("VScrollerPriceFrom",strScrollerPriceFrom); 
				SetCValue("VScrollerPriceTo",strScrollerPriceTo); 
				SetCValue("VScrollerSizeFrom",strScrollerSizeFrom); 
				SetCValue("VScrollerSizeTo",strScrollerSizeTo); 
				SetCValue("VScrollerColor",GetCValue("hdnFrom_Color")); 
				SetCValue("VScrollerClarity",GetCValue("hdn_Clarity")); 
				var TotRecs = document.getElementById("TotRecs");
			    if(TotRecs!=null)
			    {
			        var val = parseInt(TotRecs.innerHTML);
			        if(val!=null && val!=0 && val!="" && !isNaN(val))
			        {
			            var rec = parseInt(arr[2]) + parseInt(val);
			            SetInnerHtml("TotRecs",rec);
			        }
			        else
			            SetInnerHtml("TotRecs", parseInt(arr[2]));
			    }
			    DETPOPUPXML = strXml;
			    uc_EarringSearchResultGrid.SetXMLData(strXml);
                xml = CreateXmlObject(); 
                xml = loadxml(xml,strXml); 
                ShowOptionColumn('DDepth','Chk11'); 
                ShowOptionColumn('DTable','Chk12'); 
                ShowOptionColumn('DCulet','Chk13'); 
                ShowOptionColumn('DFluorescence','Chk14'); 
                ShowOptionColumn('DGirdlet','Chk15'); 
                ShowOptionColumn('DShape','Chk9'); 
                ShowOptionColumn('DColor','Chk3'); 
                ShowOptionColumn('DClarity','Chk4'); 
                ShowOptionColumn('DCut','Chk5'); 
                ShowOptionColumn('DCarat','Chk2'); 
                ShowOptionColumn('DPrice','Chk8'); 
                ShowOptionColumn('DPolish','Chk7'); 
                ShowOptionColumn('DSymmetry','Chk10'); 
                ShowOptionColumn('DDepth','Chk11'); 
            }
            else 
            {
                SetHide("tbl");
                SetHide("tblDataGrid");
                SetVisible("spannoresult"); 
                SetVisible("tblSearchPanal");
                SetInnerHtml("spannoresult","<font style=\"color:red;\"> No Record Found</font>"); 
                SetInnerHtml("PAGING",""); 
                SetInnerHtml("numofsearchresult",""); 
                //SHeightP("tblInnerDataGrid","100px"); 
            } 
            Svisibile("imgShowLoading","hidden"); 
            //SHeightP("tblInnerDataGrid","auto"); 
        } 
        else 
        {
            SetHide("tbl");
            SetHide("tblDataGrid");
            SetVisible("spannoresult");
            SetVisible("tblSearchPanal");
            Svisibile("imgShowLoading","hidden"); 
            SetInnerHtml("spannoresult","<font style=\"color:red;\"> No Record Found</font>");
            SetInnerHtml("PAGING",""); 
            SetInnerHtml("numofsearchresult",""); 
            //SHeightP("tblInnerDataGrid","100px"); 
        } 
    } 
    catch(e) { AError("callback\n"+e.message+"\n"+e.source); }
}
function SetPagging(totalrec,pagging)
{ 
    try 
    {   
        document.getElementById("numofsearchresult").innerHTML = "Total Search Results :" + totalrec; 
        SetScroller(); 
        document.getElementById("PAGING").innerHTML = pagging; 
        SetVisible("tbl"); 
    }
    catch(e){}
}
function getURLParameters() 
{
    var sURL = window.document.URL.toString();
    if (sURL.indexOf("?") > 0)
    { 
        try
        {
            var arrParams = sURL.split("?");
            var arrURLParams = arrParams[1].split("=");
            return arrURLParams[1];
        } 
        catch(e)
        {}
    }
    return "";
}
function ShowOptionColumnID()
{ 
    var ID1=""; 
    NewDataSet = xml.getElementsByTagName("NewDataSet"); 
    table = NewDataSet[0].getElementsByTagName("Table"); 
    tablelength = NewDataSet[0].getElementsByTagName("Table").length; 
    try 
    { 
        SetClassName("PID","GRIDTHHIDE"); 
        for(i=0;i<tablelength;i++) 
        { 
            ID1 = table[i].getElementsByTagName("PID"); 
            try 
            {
                SetClassName("PID"+ID1[0].firstChild.nodeValue,"GRIDTDHIDE");
            } 
            catch(e){} 
         } 
     } 
     catch(e){}
 }
function SetDiamondDetail(id,obj,str)
{ 
    try 
    { 
        strD_ID = id; 
        diamond_Id=id; 
        strD_Type = ""; 
        if(str.trim()!="") 
        { 
            showSTMenu(id,obj); 
        } 
    } 
    catch(e) 
    { 
        AError("SetDiamondDetail\n"+e.message+"\n"+e.source); 
    }
}
function showSTMenu(dii,obj)
{ 
    try 
    { 
        posX=findPosX(obj); 
        posY=findPosY(obj); 
        STopP("DHTMLMENU",(posY+"px")); 
        SLeftP("DHTMLMENU",(posX+"px")); 
        Svisibile("DHTMLMENU","visible"); 
    } 
    catch(e) 
    { 
        AError("showSTMenu\n"+e.message+"\n"+e.source); 
    }
}
function ShowHideoption(sender)
{ 
    try 
    {
         //SetHide("Chk6"); 
        //SetHide("spanReport");
        //document.getElementById("Chk6").style.visibility = "false";
        if(isShowHideoption==false && GetClassName("tblInnerDataGrid")=="VISIBLE")
		{
			uc_NavigatePanel.GetShowHideGridColumn(callback_ShowHideoption);
			strtempSTop=findPosY(sender)-55+"px";
		}
        else 
        { 
            SetHide("tblCut"); 
            SetHide("tblColor"); 
            SetHide("tblSize"); 
            SetHide("topControlPanal"); 
            SLeftP("optionbyname",(findPosX(document.getElementById("tblDataGrid"))+"px"));
            STopP("optionbyname",(findPosY(sender)-55+"px"));
            SetVisible("optionbyname"); 
        } 
    } 
    catch(e) 
    { 
        AError("ShowHideoption\n"+e.message+"\n"+e.source); 
    }
}

function callback_ShowHideoption(res)
{
	try
	{
		if(res.value != null && res.value != "")
		{
			isShowHideoption=true;SetInnerHtml("optionbyname",res.value);
			SetHide("tblCut");
			SetHide("tblColor");
			SetHide("tblSize");
			SetHide("topControlPanal");
			SLeftP("optionbyname",(findPosX(document.getElementById("tblDataGrid"))+"px"));
			STopP("optionbyname",strtempSTop);
			SetVisible("optionbyname");
		}
	}
	catch(e) 
	{ 
		AError("callback_ShowHideoption:"+e.message);
	}
}

//function ShowOptionColumn(id,chkid)
//{ 
//    try 
//    { 
//        var ID=""; NewDataSet = xml.getElementsByTagName("NewDataSet"); 
//        table = NewDataSet[0].getElementsByTagName("Table"); 
//        tablelength = NewDataSet[0].getElementsByTagName("Table").length; 
//        if(document.getElementById(chkid).checked==true) 
//        { 
//            SetVisible(id); 
//            for(i=0;i<tablelength;i++) 
//            { 
//                ID = table[i].getElementsByTagName("PID");
//                SetVisible("IDT"+id+ID[0].firstChild.nodeValue); 
//            } 
//        } 
//        else 
//        {
//            SetHide(id); 
//            for(i=0;i<tablelength;i++) 
//            { 
//                ID = table[i].getElementsByTagName("PID");
//                SetHide("IDT"+id+ID[0].firstChild.nodeValue); 
//            } 
//        } 
//        SLeftP("optionbyname",(findPosX(document.getElementById("tblDataGrid"))+"px"));
//        STopP("optionbyname",(findPosY(document.getElementById("img21"))-55+"px")); 
//    } 
//    catch(e) 
//    { 
//        AError("ShowOptionColumn\n"+e.message+"\n"+e.source); 
//    }
//}

function ShowOptionColumn(id,chkid)
{ 
    try 
    { 
        var ID=""; NewDataSet = xml.getElementsByTagName("NewDataSet"); 
        table = NewDataSet[0].getElementsByTagName("Table"); 
        tablelength = NewDataSet[0].getElementsByTagName("Table").length; 
        if(document.getElementById(chkid).checked==true) 
        { 
            SetVisible(id);
            SetVisible(id+"B");
            var sepobj = document.getElementById(id+"SEP");
		    if(sepobj!=null)
		    {
		        sepobj.style.visibility = "visible";
		        sepobj.style.display='';
		    }
		    var sepobjb = document.getElementById(id+"BSEP");
		    if(sepobjb!=null)
		    {
		        sepobjb.style.visibility = "visible";
		        sepobjb.style.display='';
		    }
            for(i=0;i<tablelength;i++) 
            { 
                ID = table[i].getElementsByTagName("PID");
                SetVisible("IDT"+id+ID[0].firstChild.nodeValue); 
                var sepobj = document.getElementById("IDT"+id+ID[0].firstChild.nodeValue + "SEP");
		        if(sepobj!=null)
		        {
		            sepobj.style.visibility = "visible";
		            sepobj.style.display='';
		        }
            } 
        } 
        else 
        {
            SetHide(id); 
            SetHide(id+"B");
            var sepobj = document.getElementById(id+"SEP");
		    if(sepobj!=null)
		    {
		        sepobj.style.visibility = "hidden";
		        sepobj.style.display="none";
		    }
		    var sepobjb = document.getElementById(id+"BSEP");
		    if(sepobjb!=null)
		    {
		        sepobjb.style.visibility = "hidden";
		        sepobjb.style.display="none";
		    }
            for(i=0;i<tablelength;i++) 
            { 
                ID = table[i].getElementsByTagName("PID");
                SetHide("IDT"+id+ID[0].firstChild.nodeValue);
                var sepobj = document.getElementById("IDT"+id+ID[0].firstChild.nodeValue + "SEP");
		        if(sepobj!=null)
		        {
		            sepobj.style.visibility = "hidden";
		            sepobj.style.display="none";
		        }
            } 
        } 
        //SLeftP("optionbyname",(findPosX(document.getElementById("tblDataGrid"))+"px"));
        //STopP("optionbyname",(findPosY(document.getElementById("img21"))-55+"px")); 
    } 
    catch(e) 
    { 
        AError("ShowOptionColumn\n"+e.message+"\n"+e.source); 
    }
}

function CloseShowOption()
{ 
    try 
    { 
        SLeftP("optionbyname",(0+"px")); 
        STopP("optionbyname",(0+"px")); 
        SetHide("optionbyname") ; 
    } 
    catch(e){}
}

function GetDiamondDetail()
{ 
    try 
    { 
        if(strXslItemDetail==null || strXslItemDetail.trim()=="") 
		{ 
			GetStyleXsl(); 
		}
		SetHide("tbl_scroller_outer"); 
		SetFocus("linktop_focus"); 
        var str = strXslDetail, temp = null; 
        id = strD_ID; 
        str = str.replace("IDNUMBER",id); 
        SetVisible("extrabar"); 
        SetHide("tblSettingStyle"); 
		SetHide("tblItemDisplay"); 
		SetHide("tblSettingStylePanal");
        SetInnerHtml("grid_detail_stockno1","Stock No.: "+GetNodeValue1(xml,strD_ID,"DIAMOND1STOCK")); 
        SetInnerHtml("grid_detail_name1","Name: "+GetNodeValue1(xml,strD_ID,"DIAMOND1NAME")); 
        SetInnerHtml("grid_detail_price1","Price: $"+GetNodeValue1(xml,strD_ID,"DIAMOND1PRICE")); 
        SetInnerHtml("grid_detail_stockno2","Stock No.: "+GetNodeValue1(xml,strD_ID,"DIAMOND2STOCK")); 
        SetInnerHtml("grid_detail_name2","Name: "+GetNodeValue1(xml,strD_ID,"DIAMOND2NAME")); 
        SetInnerHtml("grid_detail_price2","Price: $"+GetNodeValue1(xml,strD_ID,"DIAMOND2PRICE")); 
        datastring=TransFormNode(xml,str); 
        closeSearchGrid(); 
        CloseShowOption();
        Svisibile("Img_Ring","hidden"); 
		Sdisplay("Img_Ring","none"); 
		Svisibile("search_result","hidden"); 
		Sdisplay("search_result","none"); 
		Svisibile("loose_search","hidden"); 
		Sdisplay("loose_search","none"); 
		Svisibile("diamond_detail","visible"); 
		Sdisplay("diamond_detail","block");		
		Svisibile("item_detail","hidden"); 
		Sdisplay("item_detail","none"); 
        SetInnerHtml("IDDiamondDetail",datastring); 
        SetVisible("IDDiamondDetail"); 
        SetHide("tblSettingStyle"); 
        SetHide("tblItemDisplay"); 
        SetFocus("linktop_focus");
        SetVisible("IDDiamondDetailTable"); 
    } 
    catch(e) 
    { 
        AError(e.message+"\n"+e.source); 
    } 
}

function GetDiamondDetailNew(from,Price1,Price2) 
{
	try 
	{ 
		if(strXslItemDetail==null || strXslItemDetail=="") 
		{ 
			GetStyleXsl(); 
		}
		
		if(strXslDetailDisplay==null || strXslDetailDisplay=="") 
		{ 
		    GetDetailXslDisplay();	
		}
		
		//var str = strXslDetail; 
		var str = strXslDetailDisplay;
		var temp = null; 
		id = strD_ID; 
		str = str.replace("IDNUMBER",id); 
		
		if(from=='R')
		{
		    //str = str.replace("[DIAMONDSMALLIMAGE]",GetNodeValue(xml,id,"Image")); 
		    //SetInnerHtml("grid_detail_stockno","Stock No.: "+GetNodeValue(xml,id,"Stock")); 
		    //SetInnerHtml("grid_detail_name","Name: "+GetNodeValue(xml,id,"Name")); 
		    //SetInnerHtml("grid_detail_price","Price: $"+GetNodeValue(xml,id,"Price")); 
		    datastring=TransFormNode(xml,str);		    
		    uc_EarringSearchResultGrid.SetNUP("false");
		}
		if(from=='N')
		{
		    //str = str.replace("[DIAMONDSMALLIMAGE]",GetNodeValue(xmlNUP,id,"Image")); 
		    //SetInnerHtml("grid_detail_stockno","Stock No.: "+GetNodeValue(xmlNUP,id,"Stock")); 
		    //SetInnerHtml("grid_detail_name","Name: "+GetNodeValue(xmlNUP,id,"Name")); 
		    //SetInnerHtml("grid_detail_price","Price: $"+GetNodeValue(xmlNUP,id,"Price")); 
		    datastring=TransFormNode(xmlNUP,str);
		    uc_EarringSearchResultGrid.SetNUP("true");
		}
		uc_EarringSearchResultGrid.SetDisplayDiamondHtml(datastring);		
		SetInnerHtml("IDDiamondDetail",datastring); 
		SetVisible("IDDiamondDetail"); 
		if(from=='R')		
		    SetInnerHtml("spname",GetNodeValue(xml,id,"Name"));
		if(from=='N')    
		    SetInnerHtml("spname",GetNodeValue(xmlNUP,id,"Name"));
		uc_EarringSearchResultGrid.SetDiamondId(id);
		CloseShowOption();		
		SetVisible("IDDiamondDetailTable");
		var destination = "DiamondDetailsEarrings.aspx";
		var QueryString = null;
           try
           {    
                QueryString = location.href.substring ( location.href.indexOf ( "?" ) ); // get the QueryString from the URL
                QueryString = QueryString.split ( "&" );  // creates an array of Strings, e.g. "p=1"
                var i;
                for ( i = 0; i < QueryString.length; i++ ) 
                {
                    QueryString [ i ] = QueryString [ i ].split ( "=" ); // creates a name and value element for each parameter in the QueryString
                }
           }
           catch(e)
           {
                alert(e.message);
           }           
           if(QueryString!=null) 
           {          
                if(QueryString[0][1]!=null)
		            setTimeout("window.location='"+destination + "?Seq=" + QueryString[0][1]  + "&Price1=" + Price1 + "&Price2=" + Price2 + "&Cat_ID=" + Cat_ID + "'",0);
		        else
		            setTimeout("window.location='"+destination + "?Seq=D&Price=" + Price1 + "&Price2=" + Price2 + "&Cat_ID=" + Cat_ID + "'",0);
		   }
		   else
		        setTimeout("window.location='"+destination + "?Seq=D&Price=" + Price1 + "&Price2=" + Price2 + "&Cat_ID=" + Cat_ID + "'",0);
	} 
	catch(e) 
	{
		AError("GetDiamondDetail:"+e.message);
	}
}

var xx="",yy="",hh="",ww="",CY="",CX="",SX="",SY="", timerID=null, isHide = true, tooltiptempY =null, tooltiptempX=null;
function GetDiamondDetailTooltip(sender,id,e)
{ 
    try 
    { 
        //document.onmousemove = GetDiamondDetailTooltipHide; 
        strDiamondid = id; 
        SX = findPosX(sender); 
        SY = findPosY(sender); 
        //timerID = setInterval("TipLayer_ToolTip_show()",0); 
        TipLayer_ToolTip_show(e);
    } 
    catch(e) 
    { 
        AError("GetDiamondDetailTooltip"+e.message+"\n"+e.source); 
    }
}
function GetDiamondDetailTooltip_call(res)
{ 
    var arr = res.value; 
    try 
    { 
        if(typeof(arr)=="object" && arr.length>0) 
        { 
           SetInnerHtml("TipLayer",arr[1]);
        } 
    }catch(e){AError("GetDiamondDetailTooltip_call:"+e.message);} 
}
function TipLayer_ToolTip_show(e)
{ 
    try 
    { 
        var H = parseInt(document.getElementById("TipLayer").offsetHeight), W = parseInt(document.getElementById("TipLayer").offsetWidth); 
        xx = findPosX(document.getElementById("tbl_dataGrid")); 
        yy = findPosY(document.getElementById("tbl_dataGrid")); 
        ww = parseInt(document.getElementById("tbl_dataGrid").offsetWidth); 
        hh = parseInt(document.getElementById("tbl_dataGrid").offsetHeight); 
        CY = getScrollY(); 
        var Top = null, Left = null; 
        var evt = null;
        var nn6=document.getElementById&&!document.all;
        if(nn6)
        {     
            evt =  e; 
        }
        else
        {
            evt =  event;
        }
        tooltiptempY = evt.clientY + getScrollY(); 
        tooltiptempX = evt.clientX;      
                
        Left = tooltiptempX+W; 
        if((Left)>(xx+ww)) 
        { 
            Left = Left-(2*W)-60+55; 
        } 
        else 
        { 
            Left = Left-W+10; 
        } 
        Top = tooltiptempY-hh; 
        while((Top)<CY) 
        { 
            Top+=10; 
        } 
        var str = strXslDetail; 
        var temp = null; 
        id = strDiamondid; 
        str = str.replace("IDNUMBER",id); 
        datastring=TransFormNode(xml,str); 
        document.getElementById("TipLayer").innerHTML = datastring; 
        try 
        { 
            Svisibile("img_ear_basket","hidden"); 
            Sdisplay("img_ear_basket","none"); 
            Svisibile("img_ear_BackToSearch","hidden"); 
            Sdisplay("img_ear_BackToSearch","none"); 
            Svisibile("td_BackToSearch","hidden"); 
            Sdisplay("td_BackToSearch","none"); 
            Svisibile("tblAboutDiamond","hidden"); 
            Sdisplay("tblAboutDiamond","none"); 
        } 
        catch(e) 
        {} 
        //if(isHide==false && strDiamondid != "") 
        if(strDiamondid != "") 
        { 
            strD_ID = strDiamondid; 
            document.getElementById("TipLayer").style.top = Top+"px"; 
            document.getElementById("TipLayer").style.left = Left+"px"; 
            Svisibile("TipLayer","visible"); 
            clearInterval(timerID); 
        } 
    }catch(e){AError("TipLayer_ToolTip_show\n"+e.message+"\n"+e.source+"\n"+e.stack);}
}
function TipLayer_Hide_ToolTip(e)
{ 
    try 
    { 
        clearInterval(timerID);
        SLeftP("TipLayer","0px"); 
        STopP("TipLayer","0px"); 
        Svisibile("TipLayer","hidden"); 
        SetInnerHtml("TipLayer","");
        strDiamondid = ""; 
    }catch(e){AError("TipLayer_Hide_ToolTip:"+e.message);}
}
function GetDiamondDetailTooltipHide(e)
{ 
    try 
    { 
        var evt = nn6 ? e : event; 
        tooltiptempY = evt.clientY + getScrollY(); 
        tooltiptempX = evt.clientX; 
        var xx1 = findPosX(document.getElementById("tbl_dataGrid")), yy1 = findPosY(document.getElementById("tbl_dataGrid")), ww1 = parseInt(document.getElementById("tbl_dataGrid").offsetWidth), hh1 = parseInt(document.getElementById("tbl_dataGrid").offsetHeight); 
        if(tooltiptempX>xx1 && tooltiptempX<(xx1+ww1-25) && tooltiptempY>yy1 && tooltiptempY<(yy1+hh1)) 
        { 
            isHide=false; 
        } 
        else 
        { 
            isHide=false; 
            //isHide=true; 
            //Svisibile("TipLayer","hidden"); 
        } 
    }catch(e){AError("GetDiamondDetailTooltipHide:"+e.message);}
}
function Collapse(id)
{ 
    try 
    { 
        if(document.getElementById(id).className=="VISIBLE") 
        { 
            
            SetSrc("img3","./images/showArrow.gif"); 
            SetHide(id); 
            SetHide("tbl");
            SetHide("tbl_scroller_outer");
            SCursor("img21","default");
		    document.getElementById("img21").title="";
        } 
        else 
        { 
            
            SetSrc("img3","./images/closeArrow.gif"); 
            SetVisible(id); 
            SetVisible("tbl"); 
            SetVisible("tbl_scroller_outer");
            SCursor("img21","pointer");
		    document.getElementById("img21").title="Click Here";
        } 
    }catch(e){AError("Collapse\n"+e.message+"\n"+e.source+"\n"+e.stack);} 
}
function CloseDetailPage()
{ 
    try 
    { 
        if(document.getElementById("IDDiamondDetail").className=="VISIBLE") 
        { 
            SetHide("IDDiamondDetail"); 
            SetSrc("imgDetail","./images/showArrow.gif"); 
        } 
        else 
        { 
            SetVisible("IDDiamondDetail"); 
            SetSrc("imgDetail","./images/closeArrow.gif"); 
        } 
    }catch(e){AError("CloseDetailPage\n"+e.message+"\n"+e.source+"\n"+e.stack);}
}
function openNewWindow(url)
{
    var newwin=window.open(url,"MySolitaire","height=400,width=500,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes");
}
function popuponclick(url)
{
    my_window = window.open(url,"mywindow","status=1,width=550,height=400");
} 
function fnShowPackCatImg(intCat_ID)
{
    var strurl="http://www.mysolitaire.com/Website/ViewPackImg.asp?Cat_ID=156" ;
    window.open(strurl,'MySolitaire','toolbar=no,status=yes,scrollbars=yes,width=550,height=540');
}
function fnBacktoSearch()
{ 
    try 
    { 
        SetHide("tblItemDisplay");
        SetVisible("tbl"); 
        SetVisible("tbl_scroller_outer"); 
        SetVisible("tblDataGrid"); 
        SetVisible("tblInnerDataGrid");
        SetHide("IDDiamondDetailTable");
        SetHide("extrabar");
        SetSrc("img3","images/closeArrow.gif");
        SetHide("tblSettingStyle");
        SetHide("tblItemDisplay");
    }catch(e){AError("fnBacktoSearch:"+e.message);} 
}

function BackToResult() 
{ 
	try 
	{ 
		SetVisible("tblDataGrid"); 
		SetVisible("tblInnerDataGrid"); 
		SetHide("tblSettingStyle"); 
		SetHide("tblItemDisplay");
	}catch(e){AError("BackToResult:"+e.message);} 
} 

function FillTopGrid()
{
	try
	{
		uc_SearchGrid.getDiamondShapes("",callback_FillTopGrid);
	}catch(e){AError("FillTopGrid:\n"+e.message+"\n"+e.stack);}
}

function callback_FillTopGrid(res)
{
	try
	{
		SetInnerHtml("divGrid",res.value);
		onloadfun();
	}catch(e){AError("callback_FillTopGrid:"+e.message);}
}

function FillScroller_html()
{
	try
	{
		if(isSHtmlVisible==false)
		{
			uc_EarringScroller.GetScrollerHtml(callback_FillScroller_html);
		}
	}catch(e){AError("FillScroller_html:"+e.message+e.stack);}
}

function callback_FillScroller_html(res)
{
	try
	{
		SetInnerHtml("div_Scroller_html",res.value);
		isSHtmlVisible = true;
		BindScroller();
	}catch(e){AError("callback_FillScroller_html:"+e.message);}
}

function RetainCompareChecks()
{

    var from = "";
    var arrDiaID = new Array();
    var hdnDiaCmprIds = "";
    var hdnDiaCmprIdsobj = document.getElementById("ctl00_CPHSearch_hdnDiaCmprIds");
    var hdnfrom = document.getElementById("ctl00_CPHSearch_hdnfrom");
    var frm = document.forms["aspnetForm"];
    if(hdnfrom!=null)
        from = hdnfrom.value;    
    if(frm)
    {
        try
        {
            if(from=='REC')        
                chkcollection = frm.elements["chk"];        
            if(from=='NUP')        
                chkcollection = frm.elements["chkNUP"];
            if(chkcollection)
            {
                hdnDiaCmprIds = hdnDiaCmprIdsobj.value;
                arrDiaID = hdnDiaCmprIds.split(",");
                for(var j=0;j<arrDiaID.length;j++)
                {
                    for(var i=0; i < chkcollection.length; i++)
                    {
                        if(arrDiaID[j] == chkcollection[i].value)
                        {
                            chkcollection[i].checked = true;
                        }
                    }
                }
            }
        }
        catch(e)
        {
        }
    }
}

function CollectCompareIds(from,ID)
{   
    var diaidlist="";
    var arrDiaID = new Array();
    var arrDiaID1 = new Array();
    var flag = false;
    var hdnDiaCmprIds = "";
    var hdnDiaCmprIdsobj = document.getElementById("ctl00_CPHSearch_hdnDiaCmprIds");
    var hdnfrom = document.getElementById("ctl00_CPHSearch_hdnfrom");
    var frm = document.forms["aspnetForm"];
    if(frm)
    {
        if(from=='REC')        
            chkcollection = frm.elements["chk"];        
        if(from=='NUP')        
            chkcollection = frm.elements["chkNUP"];
        if(hdnfrom!=null)
                hdnfrom.value = from;
        if(chkcollection)
        {
              //Changes for comparison across pages
              hdnDiaCmprIds = hdnDiaCmprIdsobj.value;
              var remstr1 = "";
              var remstr2 = "";
              var remstr3 = "";
              var remstr4 = "";  
              var repl = "";
              var tworepl = "";
              
              for (var i=0; i < chkcollection.length; i++)
              {   
                  if (chkcollection[i].checked)
                  {     
                        if(i==chkcollection.length)
                        {
                            if(hdnDiaCmprIds.indexOf(chkcollection[i].value)==-1)
                                hdnDiaCmprIds += chkcollection[i].value + ",";
                        }
                        else
                        {   
                            var ndx = hdnDiaCmprIds.search(/,/);
                            if(ndx==-1)
                            {
                                if(hdnDiaCmprIds.indexOf(chkcollection[i].value)==-1)
                                    hdnDiaCmprIds += "," + chkcollection[i].value + ",";                            
                            }
                            else
                            {
                                if(hdnDiaCmprIds.indexOf(chkcollection[i].value)==-1)
                                    hdnDiaCmprIds += "," + chkcollection[i].value + ",";
                            }
                        }
                        flag = true;
                  }
                  if(chkcollection[i].checked==false)
                  { 
                    remstr4 = chkcollection[i].value;
                    if(hdnDiaCmprIds!="")
                    {
                        hdnDiaCmprIds = hdnDiaCmprIds.replaceAll(remstr4,',');
                    }
                  }
              }
              arrDiaID = hdnDiaCmprIds.split(",");              
              for(var k=0;k<arrDiaID.length;k++)
              {
                if(arrDiaID[k]!=null && arrDiaID[k]!="")
                    arrDiaID1[k] = arrDiaID[k];
              }
              arrDiaID = null;
              arrDiaID = arrDiaID1;
              for(var j=0;j<arrDiaID.length;j++)
              {
                if(j==arrDiaID.length-1)
                {
                    if(arrDiaID[j]!=null && arrDiaID[j]!="")
                        diaidlist += arrDiaID[j];
                }
                else
                {
                    if(arrDiaID[j]!=null)
                    {
                        if(arrDiaID[j]!="")
                            diaidlist += arrDiaID[j] + ",";
                    }
                }
              }
              hdnDiaCmprIdsobj.value =  diaidlist;
        }
    }
}

function SetCompareParameter(from)
{      
    var diaidlist="";
    var arrDiaID = new Array();
    var flag = false;
    var hdnDiaCmprIds = "";
    var hdnDiaCmprIdsobj = document.getElementById("ctl00_CPHSearch_hdnDiaCmprIds");
//    if(hdnDiaCmprIdsobj!=null)
//    {
//        if(DYROCMPRFLG!=false)
//        {
//            hdnDiaCmprIds = hdnDiaCmprIdsobj.value + ",";
//        }
//        else
//        {
//            hdnDiaCmprIds = hdnDiaCmprIdsobj.value;
//        }
//    }
//    var frm = document.forms["aspnetForm"];
//    if(frm)
//    {
//        if(from=='REC')
//            chkcollection = frm.elements["chk"];
//        if(from=='NUP')    
//            chkcollection = frm.elements["chkNUP"];
//            
//        if(chkcollection)
//        {
//              for (var i=0; i < chkcollection.length; i++)
//              {
//                  if (chkcollection[i].checked)
//                  {    
//                        arrDiaID[i] = chkcollection[i].value;
//                        flag = true;
//                  }
//              }
//              //Changes for comparison across pages
//              if(hdnDiaCmprIds!=null)
//                diaidlist += hdnDiaCmprIds;
//                
//              for(var j=0;j<arrDiaID.length;j++)
//              {
//                if(j==arrDiaID.length-1)
//                {
//                    if(arrDiaID[j]!=null)
//                        diaidlist += arrDiaID[j];
//                }
//                else
//                {
//                    if(arrDiaID[j]!=null)
//                        diaidlist += arrDiaID[j] + ",";
//                }
//              }
//              
//              hdnDiaCmprIdsobj.value =  diaidlist;
                if(hdnDiaCmprIdsobj.value!="")
                {
                    diaidlist = hdnDiaCmprIdsobj.value;
                    SelectDiamondEarrings.setCompareDiaIds(diaidlist);
                    flag = true;
                }
                            
          //logic for html
          //if(from!="VP")
          //{
              if(flag==false || diaidlist=="")
              {
                alert("Please select diamonds to compare.");
                return;
              }
          //}
//          if(from=="VP")
//          {
//                if(diaidlist=="")
//                {
//                    alert("Previous comparison does not exist.");
//                    return;
//                }
//          }
          
          var destination = "DiamondCompareEarrings.aspx";
          var QueryString = null;
           try
           {    
                QueryString = location.href.substring ( location.href.indexOf ( "?" ) ); // get the QueryString from the URL
                QueryString = QueryString.split ( "&" );  // creates an array of Strings, e.g. "p=1"
                var i;
                for ( i = 0; i < QueryString.length; i++ ) 
                {
                    QueryString [ i ] = QueryString [ i ].split ( "=" ); // creates a name and value element for each parameter in the QueryString
                }
           }
           catch(e)
           {
                alert(e.message);
           }
           if(QueryString!=null)
           {
                //window.location.target="_new";
                //top.location.target="_top" 
                if(QueryString[0][1]!=null)
                {
                    //setTimeout("window.location='"+destination + "?Seq=" + QueryString[0][1] +  "&Dia_Ids=" + diaidlist + "&from=" + from + "'",0);
                    window.open(destination + "?Seq=" + QueryString[0][1] +  "&Dia_Ids=" + diaidlist + "&from=" + from);
                }
                else
                {
                    //setTimeout("window.location='"+destination + "?Seq=D&Dia_Ids=" + diaidlist + "&from=" + from + "'",0);    
                    window.open(destination + "?Seq=D&Dia_Ids=" + diaidlist + "&from=" + from);    
                }
           }
		  
        //}
    //}
}

function CompareDiamondDetails(from,DiaID,Price)
{
	try 
	{ 
//		if(strXslItemDetail==null || strXslItemDetail=="") 
//		{ 
//			GetStyleXsl(); 
//		}		 
//		if(strXslDetail==null || strXslDetail=="")
//		{
//		    GetDetailXsl();
//		}
        if(strXslDetailDisplay==null || strXslDetailDisplay=="")
		{
		    GetDetailXslDisplay();
		}
		var str = strXslDetailDisplay; 
		var temp = null; 
		id = DiaID; 
		str = str.replace("IDNUMBER",id); 
		
		if(from=='R')
		{
		    var stringxml = DiamondCompareEarrings.GetXMLText();
		    xml = CreateXmlObject(); 
			xml = loadxml(xml,stringxml.value);
		    str = str.replace("[DIAMONDSMALLIMAGE]",GetNodeValue(xml,id,"Image")); 
		    SetInnerHtml("grid_detail_stockno","Stock No.: "+GetNodeValue(xml,id,"Stock")); 
		    SetInnerHtml("grid_detail_name","Name: "+GetNodeValue(xml,id,"Name")); 
		    SetInnerHtml("grid_detail_price","Price: $"+GetNodeValue(xml,id,"Price")); 
		    datastring=TransFormNode(xml,str);
		    uc_EarringSearchResultGrid.SetNUP("false");
		}		
		if(from=='N')
		{
		    var stringxml = DiamondCompareEarrings.GetNUPXMLText();
		    xmlNUP = CreateXmlObject(); 
			xmlNUP = loadxml(xmlNUP,stringxml.value);
		    str = str.replace("[DIAMONDSMALLIMAGE]",GetNodeValue(xmlNUP,id,"Image")); 
		    SetInnerHtml("grid_detail_stockno","Stock No.: "+GetNodeValue(xmlNUP,id,"Stock")); 
		    SetInnerHtml("grid_detail_name","Name: "+GetNodeValue(xmlNUP,id,"Name")); 
		    SetInnerHtml("grid_detail_price","Price: $"+GetNodeValue(xmlNUP,id,"Price")); 
		    datastring=TransFormNode(xmlNUP,str);
		    uc_EarringSearchResultGrid.SetNUP("true");
		}		
		uc_EarringSearchResultGrid.SetDisplayDiamondHtml(datastring);		 
		SetInnerHtml("IDDiamondDetail",datastring); 
		SetVisible("IDDiamondDetail"); 
		if(from=='R')		
		    SetInnerHtml("spname",GetNodeValue(xml,id,"Name"));
		if(from=='N')    
		    SetInnerHtml("spname",GetNodeValue(xmlNUP,id,"Name"));		    
		uc_EarringSearchResultGrid.SetDiamondId(id);
		CloseShowOption();		
		SetVisible("IDDiamondDetailTable");
		var destination = "DiamondDetailsEarrings.aspx";		
		var QueryString = null;
           try
           {    
                QueryString = location.href.substring ( location.href.indexOf ( "?" ) ); // get the QueryString from the URL
                QueryString = QueryString.split ( "&" );  // creates an array of Strings, e.g. "p=1"
                var i;
                for ( i = 0; i < QueryString.length; i++ ) 
                {
                    QueryString [ i ] = QueryString [ i ].split ( "=" ); // creates a name and value element for each parameter in the QueryString
                }
           }
           catch(e)
           {
                alert(e.message);
           }           
           if(QueryString!=null)
           {
                if(QueryString[0][1]!=null) 
                {
		            //setTimeout("window.opener.location='"+destination + "?Seq=" + QueryString[0][1] + "&Cat_ID=" + Cat_ID + "'",0);
		            window.opener.focus();
		            //opener.window.focus();
		            window.opener.location=destination + "?Seq=" + QueryString[0][1] + "&Cat_ID=" + Cat_ID;
		        }
		        else		            
		        {   
		            //setTimeout("window.opener.location='"+destination + "?Seq=D&Cat_ID=" + Cat_ID + "'",0);
		            window.opener.focus();
		            //opener.window.focus();
		            window.opener.location=destination + "?Seq=D&Cat_ID=" + Cat_ID;
		        }
		   }
	} 
	catch(e) 
	{
		AError("GetDiamondDetail:"+e.message);
	}
}

function SetCompareParameterPREVCOMP(from)
{
    if(from=="VP")
    {
        FROMPREVCOMP = from;
        SelectDiamondEarrings.getCompareDiaIds(callback_getCompareDiaIds);
    }
}

function callback_getCompareDiaIds(res)
{
    if(res!=null && res.value!=null)
    {
        if(res.value!="")
        {
              var diaidlist = res.value;
              var destination = "DiamondCompareEarrings.aspx";
              var QueryString = null;
               try
               {    
                    QueryString = location.href.substring ( location.href.indexOf ( "?" ) ); // get the QueryString from the URL
                    QueryString = QueryString.split ( "&" );  // creates an array of Strings, e.g. "p=1"
                    var i;
                    for ( i = 0; i < QueryString.length; i++ ) 
                    {
                        QueryString [ i ] = QueryString [ i ].split ( "=" ); // creates a name and value element for each parameter in the QueryString
                    }
               }
               catch(e)
               {
                    alert(e.message);
               }
               if(QueryString!=null)
               {
                    if(QueryString[0][1]!=null)
                    {
                        //setTimeout("window.location='"+destination + "?Seq=" + QueryString[0][1] +  "&Dia_Ids=" + diaidlist + "&from=" + FROMPREVCOMP + "'",0);
                        window.open(destination + "?Seq=" + QueryString[0][1] +  "&Dia_Ids=" + diaidlist + "&from=" + FROMPREVCOMP);
                    }
                    else
                    {
                        //setTimeout("window.location='"+destination + "?Seq=D&Dia_Ids=" + diaidlist + "&from=" + FROMPREVCOMP + "'",0);    
                        window.open(destination + "?Seq=D&Dia_Ids=" + diaidlist + "&from=" + FROMPREVCOMP);    
                    }
               }
          }
          else
          {
            alert("Previous comparison does not exist.");
            return;
          }
    }
    else
    {   
        alert("Previous comparison does not exist.");
        return;
    }
}

//function GetStyleXsl()
//{
//	if(http!=null)
//	{
//		try
//		{
//			SendRequest(http,"XmlData/EarringDetailEnhanced.xsl","GET");
//			strXslItemDetail = GetText(http);
//			//Add function here to add style html into session
//			uc_SearchResultGrid.SetDisplayStyleHtml(strXslItemDetail,callback_SetDisplayStyleHtml);			
//		}
//		catch(ex)
//		{
//			AError(ex.message+"\n"+ex.source);
//		}
//	}
//	else
//	{
//		AError("Your Browser does not support this script.");
//		RedirectIt();
//	}
//}

