﻿var xmlHttp;
var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0; 
var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0; 
var is_opera = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0; 

//netscape, safari, mozilla behave the same??? 
var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0;

function add_AddToWishList(requestURL, id){
   var url = requestURL + '?CallTypeID=4&RingID=' + id.toString();
   
   //Create the xmlHttp object to use in the request 
   //stateChangeHandler will fire when the state has changed, i.e. data is received back 
   // This is non-blocking (asynchronous) 
   xmlHttp = GetXmlHttpObject(stateAddToWishListChangeHandler); 
   
   //Send the xmlHttp get to the specified url 
   xmlHttp_Get(xmlHttp, url);
}
 
function get_DesignerBioAndHeroImage(requestURL, designerID){ 
   var url = requestURL + '?CallTypeID=3&DesignerID=' + designerID.toString();
   
   //Create the xmlHttp object to use in the request 
   //stateChangeHandler will fire when the state has changed, i.e. data is received back 
   // This is non-blocking (asynchronous) 
   xmlHttp = GetXmlHttpObject(stateDesignerBioAndHeroImageChangeHandler); 
   
   //Send the xmlHttp get to the specified url 
   xmlHttp_Get(xmlHttp, url);       
}

function get_DiamondStyleAndDesignerDataForStyleID(requestURL){ 
   var url = requestURL + '?CallTypeID=1&StyleID=' + oDrpDnRingStyle.value.toString();
   
   oDrpDnDiamondStyle.disabled=true;
   oDrpDnDesigner.disabled=true;
   oBtnFindIt.disabled=true;
   
   oIndicatorDiamondStyle.style.visibility = 'visible';
   oIndicatorDiamondStyle.src=sImagesRootPath + "arrowsProcessing.gif";
   oIndicatorDiamondStyle.alt="Processing diamond styles...";
   
   oIndicatorDesigner.style.visibility = 'visible';
   oIndicatorDesigner.src=sImagesRootPath + "arrowsProcessing.gif";
   oIndicatorDesigner.alt="Processing designers...";
         
   //Create the xmlHttp object to use in the request 
   //stateChangeHandler will fire when the state has changed, i.e. data is received back 
   // This is non-blocking (asynchronous) 
   xmlHttp = GetXmlHttpObject(stateDiamondStyleAndDesignerChangeHandler); 
   
   //Send the xmlHttp get to the specified url 
   xmlHttp_Get(xmlHttp, url);       
}

function get_DesignersForRingStyleIDAndDiamondStyleID(requestURL){ 
   var url = requestURL + '?CallTypeID=2&StyleID=' + oDrpDnRingStyle.value.toString() + '&DiamondStyleID=' + oDrpDnDesigner.value.toString();
   
   oDrpDnDesigner.disabled=true;
   oBtnFindIt.disabled=true;
   
   oIndicatorDesigner.style.visibility = 'visible';
   oIndicatorDesigner.src=sImagesRootPath + "arrowsProcessing.gif";
   oIndicatorDesigner.alt="Processing designers...";
         
   //Create the xmlHttp object to use in the request 
   //stateChangeHandler will fire when the state has changed, i.e. data is received back 
   // This is non-blocking (asynchronous) 
   xmlHttp = GetXmlHttpObject(stateDesignerChangeHandler);
   
   //Send the xmlHttp get to the specified url 
   xmlHttp_Get(xmlHttp, url);       
}

//stateChangeHandler will fire when the state has changed, i.e. data is received back 
// This is non-blocking (asynchronous) 
function stateAddToWishListChangeHandler()
{
    //readyState of 4 or 'complete' represents that data has been returned 
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){ 
        
        //Gather the results from the callback 
        var str = xmlHttp.responseText;
        
        // code for IE
        if (window.ActiveXObject)
        {
            var doc=new ActiveXObject("Microsoft.XMLDOM");
            doc.async="false";
            doc.loadXML(str);
        }
        // code for Mozilla, Firefox, Opera, etc.
        else
        {
            var parser=new DOMParser();
            var doc=parser.parseFromString(str,"text/xml");
        }
        //alert(str);
    }
}

//stateChangeHandler will fire when the state has changed, i.e. data is received back 
// This is non-blocking (asynchronous) 
function stateDesignerBioAndHeroImageChangeHandler() 
{ 
    //readyState of 4 or 'complete' represents that data has been returned 
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){ 
        
        //Gather the results from the callback 
        var str = xmlHttp.responseText;
        
        // code for IE
        if (window.ActiveXObject)
        {
            var doc=new ActiveXObject("Microsoft.XMLDOM");
            doc.async="false";
            doc.loadXML(str);
        }
        // code for Mozilla, Firefox, Opera, etc.
        else
        {
            var parser=new DOMParser();
            var doc=parser.parseFromString(str,"text/xml");
        }
        
        //Split the hero image and the bio
        var sHeroImage='';
        var sBio='';
        var sDelim = '::::::::::';
        var iDelimIndex = str.indexOf(sDelim);        
        
        if(iDelimIndex > -1)
        {
            sHeroImage = str.substring(0, iDelimIndex);
            sBio = str.replace(sHeroImage + sDelim, '');                      
        }
        
        designerHeroImage.src = sImagesRootPath + 'Designers/Heros/' + sHeroImage;
        // set the bio content
        var hasInnerHTML = (document.getElementsByTagName("body")[0].innerHTML != undefined) ? true : false;
        if (hasInnerHTML) {
            designerBioContent.innerHTML = sBio;            
        }
        else {
            // innerHTML should be supported for all browsers, so this should rarely be entered.
            designerBioContent.innerHTML = sBio;            
        }
        
        // resize the content areas        
        layoutNoFeatureAreaFixup('pageContentAreaFrameHostNavArea', 'pageContentAreaMainArea');
    } 
}

//stateChangeHandler will fire when the state has changed, i.e. data is received back 
// This is non-blocking (asynchronous) 
function stateDiamondStyleAndDesignerChangeHandler() 
{ 
    //readyState of 4 or 'complete' represents that data has been returned 
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){ 
        
        //Gather the results from the callback 
        var str = xmlHttp.responseText;        
        
        // code for IE
        if (window.ActiveXObject)
        {
            var doc=new ActiveXObject("Microsoft.XMLDOM");
            doc.async="false";
            doc.loadXML(str);
        }
        // code for Mozilla, Firefox, Opera, etc.
        else
        {
            var parser=new DOMParser();
            var doc=parser.parseFromString(str,"text/xml");
        }
        
        //Remove any items currently listed in the drop downs
        while(oDrpDnDiamondStyle.options.length > 1)
        {oDrpDnDiamondStyle.remove(oDrpDnDiamondStyle.options.length - 1);}
        
        while(oDrpDnDesigner.options.length > 1)
        {oDrpDnDesigner.remove(oDrpDnDesigner.options.length - 1);}
        
        //Split the diamond styles and the designers
        var sDiamondStyles='';
        var sDesigners='';
        var sDelim = '::::::::::';
        var iDelimIndex = str.indexOf(sDelim);        
        
        if(iDelimIndex > -1)
        {
            sDiamondStyles = str.substring(0, iDelimIndex);
            sDesigners = str.replace(sDiamondStyles + sDelim, '');
           
            //Add the options for the Diamond Style
            var sArrStyles = sDiamondStyles.split('%%%%');
            for(var i=0; i<sArrStyles.length; i++)
            {
                if(sArrStyles[i].length > 0)
                {
                    // now split the ID from the Name
                    var sID = sArrStyles[i].substring(0, sArrStyles[i].indexOf('****'));
                    var sName = sArrStyles[i].replace(sID + '****','');
                    
                    
                    var oNewOption = new Option(sName,sID);
                    oDrpDnDiamondStyle.options[oDrpDnDiamondStyle.options.length] = oNewOption;                    
                }
            }
            //Add the options for the Designers
            var sArrDesigners = sDesigners.split('%%%%');
            for(var i=0; i<sArrDesigners.length; i++)
            {
                if(sArrDesigners[i].length > 0)
                {
                    // now split the ID from the Name
                    var sID = sArrDesigners[i].substring(0, sArrDesigners[i].indexOf('****'));
                    var sName = sArrDesigners[i].replace(sID + '****','');
                    
                    
                    var oNewOption = new Option(sName,sID);
                    oDrpDnDesigner.options[oDrpDnDesigner.options.length] = oNewOption;                    
                }
            }
        }
        
        oDrpDnDiamondStyle.disabled=false;
        oDrpDnDesigner.disabled=false;
        oBtnFindIt.disabled=false;
        
        oIndicatorDiamondStyle.style.visibility = 'hidden';
        oIndicatorDiamondStyle.src=sImagesRootPath + "arrowsDoubleHorizontal.jpg";
        oIndicatorDiamondStyle.alt="Diamond style search process status";
        
        oIndicatorDesigner.style.visibility = 'hidden';
        oIndicatorDesigner.src=sImagesRootPath + "arrowsDoubleHorizontal.jpg";
        oIndicatorDesigner.alt="Designer search process status";
    } 
}

//stateChangeHandler will fire when the state has changed, i.e. data is received back 
// This is non-blocking (asynchronous) 
function stateDesignerChangeHandler() 
{ 
    //readyState of 4 or 'complete' represents that data has been returned 
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){ 
        
        //Gather the results from the callback 
        var str = xmlHttp.responseText;        
        
        // code for IE
        if (window.ActiveXObject)
        {
            var doc=new ActiveXObject("Microsoft.XMLDOM");
            doc.async="false";
            doc.loadXML(str);
        }
        // code for Mozilla, Firefox, Opera, etc.
        else
        {
            var parser=new DOMParser();
            var doc=parser.parseFromString(str,"text/xml");
        }
        
        //Remove any items currently listed in the drop downs
        while(oDrpDnDesigner.options.length > 1)
        {oDrpDnDesigner.remove(oDrpDnDesigner.options.length - 1);}
        
        //Add the options for the Designers
        var sArrDesigners = str.split('%%%%');
        for(var i=0; i<sArrDesigners.length; i++)
        {
            if(sArrDesigners[i].length > 0)
            {
                // now split the ID from the Name
                var sID = sArrDesigners[i].substring(0, sArrDesigners[i].indexOf('****'));
                var sName = sArrDesigners[i].replace(sID + '****','');
                
                
                var oNewOption = new Option(sName,sID);
                oDrpDnDesigner.options[oDrpDnDesigner.options.length] = oNewOption;                    
            }
        }
        
        oDrpDnDesigner.disabled=false;
        oBtnFindIt.disabled=false;
        
        oIndicatorDesigner.style.visibility = 'hidden';
        oIndicatorDesigner.src=sImagesRootPath + "arrowsDoubleHorizontal.jpg";
        oIndicatorDesigner.alt="Designer search process status";
    } 
}  

// XMLHttp send GET request 
function xmlHttp_Get(xmlhttp, url) { 
    xmlhttp.open('GET', url, true); 
    xmlhttp.send(null); 
} 

function GetXmlHttpObject(handler) { 
    var objXmlHttp = null;    //Holds the local xmlHTTP object instance 

    //Depending on the browser, try to create the xmlHttp object 
    if (is_ie){ 
        //The object to create depends on version of IE 
        //If it isn't ie5, then default to the Msxml2.XMLHTTP object 
        var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP'; 
         
        //Attempt to create the object 
        try{ 
            objXmlHttp = new ActiveXObject(strObjName); 
            objXmlHttp.onreadystatechange = handler; 
        } 
        catch(e){ 
        //Object creation errored 
            alert('IE detected, but AJAX object could not be created. You may have active scripting or ActiveX controls disabled'); 
            return; 
        } 
    } 
    else if (is_opera){ 
        //Opera has some issues with xmlHttp object functionality 
        alert('Opera detected. This page may not function exactly as expected.'); 
        return; 
    } 
    else{ 
        // Mozilla | Netscape | Safari 
        objXmlHttp = new XMLHttpRequest(); 
        objXmlHttp.onload = handler; 
        objXmlHttp.onerror = handler; 
    } 
     
    //Return the instantiated object 
    return objXmlHttp; 
}

