Number.prototype.NaN0=function(){return isNaN(this)?0:this;}

//return the string with no ending and begening spaces
function trim(txt) {
	return txt.replace(/^\s*|\s*$/g,"");
}

//returns the first parent Element found with the tag name especified
function getParentElementByTagName(node, type){
	if ( node ) {
		if ( node.parentNode ) {
			try{
				if ( node.parentNode.tagName.toLowerCase() == type.toLowerCase() ) 
					return node.parentNode;
				else
					return getParentElementByTagName( node.parentNode, type );
			}catch(e){}
		}
		else
			return null;
	}
	else
		return null;
}

//functions to add/remove event listeners
function addEvent( obj, type, fn ) {
	if ( obj.attachEvent ) {
  	obj['e'+type+fn] = fn;
   	obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } 
	else
  	obj.addEventListener( type, fn, false );
}
function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
  } 
	else
  	obj.removeEventListener( type, fn, false );
}

//get the position of an object from top and left of the window
function getRealLeft(obj) {
	xPos = obj.offsetLeft;
	tempEl = obj.offsetParent;
	while (tempEl != null) {
		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	return xPos;
}
function getRealTop(obj) {
	yPos = obj.offsetTop;
	tempEl = obj.offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop + tempEl.scrollTop;
		tempEl = tempEl.offsetParent;
	}		
	return yPos;
} 


/*
returns the position of an element in x and y coordenates
*/
function getPosition(e){
	
	var left = 0;
	var top  = 0;
	while (e.offsetParent){
		left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
		top += e.offsetTop + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);		
		if (e.parentNode && e.parentNode.tagName.toLowerCase() !='body'){
			left -= e.parentNode.scrollLeft;
			top  -= e.parentNode.scrollTop;
		}
		e = e.offsetParent;
	}
	left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
	top  += e.offsetTop + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
	return {x:left, y:top};
}

/* remove all child nodes of an object */
function removeChildNodesFromObj(obj){
	while (obj.childNodes.length > 0){
		obj.removeChild( obj.firstChild )
	}
}


/*this functions add caracters to any string */
function padLeft(_Str,thePad,howLong){
	var _temp = ''; thePad=thePad.charAt(0);
	for(var i=0; i< howLong-_Str.length; i++)
		_temp = thePad + _temp;
	return _temp + _Str;
}
function padRight(_Str,thePad,howLong){
	var _temp = '';thePad=thePad.charAt(0);
	for(var i=0; i< howLong-_Str.length; i++)
		_temp = thePad + _temp;
	return _Str + _temp;
}
function padBoth(_Str,thePad,howLong){
	var _temp = '';thePad=thePad.charAt(0);
	for(var i=0; i< howLong-_Str.length; i++)
		_temp = thePad + _temp;
	var _Str1 = _temp.substring(0,_temp.length/2);
	var _Str2 = _temp.substring(_Str1.length);
	return _Str2 + _Str + _Str1;
}

/* adds aJS includ to html head if not already included */
function addJsFileToHead(jsFilePath){
	if ( document.getElementsByTagName('head') ){
		if ( document.getElementsByTagName('head')[0].getElementsByTagName('script') ){
			var scripts = document.getElementsByTagName('head')[0].getElementsByTagName('script');
			var i=0;
			var scriptFound = false;
			for (i=0; i < scripts.length; i++){
				if ( scripts[i].src == jsFilePath ){
					scriptFound=true;
					break;
				}
			}
			if (!scriptFound){
				var js = document.createElement("script"); 
				js.setAttribute("type","text/javascript"); 
				js.setAttribute("src", jsFilePath );
				js.setAttribute("language", "javascript"); 
				document.getElementsByTagName("head")[0].appendChild(js);
				js=null;
			}
			scripts = null; i=null; scriptFound=null;
		}
	}
}

/* adds a CSS include to html head if not already included */
function addCSSFileToHead(CSSFilePath){
	if ( document.getElementsByTagName('head') ){
		if ( document.getElementsByTagName('head')[0].getElementsByTagName('link') ){
			var csss = document.getElementsByTagName('head')[0].getElementsByTagName('link');
			var i=0;
			var cssFound = false;
			for (i=0; i < csss.length; i++){
				if ( csss[i].getAttribute("href") == CSSFilePath ){
					cssFound=true;
					break;
				}
			}
			if (!cssFound){
				var css = document.createElement("link"); 
				css.setAttribute("type","text/css"); 
				css.setAttribute("rel","stylesheet");
				css.setAttribute("href", CSSFilePath );
				document.getElementsByTagName("head")[0].appendChild(css);
				css=null;
			}
			csss = null; i=null; cssFound=null;
		}
	}
}

/*returns the X and Y of the mouse given event argument */
function mouseCoords(ev){
	try {
		if(ev.pageX || ev.pageY){
			return {x:ev.pageX, y:ev.pageY};
		}
		return {
			x:ev.clientX + document.body.scrollLeft + document.documentElement.scrollLeft,   //- document.body.clientLeft,
			y:ev.clientY + document.body.scrollTop 	+ document.documentElement.scrollTop   //- document.body.clientTop
		};
	}
	catch(err){
		return {x:0, y:0};
	}
}

/*
returns the scroll of page
*/
function getPageScroll(){
	var x,y;
	if (self.pageYOffset) {
		// all except Explorer
		x = self.pageXOffset;
		y = self.pageYOffset;
	}	
	else if (document.documentElement && document.documentElement.scrollTop) {
		// Explorer 6 Strict
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (document.body) {
		// all other Explorers
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}
	return {x:x, y:y};
}

//returns the left characters of a string
function Left(str, n){
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
		return String(str).substring(0,n);
}

//returns the right characters of a string
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function selectedValue(select, value){
	//alert(select.options.length +'-'+ value);
	for(var i=0; i< select.options.length; i++){
		if (select.options[i].value == value){
			select.selectedIndex = i;
			return;
		}
	}
}

var commonUtils = new Object;

commonUtils.replaceEnterWithBr = function(text){ 
	return text.toString().replace(/\n/g, '<br>');
}

//cut a text with the length you want
commonUtils.cutLongWordsFromText = function(text, maxLength){
	var words = text.split(" ");
	var resultText = '';
	var i=0;
	for (i=0 ; i < words.length; i++ ) {
		while ( words[i].length > maxLength ) {
			resultText += words[i].substring(0, maxLength) + ' ' ;
			words[i] = words[i].substring(maxLength);
		}
		resultText += words[i] + ' ';
	}
	return resultText;
}

//cut every word that is longer than the given HTML text 
commonUtils.cutLongWordsFromHTMLText = function(text, maxLength){
	var origText = text;
	text = text.replace(/<\/?[^>]+>/gi, " "); //this replaces any tag with a space
	var words = text.split(" ");
	var i=0;
	var cutWord, origWord;
	for (i=0 ; i < words.length; i++ ) {
		if ( words[i].length > maxLength ){
			cutWord = '';
			origWord = words[i];
			while ( words[i].length > maxLength ) {
				cutWord += words[i].substring(0, maxLength) + " " ;
				words[i] = words[i].substring(maxLength);
			}
			cutWord += words[i] + ' ';
			//now replace in the original text the cut word
			origText=origText.replace(origWord, cutWord);
		}
	}
	words=cutWord=origWord=i=null;
	return origText;
}

commonUtils.getFormatDate = function(year,month,day){
	return year + "-" + month + "-" + day + " 00:00:00";
}

//this function finds any opening or closing HTML tag that doesn't follow the tree consistence and fixes it
commonUtils.normalizeHTMLtags = function(text){
	var tagsStack = new Array();
	var endOfTag = 0;	var firstSpace = 0;	var firstGreater = 0;
	var closingTab = '';
	for (var i=0; i < text.length; i++){
		//if an opening tag is found
		if ( text.charAt(i)=='<' && text.charAt(i+1) && text.charAt(i+1)!='/' && text.charAt(i+1)!=' ' ){
			firstGreater = text.indexOf('>', i) ;
			if (firstGreater == -1) firstGreater = text.length-1;
			firstSpace = text.indexOf(' ', i) ;
			if (firstSpace == -1) firstSpace = text.length-1;
			endOfTag = (firstSpace < firstGreater) ? firstSpace : firstGreater;
			tagsStack.push( text.substring(i + 1, endOfTag ) );
			i=endOfTag;
		}
		//if a closing tag is found
		else if ( text.charAt(i)=='<' && text.charAt(i+1) && text.charAt(i+1)=='/' ){
			firstGreater = text.indexOf('>', i);
			if (firstGreater == -1) firstGreater = text.length-1;
			firstSpace = text.indexOf(' ', i);
			if (firstSpace == -1) firstSpace = text.length-1;
			endOfTag = (firstSpace < firstGreater) ? firstSpace : firstGreater;
			closingTab = text.substring(i + 2, endOfTag );
			if ( tagsStack[tagsStack.length-1] == closingTab ){ //it is ok
				tagsStack.pop();
				i=endOfTag;
			}
			else{ //it is not ok
				if (tagsStack.length){
					//an other  ending tag should  be here, so I add it
					closingTab = tagsStack.pop();
					text = text.substring(0, i) + '</' + closingTab + '>' + text.substring(i);
					i += closingTab.length;
				}
				else{
					//the closing tab must be deleted, because there is no stack of opening tabs
					text = text.substring(0, i) + text.substring(endOfTag+1);
					i--; //so it continius analyzing from this point
				}
			}
		}
	}
	tagsStack=endOfTag=firstSpace=firstGreater=closingTab=null;
	return text;
}

//returs true if mail is valid
commonUtils.isValidEmail = function(eMail){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(eMail))
		return true;
	else
		return false;
}

//login function
function doBeforeLogin(frm){    
	if (frm.remember.checked){
		var expDate = addDaysToDate( new Date(), 30 )  ;
		setCookie('el_hood_remember_me', frm.argument_email.value, expDate, null, null, null);
		setCookie('el_hood_remember_me_pass', frm.argument_password.value, expDate, null, null, null);
	}
	else{
		deleteCookie('el_hood_remember_me', null, null)
		deleteCookie('el_hood_remember_me_pass', null, null)
	}
}


// ******************************************************************
// This function accepts a string variable and verifies if it is a
// proper date or not. It validates format matching either
// mm-dd-yyyy or mm/dd/yyyy. Then it checks to make sure the month
// has the proper number of days, based on which month it is.

// The function returns true if a valid date, false if not.
// ******************************************************************

function isDate(dateStr) {

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	
	if (matchArray == null) {
		//alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
		return false;
	}
	
	month = matchArray[1]; // p@rse date into variables
	day = matchArray[3];
	year = matchArray[5];

	if (month < 1 || month > 12) { // check month range
		//alert("Month must be between 1 and 12.");
		return false;
	}

	if (day < 1 || day > 31) {
		//alert("Day must be between 1 and 31.");
		return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		//alert("Month "+month+" doesn`t have 31 days!")
		return false;
	}

	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			//alert("February " + year + " doesn`t have " + day + " days!");
			return false;
		}
	}

	return true; // date is valid
}

/* this function replaces some characters by an "_" */
function removeCharacters(fileName)
{
	/* the characters in unicode are the vocals with accents in lowercase and uppercase, the enie, cz and open exclamation and open question signs */
	/* if this expresion is changed, the correspondent one in fileManager must be changed too, (GenericFileSaver.getFileName)!!!*/
	//var re = /(\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|-|_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$)/g;
	//var re = /(\u00E1|\u00E9|\u00ED|\u00FA|\u00F3|\u00DA|\u00C9|\u00F1|\u00FC|\u00DC|\u00BF|\u00C1|\u00CD|\u00D3|\u00A1|\u00C7|\u00E7|\u00D1|\u00C7|\u00E7|@|·|#|~|`|%|\*|\^|&|\(|\)|\+|\=|\[|\]|\}|\{|;|:|'|"|<|>|\?|\||\\|\!|\,|\$)/g;
	var re = /[^a-z0-9_\\.]/gi;
	var a="_";
	return fileName.replace(re, a);
}

// for change tab class
function changeTabSection(tabSelect, tabUnselect, sectionSelect, sectionUnselect){
	document.getElementById(tabSelect).className = 'tabSel';
	document.getElementById(tabUnselect).className = 'tabUnSel';
	document.getElementById(sectionSelect).style.display = 'block';
	document.getElementById(sectionUnselect).style.display = 'none';
}

//This function get a lookup and set in a select.
function fillSelect( lookupCommand, filter, targetSelect, notSelect){
	//filter example: |idCategoryField:3
	if(filter){
		var url = "/frontEnd/ElhoodCocoonGenerator.xml?invoke=nothing&lookup="+lookupCommand+filter+"&language="+globalLanguage;
	}
	else{
		var url = "/frontEnd/ElhoodCocoonGenerator.xml?invoke=nothing&lookup="+lookupCommand+"&language="+globalLanguage;
	}
	var xml = ajaxCall(url, null, null, null, true);
	getLookupResult(xml, targetSelect, notSelect);
}

function getLookupResult(xml, targetSelect, notSelect){
	try{
		var response = xml.getElementsByTagName('element');
		var select = document.getElementById(targetSelect);
		if (select.length != 1){
			var j=select.length;
			for (i=0 ; i<j ; i++){
				select.removeChild(select.firstChild);
			}
			if(!notSelect){
				newOption = document.createElement('option');
				if(globalLanguage == 'es'){
					newText = document.createTextNode('-- Seleccionar --');
				}
				if(globalLanguage == 'en'){
					newText = document.createTextNode('-- Select --');
				}
				newOption.appendChild(newText);
				select.appendChild(newOption);
			}
		}
		for (var i = 0; i<response.length; i++){
			newOption = document.createElement('option');
			newOption.value = response[i].getAttribute('id');
			newText = document.createTextNode(response[i].firstChild.nodeValue);
			newOption.appendChild(newText);
			select.appendChild(newOption);
		}
	}catch(e){}	
}


function changeRadioOption(plId, langId, genre) {
	var popRadio = window.open("/frontEnd/player.xhtml?xsl=radioPlayer.xsl&plid="+plId+"&language="+langId+"&component=&genre="+genre+"&invoke=nothing&nocache="+Math.random(),"CyloopRadioPlayer","width=350, height=790, scrollbars=no, toolbars=no, status=no, resizeable=no");
		popRadio.focus();
}

function popUpWindowAdvanced(width,height,id){
  // for the future
}

function goHome(){
	document.frmCallHome.submit();
}
/*BROWSERS CSS SELECTOR*/
/*.ei .ei6 .ei7 .gecko*/
var css_browser_selector = function() {
	var 
		ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();

function openPopupLayer(layerId){
	var layer = document.getElementById(layerId);
	layer.style.display = 'block';
	allFlashesVisibility('hidden');
}
function closePopupLayer(layerId){
	var layer = document.getElementById(layerId);
	layer.style.display = 'none';
	allFlashesVisibility('visible');
}
function allFlashesVisibility(state){ // visible or hidden
	var flashes = document.getElementsByTagName('object');
	for (i=0;i<flashes.length;i++){
		flashes[i].style.visibility=state;
	}
}

function changeMultimediaTab(section){
		var IE = navigator.appName.indexOf("Microsoft") != -1;
		var swfObj = IE ? musicPlayer_public : window.document.musicPlayer_public;
		var music = document.getElementById('multimediaTabHomeMusic');
		var video = document.getElementById('multimediaTabHomeVideo');
		if(section == 'video'){
			video.style.display = 'block';
			music.style.display = 'none';
			try{ swfObj.pausePlayer(); }catch (e){};
		}else{
			video.style.display = 'none';
			music.style.display = 'block';	
			setTimeout('window.document.musicPlayer_public.startPlayer()',2000);
		}
	
}

var currentLayer;
function displayPopUpLayer(layerBkg, layerImg, divCont){

	if(argument_terra && layerBkg == 'loginFormBackground'){
		//redirect to login terra
		document.frmTerraLogin.submit();
	}else{

		var container = document.getElementById('container');
		var divLayer = document.getElementById(layerBkg);
		var divLayerImg = document.getElementById(layerImg);
		var divContainer = document.getElementById(divCont);
		
		//Get width and heigth of container.
		var bodydocument = document.getElementsByTagName('body');
		var backgroundHeight = Element.getHeight(bodydocument[0]);
		var backgroundWidth = Element.getWidth(bodydocument[0]);
		
		//set all flashes Hidden
		allFlashesVisibility('hidden');
		
		//Set block the background div
		divLayer.style.display = 'block';
	currentLayer = layerBkg;
		
		//Set width and heigth of container to Background div
		divLayer.style.height = backgroundHeight + 'px';
		divLayer.style.width = backgroundWidth + 'px';
		
		//set position on popup
		this.browser = new BrowserSniffer();
		if (this.browser.isMsie  && this.browser.VersionMinor <= 7 ){
			var windowOffset = window.document.documentElement.scrollTop;
			var offset = windowOffset + 100;
		}
		else{
			var windowOffset = window.pageYOffset;
			var offset = windowOffset + 100;
		}
		divLayerImg.style.top = offset + 'px';
		divContainer.style.top = offset + 'px';
	}
}
function sendAddComment(idAuthor, idTarget, isHomePage){
	var elem = document.getElementById('addCommentText');
	var val=elem.value.replace(/</g,'&lt;').replace(/>/g,'&gt;');
	var text = new String(replaceForUsrText(val));
	var textToPaste = new String(val);
	if(text.length > 0) {
		var url = 'xsl=none&component=profileMgr&invoke=addComment&argument_idUserAuthor=' + idAuthor + '&argument_idUserTarget=' + idTarget + '&argument_idPhoto=&argument_size=&argument_image=&argument_text=' + text;
		jQuery.ajax({
			type: "POST",
			url: "/frontEnd/sarasa.xhtml",
			data: url,
			success: function(xml){
				setAddComment(xml, idAuthor, textToPaste,isHomePage);
				allFlashesVisibility('visible');
			}
		});
	}
}

function setAddComment(xml, idAuthor, text, isHomePage){
	document.getElementById('addCommentText').value = '';

	
	var XmlDoc = xml;
	var userinfo = XmlDoc.getElementsByTagName("userinfo");
	var usrImageSrc = '/images/no_picture_sm.gif';
		try {
			if (userinfo[0].getElementsByTagName("image")[0].firstChild.nodeValue){
				var sourceImg = userinfo[0].getElementsByTagName("source")[0].firstChild.nodeValue;
				var photo = userinfo[0].getElementsByTagName("image")[0].firstChild.nodeValue;
				usrImageSrc = '/storage/storage?fileName=/'+ sourceImg + '/' +idAuthor + '/image/thumbnail/' + photo
			}
		}catch(e){};
	var nickname = userinfo[0].getElementsByTagName("nickname")[0].firstChild.nodeValue;
	var foldername = userinfo[0].getElementsByTagName("foldername")[0].firstChild.nodeValue;
	var date = userinfo[0].getElementsByTagName("issued")[0].firstChild.nodeValue;

	var result;
	result ='<div class="commentRowContainer2">';
	result += '<div class="commentImg">';
	result += '  <a href="/' + foldername + '"><img style="margin-top: 3px;" class="link" src="'+usrImageSrc+'" border="0" height="60" width="60"></a>';
	result += '</div>';

	if(!isHomePage)
		result += '<div style="overflow: hidden; width: 622px;" class="commentInfo">';
	else
		result += '<div class="commentInfo">';

	result += '<div class="commentTitle">';
	result += '<span style="margin-left: 5px; line-height: 20px;" class="floatLeft">';
	result += nickname + '&nbsp;|&nbsp;';
	result += '</span>';
	result += '<span style="line-height: 20px;" class="floatLeft">';
	result += formatPopDate(date);
	result += '</span><div class="br"></div></div>';
	
	if(!isHomePage)
		result += '<div style="overflow: hidden;" class="bodyFontColor">';
	else
		result += '<div style="overflow: auto;" class="bodyFontColor">';	
	
	result += text;
	result += '<br>';
	result += '</div></div><div class="br"></div></div>';

	var currDiv = document.getElementById('CommentList');
	var temp = new String( currDiv.innerHTML );

	currDiv.innerHTML = result;
	if(temp.substring(0,3) != "<p>")
		currDiv.innerHTML += temp;
	
	//closePopupLayer('addFriendPopUpElements'); 
}

function formatPopDate(d){
	var d = new Date();
	return ((d.getMonth()<9)?"0":"") + (d.getMonth()+1) + "/" + d.getDate() + "/" + d.getFullYear();
}

function sendFriendRequest(idAuthor, idTarget){
	var url = '/frontEnd/sendFR.xhtml?xsl=none&component=userMgr&invoke=createFriendRequest&argument_dataMap_idAuthor=' + idAuthor +'&argument_dataMap_idTarget=' + idTarget + '&language=' + globalLanguage;
	var xml = ajaxCall(url, null, null, null, true);
	commonPopUp.close('addFriendsTitle','addFriendPopUpElements');
	document.location.reload();
}
function sendAddFavorites(idUser, idArtist){
	var url = '/frontEnd/sendFR.xhtml?xsl=none&component=userMgr&invoke=addHoodmark&argument_idUser=' + idUser +'&argument_idArtist=' + idArtist + '&language=' + globalLanguage;
	var xml = ajaxCall(url, null, null, null, true);
	commonPopUp.close('addFavoritesTitle','addToFavoritesElements');
	document.location.reload();
}

function getHost() {
	var url = window.location.href;
	var nohttp = url.split('//')[1];
	var hostPort = nohttp.split('/')[0];
	return hostPort;
}

function getURLVar( pDelimeter, pPos ) {
	var url = document.URL;
	var noHttp = url.split('//')[1];
	var urlVar = noHttp.split( pDelimeter )[ pPos ];
	return urlVar;
}

function cityKeyUpMethod(obj,ev,comboStateId,paren){
	if (ev.keyCode){ // cases to avoid the city input
		if ((ev.keyCode!=32)&&($(obj.id).value.length>=1)&&(ev.keyCode!=13)) $(obj.id+'_hidden').value='';
		if ((ev.keyCode==40)||(ev.keyCode==38)) $(obj.id+'_hidden').value=''; // UP or DOWN arrow
	}
	var rnd=Math.random();
	var stateValue=document.getElementById(comboStateId).value;
	if(document.getElementById(comboStateId).value!='')
		ajax_showOptions(obj,'xsl=searchCities.xsl&invoke=nothing&lookup=cities|idRegionField:'+ stateValue +';cityName:'+obj.value+'%25&language=&rnd='+rnd,ev,null,paren);
	/*
	if ($(obj.id+'_hidden').value=='') 
		alert($('artistPrefs').getAttribute('language')=='es'?'Debe ingresar el campo Ciudad':'Please enter the City');
	*/
}
			
function param( name ){
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp ( regexS );
	var tmpURL = window.location.href;
	var results = regex.exec( tmpURL );
	if( results == null )
		return"";
	else
		return results[1];
}
function globalEspanish(){
	if (!argument_terra) var argument_terra=0;
	var url = window.location.href;
	var language = '';
	if(url.indexOf("/artistas")!=-1 
		|| url.indexOf("/gente")!=-1 
		|| url.indexOf("/musica")!=-1 
		|| url.indexOf("/registrate")!=-1 
		|| url.indexOf("/registrar_artista")!=-1 
		|| url.indexOf("/aviso_legal")!=-1 
		|| url.indexOf("/privacidad")!=-1 
		|| url.indexOf("/consejos_de_seguridad")!=-1 
		|| url.indexOf("/comunidad")!=-1 
		|| url.indexOf("/comentarios")!=-1
		|| url.indexOf(".es")!=-1
		|| argument_terra == 1){
		language = 'es';
	}else{
		language = 'en';
	}
	return language;
}
// LogOut Function --------------------------------------------------------------
function redirectLogOut(){
	var expDate = addDaysToDate( new Date(), 365 );
	setCookie('ElhoodLogin', '081240105039217099080020', expDate, '/', null, null);
	window.location.href='/';
}
// ------------------------------------------------------------------------------

// Return the Host Partner
function getPartner(){
	if (!argument_terra) var argument_terra=0;
	var host = getHost();
	var partner;
	if(host.indexOf("terra")!=-1 || argument_terra == 1){
		partner = 'TERRA';
	}else{
		partner = 'ELHOOD';
	}
	return partner;
}
