var jsddlwidth;
var jsddlmetal;
var jsddlweight;
var jsmetal;
var jsimgMainImage;
var jsmetalid;
var jsselmetal;
var jsselweight;
var jslblprate;
			
			var ns6 = document.getElementById && !document.all;
			var ie4 = document.all;						
			var ns4 = document.layers;
			var ct=0;
			
			function getObjectByID(Objid){	
				if(ns4)
				{
					return eval('document.' + Objid)
				}
				if(ns6)
				{
					return document.getElementById(Objid);
				}
				if(ie4)
				{
					return document.all(Objid);      
				}  
				return null
			}


			function SetText(objid,msg, fg, bg){
				if(!fg) fg = "#ff0000";
				if(!bg) bg = "#FFFFFF";
				var content = msg ;
				if(ns4)
				{
					objItm = eval('document.' + objid)
					objItm.document.write(content);
					objItm.document.close();
					objItm.visibility = "visible";
				}
				if(ns6)
				{
					document.getElementById(objid).innerHTML = content;
				}
				if(ie4)
				{
					document.all(objid).innerHTML=content;
				}  
			}
		
//Global XMLHTTP Request object
var XmlHttp;
var currentCntrl = 0


//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp()
{	firstgo = 0
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
	
}


//Called when response comes back from server
function HandleResponse()
{

    ////////////////////////////////////////////

    document.getElementById("divloadingPRINTING").innerHTML = "<img src='images/loader.gif' alt='loading' />"
    var windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
    var h = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
    var windowWidth = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
    var IpopTop = ((windowHeight - document.getElementById("divloadingPRINTING").offsetHeight) / 2);
    document.getElementById("divloadingPRINTING").style.top = (IpopTop + h) + 'px';
    document.getElementById("divloadingPRINTING").style.left = ((document.body.clientWidth / 2)) + 'px';
    document.getElementById("divloadingPRINTING").style.display = "block";

    //////////////////////////////////////////////
	
	
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{	
		   	
			ClearAndSetDdlItems(XmlHttp.responseXML.documentElement);
			ddlweighdimondOnChange(jsddlwidth, jsddlmetal, jsddlweight, jsmetal, jsimgMainImage, jsmetalid, jsselmetal, jsselweight, jslblprate);	
			
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}

//Clears the contents of state combo box and adds the states of currently selected country
function ClearAndSetDdlItems(RowNode)
{
 	
	var textValue; 
	var optionItem;
	var val;
var ddlList;
   if(currentCntrl < 1)
       ddlList = jsddlmetal; 
		
   else
       ddlList = jsddlweight;
		
	//Clears the state combo box contents.			
	//alert(ddlList);	
		
	if (ddlList!=null)
	{
		if(ddlList.options.length)
		{	
			ddlList.options.length = 0;
		}
	}
	
		var RowNodes = RowNode.getElementsByTagName('item');
		//[document.getElementById("ddlweighdimond").selectedIndex].text	
		//Add new states list to the state combo box.
		for (var count = 0; count < RowNodes.length; count++)
		{
   			textValue = GetInnerText(RowNodes[count]);
   			var value1 = RowNodes[count].getAttribute('value');
   			optionItem = new Option(textValue ,value1 ,  false, false);
			ddlList.options[ddlList.length] = optionItem;
		}



//		if (currentCntrl == 0) {
//		    //ddlmetalOnChange();	
//		    //alert(currentCntrl );
//		    //var RowNodes = RowNode.getElementsByTagName('item');
//		    ddlmetalOnChange();
//		}

	if (ddlList == jsddlmetal) 
	{
	    if (jsddlmetal)
		{
		    ddlmetalOnChange(jsddlwidth, jsddlmetal, jsddlweight, jsmetal, jsimgMainImage, jsmetalid, jsselmetal, jsselweight, jslblprate);	
		}

		if (jsddlweight)
			{
			    ddlweighdimondOnChange(jsddlwidth, jsddlmetal, jsddlweight, jsmetal, jsimgMainImage, jsmetalid, jsselmetal, jsselweight, jslblprate);
			}
	}

}

//Returns the node text value 
function GetInnerText (node)
{	
	 return (node.textContent || node.innerText || node.text) ;
}


//Gets called when country combo box selection changes
function ddlwidthOnChange(inddlwidth, inddlmetal, inddlweight, inmetal, inimgMainImage, inmetalid, inselmetal, inselweight, inlblprate) 
{
    jsddlwidth = inddlwidth;
    jsddlmetal = inddlmetal;
    jsddlweight=inddlweight;
    jsmetal=inmetal;
    jsimgMainImage=inimgMainImage;
    jsmetalid=inmetalid;
    jsselmetal=inselmetal;
    jsselweight=inselweight;
    jslblprate = inlblprate;


    
    
    
    
    
	currentCntrl = 0
	if (jsddlwidth)
		{
		    var ddlwidth = jsddlwidth;
			//Getting the selected country from country combo box.
			var Widthid = ddlwidth.options[ddlwidth.selectedIndex].value;
		}
		
	
	
	
	// URL to get states for a given country
	var requestUrl = AjaxServerPageName + "?Widthid=" + encodeURIComponent(Widthid) ;
	
	CreateXmlHttp();
	
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response		
		XmlHttp.onreadystatechange = HandleResponse;
				
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
}

//code adde dby devang


//Gets called when state combo box selection changes
function ddlmetalOnChange(inddlwidth, id, inddlweight, inmetal, inimgMainImage, inmetalid, inselmetal, inselweight, inlblprate) 
{



        jsddlwidth = inddlwidth;
        jsddlmetal = id;
        jsddlweight = inddlweight;
        jsmetal = inmetal;
        jsimgMainImage = inimgMainImage;
        jsmetalid = inmetalid;
        jsselmetal = inselmetal;
        jsselweight = inselweight;
        jslblprate = inlblprate;
    
   
	
	
	//************************code added by devang
    var str = jsmetal.value;
	var arr=str.split(',');
	
	var i;
	for (i=0;i<arr.length-1;i++)
	{
	    if (arr[i]==0)
	    {
	        var defImg=arr[i+1];
	        
	    }
	}
	i=0;
	for (i=0;i<arr.length-1;i++)
	{
	    
	    if (arr[i]==id.value)
	    {
	        jsimgMainImage.src = "ExtraThumbimages/" + arr[i + 1];
	         
	    }
	    else if(arr[i]==0 && arr[i]!=id.value)
	    {
	        jsimgMainImage.src = "ExtraThumbimages/" + defImg;
	        
	    }
	    
	}
	jsmetalid.value = id.value;
	inmetalid.value = id.value;
	
	//************************************************

	
	currentCntrl = 1
	//Getting the selected country from country combo box.
	if (jsddlmetal)
	{
	    var ddlmetal = jsddlmetal;	
	var Metalid=  ddlmetal.options[ddlmetal.selectedIndex].value;
	}

	if (jsddlwidth)
	{
	    var ddlwidth = jsddlwidth;
	var Widthid = ddlwidth.options[ddlwidth.selectedIndex].value;
	}
	
	//alert(Widthid);	
	// URL to get states for a given country 
	var requestUrl = AjaxServerPageName + "?Widthid=" + encodeURIComponent(Widthid) + "&Metalid=" + encodeURIComponent(Metalid);
	
	CreateXmlHttp();	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponse;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
}

function ddlweighdimondOnChange(inddlwidth, inddlmetal, inddlweight, inmetal, inimgMainImage, inmetalid, inselmetal, inselweight, inlblprate)
{

    jsddlwidth = inddlwidth;
    jsddlmetal = inddlmetal;
    jsddlweight = inddlweight;
    jsmetal = inmetal;
    jsimgMainImage = inimgMainImage;
    jsmetalid = inmetalid;
    jsselmetal = inselmetal;
    jsselweight = inselweight;
    jslblprate = inlblprate;

	
	
	
	if (jsddlmetal)
	{
	    jsselmetal.value = jsddlmetal.value; 	
	//alert(document.getElementById("selmetal").value);
	}
	
	//alert(document.getElementById("ddlweighdimond").options.length);
	jsselweight.value = jsddlweight.options[jsddlweight.selectedIndex].text;
	jslblprate.value = jsddlweight.value;
	
	//alert(document.getElementById("imgAddtocart"));
	if (jslblprate.value == 0)
	{
	//alert('in');
	    SetText("_ctl0_ContentPlaceHolder1_ContentRate", "POA");
		if (document.getElementById("_ctl0_ContentPlaceHolder1_imgAddtocart"))
		{
		//alert('without price');
		    document.getElementById("_ctl0_ContentPlaceHolder1_imgAddtocart").style.visibility = "hidden";
		    document.getElementById("_ctl0_ContentPlaceHolder1_imgbtnWatch").style.visibility = "hidden";
		}
	}
	else
	{
	//traction.Style.Add("visibility", "visible")
	    //alert(document.getElementById("traction"));
	    SetText("_ctl0_ContentPlaceHolder1_ContentRate", jslblprate.value);
	    if (document.getElementById("_ctl0_ContentPlaceHolder1_imgAddtocart"))
		{
		    //alert('price');
		    document.getElementById("_ctl0_ContentPlaceHolder1_imgAddtocart").style.visibility = "visible";
		    document.getElementById("_ctl0_ContentPlaceHolder1_imgbtnWatch").style.visibility = "visible";
		}
	}

	document.getElementById("divloadingPRINTING").innerHTML = "";
	document.getElementById("divloadingPRINTING").style.display = "none";      
}




