var up=userParameters();  //used to is_robot 
function do_onload() {
	/*$("input[type='hidden']").hide();
	$("table").attr("cellSpacing","0")
	$("table").attr("cellPadding","0")
	$("tr").attr("vAlign","top")*/
	$("input[type='checkbox']").attr("style","border:none");
	$("input[type='radio']").attr("style","border:none");
	$("label").hover(
      function () {
        $(this).addClass('hovered');
      }, 
      function () {
        $(this).removeClass('hovered');
      }
    );
    $("#left_menu a").click(function () { 
      	showLoading('content',true)
    });  
    $("#searchresult a").click(function () { 
      	showLoading('content',true)
    });
   $(".path a").click(function () { 
      	showLoading('content',true)
    });
    $(".suggested_cats a").click(function () { 
      	showLoading('content',true)
    });  
    $(".popular_searches a").click(function () { 
      	showLoading('content',true)
    }); 
    var kw;
    try {
      kw=$('#keyword').val(); 
      if(typeof(kw)=='undefined')
    	  kw=''
    } catch(exx) { kw=''}; 
    var kw_for_url=kw.replace(' ','+');
    kw_for_url=escape(kw_for_url);
    if(kw) {
	    if(kw.length>2) {
	    	$('#desc_search').removeAttr('disabled');
	    	$('#remove_keyword').show()
	    }
    }
    if(kw_for_url) {
		$('.suggested_cats a').each(function(){
			h=this.getAttribute('href')
			this.setAttribute('href',h+'?keyword='+kw_for_url)
		});
		$('#categories_list a').each(function(){
			h=this.getAttribute('href')
			this.setAttribute('href',h+'?keyword='+kw_for_url)
		})	;
		$('.path a').each(function(){
			h=this.getAttribute('href')
			this.setAttribute('href',h+'?keyword='+kw_for_url)
		});		

    }
    $('#remove_keyword').click(function(){
    	//1.remove the search word from input
    	$('#keyword').val('');
    	//2. remove keyword from cat list
    	$('.left_menu a').each(function(){
    		var href=this.getAttribute('href')
    		var href2=href.substr(0,href.indexOf('?'))
    		this.setAttribute('href',href2);
    	})
    	//3. remove from path
    	$('.path a').each(function(){
    		var href=this.getAttribute('href')
    		var href2=href.substr(0,href.indexOf('?'))
    		this.setAttribute('href',href2);   		
    	});
    	//4. remove from suggested cats
    	$('.suggested_cats a').each(function(){
    		var href=this.getAttribute('href')
    		var href2=href.substr(0,href.indexOf('?'))
    		this.setAttribute('href',href2);   		
    	});    	
    	//5. hide itself
    	$(this).hide()
    	
    })
//    add_csrf_param(csrf); 
//    if(document.location.pathname.indexOf('index.php')>-1 || document.location.pathname=='/') { //index page
//		$('.clouds a').each(function(){
//				h=this.getAttribute('href')
//				this.setAttribute('href',h+'&csrf_param='+csrf)
//			}
//		)	
//    }
//	$('.suggested_cats a').each(function(){
//			h=this.getAttribute('href')
//			this.setAttribute('href',h+'&csrf_param='+csrf)
//		}
//	) 
	$("div.left_menu_top").hover(
      function () {
        $(this).addClass('hovered');
      }, 
      function () {
        $(this).removeClass('hovered');
      }
    );	
    $('.forum_link').hover(
    		function(){
    			$(this).addClass('forum_link_hovered');
    		},
    		function(){
    			$(this).removeClass('forum_link_hovered');
    		}    		
    )
	//set to no robot
//	var url2="ajax_stuff/is_robot.php"; 
//    $.get(url2, {param: up })
}

function toggleFields(txt) {
	if(txt.length>2){
		elt1=document.getElementById('search_all_categories1')
		if(elt1)
			elt1.removeAttribute('disabled')
		document.getElementById('desc_search').removeAttribute('disabled');
		$('#remove_keyword').show();
	}
}
function processCaptcha() {
	n1=document.getElementById('cnumber1').innerHTML
	n2=document.getElementById('cnumber2').innerHTML
	document.getElementById('csum').value=parseInt(n1)+parseInt(n2)
	document.getElementById('captcha').style.display='none'
}	
function showLoading(parentEltId,hideSubContent){
	if(hideSubContent) {
		subc=document.getElementById('subcontent')
		if(subc)
			subc.parentNode.removeChild(subc)
		/*document.getElementById('subcontent').style.visibility='hidden'
		document.getElementById('subcontent').style.height='1px'*/
	}
	$('#loading').css('position','relative').css('top','0').css('left','0')
	parentId='#'+parentEltId; 
	$(parentId).append($('#loading'))
	
	$('#loading').css('height',$(parentId).height())
}
function removeLoading() {
	$('#loading').css('position','absolute').css('top','-9999').css('left','-9999');
	$('#loading_container').append($('#loading'));//alert()
}

function userParameters() {
	s=screen.availHeight;
	s+=','+screen.availWidth
	s+=','+screen.colorDepth
	s+=','+screen.height
	s+=','+screen.width
	return s
}
function log_broker(frm) {
	var url="ajax_stuff/log_broker.php"
	partner_id=frm.elements['partner_id'].value
	lot_number=frm.elements['lot_number'].value
	username=null
	if(typeof(frm.elements['usr'])!=='undefined')
		username=frm.elements['usr'].value
	$.get(url, {partner_id: partner_id,lot_number: lot_number, username: username }); 
}
function Trim(str) {
	str=str.replace(/^\s*|\s*$/g,"")
   return str;
}
function processCorrectTranslating(p) {

	rname=$('#right_name').val()
	wname=$('#wrong_name').val()
	cments=$('#comments').val(); 
	csrf=$('#csrf_param').val(); 
//	if(!csrf) 
//		return false
	if(rname.length>0 && wname.length>0) {
		$('#correct_translation_wait').show()
		var url="ajax_stuff/sendmail.php"; 
		/*if this is a page with 'ru' or 'de', go one subdir higher */
		if(p.indexOf('/')>-1)
			url='../'+url
		$.get(url, {right_name: rname,wrong_name: wname, comments:cments, csrf_param:csrf},
	   		function(data, isSuccess){
	   		if(isSuccess){ //alert('data: '+data)
	   			if(data) {
	   				$('#div_correct_translating').html(data)
	   			}
	   	    }	
	   		else {
	   			
	   		}
	   
	   	});			
	}
}

function add_csrf_param(param) {
	$('#csrf_param').val(param)
}
function log_action(action,param, lang) { 
	var url="ajax_stuff/log_action.php"; 
	/*if this is a page with 'ru' or 'de', go one subdir higher */
	p=document.location.href
	if(p.indexOf('/ru/')>-1 || p.indexOf('/de/')>-1)
		url='../'+url
	$.get(url, {action: action,param: param, lang: lang, visitorId: up});	
}

function processLinks(val) {
	if(Trim(val)=='') {
		//remove keyword from links
    	$('.path a').each(function(){	    		
    		this.setAttribute('href',this.getAttribute('href').replace('keyword','oldkeyword'))
    	})
    	$('.left_menu a').each(function(){	    		
    		this.setAttribute('href',this.getAttribute('href').replace('keyword','oldkeyword'))
    	})			
	}
}

function do_translate(frm) {
	try {
		backup=$('#translating').html()
		$('#translating p').html('')
		cnt=$('#translating').html(); 
		$('#translating').html(backup);
	}
	catch(exx) {alert(exx.message)}
	if(!cnt)
			return false;
	frm.elements['translating_content'].value=cnt
	frm.submit()
}
function toggleNav(n) {
	if(n) {
		$('#categories_list').show();
		$('#left_menu_top').addClass('hovered')
	}
	else {
		$('#categories_list').hide();
		$('#left_menu_top').removeClass('hovered')
	}
}
function submit_searchform(frm, lang) {
	cat_id_known = frm.elements['cat_id'].value.length;
	if(cat_id_known)
		return true;
	if(testIt(frm)) {
		showLoading('content',true);
		//save the search word
		var sw=frm.elements.keyword.value;
		log_action('search_word',sw,lang);
		return true;
	} 
	else return false	
	
}
function testIt(_form){ 
	t=Trim(_form.elements['keyword'].value); 
	if(t.length<3) {
		//alert('wwedite kljuchewoe slowo')
		return false;
	}
	else return true;
}

function vote(keyword, yt_url, score) {
	var url="ajax_stuff/yt_vote.php"; 
	/*if this is a page with 'ru' or 'de', go one subdir higher */
	p=document.location.href
	if(p.indexOf('/ru/')>-1 || p.indexOf('/de/')>-1)
		url='../'+url;
	$.get(url, {keyword: keyword, yt_url: yt_url, score: score},
	   		function(data, isSuccess){
   		if(isSuccess){ //alert('data: '+data)
   				$('#vote_video_plus').hide();
   				$('#vote_video_minus').hide();
   				$('#vote_container').hide();
   				$('#vote_ack').show();

   	    }	
   		else {
   			
   		}
	}
	);	
}

