// Copyright (C) 2005 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Distribute this code, any part or any modified version of it.
//     Instead, you can link to the homepage of this code:
//     http://www.php-development.ru/javascripts/smart-forms.php.
//
// YOU MAY
// (1) Use this code on your website.
// (2) Use this code as a part of another product provided that
//     its main use is not creating javascript menus.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind, either
// expressed or implied, including, but not limited to, the implied warranties
// of merchantability and fitness for a particular purpose. You expressly
// acknowledge and agree that use of this code is at your own risk.

// If you find my script useful, you can support my site in the following ways:
// 1. Vote for the script at HotScripts.com (you can do it on my site)
// 2. Link to the homepage of this script or to the homepage of my site:
//    http://www.php-development.ru/javascripts/smart-forms.php
//    http://www.php-development.ru/
//    You will get 50% commission on all orders made by your referrals.
//    More information can be found here:
//    http://www.php-development.ru/affiliates.php

// ----- Popup Control ---------------------------------------------------------   

Shadowbox.loadSkin('classic', '../includes/shadowbox/src/skin'); // use the "classic" skin
Shadowbox.loadLanguage('en', '../includes/shadowbox/src/lang'); // use the English language
Shadowbox.loadPlayer(['img'], '../includes/shadowbox/src/player'); // use img and qt players

    
function at_display(x)
{
  win = window.open();
  for (var i in x) win.document.write(i+' = '+x[i]+'<br>');
}

// ----- Show Aux -----

function at_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);  

  var top  = (c["at_position"] == "y") ? p.offsetHeight+2 : 0;
  var left = (c["at_position"] == "x") ? p.offsetWidth +2 : 0;  
    
  
  
  /*
  for (; p; p = p.offsetParent)
  {  	
    top  += p.offsetTop;
    left += p.offsetLeft;  
  }      */    
      
  if (navigator.appName.indexOf('Microsoft') >= 0){  	
  	left = p.offsetParent.offsetLeft + p.offsetLeft;
  } else {
  	left = p.offsetLeft;
  }  
        
  if (left + c.offsetWidth > 1020){
	left=left+(p.offsetWidth-c.offsetWidth)-3;
  }      
  
  top = 55;
  
  c.style.position   = "absolute";
  c.style.top        = top +'px';
  c.style.left       = left+'px';  
  c.style.visibility = "visible";      
}

// ----- Show -----

function at_show()
{	
  p = document.getElementById(this["at_parent"]);
  c = document.getElementById(this["at_child" ]);

  at_show_aux(p.id, c.id);

  clearTimeout(c["at_timeout"]);
}

// ----- Hide -----

function at_hide()
{		
  c = document.getElementById(this["at_child"]);        
  c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", 100);  
}

// ----- Click -----

function at_click()
{
  p = document.getElementById(this["at_parent"]);
  c = document.getElementById(this["at_child" ]);

  if (c.style.visibility != "visible") at_show_aux(p.id, c.id);
  else c.style.visibility = "hidden";

  return false;
}



function at_attach(parent, child, showtype, position, cursor)
{				  	    		
  p = document.getElementById(parent);
  c = document.getElementById(child);                          
     
  id = p.id.substr(9, p.id.length);                     
  
  color = document.getElementById('link'+id).style.color;
  
  if (typeof(oldcolor) != 'undefined'){
  	  document.getElementById('link'+oldid).style.color = oldcolor;
  }  
  oldid = id;
  oldcolor = document.getElementById('link'+id).style.color;
  
  if (p == null || c == null){
  	return true;
  }
  
  

  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {
    case "click":
      p.onclick     = at_click;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
    case "hover":        
      p.onmouseover = at_show;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
  }  
}       

function comprobarcapa(id, e){
		
	var o = document.getElementById('div'+id);
	var d = document.getElementById('divparent'+id);	
	
	if (!document.all)
	       {
	       event = e;
	       py = e.pageY; 
	       px = e.pageX;
	       }
	else{		
	       py = event.clientY +document.body.scrollTop; 
	       px = event.clientX +document.body.scrollLeft;
	       }		
	       	
	diferencia = ((document.body.offsetWidth - 1024)/2) + 27;		       		
	px = px - diferencia;       
	       	
	ladoizquierdo = o.offsetLeft;
	ladoderecho = o.offsetLeft + o.offsetWidth;
	ladosuperior = d.offsetTop;
	ladoinferior = o.offsetTop + o.offsetHeight;
			
		if (px < ladoizquierdo || px > ladoderecho || py > ladoinferior){
			document.getElementById('link'+id).style.color = 'black';
		}
			
}
correcto = 0;
alturaold = 0;

function alturaCorrecta()
{
/*		
	if (document.getElementById("right2")){				
    
    
    alturaTotal=document.getElementById("right2").offsetHeight;      		
		altura=document.getElementById("content121").offsetHeight; //Obtiene la altura de "contenido"
		alturawhitebox=document.getElementById("content12").offsetHeight; //Obtiene la altura de "contenido"
		alturatop=document.getElementById("steps").offsetHeight; //Obtiene la altura de "contenido"		  
				
		if(alturaTotal>altura){ //Si "contenido" no supera a "altura"			
			if (alturaold == 0){
			  alturaold = parseInt(alturaTotal + 20);
			}
			document.getElementById("content12").style.height = parseInt((alturaTotal+alturatop+20)) + "px"; //La altura de "contenido" default
			correcto = 1;
		}
		
		else if (alturawhitebox < (altura+alturatop + 30)){ //Si si lo supera		
			if (alturaold == 0){
			  alturaold = parseInt(altura + 30);	
			}
			document.getElementById("content12").style.height = parseInt((altura+alturatop +30)) + "px"; //La altura de "contenido" se hace adaptable						
			correcto = 1;
		} 
    
    if (document.getElementById("innerleft2").offsetHeight > document.getElementById("left2").offsetHeight){     
      document.getElementById("content12").style.height = (parseInt(document.getElementById("innerleft2").offsetHeight) + 30) + "px";  
    }         
	}
*/
}

function restoreAltura(){	
	document.getElementById("content12").style.height = parseInt(alturaold + alturatop) + "px"; 
	alturaCorrecta();
}

if (correcto != 1){
  setTimeout('alturaCorrecta()', 100);
}


// CODIGO PARA ELIMINAR LOS BORDES DE LOS A 
//add event function   
function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, true); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}
                         



//Find all link elements and add an onfocus attribute and value   
function hideFocusBorders(){	

  Shadowbox.init();  
  
	var theahrefs = document.getElementsByTagName("a");
	
	if (!theahrefs){		
		return;
	}
	
	for(var x=0;x!=theahrefs.length;x++){				
		theahrefs[x].onfocus = function stopLinkFocus(){this.hideFocus=true;};
	}                      
}

      
// HTMLENTITIES
String.prototype.htmlEntities = function () {   
   return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
};

// ADDSLASHES
function addslashes(str) {
  str=str.replace(/\'/g,'\\\'');
  str=str.replace(/\"/g,'\\"');
  str=str.replace(/\\/g,'\\\\');
  str=str.replace(/\0/g,'\\0');
  return str;
}
// STRIPSLASHES
function stripslashes(str) {
  str=str.replace(/\\'/g,'\'');
  str=str.replace(/\\"/g,'"');
  str=str.replace(/\\\\/g,'\\');
  str=str.replace(/\\0/g,'\0');
  return str;
}



//PLUGIN DE PUNTUACION DE ESTRELLAS
starsid = 0;
starsrating = 0;
desactivarstars = 0;	
checklogin = 0;


function checkfocus(){

  
	if (typeof($cdAjaxVote) == 'function'){
    if (checklogin == 1){
      checklogin = 0;
    } else {
	    $cdAjaxVote("div#cd_ajaxvote_" + starsid).find("a#link"+starsrating).focus();	  
    }
	} 
}

// Controla el texto de los inputs (correo electrónico y contraseña)
var LGemail = 'Correo electrónico';

function LoginTextControlInit(){
	var username = document.getElementById('modlgn_username');
	
		if(username != null && !username.value){
			username.style.color = "#B4BED2";
			username.value = LGemail;
		}
		
}

function LoginTextControl(obj){
	
	if(obj.id == 'modlgn_username'){
		if(obj.value == LGemail){
			obj.style.color = "#000000";
			obj.value = '';
			
		} else if(!obj.value){
			obj.style.color = "#B4BED2";
			obj.value = LGemail;
		}
		
	} 
	
}


addEvent(window, 'load', hideFocusBorders);

function isInteger(s) {
  var n = trim(s);
  return n.length > 0 && !(/[^0-9]/).test(n);
}

function isFloat(s) {
  var n = trim(s);
  return n.length>0 && !(/[^0-9.]/).test(n) && (/\.\d/).test(n);
}




 
