var fila_actual="";

function encode_utf8( s )
{  
 return unescape( encodeURIComponent( s ) );
}

function decode_utf8( s )
{
 return decodeURIComponent( escape( s ) );
}


//innerText doesn't exists on firefox so we need to create it as a property
var isIE = (window.navigator.userAgent.indexOf("MSIE")> 0);  
if (! isIE){   
  HTMLElement.prototype.__defineGetter__("innerText",function () { return(this.textContent); });   
  HTMLElement.prototype.__defineSetter__("innerText",function (txt) { this.textContent = txt; });
    
} 


function close_fullscreen(){	
	//document.getElementById('fixeddiv').style.display='none';
	document.getElementById('ifscreen').style.display='none';
	document.getElementById('fscreen').style.display='none';
 }

function close_fullscreen2(){	
	document.getElementById('ifscreen').style.display='none';
	document.getElementById('fscreen').style.display='none';
}



 function show_fullscreen(){
    document.getElementById('fscreen').style.display='';

 }

function show_signupwdow(){
 show_fullscreen();
document.getElementById('ifscreen').style.display='';
document.getElementById('fscreen').style.display='';
 document.getElementById('ifscreen').style.width='491px';
llamarasincrono('signup.php','ifscreen',2);
 //setTimeout(' move_center_center();',1500);
}


function show_editwdow(id){
 show_fullscreen();
	document.getElementById('ifscreen').style.display='';
	document.getElementById('fscreen').style.display='';
  document.getElementById('ifscreen').style.width='491px';
 llamarasincrono('signup.php?a=edit&id='+id,'ifscreen',2);
 setTimeout('load_info();',2000);
}


function show_preminder(){
 //document.getElementById('fixeddiv').style.display='none';
 
 show_fullscreen();
document.getElementById('ifscreen').style.display='';
document.getElementById('fscreen').style.display='';
 document.getElementById('ifscreen').style.width='395px';
 llamarasincrono('password_reminder.php','ifscreen',2);
 //setTimeout(' move_center_center2();',1500);

}


function  cambiar_cursor(opcion) 
{
 if (opcion==1)
   document.body.style.cursor='pointer';
 if (opcion==2)
   document.body.style.cursor='';
   
}



function saveUser(doc,Form){//Create the user acount
 document.getElementById('uexists').style.display='none';
 var ue=document.getElementById('ue').value;
if (ue>0){
  document.getElementById('uexists').style.display='';
  document.getElementById('loading').style.display='none';
}
 else {
  var rsuces=0;
  var info="";
  var myForm=document.getElementById(Form);
  for (var i=0 ; i < myForm.length ; i++){ 
	fieldActive=myForm.elements[i];
	if ((typeof(fieldActive.name)!= "undefined")&&(typeof(fieldActive.name)!= "")) { //if 1

   if (fieldActive.name.indexOf("sl_")!=-1)
	{
	  info=info + fieldActive.name.substr(3)+"|";
	  info=info+doc.getElementById(fieldActive.name).value+";";
	}

   if ((fieldActive.name.indexOf("chk_")!=-1)&&(doc.getElementById(fieldActive.name).checked))
	  info=info + fieldActive.name.substr(4)+"|true;";

	if((fieldActive.name.indexOf("txt_")!=-1)&&(doc.getElementById(fieldActive.name).value))
	 info=info+fieldActive.name.substr(4)+"|$"+doc.getElementById(fieldActive.name).value+"$;";
	
	}//if 1
  }//for
  info=  info.substring(0,info.length-1);
  
  llamarasincrono('includes/functions/validations.php?string='+info,'vc',1); 
  setTimeout("validate('"+info+"');",3000);  
  
  }//si el usuario no existe



} // de la funcion 

function save()
{
   document.getElementById('loading').style.display='';
  llamarasincrono('signupAdd.php?a=eu&user='+document.getElementById('txt_username').value,'ue',1);

  setTimeout("saveUser(document,'signup')",4000); 
}



function  updateUser()
{
 if (document.getElementById('updateUser').value==1){
   alert("The information has been updated.");
  window.location.reload();
 }
}


function show_sitethumbnail(url){
 document.getElementById('tr_uthumbnail').style.display='';
 document.getElementById('lbl_txtpreview').innerText=url;
llamarasincrono('sitethumbnailpreview.php?site='+url,'uthumbnail',2);
}

function validate(data){
  var empty_fields=false;
  
  if (document.getElementById('txt_username').value=='')
	  var empty_fields=true;
   if (document.getElementById('txt_password').value=='')
	  var empty_fields=true;
   if (document.getElementById('txt_name').value=='')
	  var empty_fields=true;
   if (document.getElementById('txt_email').value=='')
	  var empty_fields=true;
   if (document.getElementById('txt_url').value=='')
	  var empty_fields=true;
   if (document.getElementById('sl_track_frequency').value=='-1')
	  var empty_fields=true;
   if (document.getElementById('txt_industrie').value=='')
	  var empty_fields=true;
	  
	  


	if ((empty_fields==false)&&(document.getElementById('vc').value==1)){

		llamarasincrono('signupAdd.php?a=su&datos='+data,'sup',1); 

    //setTimeout('if (document.getElementById("sup").value==1){alert("Thank you for your registration!!.");window.location="lvtool.php";}',7000);
      //setTimeout('alert("Thank you for your registration!!.");window.location="lvtool.php";',7000);
	   setTimeout("alert('Please check your email and then activate your account.');if (document.getElementById('action').value=='edit') close_fullscreen2(); else close_fullscreen();",7000);
  	}
	else{
	 alert("Please check the information provided.");
	}
 document.getElementById('loading').style.display='none';
}



function preminder_validate(){
 //document.getElementById('panswer').innerHtml="";
 document.getElementById('panswer').innerHTML='<img src="imgs/roller.gif" width="16" height="16" />';
 llamarasincrono('preminder.php?m='+document.getElementById('txt_email').value,'mail',1);
  setTimeout("preminder_confirm();",3000); 
}

function preminder_confirm(){
   var answer="";
   document.getElementById('panswer').innerHTML="";
   var ecomfirmed=document.getElementById('mail').value;
	if (ecomfirmed)
	 answer="We just sent the password to the provided email.";
	else 
	 answer="The email provided does not exists in our database.";

 document.getElementById('panswer').innerHTML=answer;
	
}


function obtener_valores(myForm,id){
  //llamarasincrono('tbl_backlinks.php?action=ea&id='+id,'cinvisible',2);
  var registros=document.getElementById('cinvisible').value;
  //var registros=document.getElementById('bien').value;
  //alert("información pasada desde php"+registros);
  myForm=document.getElementById(myForm);
  var r=false;
  for (var i=0 ; i < myForm.length ; i++){ 
	fieldActive=myForm.elements[i];
 	if ((typeof(fieldActive.name)!= "undefined")&&(typeof(fieldActive.name)!= "")) { //if 1
   // alert(fieldActive.name);
	 if ((((fieldActive.name.indexOf("txt_")!=-1)||(fieldActive.name.indexOf("sl_")!=-1))&&(fieldActive.value=="")||(fieldActive.value==-1))
	 ||((fieldActive.name.indexOf("chk_")!=-1)&&(fieldActive.checked==false)))
	 {//LLAVES
	   var componente=fieldActive.name.substr(fieldActive.name.indexOf("_")+1)+"|";
	   var posicion=registros.indexOf(componente);
	   var valor="";
	   var cadena="";
	   var temporal="";
	   var largo=componente.length;
	   //alert("este es el componente"+componente+"la posicion: "+posicion);
	   if (posicion>-1){
		 temporal=registros.substr(posicion+largo);
		 if (temporal.indexOf(';')>-1)
		    valor=temporal.substring(0,temporal.indexOf(';'));
		 else
		    valor=temporal.substring(0,temporal.length);	
		// alert("el componente real es: "+fieldActive.name+" el componente es: "+componente+ "la cadena es:"+valor);
		 if (fieldActive.name.indexOf("sl_")!=-1){
		   document.getElementById(fieldActive.name).value=valor;		   
		   if (fieldActive.name=="sl_ciudad")
		      imp_barrio();
		 }
		 else if (fieldActive.name.indexOf("txt_")!=-1){
		    if (fieldActive.name=="txt_construido"){//esto se hace para reemplazar el guión por un slash en el campo de fecha
			  document.getElementById(fieldActive.name).value=valor.replace("-", "/");
			  document.getElementById(fieldActive.name).value=document.getElementById(fieldActive.name).value.replace("-", "/");
			}  
			else  
			  document.getElementById(fieldActive.name).value=valor;
		 }
         else if ((fieldActive.name.indexOf("chk_")!=-1)&&(valor)){
		    document.getElementById(fieldActive.name).checked=true;
		 }		 
	   } 
	   r=true;
	 }//if 2 
	}//if 1
  }//for
 return (r);
}


 function update(id){
   
  var doc=document;
  var Form='signup';
  var ue=document.getElementById('updateUser').value;
  var rsuces=0;
  var info="";
  var myForm=document.getElementById(Form);
  for (var i=0 ; i < myForm.length ; i++){ 
	fieldActive=myForm.elements[i];
	if ((typeof(fieldActive.name)!= "undefined")&&(typeof(fieldActive.name)!= "")) { //if 1

   if (fieldActive.name.indexOf("sl_")!=-1)
	{
	  info=info + fieldActive.name.substr(3)+"|";
	  info=info+doc.getElementById(fieldActive.name).value+";";
	}

   if ((fieldActive.name.indexOf("chk_")!=-1)&&(doc.getElementById(fieldActive.name).checked))
	  info=info + fieldActive.name.substr(4)+"|true;";

	if((fieldActive.name.indexOf("txt_")!=-1)&&(doc.getElementById(fieldActive.name).value))
	 info=info+fieldActive.name.substr(4)+"|$"+doc.getElementById(fieldActive.name).value+"$;";
	
	}//if 1
  }//for
  info=  info.substring(0,info.length-1);
 
 
  llamarasincrono('tbl_backlinks.php?action=uu&datos='+info+'&llave='+id,'updateUser',1);
  setTimeout("updateUser()",500); 
 
 
 }
 
 


 
  function limpiarfondo(){
  
   if(document.getElementsByTagName){  
      var table = document.getElementById("competitorstbl");   
      var rows = table.getElementsByTagName("tr");   
      for(i = 0; i < rows.length; i++){           
            rows[i].className = ""; 
       }//for 
   }//if 1 
 }//function

 
 function iluminarfila(pos){
	fila_actual=document.getElementById('competitorstbl').rows[pos].id;
	document.getElementById('competitorstbl').rows[pos].className ='hlt';
 }
 
function show_competitorwdow(){
 window.scroll(0,0);
 show_fullscreen();
 document.getElementById('ifscreen').style.display='';
 document.getElementById('fscreen').style.display='';
 llamarasincrono('admCompetitors.php','ifscreen',2);
    document.getElementById('loading').style.display='';
}

function loguin_enter(myfield,e)//detecta el presionar el enter en el campo de buscar por código
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   document.forms[0].submit();
   return false;
   }
else
   return true;
}

function competitor_enter(myfield,e)//detecta el presionar el enter en el campo de buscar por código
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   create_competitor();
   return false;
   }
else
   return true;
}

function create_competitor(){
 setTimeout('window.location.reload();',10000);
document.getElementById('loading').style.display='';
llamarasincrono('manCompetitors.php?acc=add&id='+document.getElementById('id').value+'&url='+document.getElementById('txt_competitor').value+'&freq='+document.getElementById('ufrequency').value+'&ntupdate='+document.getElementById('nextUpdate').value,'ccompetitor',1);
  //  document.getElementById('loading').style.display='none';
  
}


function delete_competitor(site){
 if (confirm("Do you really want to delete this competitor?"))
 {
  llamarasincrono('manCompetitors.php?acc=del&ids='+site+'&id='+document.getElementById('id').value,'ccompetitor',1);
 setTimeout('if (document.getElementById("ccompetitor").value)window.location.reload();',5000);
 }
  //  document.getElementById('loading').style.display='none';
  
}


function getTittle(){
  llamarasincrono('includes/functions/metatags.php?acc=3&url='+ document.getElementById('competitorsUrl').value,'mtagsinfo',2);
}

function getKeywords(){
  llamarasincrono('includes/functions/metatags.php?acc=1&url='+ document.getElementById('competitorsUrl').value,'mtagsinfo',2);
}

 function getDescription(){
  llamarasincrono('includes/functions/metatags.php?acc=2&url='+ document.getElementById('competitorsUrl').value,'mtagsinfo',2);
}
