﻿function CheckImgSrc()
{
	/*var colImages = document.images;
		
	for (i=0; i < colImages.length; i++)
	{
		if (colImages(i).fileSize==-1)
		{
			colImages(i).style.display="none";
		}
		
	}*/
}
//Hides a given image
function hideImage(cImg)
{
  cImg.style.display="none";
}
//Returns an xml string of form command structure
   //
   //Accepts:
   // Parameters seperated by a comma. The first is the
   // name of the command and then pairs of parameter name & value.
   //
   //Example:
   // var sCommand = getFormCommand('delProduct', 'prod_id', 331) 	 	
   function getFormCommand() {
     var sXML = '<command name="' + arguments[0] + '">'
     var i=1
     while (i<arguments.length){
		sXML += '<param name="' + arguments[i] + '" value="' + arguments[i+1] + '"/>'     
		i+=2
     } 
     sXML+='</command>'
     return sXML
  } 
//for Site's with Hiericial menu
var LastSubDiv;
function SetMenu(subDiv)
{
	var SubObj
	SubObj = window.document.getElementById(subDiv)
	if(SubObj.style.display=="none")
		SubObj.style.display="inline"
	else
		SubObj.style.display="none"

	if(LastSubDiv != subDiv)
	{
		if(LastSubDiv!="" && LastSubDiv!=null)
		{
			SubObj = window.document.getElementById(LastSubDiv)
			SubObj.style.display="none"
		}
		LastSubDiv = subDiv
	}
}
function ChangeHref(vName)
{
   var vData=document.getElementById(vName).value
   vData = vData.replace(/([hH][rR][eE][fF]=)([\"\'](http:)([^<]*)[\"\'])/ig,"$1$2 onClick='javascript:window.open($2);return false;'");
   return vData;
}

function writeFlash(id,fName,fWidth,fHeight) {
    document.getElementById(id).innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='"+fWidth+"' height='"+fHeight+"' id='myflash' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='"+fName+"' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><embed src='"+fName+"' quality='high' bgcolor='#ffffff' width='"+fWidth+"' height='"+fHeight+"' name='mymovie' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
}
function writeImage(id,fName,fLink,fWidth,fHeight) {
    document.getElementById(id).innerHTML = "<img src='"+fName+"' style='cursor:hand' onclick='javascript:BannerAim('"+fLink+"');' width='"+fWidth+"' height='"+fHeight+"' onerror='this.style.display=\"none\"'></img>";
}

function GetBanner(tdID,bSc,bDp,bLc,bWidth,bHeight)
{
   var vdata = "<content>Banner<banners><banner sc='' dp='' lc=''/></banners></content>";
   var olXMLsource = new ActiveXObject("Microsoft.XMLDOM");
   olXMLsource.async = false;
   olXMLsource.loadXML(vdata);
   var oSc=olXMLsource.selectSingleNode("//banner/@sc");
   oSc.text=bSc
   var oDp=olXMLsource.selectSingleNode("//banner/@dp");
   oDp.text=bDp
   var oLc=olXMLsource.selectSingleNode("//banner/@lc");
   oLc.text=bLc

   var httpOb = GetHttp(olXMLsource);
   if(httpOb.status==200)
   {
     var obj = httpOb.responseText
     if(obj!=null && obj!="")
     {
      if(obj.indexOf('swf')>-1)
      {
        writeFlash(tdID,obj.split(";")[0],bWidth,bHeight);
      }
      else
      {
        writeImage(tdID,obj.split(";")[0],obj.split(";")[1],bWidth,bHeight);
      }
     }
   }
}

function GetHttp(XmlSource,vHttps)
{
    if(vHttps!=null && vHttps!="")
         var oXMLServer = "https://www.ecomtrade.co.il/grandarena/UpdateXml.asp";
    else
         var oXMLServer = "http://www.ecomtrade.co.il/grandarena/UpdateXml.asp";

    var HttpRequest;
    if (window.XMLHttpRequest)
    {
          // If IE7, Mozilla, Safari, etc: Use native object
          HttpRequest = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
              // ...otherwise, use the ActiveX control for IE5.x and IE6
              HttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    HttpRequest.open("POST",oXMLServer,false);
    HttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    HttpRequest.send(XmlSource);
    return HttpRequest;
}
function changeFields(oForm)
{
	if (document.all.opt_pay[0].checked){
        document.all["OrderByName"].style.display="inline";
        document.all["OrderByCard"].style.display="none";
	    try{
		document.all["Card Number"].style.background = "gray";
        document.all["Card Number"].required="";
        }catch(e){};
		try{
           document.all["ID Number"].style.background = "gray"
           document.all["ID Number"].required="";
        }catch(e){};
        try{
		document.all["Card Holder"].style.background = "gray";
		document.all["Card Holder"].required="";
        }catch(e){};
    	try{
		document.all["Card Type"].style.background = "gray";
		document.all["Card Type"].required="";
        }catch(e){};
		try{
		document.all["Mounth"].style.background = "gray";
		document.all["Mounth"].required="";
        }catch(e){};
		try{
		document.all["Year"].style.background = "gray";
		document.all["Mounth"].required="";
        }catch(e){};
        try{
		    document.all["web_money"].style.background = "gray";
		}catch(e){};
        try{		    
		    document.all["mail_money"].style.background = "gray";
		}catch(e){};    
        try{		
		    document.all["yandex"].style.background = "gray";
        }catch(e){};		    
        try{        
		    document.all["cash"].style.background = "gray";
		}catch(e){};    
        try{		
		    document.all["bank_transfer_id"].style.background = "gray";
		    document.all["bank_transfer_code"].style.background = "gray";
		    document.all["bank_transfer_name"].style.background = "gray";
		    document.all["bank_transfer_account"].style.background = "gray";
        }catch(e){};
	}
	else{
        document.all["OrderByName"].style.display="none";
        document.all["OrderByCard"].style.display="inline";
		try{
		    document.all["Card Number"].style.background = "white";
		    document.all["Card Number"].required="true";
        }catch(e){};
		try{
           document.all["ID Number"].style.background = "white"
           document.all["ID Number"].required="true";
        }catch(e){};
		try{
		    document.all["Card Holder"].style.background = "white";
		    document.all["Card Holder"].required="true";
        }catch(e){};
    	try{
		    document.all["Card Type"].style.background = "white";
		    document.all["Card Type"].required="true";
        }catch(e){};
		try{
		    document.all["Mounth"].style.background = "white";
		    document.all["Mounth"].required="true";
        }catch(e){};
		try{
		    document.all["Year"].style.background = "white";
		    document.all["Year"].required="true";
        }catch(e){};
        try{
		    document.all["web_money"].style.background = "white";
		}catch(e){};    
        try{		
		    document.all["mail_money"].style.background = "white";
		}catch(e){};    
        try{		
		    document.all["yandex"].style.background = "white";
        }catch(e){};		    
        try{        
		    document.all["cash"].style.background = "white";
        }catch(e){};		    
        try{        
		    document.all["bank_transfer_id"].style.background = "white";
		    document.all["bank_transfer_code"].style.background = "white";
		    document.all["bank_transfer_name"].style.background = "white";
		    document.all["bank_transfer_account"].style.background = "white";
        }catch(e){};
	}
}

function ChangeClass(vObj,vClass,vImage)
{
     vObj.className=vClass;
     if(vImage!=null && vImage!="")
     {
       document.getElementById("img_"+vObj.id.substr(3)).src=vImage
     }
}
function checkImageState()
{
   if(document.getElementById("imgLarge").style.display=="none")
   {
      document.getElementById("btnLarge").style.display="none";
   }
}

var LastID=1;
function ShowLargePic(vSrc)
{
        var vS = vSrc.src
        vS = vS.replace("/s/s","/s");
        document.getElementById("LargeImage").src =vS;
 }
function ChangeImg(vId)
 {
        var x;
        var y;
        x = document.getElementById("LargeImage").src
        y = x.substr(x.length-4,4)
        x = x.substr(0,x.length-5)
        document.getElementById("tdImg"+LastID).className="silver";
        document.getElementById("tdImg"+vId).className="page_text";
        document.getElementById("LargeImage").src =x+vId+y ;
        LastID=vId;
}
function OpenZoom(vSrc,bExt)
{
    var vS = vSrc;
    if(vS.indexOf("_")==-1)
    {
        if(vS.indexOf(".jpg")!='-1')
            vS = vS.replace(".jpg","b."+bExt);
        else
            vS = vS.replace(".gif","b."+bExt);
    }    
    var x = "zoomRU.htm?"+vS 
    window.open(x, 'Zoom', 'resizable=yes, menubar=no, titlebar=no, scrollbars=1, toolbar=no, status=no, location=no, directories=no, top=0, left=0');return false;
}
function ChangeAccomp(vSel)
{
	var Arr = vSel.value.split(":");
	var tbl = document.all["tblAccomp"].rows.length;
	if(tbl==3)
		ChangeAccompById(vSel,document.all["chk_accomp_prod"],document.all["accompPrice"],document.all["tdaccompImg"],document.all["tdaccompHref"],document.all["sel_accomp_prod_qty"],document.all["inpCompQty"])
	else
	{
		var i=0;
		for(;i<tbl-2;i++)
		{
			if(Arr[0]==document.all["inpComp"][i].value)
			{
				break;
			}
		}
		ChangeAccompById(vSel,document.all["chk_accomp_prod"][i],document.all["accompPrice"][i],document.all["tdaccompImg"][i],document.all["tdaccompHref"][i],document.all["sel_accomp_prod_qty"][i],document.all["inpCompQty"][i])
	}	
}
function ChangeAccompById(vSel,oChk,oPrice,tdImg,tdHref,sQty,iQty)
{
	iQty.value = sQty.value
	var Arr = vSel.value.split(":");
	oChk.value = Arr[1];
	oPrice.innerText= formatCurrency(Arr[4]==0?Arr[3]:Arr[4]);

	var imgPath = "shops/"+Arr[6]+"/p"+Arr[1]+"b."+Arr[7];
	if(Arr[5]!="")
	{
		if(Arr[5].indexOf('http://')>0)
			imgPath = Arr[5]
		else
			imgPath = "shops/"+Arr[6]+"/"+Arr[5];
	}	
	var Img ="<img id='accompImg' name='accompImg' border='0' hspace='0' vspace='0' style='cursor:hand' onclick='"
	Img += "window.open(\"zoom.htm?"+ imgPath + "\", \"Zoom\", \"resizable=yes, menubar=no, titlebar=no, scrollbars=1, toolbar=no, status=no, location=no, directories=no, top=0, left=0\");return false;"
	Img += "' src='"
	Img += "shops/" + Arr[6] + "/small-2.gif"
	Img += "'>"

	tdImg.innerHTML = Img;

	Img = "<a id='accompHref' name='accompHref' href='"
    Img += "javascript:void(window.open(\"printproduct.asp?pc=" + Arr[1] + "\",\"\",\"\"))'>"
    Img += "<img border='0' hspace='0' vspace='0' src='"
    Img += "shops/" + Arr[6] + "/small-1.gif'/></a>"
	tdHref.innerHTML = Img;
}
function formatCurrency(num)
{
	num = num.toString().replace(/\₪|\,/g,'');
	num = num.toString().replace(/\руб.|\,/g,'');
	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 SetData()
{
   try
   {
	var tbl = document.all["tblAccomp"].rows.length;
	if(tbl==3)
	{
		if(!document.all["chk_accomp_prod"].checked)
		{
			document.all["sel_accomp_prod_qty"].text = "-1";
			document.all["inpCompQty"].value = "";
		}
	}
	else
	{
		var i=0;
		for(;i<tbl-2;i++)
		{
			if(!document.all["chk_accomp_prod"][i].checked)
			{
				document.all["sel_accomp_prod_qty"][i].value = "-1";
				document.all["inpCompQty"][i].value = "";
			}
		}
	}
   }
   catch(e){};
   return true;
}
