// 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



// 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.style.color = "#E1D6D6";
			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 = "#E1D6D6";
			obj.value = LGemail;
		}
		
	} 
	
}


addEvent(window, 'load', hideFocusBorders);
addEvent(window, 'load', LoginTextControlInit);

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);
}

/**
 * @date 10/01/2011
 * @author Jesús García
 * Permite ajustar la distribución de los menús adaptado al tamaño.
 */

addEvent(window, 'load', function(){	
	$$('ul.menu li').each(function(el){	
		addEvent(el, 'mouseover', function()
		{					
			var ul= el.getElement('ul');						
			
			if (ul != null)
			{								
				var ulParent = ul.getParent().getParent();
				
				if (ulParent.hasClass('menu') == false)
				{

					var parentN = ulParent.getCoordinates();
					var childN = ul.getCoordinates();
										
					if (childN.right > parentN.left)
					{						
						var marginLeft = -(parentN.width + childN.width - 15);						
						var marginTop = -40;
						
						if(/MSIE 7.0/i.test(navigator.userAgent)) {
							marginLeft = -(parentN.width + childN.width - 30);
							marginTop = -25;																
						}
						ul.setStyle('margin-left', marginLeft + "px" );							
						ul.setStyle('margin-top', marginTop + "px" );
						ul.addClass('visible');						
					}
					
				} else
				{				
					var parentN = ul.getParent().getCoordinates();
					var childN = ul.getCoordinates();	
					var limit = 20;
					
					if (((parentN.right + limit) < (childN.right)))
					{															
						marginLeft = parentN.right - childN.right + limit;
						ul.setStyle('margin-left', marginLeft + "px" );																	
						
						ul.addClass('visible');						
						
						if(/MSIE 7.0/i.test(navigator.userAgent)) {
							
							var elements = ul.getElements('li');	
							
							var widthaux = ul.getCoordinates().width;							
							
							for (cli = 0; cli < elements.length; cli++)
							{
								elements[cli].setStyle('width', widthaux);
							}						
						}
					}				
				}
			}
		});
	});	
});
