var replace_to = "%26";


function highlight(field) {
       field.focus();
       field.select();
}

/****************************************************************************************************/

function redirect_mazplan()
	{
		model = document.getElementById('model').value;
		window.location.href="auto_mazaci_plan/"+model+'.html';
	}

/****************************************************************************************************/

function changeModelsList(fabric)
	{
		 document.getElementById('model_span').innerHTML="Spracovávam.. čakajte";
		 $.ajax({
		   type: "POST",
		   url: "result.php",
		   data: "mode=changeModelsList"+"&fabric="+fabric,
		 	success: function(html){    
		 	  $("#model_span").html(html);
		 	  }
		   })
	}

/****************************************************************************************************/

function sendmessage(type)
 {  	
	 
	 
	 c = document.getElementById("c").value;
	 number = document.getElementById("number").value;
	 
	 if ((number==c)&&document.getElementById("user_id").value!='') { 
			 document.getElementById("comments").setAttribute("class", "transparent_class");
			 document.getElementById('preloading').style.visibility = 'visible';
			 
			 $.ajax({
			   type: "POST",
			   url: "result.php",
			   data: "mode=sendmessage"+"&type_id=" + type + "&message_id=" + document.getElementById("message_id").value + "&title_id=" + document.getElementById("title_id").value + "&user_id=" + document.getElementById("user_id").value,
			   success: function(html){       
				 	$("#comments").html(html);
				 	document.getElementById('preloading').style.visibility = 'hidden';
					document.getElementById("comments").setAttribute("class", "no-transparent_class");
				 } 
			 });
			 } else 
			 	{
			 		if (number!=c) alert("Zadajte správny výsledok !");
			 		if (document.getElementById("user_id").value=='') alert("Zadajte meno!");
			 	}
	  return false; 
}


function banner_sita()
{
		   var m3_u =
		(location.protocol=='https:'?'https://rs.webnoviny.sk/www/delivery/ajs.php':'http://rs.webnoviny.sk/www/delivery/ajs.php');
		   var m3_r = Math.floor(Math.random()*99999999999);
		   if (!document.MAX_used) document.MAX_used = ',';
		   document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
		   document.write ("?zoneid=371");
		   document.write ('&amp;cb=' + m3_r);
		   if (document.MAX_used != ',') document.write ("&amp;exclude=" +
		document.MAX_used);
		   document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet
		? '&amp;charset='+document.characterSet : ''));
		   document.write ("&amp;loc=" + escape(window.location));
		   if (document.referrer) document.write ("&amp;referer=" +
		escape(document.referrer));
		   if (document.context) document.write ("&context=" + escape(document.context));
		   if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
		   document.write ("'><\/scr"+"ipt>");
}

/****************************************************************************************************/

function displayElement(tovarID,kat,vyr,viscosity,trieda,orderBy,orderType,limitDown,limitUp,searchStr,active,lang,mode)  
 {  
	
	 document.getElementById("main-content").setAttribute("class", "transparent_class");
	 document.getElementById('preloading').style.visibility = 'visible';
 
	 $.ajax({
	   type: "POST",
	   url: "result.php",
	   data: "mode=" + mode + "&tovarID=" + tovarID + "&kat=" + kat + "&vyr=" + vyr + "&viscosity=" + viscosity + "&trieda=" + trieda + "&orderBy=" + orderBy + "&orderType=" + orderType + "&limitDown=" + limitDown + "&limitUp=" + limitUp + "&search=" + searchStr + "&active=" + active + "&lang=" + lang,
	   success: function(html){       
	         document.getElementById('preloading').style.visibility = 'hidden';
	         document.getElementById("main-content").setAttribute("class", "no-transparent_class");
	         $("#main-content").html(html);
			 $(document).ready( function(){ $("#infinite").scrollable({  size:3, speed:1000 }); });
		 
		 } 
	 });
	 
	 
	 $.ajax({
	   type: "POST",
	   url: "result.php",
	   data: "mode=showmessages"+"&type_id=O"+tovarID,
	   success: function(html){     
	   		   
	         $("#comments").html(html);  
		 } 
	 });
	
	 return false;
}


/****************************************************************************************************/

function displayTovarThumbs(kat,vyr,viscosity,trieda,orderBy,orderType,limitDown,limitUp,searchStr,active,lang,mode)  
 {  
	 
	 document.getElementById("main-content").setAttribute("class", "transparent_class");
	 document.getElementById('preloading').style.visibility = 'visible';
	 
	 $.ajax({
	   type: "POST",
	   url: "result.php",
	   data: "mode=" + mode + "&kat=" + kat + "&vyr=" + vyr + "&viscosity=" + viscosity + "&trieda=" + trieda + "&orderBy=" + orderBy + "&orderType=" + orderType + "&limitDown=" + limitDown + "&limitUp=" + limitUp + "&searchStr=" + searchStr + "&active=" + active + "&lang=" + lang+"&dummy="+Math.random(),
	   success: function(html){       
	         document.getElementById('preloading').style.visibility = 'hidden';
	         document.getElementById("main-content").setAttribute("class", "no-transparent_class");
	         $("#main-content").html(html);  
		 } 
	 });
	 
	 return false;
}

function vyber_auto()
	{
		document.getElementById('preloading').style.visibility = 'visible';
	 
		var znacka = document.getElementById("znacky").value;
		   $.ajax({
		   type: "POST",
		   url: "result.php",
		   data: "mode=getAuta" + "&znacka=" + znacka,
		   success: function(html){       
			     document.getElementById('preloading').style.visibility = 'hidden';
			     $("#auta").html(html);  
			 } 
	 });
	 
	 return false;
	}



/****************************************************************************************************/

function validate_form(Name_First, Name_Second, city, email, email1, email2, email3)
	{
	 
	 function validate(email) {
		   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		   var address = email;
		   if(reg.test(address) == false) {
			  //alert('Invalid Email Address');
			  return false;
		   } else return true;
		}
		
	 var a = parseInt(document.getElementById('a').value);
	 var b = parseInt(document.getElementById('b').value);
	 var c = parseInt(document.getElementById('number').value);
	 
	
	 
	 if (a+b==c) 
			{
		 		var ok=true;
		 	} else var ok=false;
		 
	
	 if (Name_First==''||Name_Second==''||city=='') ok=false;
	 
	 if (!(validate(email)&&validate(email1)&&validate(email2)&&validate(email3))) ok=false;
	
	return ok;
	
	}

/****************************************************************************************************/

function send_answer()
	{
		//var answer=document.poll.odpoved.value;
		for (var i=0; i < document.poll.odpoved.length; i++)
		   {
		   if (document.poll.odpoved[i].checked)
			  {
			  var answer = document.poll.odpoved[i].value;
			  }
		   }
		//alert(rad_val);
		var Name_First = document.poll.Name_First.value;
		var Name_Second = document.poll.Name_Second.value;
		var city = document.poll.city.value;
		var email = document.poll.email.value;
		var email1 = document.poll.email1.value;
		var email2 = document.poll.email2.value;
		var email3 = document.poll.email3.value;
		
	   var ok = validate_form(Name_First, Name_Second, city, email, email1, email2, email3);
	   
	   if (ok)
	   	{	
			   $.ajax({
			   type: "POST",
			   url: "result.php",
			   data: "mode=send_answer" + "&Name_First=" + Name_First + "&Name_Second=" + Name_Second + "&city=" + city + "&email=" + email + "&email1=" + email1 + "&email2=" + email2 + "&email3=" + email3 + "&answer=" + answer,
			   success: function(html){       
					 document.getElementById('preloading').style.visibility = 'hidden';
					 document.getElementById("main-content").setAttribute("class", "no-transparent_class");
					  document.getElementById('Name_First').value='';
					  document.getElementById('Name_Second').value='';
					  document.getElementById('city').value='';
					  document.getElementById('email').value='';
					  document.getElementById('email1').value='';
					  document.getElementById('email2').value='';
					  document.getElementById('email3').value='';
					 $("#hlaska").html(html);  
				 } 
			 })
		} else alert('Nesprávne ste vyplnili požadované údaje !');
	 
	 return false;

	}

/****************************************************************************************************/

function insertItemIntoChart(tovarID,amount,lang,mode)  
 {  

	 document.getElementById("main-content").setAttribute("class", "transparent_class");
	 document.getElementById('preloading').style.visibility = 'visible';

	 $.ajax({
	   type: "POST",
	   url: "chart.php",
	   data: "mode=" + mode + "&tovarID=" + tovarID + "&amount=" + amount + "&lang=" + lang,
	   success: function(html){       
	         document.getElementById('preloading').style.visibility = 'hidden';

	         document.getElementById("main-content").setAttribute("class", "no-transparent_class");
	         $("#shopping-chart").html(html);  
		 } 
	 });
	 
	 return false;
}

/****************************************************************************************************/

function displayProcuctDetails(tovarID,orderBy,orderType,lang,mode)  
 {  
	
	 document.getElementById("main-content").setAttribute("class", "transparent_class");
	 document.getElementById('preloading').style.visibility = 'visible';
 
	 $.ajax({
	   type: "POST",
	   url: "chart.php",
	   data: "mode=" + mode + "&tovarID=" + tovarID + "&orderBy=" + orderBy + "&orderType=" + orderType + "&lang=" + lang,
	   success: function(html){       
	         document.getElementById('preloading').style.visibility = 'hidden';
	         document.getElementById("main-content").setAttribute("class", "no-transparent_class");
	         $("#main-content").html(html);
			 $(document).ready( function(){ $("#infinite").scrollable({  size:3, speed:1000 }); });
		 } 
	 });
	 
	 return false;
}

/****************************************************************************************************/

function displayChartContent(orderBy,orderType,lang,mode)  
 {  
	
	 document.getElementById("main-content").setAttribute("class", "transparent_class");
	 document.getElementById('preloading').style.visibility = 'visible';
 

	 $.ajax({
	   type: "POST",
	   url: "chart.php",
	   data: "mode=" + mode + "&orderBy=" + orderBy + "&orderType=" + orderType + "&lang=" + lang,
	   success: function(html){       
	         document.getElementById('preloading').style.visibility = 'hidden';
	         document.getElementById("main-content").setAttribute("class", "no-transparent_class");
	         $("#main-content").html(html);
		 } 
	 });

	 
	 return false;
}

/****************************************************************************************************/

function removeItemFromChart(tovarID,orderBy,orderType,lang,mode)  
 {  

	 document.getElementById("main-content").setAttribute("class", "transparent_class");
	 document.getElementById('preloading').style.visibility = 'visible';

	 $.ajax({
	   type: "POST",
	   url: "chart.php",
	   data: "mode=" + mode + "&tovarID=" + tovarID + "&orderBy=" + orderBy + "&orderType=" + orderType + "&lang=" + lang,
	   success: function(html){       
	         document.getElementById('preloading').style.visibility = 'hidden';
	         document.getElementById("main-content").setAttribute("class", "no-transparent_class");
	         $("#main-content").html(html);  
		 } 
	 });

	 $.ajax({
	   type: "POST",
	   url: "chart.php",
	   data: "mode=reloadSmallShoppingChart&lang=" + lang,
	   success: function(html){       
	         $("#shopping-chart").html(html);  
		 } 
	 });

	 return false;
}


/****************************************************************************************************/

/****************************************************************************************************/
 
function changeChartItem(chart_id,orderBy,orderType,lang,mode){
         
   document.getElementById('preloading').style.visibility = 'visible';

   var amount    = document.getElementById('input-amount-' + chart_id).value;
 
	 $.ajax({
	   type: "POST",
	   url: "chart.php",
	   data: "mode=" + mode + "&chart_id=" + chart_id + "&amount=" + amount + "&orderBy=" + orderBy + "&orderType=" + orderType + "&lang=" + lang,
	   success: function(html){
	         document.getElementById('preloading').style.visibility = 'hidden';
 			 $("#main-content").html(html);
		 } 
	 });

}

/****************************************************************************************************/

function post(URL, PARAMS) {
	var temp=document.createElement("form");
	temp.action=URL;
	temp.method="POST";
	temp.style.display="none";
	for(var x in PARAMS) {
		var opt=document.createElement("textarea");
		opt.name=x;
		opt.value=PARAMS[x];
		temp.appendChild(opt);
	}
	document.body.appendChild(temp);
	temp.submit();
	return temp;
}

/*****************************************************************************************************/

function onEnter(evt) {
var keyCode = null;

if( evt.which ) {
keyCode = evt.which;
} else if( evt.keyCode ) {
keyCode = evt.keyCode;
}
if( 13 == keyCode ) {
fulltextjs(0);
return false;
}
return true;
}

/*****************************************************************************************************/
 
function fulltextjs(limitDown){
         
   var wordjs    = document.getElementById('fsearch').value;

		post("http://www.eoil.sk", {
			word:wordjs,
			lD:limitDown,
			pid:20,
			applyf:'fulltext'
		})
	return false;
 	
}

/*****************************************************************************************************/
 
function applyFilter(pid,orderBy,orderType,limitDown,limitUp,lang,mode){
         
  // window.location.href="http://www.eoil.sk/#vyhladavac";


  // document.getElementById('preloading').style.visibility = 'visible';

   var producer    = document.getElementById('search-producer').value;
   var category    = document.getElementById('search-category').value;
   var viscosity   = document.getElementById('search-viscosity').value.replace(/&/g,replace_to);
   var trieda      = document.getElementById('search-trieda').value;


		post("http://www.eoil.sk", {
			vyr:producer,
			kat:category,
			vis:document.getElementById('search-viscosity').value,
			tr:trieda,
			lD:limitDown,
			pid:20,
			applyf:'applyf'
		})
	return false;
 	
}


/****************************************************************************************************/
 
function ShowHideLogin(radioObj){
		 
	if(radioObj.checked){
		if(radioObj.value == 1 ){
		   $('#login').slideToggle('slow');	
		   $('#new_user').hide('slow');
		}else if(radioObj.value == 2){
		   $('#new_user').slideToggle('slow');
		   $('#login').hide('slow');	
		}
	}
  return false;
}

/****************************************************************************************************/
 
function ShowHideDoprava(radioObj){
		 
	if(radioObj.checked){
		if(radioObj.value == 1 ){
		   $('#doprava1').slideToggle('slow');	
		   $('#doprava2').hide('slow');
		   $('#doprava3').hide('slow');
		}else if(radioObj.value == 2){
		   $('#doprava2').slideToggle('slow');	
		   $('#doprava1').hide('slow');
		   $('#doprava3').hide('slow');
		}else if(radioObj.value == 3){
		   $('#doprava3').slideToggle('slow');	
		   $('#doprava1').hide('slow');
		   $('#doprava2').hide('slow');
		}


	}
  return false;
}




/****************************************************************************************************/

function update_clanok(id)  
 {  

   //document.getElementById('preloading').style.visibility = 'visible';
   var clanok_content    = document.getElementById('clanok_text').value;
   if (document.getElementById('active_cl').checked) clanok_active=1; else clanok_active=0;

   
	 $.ajax({
	   type: "POST",
	   url: "result.php",
	   //data: "mode=updateclanok" + "&cl_id=" + id + "&clanok_content=" + clanok_content + "&clanok_active" + clanok_active,
	   success: function(html){       
	   		alert("id="+id+"  "+"active="+clanok_active+"   "+clanok_content);
		 } 
	 });
	 
	 return false;
}


/****************************************************************************************************/

function displayUserObjednavky(orderBy,orderType,limitDown,limitUp,searchStr,active,lang,mode)  
 {  

   document.getElementById('preloading').style.visibility = 'visible';


	 $.ajax({
	   type: "POST",

	   url: "result.php",
	   data: "mode=" + mode + "&orderBy=" + orderBy + "&orderType=" + orderType + "&limitDown=" + limitDown + "&limitUp=" + limitUp + "&search=" + searchStr + "&active=" + active + "&lang=" + lang,
	   success: function(html){       
	         document.getElementById('preloading').style.visibility = 'hidden';
	         $("#main-content").html(html);  

		 } 
	 });
	 
	 return false;
}

function displayUserObjednavkaDetails(id,orderBy,orderType,limitDown,limitUp,searchStr,active,lang,mode)  
 {  

   document.getElementById('preloading').style.visibility = 'visible';


	 $.ajax({
	   type: "POST",
	   url: "result.php",
	   data: "mode=" + mode + "&id=" + id + "&orderBy=" + orderBy + "&orderType=" + orderType + "&limitDown=" + limitDown + "&limitUp=" + limitUp + "&search=" + searchStr + "&active=" + active + "&lang=" + lang,
	   success: function(html){       
	         document.getElementById('preloading').style.visibility = 'hidden';
	         $("#main-content").html(html);  
		 } 
	 });
	 
	 return false;
}





