function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function OnDescription( url, width, height )
{ 
	w = (width != null) ? width : 700;
	h = (height != null) ? height : 580;
	if (screen) {
		leftPos = screen.width/2-w/2
		topPos = screen.height/2-h/2
	}
	photoWin =  window.open( url, null, "width="+w+",height="+h+",top="+topPos+",left="+leftPos+",location=no,menubar=no,scrollbars=no,toolbar=no,resizable=yes", "true"); 
	photoWin.focus();
}

function OnInvoiceCurrentPrint( orderID ){
	OnDescription("/Print/Print.aspx?Page=InvoiceCurrentPrint&PrintMode=1&ID=" + orderID);
}

function OnMailWindow( url ){
  	window.open(url,"zoom_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=1,width=350,height=600");
}

function OnComparePrint( lang, currency, params ){
	OnDescription("/Print/Print.aspx?Page=CompareFeaturesPrint&PrintMode=1&L=" + lang + "&C=" + currency + "&Params=" + params);	
}

function OnCatalogPrint( lang, currency ) {
	OnDescription("/Print/Print.aspx?Page=CatalogPrint&L=" + lang + "&C=" + currency);
}

function OnItemPrint( id ) {
	OnDescription("/Print/Print.aspx?Page=ItemPrint&ID=" + id);
}

function OnLeasingPrint( id, price ) {
	OnDescription("/Print/Print.aspx?Page=LeasingPrint&ID=" + id + "&Price=" + price);
}

function OnItemPrint_v01( id ) {
	OnDescription("/Print/Print.aspx?Page=ItemPrint_v01&ID=" + id);
}

function OnItemGallery( lang, currency, accountCode, ID ) {
	OnDescription("/Print/Print.aspx?Page=ItemGallery&L=" + lang + "&C=" + currency + "&AccountCode=" + accountCode + "&ID=" + ID);
}

function OnToCart( id ) {	
	
	url = window.document.URL.replace("=", "|").replace("=", "|").replace("=", "|");
	SetCookie("url", url);
	location.href = 'default.aspx?Page=ToCart&ID=' + id;
}

function OnReturnToBuy( defaultvalue ) {
	window.location.href = GetValue("url", defaultvalue ).replace("|", "=").replace("|", "=").replace("|", "=");	
}

function OnCheckBox( id ){	
	var checkbox;
	if( id.checked ){
		checkbox = GetValue("checkbox", "" )
		checkbox = checkbox + "," + id.value;
		SetCookie("checkbox", checkbox);
	}
	else{
		checkbox = GetValue("checkbox", "" )
		checkbox = checkbox.replace("," + id.value, "");
		SetCookie("checkbox", checkbox);
	}
}

function OnStepN( pagename ){
	window.location.href = 'default.aspx?Page=' + pagename;
}


function OnCartPrint( lang, currency ){
	OnDescription("/Print/Print.aspx?Page=CartPrint&PrintMode=1&L=" + lang + "&C=" + currency);
}

function OnCart4Print( lang, currency ){
	OnDescription("/Print/Print.aspx?Page=Cart4Print&PrintMode=1&L=" + lang + "&C=" + currency);
}

function OnCart5Print(){
	OnDescription("/Print/Print.aspx?Page=Cart5Print&PrintMode=1");
}

function OnCartCurrentPrint( orderID, lang, currency ){
	OnDescription("/Print/Print.aspx?Page=CartCurrentPrint&PrintMode=1&OrderID=" + orderID + /*"&L=" + lang +*/ "&C=" + currency);
}

function OnAgreePrint( lang ){
	OnDescription("/Print/Print.aspx?Page=AgreePrint&L=" + lang);
}
//-----------------------------------------------------------------------------------------
function NameDefined(ckie,nme){
   var splitValues
   var i
   for (i=0;i<ckie.length;++i)
   {
      splitValues=ckie[i].split("=")
      if (splitValues[0]==nme) return true
   }
   return false
}

function DelBlanks( strng ){
   var result=""
   var i
   var chrn
   for (i=0;i<strng.length;++i) {
      chrn=strng.charAt(i)
      if (chrn!=" ") result += chrn
   }
   return result
}

function GetValue( cname, defaultvalue ) {  
   var cookie = document.cookie           
   var chkdCookie = DelBlanks(cookie)  
   var nvpair = chkdCookie.split(";")
   if(NameDefined(nvpair,cname)){   
      tvalue = GetCookieValue(nvpair,cname) 
      return tvalue;	  
   }
   else return defaultvalue;
}

function GetCookieValue( ckie, nme ){
   var splitValues
   var i
   for(i=0;i<ckie.length;++i) {
      splitValues=ckie[i].split("=")
      if(splitValues[0]==nme) return splitValues[1]
   }
   return ""
}

function SetCookie( cname, cvalue ) {
      var futdate = new Date()		
      var expdate = futdate.getTime() 
      expdate += 24*3600*1000  //expires in 24 hour(milliseconds)
      futdate.setTime(expdate)
      var newCookie= cname + "=" + cvalue + "; path=/;"	//Set the new cookie values up
      newCookie += " expires=" + futdate.toGMTString()
      window.document.cookie = newCookie 
      
}
//-----------------------------------------------------------------------------------------
function OnPriceChange( code, isDiscount ) { 
	window.open( "/Pub/PriceChange.aspx?itemcode=" + code + "&isDiscount=" + isDiscount, null, "width=780,height=400,location=no,menubar=no,scrollbars=no,toolbar=no", "true"); 
}
function OnChat() { 
	window.open("../Chat/CuteSoft_Client/CuteChat/SupportClient.aspx", null, "width=780,height=400,location=no,menubar=no,scrollbars=no,toolbar=no", "true"); 
}
function OnGlossaryWord( gid ) {	
	OnDescription( "/Print/Print.aspx?Page=GlossaryInner&gid=" + gid, 400, 320);
}

function OnRepairPrint() {
	OnDescription("/Print/Print.aspx?Page=RepairPrint");
}

function OnGlossaryPrint( gid ) {	
	OnDescription( "/Print/Print.aspx?Page=GlossaryPrint&char=" + gid);	
}

function OnCalcPrint() {
	OnDescription("/Print/Print.aspx?Page=CalculatorPrint");
}

function OnCart3Print() {
	OnDescription("/Print/Print.aspx?Page=Cart3Print&PrintMode=1");
}

function OnBuy() {
	window.location.href = '/Pub/?Page=Cart';
}

function OnNewPrint(ID) {
	OnDescription("/Print/Print.aspx?Page=NewsPrint&ID=" + ID);	
}	

function OnQuantityChange( quantity ) {
	$("." + quantity.id).val(quantity.value)
	return false;
}

function OnPlus( quantity ) {
	if (!isNaN(quantity.value)) quantity.value++;	
	else quantity.value = 1; 
	quantity.select()	
	
	$("." + quantity.id).val(quantity.value)
	//evaluateObjectResult( quantity )
}

function OnMinus( quantity ) {
	if (!isNaN(quantity.value) && quantity.value>1) quantity.value--;
	else quantity.value='1'; 
	quantity.select();
	
	$("." + quantity.id).val(quantity.value)
	//evaluateObjectResult( quantity )
	return false;
}

function AddToCart(id, cartType, orderID, userProviderID, discount, buttonStyle, toButtonStyle){
  
       $.jmsajax({
                type: "POST",
                url: "/Pub/default.aspx",
                method: "AddCartItem",
                data: {ID:id, Quantity:$("input#Q" + id).val(), CartType:cartType, OrderID:orderID, UserProviderID:userProviderID, Discount:discount, ToCartButtonStyle:toButtonStyle},
                success: function(data) {
                    $("#" + cartType + "Content").fadeIn("fast",function() {$(this).html(String(data))});                    
                    $("#btnCart_" + id).fadeOut("fast").attr('class', buttonStyle).fadeIn("fast");
                    
                    
                       $.jmsajax({
                        type: "POST",
                        url: "/Pub/default.aspx",
                        method: "RefreshCartTotalQuantity",
                        data: {},
                        success: function(data) {
                            $("#CartTotalQuantity").fadeOut("fast",function() {$(this).html(String(data))}).fadeIn("fast");
                        }
                        });
                        
                }
       });
      
       ChangeImg("cartImg_" + id,"/Images/design/btn_inCart.gif");
}

function ChangeImg(elementID,image){
        $('#'+elementID).fadeOut("fast").attr({src : image}).fadeIn("fast");  
}
 
function RemoveItem(id, cartType, buttonStyle){
        $.jmsajax({
            type: "POST",
            url: "/Pub/default.aspx",
            method: "RemoveCartItem",
            data: {ID:id, CartType:cartType, ButtonStyle:buttonStyle},
            success: function(data) {
                $("#" + cartType + "Content").fadeIn("fast",function() {$(this).html(String(data))});
                $("#btnCart_" + id).fadeOut("fast").attr('class', buttonStyle).fadeIn("fast");
                       $.jmsajax({
                        type: "POST",
                        url: "/Pub/default.aspx",
                        method: "RefreshCartTotalQuantity",
                        data: {},
                        success: function(data) {
                            $("#CartTotalQuantity").fadeOut("fast",function() {$(this).html(String(data))}).fadeIn("fast");
                        }
                        });
            }
        });
        ChangeImg("cartImg_" + id,"/Images/design/btn_toCart.gif");
      }
      
function RefreshCart(){
        $.jmsajax({
            type: "POST",
            url: "/Pub/default.aspx",
            method: "RefreshCart",
            data: {},
            success: function(data) {
                $("#CatalogStoreContent").fadeIn("fast",function() {$(this).html(String(data))});
            }
        });
      }
    
    function AddRemoveCartCompareItem(ID, itemID){
       $.jmsajax({
                type: "POST",
                url: "/Pub/default.aspx",
                method: "AddRemoveCartCompareItem",
                data: {ID:ID, ItemID:itemID},
                success: function(data) {
                    $("#CompareContent").fadeIn("fast",function() {$(this).html(String(data))});
                }
       });
}

function RemoveCartCompareItem(ID, itemID){
       $.jmsajax({
                type: "POST",
                url: "/Pub/default.aspx",
                method: "AddRemoveCartCompareItem",
                data: {ID:ID, ItemID:itemID},
                success: function(data) {
                    $("#CompareContent").fadeIn("fast",function() {$(this).html(String(data))});
                }
       });
       UncheckCheckbox("chkItemCompare_" + ID);
}


function UncheckCheckbox(elementID){
    $('input[name=' + elementID + ']').attr('checked', false);  
}

