/*
    Plugin: iframe autoheight jQuery Plugin
    Author: original code by NATHAN SMITH; converted to plugin by Jesse House
    File: jquery.iframe-auto-height.plugin.js
    Description: when the page loads set the height of an iframe based on the height of its contents
    Remarks: original code from http://sonspring.com/journal/jquery-iframe-sizing
    Version: 1.0.0 - see README: http://github.com/house9/jquery-iframe-auto-height
*/
(function ($)
{
    $.fn.iframeAutoHeight = function (options)
    {
        // set default option values
        var options = $.extend({ heightOffset: 0 }, options);

        // iterate over the matched elements passed to the plugin
        $(this).each(function () {
            // Check if browser is Opera or Safari(Webkit so Chrome as well)
            if ($.browser.safari || $.browser.opera) {  // || $.browser.msie || $.browser.mozilla
                // Start timer when loaded.
                $(this).load(function () {
                    var iframe = this;
                    // var delayedResize = function () {
                        resizeHeight(iframe);
                    // };
                    // setTimeout(delayedResize, 0);
                    // delayedResize();
                });

                // Safari and Opera need a kick-start.
                /*var source = $(this).attr('src');
                $(this).attr('src', '');
                $(this).attr('src', source);*/
            } else {
                // For other browsers.
                $(this).load(function () {
                    resizeHeight(this);
                });
            }

            // resizeHeight
            function resizeHeight(iframe) {
                // Set inline style to equal the body height of the iframed content plus a little
                var newHeight = iframe.contentWindow.document.body.offsetHeight - options.heightOffset;
                iframe.style.height = newHeight + 'px';
            }
        }); // end
    }
})(jQuery);








function isValidEmail(emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		//alert("Email address seems incorrect (check @ and .'s)");
		alert("Parece incorrecta la dirección de correo electrónico (@ y comprobar. S)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			//alert("Ths username contains invalid characters.");
			alert("Ths nombre de usuario contiene caracteres no válidos.");
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			//alert("Ths domain name contains invalid characters.");
			alert("Ths nombre de dominio contiene caracteres no válidos.");
			return false;
		}
	}
	if (user.match(userPat)==null) {
		//alert("The username doesn't seem to be valid.");
		alert("El nombre de usuario no parece ser válida.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				//alert("Destination IP address is invalid!");
				alert("Dirección IP de destino no es válido!");
				return false;
	   		}
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			//alert("The domain name does not seem to be valid.");
			alert("El nombre de dominio no parece ser válida.");
			return false;
	   }
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 &&
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		//alert("The address must end in a well-known domain or two letter " + "country.");
		alert("La dirección debe acabar en un conocido o de dominio de dos letras "+" país.");
		return false;
	}
	// Make sure there's a host name preceding the domain.
	if (len<2) {
		//alert("This address is missing a hostname!");
		alert("Esta dirección se encuentra un nombre!");
		return false;
	}
	return true;
}






var frm;
var form;
function checkDuplicate(frm,table,objField,objId,objMode,objparentId,objExtra)
{
	var PostParam = "";
	var ext_where_param = '';
	form = frm;
	with(frm)
	{
		var Field_val = document.getElementById(objField).value;

		var Id_val = document.getElementById(objId).value;
	}

	extra = '';

	if(objparentId)
	{
		var PId_val = document.getElementById(objparentId).value;
		if(PId_val!='')
			extra += "&PId_val="+PId_val+"&PId="+objparentId;
		else
			extra += "&PId_val=0&PId="+objparentId;
	}
	if(document.getElementById('member_type'))
	extra += "&member_type="+member_type;

	if(document.getElementById(objExtra)){
		if(document.getElementById(objExtra).value != ''){
			extra += "&iParentId="+document.getElementById(objExtra).value;
		}
	}

	PostParam = "table="+table+"&mode="+objMode.value+"&Field_val="+Field_val+"&Id_val="+Id_val+"&Field="+objField+"&Id="+objId+extra;
	PostParam = PostParam  + ext_where_param;
	var url = SITE_AJAX_URL+"checkDuplicateRecord.php?";
	var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
	var params = PostParam;
  	url = url+PostParam;
	//alert(url);
	//return false;
	if (window.XMLHttpRequest)
	{
        http = new XMLHttpRequest();
        http.onreadystatechange = handleHttpResponse_status;
		http.open("post", url, true);
        http.setRequestHeader("Content-Type", contentType);
        http.send(params);
        status = true;
		// ActiveX XMLHttpRequest object
    }
	else if (window.ActiveXObject)
	{
        http = new ActiveXObject("Microsoft.XMLHTTP");
        if (http)
		{
            http.onreadystatechange = handleHttpResponse_status;
            http.open("post", url, true);
            http.setRequestHeader("Content-Type", contentType);
			http.send(params);
            status = true;
        }
    }
}
function handleHttpResponse_status()
{
	if (http.readyState == 4)
	{
      	isWorking = false;
/*		alert(http.responseText);
		return false;*/
    	if (http.responseText.indexOf('invalid') == -1)
		{

    		var xmlDocument = http.responseXML;
    		var existId = xmlDocument.getElementsByTagName('exist').item(0).firstChild.data;
			var field = xmlDocument.getElementsByTagName('field').item(0).firstChild.data;
		/*	alert(field);
			return false;*/
			if(existId == '1')
			{
				if(field == 'vEmail'){
					alert("Dirección E-Mail ya existe.");
					return false;
				}else if(field == 'vCategory'){
					alert("Product Category Already Exist.");
					return false;
				}else if(field == 'vProductName'){
					alert("Product Already Exist.");
					return false;
				}else if(field == 'vUrl'){
					alert("Esta tienda es url ya asignar a otro almacén.");
				}if(field == 'tComment'){
					alert("Usted ya ha dado un comentario para este artículo.");
					return false;
				}else{
					alert("Registro ya existen.");
					return false;
				}
			}
			else
			{
				form.submit();
			}
		}
	}
}








var frm;
var returrnnn = 0;
var submit_form = 'No';
function checkDuplicateUrl(frm,table,objField,objId,objMode,objparentId,objExtra,submitfrm) {
	var PostParam = "";
	var ext_where_param = '';
    if(!submitfrm){
        submitfrm = 'No';
    }else{
        submit_form = submitfrm;
    }
	form = frm;
	extra = '';
    with(frm)
	{
		//var Field_val = document.getElementById(objField).value;
        //&Field_val="+Field_val+"
        //&Field="+objField+"
        objFieldArr =  objField.split(',');
        for(i=0;i<objFieldArr.length;i++){
            extra+= "&Field[]="+objFieldArr[i]+"";
            Field_val = document.getElementById(objFieldArr[i]).value;
            extra+= "&Field_val[]="+Field_val+"";
        }

		var Id_val = document.getElementById(objId).value;
	}


	if(objparentId)
	{
		var PId_val = document.getElementById(objparentId).value;
		if(PId_val!='')
		extra += "&PId_val="+PId_val+"&PId="+objparentId;
		else
		extra += "&PId_val=0&PId="+objparentId;
	}
	if(document.getElementById('member_type'))
	extra += "&member_type="+member_type;


	if(document.getElementById(objExtra)){
		if(document.getElementById(objExtra).value != ''){
			extra += "&iParentId="+document.getElementById(objExtra).value;
		}
	}

	//PostParam = "table="+table+"&mode="+objMode.value+"&Field_val="+escape(Field_val)+"&Id_val="+Id_val+"&Field="+objField+"&Id="+objId+extra;
   PostParam = "table="+table+"&mode="+objMode.value+"&Id_val="+Id_val+"&Id="+objId+extra;
	PostParam = PostParam  + ext_where_param;
	var url = SITE_AJAX_URL+"checkDuplicateUrl.php?";
	var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
	var params = PostParam;
  	url = url+PostParam;
	//alert(url);
	//return false;
	if (window.XMLHttpRequest)
	{
        httpss = new XMLHttpRequest();
        httpss.onreadystatechange = handleHttpResponse_status_url;
		httpss.open("post", url, true);
        httpss.setRequestHeader("Content-Type", contentType);
        httpss.send(params);
        status = true;
		// ActiveX XMLHttpRequest object
    }
	else if (window.ActiveXObject)
	{
        httpss = new ActiveXObject("Microsoft.XMLHTTP");
        if (httpss)
		{
            httpss.onreadystatechange = handleHttpResponse_status_url;
            httpss.open("post", url, true);
            httpss.setRequestHeader("Content-Type", contentType);
			httpss.send(params);
            status = true;
        }
    }
}

function handleHttpResponse_status_url()
{
   //alert("sa");
	if (httpss.readyState == 4)
	{
      	isWorking = false;
		/*alert(http.responseText);
		return false;*/
    	if (httpss.responseText.indexOf('invalid') == -1)
		{
    		var xmlDocument = httpss.responseXML;
    		var existId = xmlDocument.getElementsByTagName('exist').item(0).firstChild.data;
			var field = xmlDocument.getElementsByTagName('field').item(0).firstChild.data;
            //alert(submit_form);return false;
			if(existId == '1')
			{
				if(field == 'vUrl' || field == 'vUrlTitle'){
					alert(MSG_URL_UNIQUE_ALREADY_EXISTS);
				}else if(field == 'tTitle'){

					alert( "This Page Title has already been assigneed. Please enter another.");
				}else if(field == 'vMeta_Description'){
					alert( "This Meta Description has already been assigneed. Please enter another.");
				}
                returrnnn=  0;
				return false;
			} else {
			   returrnnn=  1;
			}
		}
	}
}








function simpleFindObj(name, inLayer) {
	return document[name] || (document.all && document.all[name])
		|| (document.getElementById && document.getElementById(name))
		|| (document.layers && inLayer && document.layers[inLayer].document[name]);
}

var clockIncrementMillis = 60000;
var localTime;
var clockOffset;
var clockExpirationLocal;
var clockShowsSeconds = false;
var clockTimerID = null;


function clockInit(localDateObject, serverDateObject)
{
	var origRemoteClock = parseInt(clockGetCookieData("remoteClock"));
    var origLocalClock = parseInt(clockGetCookieData("localClock"));
    var newRemoteClock = serverDateObject.getTime();
    var newLocalClock = localDateObject.getTime();
    var maxClockAge = 60 * 60 * 1000;   // get new time from server every 1hr

    if (newRemoteClock != origRemoteClock) {
        document.cookie = "remoteClock=" + newRemoteClock;
        document.cookie = "localClock=" + newLocalClock;
        clockOffset = newRemoteClock - newLocalClock;
        clockExpirationLocal = newLocalClock + maxClockAge;
        localTime = newLocalClock;  // to keep clockUpdate() happy
    }
    else if (origLocalClock != origLocalClock) {
        clockOffset = null;
        clockExpirationLocal = null;
    }
    else {
        clockOffset = origRemoteClock - origLocalClock;
        clockExpirationLocal = origLocalClock + maxClockAge;
        localTime = origLocalClock;
    }
    var nextDayLocal = (new Date(serverDateObject.getFullYear(),
            serverDateObject.getMonth(),
            serverDateObject.getDate() + 1)).getTime() - clockOffset;
    if (nextDayLocal < clockExpirationLocal) {
        clockExpirationLocal = nextDayLocal;
    }
	clockToggleSeconds();
}
function clockOnLoad()
{
    clockUpdate();
}

function clockOnUnload() {
    clockClearTimeout();
}

function clockClearTimeout() {
    if (clockTimerID) {
        clearTimeout(clockTimerID);
        clockTimerID = null;
    }
}

function clockToggleSeconds()
{
    clockClearTimeout();
    if (clockShowsSeconds) {
        clockShowsSeconds = false;
        clockIncrementMillis = 60000;
    }
    else {
        clockShowsSeconds = true;
        clockIncrementMillis = 1000;
    }
    clockUpdate();
}

function clockTimeString(inHours, inMinutes, inSeconds) {
    return inHours == null ? "-:--" : ((inHours == 0
                   ? "12" : (inHours <= 12 ? inHours : inHours - 12))
                + (inMinutes < 10 ? ":0" : ":") + inMinutes
                + (clockShowsSeconds
                   ? ((inSeconds < 10 ? ":0" : ":") + inSeconds) : "")
                + (inHours < 12 ? " AM" : " PM"));
}

function clockDisplayTime(inHours, inMinutes, inSeconds) {

    clockWriteToDiv("ClockTime", clockTimeString(inHours, inMinutes, inSeconds));
}

function clockWriteToDiv(divName, newValue) // APS 6/29/00
{
    var divObject = simpleFindObj(divName);

    newValue = '<b>' + newValue + '<' + '/b>';
    if (divObject && divObject.innerHTML) {
        divObject.innerHTML = newValue;
    }
    else if (divObject && divObject.document) {
        divObject.document.writeln(newValue);
        divObject.document.close();
    }
}


function clockGetCookieData(label) {
    var c = document.cookie;
    if (c) {
        var labelLen = label.length, cEnd = c.length;
        while (cEnd > 0) {
            var cStart = c.lastIndexOf(';',cEnd-1) + 1;
            while (cStart < cEnd && c.charAt(cStart)==" ") cStart++;
            if (cStart + labelLen <= cEnd && c.substr(cStart,labelLen) == label) {
                if (cStart + labelLen == cEnd) {
                    return "";
                }
                else if (c.charAt(cStart+labelLen) == "=") {
                    return unescape(c.substring(cStart + labelLen + 1,cEnd));
                }
            }
            cEnd = cStart - 1;
        }
    }
    return null;
}
function clockUpdate()
{
    var lastLocalTime = localTime;
    localTime = (new Date()).getTime();
    if (clockOffset == null) {
        clockDisplayTime(null, null, null);
    }
    else if (localTime < lastLocalTime || clockExpirationLocal < localTime) {
        document.cookie = 'remoteClock=-';
        document.cookie = 'localClock=-';
        //location.reload();      // will refresh time values in cookies
    }
    else {
        var serverTime = new Date(localTime + clockOffset);
        clockDisplayTime(serverTime.getHours(), serverTime.getMinutes(),
            serverTime.getSeconds());
        clockTimerID = setTimeout("clockUpdate()",
            clockIncrementMillis - (serverTime.getTime() % clockIncrementMillis));
    }
}



function ShowHomeTab(id,name,name1,type,isecid,rssType,langscatid,curname)
{
	var tabfile ='';
	if(name == 'Galer�a de fotos' || name == 'Photo Gallery' || name == 'Sociales'){
		var tabfile = 'sociales';
	}else{
		//var tabfile = 'categoria/'+name+'/'+langscatid;
        var tabfile = 'categoria/'+name+'/';
	}

	if(type =='rss')
	{
		if(document.getElementById('middrss'+id)){
			document.getElementById('middrss'+id).className = "rollover-tab-active-new";
			document.getElementById('middrss'+id).innerHTML = "<span style='padding-left:10px'>"+name1+"</span>";
		}if(document.getElementById('midd'+id)){
			document.getElementById('midd'+id).className = "rollover-tab-new";
			//document.getElementById('midd'+id).innerHTML = "<A href='javascript:ShowHomeTab("+id+",\""+name+"\",\""+name1+"\",\"\","+isecid+",\""+rssType+"\");' class='rollover-tab-new'><span style='padding-left:10px'>"+name+"</span></A>";
			document.getElementById('midd'+id).innerHTML = "<div id='nextdivid' class='rollover-tab-new' onclick='clearhrefnext(this,"+id+",\""+name+"\",\""+name1+"\",\"rss\","+isecid+",\""+rssType+"\","+langscatid+",\"\",\""+curname+"\");' style='cursor:pointer'><a><span style='padding-left:10px;cursor:pointer' id='nextlinkid' onclick='clearhrefnext1(this,\""+tabfile+"\");'>"+curname+"</span></a></div>";
		}if(document.getElementById('mainSec'+id)){
			document.getElementById('mainSec'+id).style.display = "none";
		}if(document.getElementById('rssSec'+id)){
			document.getElementById('rssSec'+id).style.display = "";
		}

		if(rssType == 'URL')
		{
			if(document.getElementById('divloader'+id))
				document.getElementById('divloader'+id).style.display = "";
			LoadRSS(id,isecid);
		}
	}
	else
	{
		if(document.getElementById('divloader'+id))
				document.getElementById('divloader'+id).style.display = "none";
		if(document.getElementById('middrss'+id)){
			document.getElementById('middrss'+id).className = 'rollover-tab-new';
			document.getElementById('middrss'+id).innerHTML = "<a href='javascript:ShowHomeTab("+id+",\""+name+"\",\""+name1+"\",\"rss\","+isecid+",\""+rssType+"\","+langscatid+",\""+curname+"\");'><span style='padding-left:10px'>"+name1+"</span></a>";
		}if(document.getElementById('midd'+id)){
			document.getElementById('midd'+id).className = 'rollover-tab-active-new';
			document.getElementById('midd'+id).innerHTML = "<span style='padding-left:10px'><a href="+SITE_URL+tabfile+"  class='tablink'>"+curname+"</a></span>";
		}if(document.getElementById('mainSec'+id)){
			document.getElementById('mainSec'+id).style.display = "";
		}if(document.getElementById('rssSec'+id)){
			document.getElementById('rssSec'+id).style.display = "none";
		}
	}
}

function LoadRSS(id,isecid)
{
	//document.getElementById('divLoading'+id).style.display = "";
	var url = SITE_AJAX_URL+"loadhomerss.php?iSectionId="+isecid+"&id="+id;
	var pars = "?iSectionId="+isecid+"&id="+id;
	var url = SITE_AJAX_URL+"loadhomerss.php";
	//alert(url+pars);
	if(document.getElementById('rssSec'+id)){
	 document.getElementById('rssSec'+id).style.display = '';
	}
	var divid = 'rssSec'+id;
	//alert(url+pars)
	$("#"+divid).load(url+pars);
}





function LoadRSS1(id,isecid)
{
	//document.getElementById('divLoading'+id).style.display = "";
	var url = SITE_AJAX_URL+"loadhomerss.php?iSectionId="+isecid+"&id="+id;
	//alert(url);
	if (window.XMLHttpRequest)
  	{
  		http=new XMLHttpRequest()
  		http.open("GET",url,true)
	  	http.onreadystatechange=ShowData
	  	http.send(null)
  	}
	// code for IE
	else if (window.ActiveXObject)
  	{
  		http=new ActiveXObject("Microsoft.XMLHTTP")
    	if (http)
    	{
    		http.open("GET",url,true)
    		http.onreadystatechange=ShowData;
    		http.send()
    	}
  	}
}

function ShowData()
{
	if (http.readyState == 4)
	{
      	isWorking = false;

		if (http.responseText.indexOf('invalid') == -1)
		{
    		var xmlDocument = http.responseXML;
			var no = xmlDocument.getElementsByTagName('title').length;
			var id	= xmlDocument.getElementsByTagName('id').item(0).firstChild.data;
			var html ='';

			html+='<TABLE width="100%" border="0" cellspacing="2"  cellpadding="1">';
			if(no>0)
			{
				for(var i=0; i<no; i++)
				{
					var nvID	= xmlDocument.getElementsByTagName('title').item(i).firstChild.data;
					var arlink	= xmlDocument.getElementsByTagName('link').item(i).firstChild.data;
					var ardesc	= xmlDocument.getElementsByTagName('description').item(i).firstChild.data;

					html+='<TR>';
				    	html+='<TD><a href="'+arlink+'" target="_blank" class="greylinkbold">'+nvID+'</a></TD>';
				    html+='</TR>';
				    //<a href="'+arlink+'" target="_blank" class="greylinkbold">'+LBL_READ_MORE+'</a>
				    html+='  <TR>';
	        			html+='<TD>'+ardesc+'</TD>';
	    			html+=' </TR>';
				}
			}
			html+=' </TABLE>';

			if(document.getElementById('rssSec'+id))
			{
				document.getElementById('rssSec'+id).style.display = '';
				document.getElementById('rssSec'+id).innerHTML =html;
			}
			if(document.getElementById('divloader'+id))
			document.getElementById('divloader'+id).style.display = "none";
		}
	}
}

function Subsections(id,name,name1,type,isecid,rssType,linkid,totSec,subid)
{
	document.getElementById('mainSec'+id).style.display = "none";
	document.getElementById('rssSec'+id).style.display = "none";

	/*for(i=0; i<totSec; i++)
	{
		if(subid == i)
			document.getElementById(linkid).className = "omatter-bold";
		else
			document.getElementById(linkid).className = "";

	}*/

	if(rssType == 'URL')
	{
		if(document.getElementById('divloader'+id))
		document.getElementById('divloader'+id).style.display = "";
		LoadRSS(id,isecid);
	}
}

function clearhrefnext(obj,id1,name,name1,rss,isecid,rssType,langscatid,tabfile,curname){
	ShowHomeTab(id1,name,name1,'',isecid,rssType,langscatid,curname);
}
function clearhrefnext1(obj,tabfile){
	window.location=SITE_URL+tabfile;
}


function ShowUpcomingEvents(id,type,url)
{
	if(type =='upcoming')
	{

		document.getElementById('upcoming').className = "rollover-tab-active-new";
		document.getElementById('upcoming').innerHTML = "<span style='padding-left:10px'><a href="+SITE_URL+"eventos/proximos class='tablink'>"+LBL_UPCOMING+"</a></span>";
		//document.getElementById('upcoming').innerHTML = "<span style='padding-left:10px'>"+LBL_UPCOMING+"</span>";
		if(document.getElementById('today')){
		document.getElementById('today').className = "rollover-tab-new";
		//document.getElementById('today').innerHTML = "<A href='javascript:ShowUpcomingEvents("+id+",\"today\");' ><span style='padding-left:10px'>"+LBL_TODAY+"</span></A>";
		document.getElementById('today').innerHTML = "<div id='todaydivid' onclick='clearhreftoday(this,"+id+",\"today\");' style='cursor:pointer'><a><span style='padding-left:10px;cursor:pointer' id='todaylinkid' onclick='clearhreftoday(this);'>"+LBL_TODAY+"</span></a></div>";
		//document.getElementById('today').innerHTML = "<A href='javascript:ShowUpcomingEvents("+id+",\"today\");' ><span style='padding-left:10px'>"+LBL_TODAY+"</span></A>";
		document.getElementById('todayEvents').style.display='none';
		}
		//alert(type);
		document.getElementById('upcomingEvents').style.display='';
	}else if(type == 'today')
	{
		document.getElementById('today').className = "rollover-tab-active-new";
		document.getElementById('today').innerHTML ="<span style='padding-left:10px'><a href="+SITE_URL+"eventos/hoy class='tablink'>"+LBL_TODAY+"</a></span>";
		document.getElementById('upcoming').className = "rollover-tab-new";
		//document.getElementById('upcoming').innerHTML = "<A href='javascript:ShowUpcomingEvents("+id+",\"upcoming\");' ><span style='padding-left:10px'>"+LBL_UPCOMING+"</span></A>";
		//document.getElementById('upcoming').innerHTML = "<A href='javascript:void(o);' onclick='ShowUpcomingEvents("+id+",\"upcoming\");'></a><A href='javascript:void(o);' onclick='link();'><span style='padding-left:10px'>"+LBL_UPCOMING+"</span></A>";
		document.getElementById('upcoming').innerHTML = "<div id='upcomingdivid' onclick='clearhrefupcoming(this,"+id+",\"upcoming\");' style='cursor:pointer'><a><span style='padding-left:10px;cursor:pointer' id='upcominglinkid' onclick='clearhrefupcoming(this);'>"+LBL_UPCOMING+"</span></a></div>";
		document.getElementById('upcomingEvents').style.display='none';
		document.getElementById('todayEvents').style.display='';
	}
}

function clearhrefupcoming(obj,id1,type){
	if(obj.id =='upcomingdivid'){
		//obj.id.onclick="javascript:ShowUpcomingEvents(ShowUpcomingEvents();";
		ShowUpcomingEvents(id1,type);

	}else{
		//alert(obj.id);
		window.location=SITE_URL+'eventos/proximos';
		}
}
function clearhreftoday(obj,id1,type){
	if(obj.id =='todaydivid'){
		//obj.id.onclick="javascript:ShowUpcomingEvents(ShowUpcomingEvents();";
		ShowUpcomingEvents(id1,type);

	}else{
		//alert(obj.id);
		window.location=SITE_URL+'eventos/hoy';
		}
}


function addBannerEntry(bannerid)
{
	var url = SITE_AJAX_URL+"addBannerView.php?iBannerId="+bannerid;
/*	alert(url);
	return false;*/
	if (window.XMLHttpRequest)
  	{
  		http=new XMLHttpRequest()
  		http.open("GET",url,true)
	  	http.onreadystatechange=giveResponse;
	  	http.send(null)
  	}
	// code for IE
	else if (window.ActiveXObject)
  	{
  		http=new ActiveXObject("Microsoft.XMLHTTP")
    	if (http)
    	{
    		http.open("GET",url,true)
    		http.onreadystatechange=giveResponse;
    		http.send()
    	}
  	}
}
function giveResponse()
{
	if (http.readyState == 4)
	{
      	isWorking = false;
    	if (http.responseText.indexOf('invalid') == -1)
		{
    		var xmlDocument = http.responseXML;
			var succ = xmlDocument.getElementsByTagName('succ').item(0).firstChild.data;

			if(succ == '0'){
				document.getElementById("errormsg").style.display ='';
				document.getElementById("errormsg").innerHTML = 'Error';
				return false;
			}
		}
	}
}




function getSubscribed(val){
	var url = SITE_AJAX_URL+"subscribeNewsletter.php?val="+val;
	if (window.XMLHttpRequest)
  	{
  		http=new XMLHttpRequest()
  		http.open("GET",url,true)
	  	http.onreadystatechange=subscribeMail
	  	http.send(null)
  	}
	// code for IE
	else if (window.ActiveXObject)
  	{
  		http=new ActiveXObject("Microsoft.XMLHTTP")
    	if (http)
    	{
    		http.open("GET",url,true)
    		http.onreadystatechange=subscribeMail
    		http.send()
    	}
  	}

}
function subscribeMail()
{
	if (http.readyState == 4)
	{
      	isWorking = false;
    	if (http.responseText.indexOf('invalid') == -1)
		{
    		var xmlDocument = http.responseXML;
			var msg = xmlDocument.getElementsByTagName('msg').item(0).firstChild.data;
			if(msg == 1){
				document.getElementById('msgSubscribed').style.display = '';
				document.getElementById('msgAlreadySubscribed').style.display = 'none';
			}else if(msg == 0){
				document.getElementById('msgAlreadySubscribed').style.display = '';
				document.getElementById('msgSubscribed').style.display = 'none';
			}
		}

	}
}




var voteLeftImage = 'images/graph_left_1.gif';
var voteRightImage = 'images/graph_right_1.gif';
var voteCenterImage = 'images/graph_middle_1.gif';
var preloadedImages = new Array();

var graphMaxWidth = 130;	// It will actually be a little wider than this because of the rounded image at the left and right
var graphMinWidth = 15;	// Minimum size of graph
var pollScrollSpeed = 5;	// Lower = faster

preloadedImages[0] = new Image();
preloadedImages[0].src = voteLeftImage;
preloadedImages[1] = new Image();
preloadedImages[1].src = voteRightImage;
preloadedImages[2] = new Image();
preloadedImages[2].src = voteCenterImage;

function castVote(pollId,formObj)
{
	//alert(pollId);
	//alert(formObj);
	var elements = formObj.elements['vote[' + pollId + ']'];
	var optionId = false;
	for(var no=0;no<elements.length;no++){
		if(elements[no].checked)optionId = elements[no].value;
	}
	Poller_Set_Cookie('dhtmlgoodies_poller_' + pollId,'1',6000000);
	var url = SITE_AJAX_URL+"pollresult.php?pollId="+pollId+"&optionId="+optionId;
	//alert(url);
	//$("#poller_results").load(url);

	if (window.XMLHttpRequest)
  	{
  		http=new XMLHttpRequest()
  		http.open("GET",url,true)
	  	http.onreadystatechange=showVoteResults;
	  	http.send(null)
  	}
	// code for IE
	else if (window.ActiveXObject)
  	{
  		http=new ActiveXObject("Microsoft.XMLHTTP")
    	if (http)
    	{
    		http.open("GET",url,true)
    		http.onreadystatechange=showVoteResults;
    		http.send()
    	}
  	}
}

var pollVotes = new Array();
var pollVoteCounted = new Array();
var totalVotes = new Array();
function showVoteResults()
{
	if (http.readyState == 4)
	{
		isWorking = false;
	   	if (http.responseText.indexOf('invalid') == -1)
		{
	    	var xmlDocument 	= 	http.responseXML;
    		var noOp			=   xmlDocument.getElementsByTagName('optionid').length;
			var pollId			= 	 xmlDocument.getElementsByTagName('pollid').item(0).firstChild.data;
			var pollerTitle		= 	 xmlDocument.getElementsByTagName('pollertitle').item(0).firstChild.data;
			var totalpollvotes = 	xmlDocument.getElementsByTagName('totalpollvotes').item(0).firstChild.data;
			var resultDiv = document.getElementById('poller_results');
			var titleP = document.createElement('P');
			pollerTitle	= pollerTitle.replace('##and##','&');
			titleP.className='bmattersmall';
			titleP.innerHTML = pollerTitle;
			resultDiv.appendChild(titleP);
			pollVotes[pollId] = new Array();
			totalVotes[pollId] = 0;

			for(i=0; i<noOp; i++)
			{
				var opID		= xmlDocument.getElementsByTagName('optionid').item(i).firstChild.data;
				var opVa		= xmlDocument.getElementsByTagName('optiontext').item(i).firstChild.data;
				var opVotes		= xmlDocument.getElementsByTagName('votes').item(i).firstChild.data;
				opVa	= opVa.replace('##and##','&');
				var pOption = document.createElement('P');
				pOption.className='result_pollerOption';
				if(i != 0){
                                    extrbr = "<br>";
                                }else{
                                    extrbr = "";
                                }
				pOption.innerHTML = extrbr + opVa;
				resultDiv.appendChild(pOption);

				var voteDiv = document.createElement('DIV');
				voteDiv.className='result_pollGraph';
				resultDiv.appendChild(voteDiv);

				var leftImage = document.createElement('IMG');
				leftImage.src = voteLeftImage;
            leftImage.style.styleFloat = 'left';
            voteDiv.appendChild(leftImage);

				var numberDiv = document.createElement('DIV');
				numberDiv.style.backgroundImage = 'url(\'' + voteCenterImage + '\')';
				numberDiv.innerHTML = '0%';
				numberDiv.id = 'result_voteTxt' + opID;
            numberDiv.style.styleFloat = 'left';
				numberDiv.style.height = '16px';
				voteDiv.appendChild(numberDiv);

				var rightImage = document.createElement('IMG');
				rightImage.src = voteRightImage;
            rightImage.style.styleFloat = 'left';
				voteDiv.appendChild(rightImage);
				pollVotes[pollId][opID] = opVotes;
				totalVotes[pollId] = totalVotes[pollId]/1 + opVotes/1 ;

			}
			var totalVoteP = document.createElement('P');
			totalVoteP.className = 'result';
			//totalVoteP.innerHTML = "<br><br>"+MSG_POLL_VOTE_TOTAL+" :" + totalVotes[pollId];
			document.getElementById('poller_question').style.display ='none';
			voteDiv.appendChild(totalVoteP);
			setPercentageVotes(pollId);
			slideVotes(pollId,0);
		}
	}
}


function setPercentageVotes(pollId)
{

	for(var prop in pollVotes[pollId])
	{
		pollVotes[pollId][prop] =  Math.round( (pollVotes[pollId][prop] / totalVotes[pollId]) * 100);
	}
	/*var currentSum = 0;
	for(var prop in pollVotes[pollId])
	{
		currentSum = currentSum + pollVotes[pollId][prop]/1;
	}*/
	//pollVotes[pollId][prop] = pollVotes[pollId][prop] + (100-currentSum);
}

function slideVotes(pollId,currentPercent)
{
	currentPercent = currentPercent/1 + 1;
	for(var prop in pollVotes[pollId])
	{
		if(pollVotes[pollId][prop]>=currentPercent)
		{
			var obj = document.getElementById('result_voteTxt' + prop);
			obj.innerHTML = currentPercent + '%';
			obj.style.width = Math.max(graphMinWidth,Math.round(currentPercent/100*graphMaxWidth)) + 'px';
		}
	}
	if(currentPercent<100)setTimeout('slideVotes("' + pollId + '","' + currentPercent + '")','5');
}

function Poller_Get_Cookie(name) {

   var start = document.cookie.indexOf(name+"=");
   var len = start+name.length+1;
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
   if (start == -1) return null;
   var end = document.cookie.indexOf(";",len);
   if (end == -1) end = document.cookie.length;
   return unescape(document.cookie.substring(len,end));
}
// This function has been slightly modified
function Poller_Set_Cookie(name,value,expires,path,domain,secure) {
	expires = expires * 60*60*24*1000;
	var today = new Date();
	var expires_date = new Date( today.getTime() + (expires) );
    var cookieString = name + "=" +escape(value) +
       ( (expires) ? ";expires=" + expires_date.toGMTString() : "") +
       ( (path) ? ";path=" + path : "") +
       ( (domain) ? ";domain=" + domain : "") +
       ( (secure) ? ";secure" : "");
    document.cookie = cookieString;
}

function displayResultsWithoutVoting(pollId)
{
	var url = SITE_AJAX_URL+"pollresult.php?pollId="+pollId;
	//alert(url);
	//$("#poller_results").load(url);
	if (window.XMLHttpRequest)
  	{
  		http=new XMLHttpRequest()
  		http.open("GET",url,true)
	  	http.onreadystatechange=showVoteResults;
	  	http.send(null)
  	}
	// code for IE
	else if (window.ActiveXObject)
  	{
  		http=new ActiveXObject("Microsoft.XMLHTTP")
    	if (http)
    	{
    		http.open("GET",url,true)
    		http.onreadystatechange=showVoteResults;
    		http.send()
    	}
  	}
}

