function BuyProductWithQuantity(idProduct, prefix, URL)
{					
    BuyProductWithQuantity(idProduct, prefix, URL, null)
}
function BuyProductWithQuantity(idProduct, prefix, URL, countItems)
{					
	//var QuantityObjectId = "ItemQuantity_" + idProduct;
	var QuantityObjectId = prefix + idProduct;
	
	if ( URL.length == 0)
	{
		URL = "ps_additem.aspx?idProduct=";
	}
	
	var QuantityObject =  document.getElementById(QuantityObjectId);
	
	if (QuantityObject != null)
	{
		var QuantityObjectValue = document.getElementById(QuantityObjectId).value;
		
		QuantityInt = parseInt (QuantityObjectValue);

		if (QuantityInt < 1 || QuantityInt > 100 || isNaN (QuantityInt))
		    QuantityInt = 1;
	}
	else 
	{
	    QuantityInt = parseInt(countItems);
	    if (QuantityInt < 1 || QuantityInt > 100 || isNaN (QuantityInt))
		QuantityInt = 1;
	}
    
    URL = URL + idProduct + "&quantity=" + QuantityInt;
	
	var SelectedOptions = document.getElementById("SelectedOptions");
	if(SelectedOptions != null)
	{
		var SelectedOptionsValue = document.getElementById("SelectedOptions").value;
	    URL = URL + "&options=";
	    URL = URL + SelectedOptionsValue;
	}
    var query = window.location.search.substring(1);
	if(query.indexOf("idCartRow") != -1)
	{
	    URL = URL + "&modify=1";
	}
	
	//alert(URL);
	window.location = URL
	 
	  
}

function BuyProductQty(idProduct, prefix, URL, evObj)
{
    if (evObj.keyCode!=13)
    {
        return false;
    }    
    else
    {
        BuyProductWithQuantity(idProduct, prefix, URL)        
    }
}	
	
	
function StartSearchMainControl()
{				
	var SearchTextObject =  document.getElementById("SearchTextMainControl");
	
	//alert (SearchTextObject.value);
        if (SearchTextObject.value.length>0)
	{
		URL = "ps_searchItem.aspx?SearchText=" + SearchTextObject.value;
	    window.location = URL

	}

}

function OpenWindow(URL, WindowType)
{

    var wWidth = 600;
    var wHeight = 480;
    
    if ( WindowType == "TopBanner")
    {
        wWidth = 600;
        wHeight = 500;
    }
    
    if ( WindowType == "LeftBanner")
    {
        wWidth = 600;
        wHeight = 450;
    }
    
    if ( WindowType == "EditProduct")
    {
        wWidth = 480;
        wHeight = 320;      
    }
   

	var poz_left = screen.availWidth / 2 - wWidth/2;
	var poz_top = screen.availHeight / 2 - wHeight/2;
    var params = "left="+poz_left+",top="+poz_top+",width="+wWidth+",height="+wHeight+",toolbar=0,resizable=1";
    
	window.open(URL,'petstore',params);
}

function EnterClickEvent(event, ButtonPrefix, idProduct)
{
	event = event || window.event;
     if (event.keyCode == 13) 
     {
           src = event.target;
           if (__nonMSDOMBrowser)
            {
                src = event.target;
            }
            else
            {
                src = event.srcElement;
            }
            tagName = src.tagName.toLowerCase();
            if ((tagName != "a") && ((tagName != "input") || ((src.type != "submit") && (src.type != "reset") && (src.type != "image") && (src.type != "file")))) 
            {
                
                var ButtonTextId = ButtonPrefix + idProduct;
                document.getElementById(ButtonTextId).click();
            }
            return false;
      }
      
      return true;
}

 function goCSRSearch(e, GetValue)
 {
     e=e||window.event;
     //alert(this.location )
     var URLpath = window.location.href;
     
     if(e.keyCode == "13")
     {
        SearchText=GetValue;
        if (SearchText!=null && SearchText!='')
	    {
	        re = /[^\w '\-`]/g;
	        SearchText = SearchText.replace(re, ' ');
	        
	    }
	    if (SearchText!='')
	    {
            location.href = 'ps_CSRsearchItem.aspx?SearchText='+SearchText;
        }
        return false;
     }
 }
    function formatCurrency(num) 
    {
        num = num.toString().replace(/\$|\,/g,'');
        if(isNaN(num))
        num = "0";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num*100+0.50000000001);
        cents = num%100;
        num = Math.floor(num/100).toString();
        if(cents<10)
        cents = "0" + cents;
        for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0,num.length-(4*i+3))+','+
        num.substring(num.length-(4*i+3));
        return (((sign)?'':'-') + num + '.' + cents);
    }

 function checkCSRSearch(e, value)
 {
     e=e||window.event;
    
     if(e.keyCode == "13")
     {
        if (value == "")
        {
            alert("Please input a search string!");
            return false;
        }
     }
     return true;
 }
