GRB = {
    $: function(id) {
        return document.getElementById(id);
    }
    ,
    selectstyle: function(style,size,price)
    {
        //alert("style = " + style.toString() + " size = " + size.toString());
        var sty = document.getElementById(style);
        
        if(sty.value == "Lady")
        {
            try
            {
                var s = document.getElementById(size);
                for (i = s.length - 1; i>=0; i--) 
                {
                    if (s.options[i].value == '2X') 
                    {
                        s.remove(i);
                    }
                }
                            
                var opt = document.createElement('option');
                opt.text = 'XS';
                opt.value = 'XS';
                s.add(opt, 0); 
                s.options[0].selected = true;
            }
            catch(err)
            {
                alert("err = " + err.description);
            }
          

        }
        else if(sty.value == "Men")
        {
            //document.forms[0].
            var s = document.getElementById(size);
            for (i = s.length - 1; i>=0; i--) 
            {
                if (s.options[i].value == 'XS') 
                {
                    s.remove(i);
                }
            }
                        
            var opt = document.createElement('option');
            opt.text = '2X';
            opt.value = '2X';
            s.add(opt,s.length); 
            s.options[0].selected = true;
        
        }
        
        GRB.selectsize(style,size,price);
        //document.forms[0].submit(); 
        return true;
    }
    ,
    selectsize: function(style,size,price)
    {
        //alert("enter selectsize");
        var s = document.getElementById(size);
        var p = document.getElementById(price);        
        //alert("enter s.value = " + s.value);
        
        if(s.value == '2X')
        {            
            p.innerText = "25.00";            
        }
        else
        {
            p.innerText = "20.00";        
        }
        document.forms[0].submit(); 
        //alert(document.getElementById('ctl00_Main_rptProducts_ctl02_lb_price').innerText);
        //return true;
    }
    ,
    disclaimer:function(shippingmethod)
    {
        var method = document.getElementById(shippingmethod);
       
        if(method.value == "Lettermail" )
        {
            alert("By using this option I accept full responsibility for this shipment, since this option does not provide any tracking capability. GRB Productions Ltd. is not responsible for lost or damaged shipments.");
        }
        return true;
    }
    ,
    paypaldisclaimer:function()
    {
        alert("After completing your Paypal/Credit Card transaction, please ensure that you click the 'Return to GRB Productions' button, or wait for the page to automatically redirect back to this site, or your transaction will not be recorded in the system.");
        return true;
    }       
    ,
	convertCurrency: function()
	{
		var index = document.forms[0].ctl00_Main_ddl_currency
		
		if (index.value != "CAD")
		{
			var divs = document.getElementsByTagName('div');
			
			//alert("price = " + price);
            for (var i = 0; i < divs.length; i++) 
            {
                if (divs[i].className == 'hiddenprice') 
                {
                    var price = divs[i].innerHTML;                    
		        	var url = "CurrencyExchange.ashx?Amount=" + price +"&ConvertToCurrency="+index.value;
                    
                    //alert("url = " + url);                    
                    //alert("1 nextSibling = " + divs[i].nextSibling.innerHTML);
                    //alert("2 nextSibling = " + divs[i].nextSibling.nextSibling.innerHTML);
                                        
                    var currency = divs[i].nextSibling.nextSibling;
                    currency.innerHTML = index.value;
                    currency.style.display="inline";
                    //alert("currency = " + currency.innerHTML);

			        GRB.startProgressBar();
                    GRB.postRequest(url,divs[i].nextSibling);
                }     
            }

		}
		else
		{
			location.href="Default.aspx";
			//alert("Please select a currency!");
		}
	}
	,    
	postRequest: function(url,targetdiv)
	{
		//alert("postRequest: enter");
		var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");	
		xmlhttp.Open("POST", url, true);
		
		xmlhttp.onreadystatechange = 
			function ()
			{
				if (xmlhttp.readyState == 4)
				{					
					var response = xmlhttp.responseText;								
                    targetdiv.innerHTML=""; 
					targetdiv.innerHTML="Price:"+response;
					targetdiv.style.display="inline";
					GRB.stopProgressBar();
				}
			}	
		xmlhttp.Send();
	}      
    ,
	startProgressBar: function()
	{
	    //alert("startProgressBar");
	    
		divProgressBar.style.visibility = "visible";
		pMessage.style.visibility = "visible";
		
		progress_update();
	}
    ,
	stopProgressBar: function()
	{
	    //alert("stopProgressBar");

		divProgressBar.style.visibility = "hidden";
		pMessage.style.visibility = "hidden";
		
		progress_stop();
	}    
    ,
    checkform: function()
    {            
        /*
        name: null,
        phone: null,
        email: null,
        address1: null,
        address2: null,
        state: null,
        city: null,
        zip: null,
        code: null        
        */        
        if((GRB.checkout.name.value.length <= 0)||(GRB.checkout.name.value.length >20))
        {
            alert("name is invalid");
            return false;
        }
        if((GRB.checkout.phone.value.length <= 0)||(GRB.checkout.phone.value.length >20))
        {
            alert("phone is invalid");
            return false;
        }        
        if((GRB.checkout.email.value.length <= 0)||(GRB.checkout.email.value.length >20))
        {
            alert("email is invalid");
            return false;
        } 
        if((GRB.checkout.address1.value.length <= 0)||(GRB.checkout.address1.value.length >100))
        {
            alert("address1 is invalid");
            return false;
        }     
        if(GRB.checkout.address2.value.length >100)
        {
            alert("address2 is invalid");
            return false;
        }             
        if((GRB.checkout.city.value.length <= 0)||(GRB.checkout.city.value.length >30))
        {
            alert("city is invalid");
            return false;
        }             
        if((GRB.checkout.zip.value.length <= 0)||(GRB.checkout.zip.value.length >30))
        {
            alert("zip/Postcode is invalid");
            return false;
        }                  
        if(GRB.checkout.code.value.length != 6)
        {
            alert("Verification Code is invalid");
            return false;
        }  
        return true;        
    }
    ,    
    addLoadEvent: function(func) 
    {
        var oldonload = window.onload;
        if (typeof window.onload != 'function') 
        {
            window.onload = func;
        }
        else 
        {
            window.onload = function() 
            {
                oldonload();
                func();
            }
        }
    }
    ,
    checkout: {
        name: null,
        phone: null,
        email: null,
        address1: null,
        address2: null,
        state: null,
        city: null,
        zip: null,
        code: null

    }       
    ,
    doLoad: function()
    {
        // the timeout value should be the same as in the "refresh" meta-tag
        setTimeout( "refresh()", 2*1000 );
    }
    ,
    refresh: function()
    {
        var sURL = unescape(window.location.pathname);
        alert("sURL= " + sURL);
        window.location.href = sURL;
    }


};    

//GRB.addLoadEvent(GRB.convertCurrency);

if (typeof (registerCheckout) != 'undefined')
    GRB.addLoadEvent(registerCheckout);