function Visual(){
}

//--------- Return formatted string ---------
Visual.formatStr = function(str){
  return MultiLang.get(str);
}

//----------------------------------------------------
// Show current Categories, by ststus and from_catid
// level should not be passed
Visual.showCategoriesInLI = function(status,from_catid,clevelLI){
  if (typeof(clevelLI)!= typeof(undefined)){
     clevelLI=0;
  }else{
   clevelLI++
  }

  if (clevelLI!=0){
      document.write("<ul>");	
  }
  var arr=new Array();
  arr[0]=status;	 
  var childs=Category.getChildrenByStatus(from_catid,arr);
  for (var i=0;i<childs.size();i++){
             var c = childs.get(i);        
            document.write( '<li><div><a href="JavaScript:Novigation.goToCategory('+c.getId()+')">'+Visual.formatStr(c.getName())+'</a>' );  
             Visual.showCategoriesInLI(status,c.getId());
             document.write(  '</div></li>');
  }
  if (clevelLI!=0){
      document.write("</ul>");	
  }

}

//----------------------------------------------------
// Show all Categories, by ststus and from_catid,in select
Visual.showCategoriesInSelect = function (status,from_catid,isAll){
 var cats=Category.getAllChildren(from_catid);
 if (isAll) document.write('<option value="-2">'+Visual.strAllItems+'</option>');

  for (var j=0;j<cats.size();j++){
	  var c = cats.get(j);
	  if (status==c.getStatus())
	  {
		  document.write('<option value="'+c.getId()+'"');
		  if (Category.current()==c.getId()) document.write(" selected");
		  document.write(">");
		  document.write(Visual.formatStr(c.getName())+"</option>");
	  }

  }
  cats=null;
}
//-----------------------------------------------------------
// Return String representing form Category to To catgegory
// with HREF values
Visual.showUrlCatPath =  function (fromId,toId)
 {
    var str="";
    var arr=Category.getPath(fromId,toId);

	for (var i=0;i<arr.length;i++){	
       	 str+='<a href="JavaScript:Novigation.goToCategory('+arr[i].getId()+')">';
  	     str+=Visual.formatStr(arr[i].getName());
	     str+='</a>';
	      if (i!=arr.length-1)
	          str+=Visual.catSign;
	 }
	  
	    
      if (str!="") {
         str=Visual.catSign+str;
      }

     str='<a  href="JavaScript:Novigation.goToCategory(-2)">'+
   Visual.strCatHome+'</a>'+str;
    return str;
 }

Visual.addMSign=function(input){
  return input+Visual.priceStr;
}
//-------------------------------------------------------
// Return String with PRODUCT html view
//-------------------------------------------------------
Visual.showProductInCart = function (pr,addVal){
	
  var tStr="";
  var str="";
  if (addVal) {
	  str+='<div style="padding-'+Visual.left+':15px">';
	  for (var prop in addVal)
	  	str+="<div>"+addVal[prop]+"</div>";
   	  str+="</div>";
  }
  tStr+='<TD align="'+Visual.left+'" CLASS="cartentry01"> ';
  if (pr.getCode()!="") tStr+=" "+pr.getCode()+" ";
  tStr+=Visual.formatStr(pr.getName())+" "+str;
  tStr+='</TD>';
  return tStr;
}
Visual.showProductInCartMail = function (pr,addVal){	
  var tStr="";
  var str="";
  if (addVal) str="&nbsp;("+addVal+")";
  tStr+='<TD>';
  if (pr.getCode()!="") tStr+=" ["+pr.getCode()+"] ";
  tStr+=Visual.formatStr(pr.getName());
  tStr+=str;
  tStr+='</TD>';
  return tStr;
}


Visual.showError=function(){
 if (errors.indexOf("##")!=0){
	 alert("Error:"+errmes[errors]);
  }
}

//-----------------------------------------------------------
// Return String representing form Category to To catgegory
// with HREF values, to current product if exist
Visual.showPathToCurrentProduct =  function (fromId,toId)
 {
	var fstr="";
	if( (Product.getList()).size()==1 ) // showing only one product 
	 {
		var pr=(Product.getList()).get(0);
	    var catids=getProductCategories(pr.getId(),true);
		fstr=Visual.showUrlCatPath(fromId,catids[0])+Visual.catSign+Visual.formatStr(pr.getName());
	 }else
		 fstr=Visual.showUrlCatPath(fromId,toId);
	document.write(fstr);
 }

//------------------------------
// Show images of category tree before products
Visual.showVisualCategories = function(){
  
 if (Url.getCurrentValue('page')!=null || Url.getCurrentValue('pids')!=null) return;
 var idc=-1;
 idc=Category.current();
  if (idc<-1)idc=-1;
  var str="";
  var statusArr=new Array();
  statusArr[0]=0;
  
  var catArr = Category.getChildrenByStatus( idc,statusArr );
  if (catArr.size()<=0)  return -1;

  var inrow=3;
  str+='<table width="100%">';
  var isOpen=false;
  for (var j=0;j<catArr.size();j++){
	  if (j % inrow ==0){
		  if (isOpen) str+="</tr>";
		  str+="<tr>";
		  isOpen=true;
	  }
	  var c = catArr.get(j);
	  if (c.getPicture()!=""){
		  str+='<td align="center" valign="top">';
		  str+='<a class="CategoryMenu" '+
			 ' href="JavaScript:Novigation.goToCategory('+c.getId()+')">'+
			  Visual.formatStr(c.getName())+"</a>";
		  
		  
		   str+="<br>";
		   str+='<a href="JavaScript:Novigation.goToCategory('+c.getId()+')">';
		   str+='<img border="0" src="../pictures/'+c.getPicture()+'"></a>';
		  
		  str+="</td>";
	  }
   }
  if (isOpen) str+="</tr>";
  str+="</table>";
  document.write(str);
}


//--------------------------------------------------

Visual.showCartContentMess = function(){
  
}


Visual.showHeader = function(p){
 var ind=p.indexOf("://");
 
 if (ind!=-1 ){
	
	 if  ( Url.isSecure( Url.curLoc() ) ) 
   		p=Url.setProtocol(p,"https://");
 	else
  		p=Url.setProtocol(p,"http://");
 }

 if (Project.getFileExt(p)!="swf"){
	document.write('<img border=0 src="'+p+'" />');	  
  }else{
	document.write('<OBJECT><PARAM NAME=movie VALUE="'+p+'">');	  
	document.write('<PARAM NAME=quality VALUE=high><EMBED src="'+p+'" quality=high </EMBED></OBJECT>');	  
   }
}


Visual.showLanguagesM = function(flags){
  if (isOptionOn(flags,1)) 	document.write('<a href="/?theme=en" class="eng" ></a>');
  if (isOptionOn(flags,2)) document.write('<a href="/?theme=ru" class="rus" ></a>');
  if (isOptionOn(flags,4)) document.write('<a href="/?theme=he" class="heb" ></a>');
}


Visual.showHeaderLink= function(href,name,isActive){
  var active="";
  if (isActive) active='class="active"';
  document.write('<a '+active+' href="'+href+'">'+name+'</a>');  
  return !isActive;
}

Visual.showHeaderLinksM = function(arr){
  var url=Url.curLoc();
  var continueCheck=true;  
  for (var i=0;i<arr.length;i++){
	if (arr[i]['id']==0){
  		continueCheck = Visual.showHeaderLink('JavaScript:Novigation.moveTo(Novigation.PAGE_CART)',Visual.strCheckout, Novigation.currPage==Novigation.PAGE_CART);
	}else if (arr[i]['id']==1){
		continueCheck = Visual.showHeaderLink('/reg.php',Visual.strClubMem, continueCheck  && (url.indexOf('reg.php')!=-1) );	
	}else if (arr[i]['id']==2){
  		continueCheck = Visual.showHeaderLink('/infopage.php?ipage='+arr[i]['link'],
  												arr[i]['str'],continueCheck  && (url.indexOf(arr[i]['link'])!=-1) );
  		//continueCheck = Visual.showHeaderLink('/infopage.php?ipage=contacts.html',Visual.strContact, continueCheck  && (url.indexOf('contacts.html')!=-1) );
  		//continueCheck = Visual.showHeaderLink('/infopage.php?ipage=company.html',Visual.strAboutUs, continueCheck  && (url.indexOf('company.html')!=-1) );
  		//continueCheck = Visual.showHeaderLink('/infopage.php?ipage=terms.html',Visual.strTerms, continueCheck  && (url.indexOf('terms.html')!=-1) );
	}
  }

}

Visual.showFooterLinks = function(){
    document.write(' | <a href="/infopage.php?ipage=faq.html">'+Visual.strFAQ+'</a>'); 
    document.write(' | <a href="/infopage.php?ipage=terms.html">'+Visual.strTerms+'</a>'); 
    document.write(' | <a href="/infopage.php?ipage=news.html">'+Visual.strNews+'</a>'); 
    document.write(' | <a href="/infopage.php?ipage=contacts.html">'+Visual.strContact+'</a>');
}

Visual.mainInit= function(){
	
 if ( Category.getChildrenByStatus(-1,[1]).size()>0 ){ //visualate manufactures
   Html.displayElement('mnf_id_hidd_none',1);
 }
 if (Category.getChildrenByStatus(-1,[2]).size()>0 ){ //visualate special
   Html.displayElement('sp_id_hidd_none',1);
 }
 
 if (typeof(startScrallingCB)!= typeof(undefined)){ //we need base to take theme
  var ajaxObj = new XMLHttp(true);
  var b = document.getElementsByTagName('base');
  if (b && b[0] && b[0].href) {
   var ind1=b[0].href.indexOf("theme/");
   var ind2=b[0].href.indexOf("/",ind1+8);
   var theme=null;
   if (ind11=-1 && ind2!=-1)  theme=b[0].href.substr( ind1+6,ind2-1);
   if (theme!=null)   ajaxObj.get(Url.getCurrentLocation()+'/theme/'+theme+'/pages/tpl/news.html',startScrallingCB);		
  }
 }
 	
}

Visual.printCategoryIcon= function(iconPath,id){
	iconPath="../pictures/"+iconPath;
	document.write('<a href="JavaScript:Novigation.goToCategory('+id+')">');
    document.write('<img class="imgprodicons" border="0"  src="'+iconPath+'" >');
    document.write('</a>');
}

Visual.showCategoryIcons= function(id){
var tmpListCat=getProductCategories(id,true);
var idArr=new Array();  
idArr[1]=new Array();
idArr[2]=new Array();
for (var i=0;i<tmpListCat.length;i++)
   if (tmpListCat[i]!=-1){
  	  var c=Category.getCategoryByID(tmpListCat[i]);
  	  var st=c.getStatus();
      if (st==2 || st==1){
        var iconPath=c.getPicture();
        if (iconPath!="")
            idArr[st][idArr[st].length]=new Array(tmpListCat[i],iconPath);
      }
   } 
   
for (var st=1;st<=2;st++)   
 for (var i=0;i<idArr[st].length;i++){
	Visual.printCategoryIcon( idArr[st][i][1],idArr[st][i][0] );
 }   
   
}

Visual.showMarketPrice= function(isRTL,msg,price,currSign){
    if (Project.marketPercent<=0) return;
    if (!isNaN(Number(price))) {
	    document.write('<span class="listprice">'+msg);
	    var mPrice=new Number((100+Project.marketPercent)*price/100).toFixed(2);
        if (isRTL)
          document.write(""+mPrice+currSign); 
        else  
         document.write(""+currSign+mPrice); 
        document.write('</span>');
     }
     
}

Visual.showChkOutButton= function(id,price){
	price=Number(price);
	if (isNaN(price)) price=0;
	if ( (Project.addCartMode==0) || (Project.addCartMode==2 && price>0) ){
		document.write('<span class="buybutton">');
		document.write('<a href="javascript:Novigation.toCheckOut(Product.addToCartProp('+id+',1,Product.getProductProperties('+id+')))"><img src="images/buybutton.gif" alt="" ></a>');
		document.write('</span>');
	}

}