
function popUp (sURL, sName, x, y, dx, dy) {
  if(!sURL) return;
  window.open(sURL, sName, 'left='+x+',top='+y+',screenX='+x+',screenY='+y+',width='+dx+',height='+dy+',scrollbars=1,resizable=1');
}

function GoURL(s){
  document.location = s;
}

function Add2Fav(){
  if (document.all)
    window.external.AddFavorite(document.location.href,document.title);
}

function OpenPreview(sURL) {
  if(!sURL) return;
  var w_s = 50;
  var h_s = 50;
  var w = window.screen.width;
  var h = window.screen.height;
  popUp(sURL,'Preview' + Math.floor(Math.random()*1000), w_s, h_s, w-2*w_s, h-2*h_s-50);
}

function OpenImages(id,f){
  OpenPreview('index.php?page=images&id='+id+'&f='+f);
}

function hwReloadCat(page,cid,hwJsCats){

  var catbox = document.frm.cid;
  var new_cid = catbox.options[catbox.selectedIndex].value;
  var f1,f2,s1,s2;
  s1 = '|' + new_cid + '|';
  s2 = '|' + cid + '|';
  
  for (i = 0; i < hwJsCats.length; i++) {
    f1 = hwJsCats[i].indexOf(s1) != -1;
    f2 = hwJsCats[i].indexOf(s2) != -1;
    if(f1 && f2) return;
    if(f1 || f2) break;
  }
  
  var ch_sep = page.indexOf('?') != -1 ? '&' : '?';  
  document.location = page + ch_sep + 'cid=' + new_cid;
}

function txtCount(f, countf, max) {
  
  if(isNaN(max)) return txtCountW(f, countf, max);

  if (f.value.length > max) f.value = f.value.substring(0, max);
  else countf.value = max - f.value.length;

}

function txtCountW(f, countf, max) {
  var num = 0;
  for (x=0;x<f.value.length;x++) {
    // Counts the spaces while ignoring double spaces, usually one in between each word
    if (f.value.charAt(x) == " " && f.value.charAt(x-1) != " ")  num++;
    if (num > 250) f.value = f.value.substring(0, x);
    else countf.value = parseInt(max) - num;
  }
}

function hwGetMenuValue(ctl){
  ctl = eval('document.' + ctl);
  return ctl.options[ctl.selectedIndex].value;
}

function SwitchItemsAdm (block) {
  if(!block) block = 'chk_id';
  var on = document.frm.chk_all.checked;
  var el = document.frm.elements;
  for (var i=0; i<el.length; i++) {
    if (el[i].name.substr(0,block.length)== block && !el[i].disabled) el[i].checked=on;
  }
}

function LookupUserAdm(ctl){
  popUp('index.php?page=lookup_uid&tg='+escape(ctl),'LookupUID', 50, 50, 400, window.screen.height-150);
}

function hwGetElementById(id){
  if (document.getElementById) return (document.getElementById(id));
  else if (document.all) return (document.all[id]);
  else if ((navigator.appname.indexOf("Netscape") != -1) && parseInt(navigator.appversion == 4)) return (document.layers[id]);
}

function hwShowPass(ctl){
  alert(eval('document.frm.'+ctl).value);
}

function SwitchBlock(Id, bShow) {
  var el;
  if(document.getElementById) el = document.getElementById(Id);
  else { el = document.all ? document.all[Id] : new Object(); }
  if(!el) return;
  if(el.style) el = el.style;
  if( typeof( el.display ) == 'undefined' && !( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) ) { alert('Browser Error!'); return; }
  el.display = bShow ? 'block' : 'none';
}

function getCookie(name) {
  var p = name + "=";
  var si = document.cookie.indexOf(p);
  if (si == -1) return null;
  var ei = document.cookie.indexOf(";", si + p.length);
  if (ei == -1) ei = document.cookie.length;
  return unescape(document.cookie.substring(si + p.length, ei));
}


jQuery.noConflict();  
jQuery(document).ready(function(){  
	 
	 /*
	 jQuery.translate(function(){  //when the Google Language API is loaded 

	    function translateTo( destLang ){ 
			
	  		var tlc = jQuery.translate().toLanguageCod;// create a shorthand
			//if( tlc( destLang ) == "ru" && tlc(jQuery.cookie("malldestLang")) == "ru") // hide loading icon when surfing in English
			//return;
			jQuery('body').translate( 'russian', destLang, {   //translate from english to the selected language 
				 not: '.jq-translate-ui, noscript',  //by default the generated element has this id  
				 fromOriginal:true,   //always translate from english (even after the page has been translated) 
				 start: function(){block();},   // show loading icon
				 complete: function(){ jQuery.unblockUI(); },  // hide loading icon
				 error: function(){ jQuery('#trans-status').hide(); }  // hide loading icon
		   }); 
	    } 
		function block(){
			jQuery.blockUI({ 
			message: '<h2 style="font-size:22px">Translating..</h2>',
			css: { 
				border: 'none', 
				message: 'translating...',
				padding: '25px', 
				backgroundColor: '#000', 
				'-webkit-border-radius': '10px', 
				'-moz-border-radius': '10px', 
				opacity: .7,
				color: '#fff' 
        	} }); 
		}
		
	  jQuery('tr.cnglanglist a').click(function(){
	         var lang = jQuery(this).attr('id');
	         translateTo(lang);
	         jQuery.cookie('malldestLang', lang, { path: '/' });
	         //alert('asdasdasd');
	         return false;
				
	      });
		  
		jQuery('a.ru').click(function(){
			jQuery.cookie("malldestLang", null);
		});
		
	    var destLang = jQuery.cookie('malldestLang'); //get previously translated language 
	     
	    if( destLang )  //if it was set then 
	        translateTo( destLang ); 
	 
	  }); //end of Google Language API loaded 
	 
	 
	 */
	
jQuery('tr.cnglanglist a').click(function(){
	         var lang = jQuery(this).attr('class');
	         
		 window.location = 'http://translate.google.com/translate?hl=ru&sl=ru&tl=' + lang + '&u=http://mall.rusrek.com/';
	        
	         //alert('asdasdasd');
	         return false;
				
	      });

	 
	 
	 
	 
    	 //jQuery("#reg_select").newWindow({windowTitle:"{ads_by_regions}",ajaxURL: "/index.php?page=rusrekads",width:700,height:450});
    	 jQuery('#location_rub').attr('innerHTML',location_string);
//---------- for login window ------------------//
		tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
		imgLoader = new Image();// preload image
		imgLoader.src = tb_pathToImage;
//------------------------//
    	 jQuery("#button").hover(function() { 
    		 jQuery("#option").show();
        },function()
        {
        	jQuery("#option").hover(function()
             {
        		jQuery("#option").show();
             },function()
             {
            	 jQuery("#option").hide();
             });
             setTimeout(jQuery("#option").hide(),15000); 
        });

    	 jQuery("#one").click(function()
        {
    		 jQuery("link").attr("","#");
             return false;
        });
//------------------//
         jQuery("#button22").hover(function() { 
        	 jQuery("#option2").show();
        },function()
        {
        	jQuery("#option2").hover(function()
             {
        		jQuery("#option2").show();
             },function()
             {
            	 jQuery("#option2").hide();
             });
            setTimeout(jQuery("#option2").hide(),15000);  
        });

         jQuery("#one2").click(function()
        {
        	 jQuery("").attr("","#");
             return false;
        });

//------------------//
         jQuery("#button3").hover(function() { 
        	 jQuery("#option3").show();
        },function()
        {
        	jQuery("#option3").hover(function()
             {
        		jQuery("#option3").show();
             },function()
             {
            	 jQuery("#option3").hide();
             });
            setTimeout(jQuery("#option3").hide(),15000);
        });

         jQuery("#one3").click(function()
        {
        	 jQuery("").attr("","#");
             return false;
        });

//-------------------//
       //------------------------//
    	 jQuery("#cat_button").hover(function() { 
    		 jQuery("#cat_option").show();
        },function()
        {
        	jQuery("#cat_option").hover(function()
             {
        		jQuery("#cat_option").show();
             },function()
             {
            	 jQuery("#cat_option").hide();
             });
             setTimeout(jQuery("#cat_option").hide(),15000);
        });

    	 jQuery("#one").click(function()
        {
    		 jQuery("link").attr("","#");
             return false;
        });
		 
	
	//loadbanner('0', 'banner_id_1');
	/*
	function loadbanner(id, dis){
		var loadUrl = "/index.php?page=banners&id=" + id + '';
		jQuery("#" + dis +'').load(loadUrl);
	}
		 
  	loadbanner('1', 'banner_place1');
	loadbanner('2', 'banner_place2');
	loadbanner('3', 'banner_place3');
	loadbanner('4', 'banner_place4');
	loadbanner('5', 'banner_place5');
	loadbanner('6', 'banner_place6');
	loadbanner('7', 'banner_place7');
	loadbanner('8', 'banner_place8');
	loadbanner('9', 'banner_place9');
	loadbanner('10', 'banner_place10');
	loadbanner('11', 'banner_place11');
	loadbanner('12', 'banner_place12');
	loadbanner('13', 'banner_place13');
	loadbanner('14', 'banner_place14');
	loadbanner('15', 'banner_place15');
	
	*/
	jQuery("#banner-bottom").load("/banner_bottom.php");
	 /*
	 function loadbanner(img, dis){

		var loadUrl = "http://www.rusrek.com/ads/get/" + img + '';

		//jQuery("#" + dis +'').load(loadUrl);
		jQuery.get(loadUrl, function(data){
		  jQuery("#" + dis +'').html('asfd');
		});

	}
	*/
});  




function win_open(page,width,height){
	
	mywindow = window.open('/'+page,'page','width='+width+',height='+height+',toolbar=0');
  	mywindow.moveTo(50,50);
}



 function setLocationName(name){
	 jQuery('#location_rub').attr('innerHTML',name);
 }
 function regionsUpdate(rid){
	 regid = rid;
	 //jQuery("#regions").load("index.php?page=rusrekajax&get=region&rid="+rid);
	 if ( jQuery("#categories_list").length > 0  ) {
		document.location = '/?rid='+rid;
		return;
		 jQuery.blockUI({ css: { 
	         border: 'none', 
	         padding: '15px', 
	         backgroundColor: '#000', 
	         '-webkit-border-radius': '10px', 
	         '-moz-border-radius': '10px', 
	         opacity: .5, 
	         color: '#fff' 
	     }, message: RequestMessage });
		 jQuery("#categories_list").load("index.php?page="+RequestPage+"_ajax&rid="+rid+"&lang="+lang, function(){
				jQuery.unblockUI();
			 });
		}else{
			var f = document.getElementById('frm');
			if(f){
			if(jQuery("#select_hw_region_id").length > 0){
				jQuery("#select_hw_region_id").remove();
			}
			document.frm.hw_region_id.value = rid;
			document.frm.rid.value = rid;
			if(document.frm.notreload){
			  jQuery.get("index.php?page=empty&rid="+rid);
			  return true;
			}else{
			  document.frm.submit();
			}
			}else{
				document.location = '/?rid='+rid;
			}
		}
 }
 function categoryUpdate(cid){
	 //jQuery("#frm_submit").removeAttr("disabled");
	 jQuery("#category").load("index.php?page=rusrekajax&get=category&cid="+cid+"&lang="+lang);
 }
 function setCat(id){
	 catid = id;
	 docSubmit();
/*
	 if(catid == 0)
		jQuery("#frm_submit").attr('disabled', true); 
	 else
		jQuery("#frm_submit").removeAttr("disabled");
		*/  
 }
 function docSubmit(){
	 if(regid == 0)
		 regid = jQuery('#prereg_id').val();
	 if(catid == 0)
		 catid = jQuery('#cat_id').val();
	 
	 document.location = 'index.php?page=browse&rid='+regid+'&cid='+catid;
	//document.location = 'index.php?page=search&s_res=AND&rid='+regid+'&cid='+catid+'&lang='+lang;
		 //document.location = 'index.php?page=rusrekads&rid='+regid+'&cid='+catid;
 }
 function cngLang(lang){
	 	var _url = 'index.php?page='+RequestPage+query_string+'&lang='+lang+'&rid='+regid;
		document.location = _url; 
}


var winheight = jQuery(window).height()-40;
var divheight =  jQuery(window).height()-100;
function openAjaxConfirm() {
	var div_str = '<div id="region_select" style="width:705px; height:'+divheight+'px; overflow : auto;"><center><img src="/img/ajax-loader.gif"></center></div>';
	Dialog.alert(div_str, {windowParameters: {top:5, height:winheight, width:705, className: "alphacube", okLabel: "Close"}});
	jQuery("#region_select").load("/index.php?page=rusrekads");
}


var min=12;
var max=22;
function increaseFontSize() {
   var p = document.getElementsByTagName('div');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 16;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px";
   }
}
function decreaseFontSize() {
   var p = document.getElementsByTagName('div');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 16;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px";
   }   
}