var voteCheck = false;

function noCache(){
	var right_now = new Date();
	rndm = right_now.getSeconds()+"_"+right_now.getMinutes()+"_"+right_now.getHours();
	for(i=0;i<10;i++){
		rndm = rndm + Math.floor(Math.random()*20);
	}
	return rndm;
}

function voteCall(){
	formObj = $('pollVote');
	if(voteCheck==false) {
		alert("You need to select an option before voting.");
	}
	else {
		ajaxUpdate($('pollPanel'),'poll_content_includeE.jsp',"&"+formObj.serialize());
	}
}

function voteCall2(){
	formObj = $('pollVote');
	if(voteCheck==false) {
		alert("You need to select an option before voting.");
	}
	else {
		ajaxUpdate($('pollPanel'),'poll_franchise.jsp',"&"+formObj.serialize());
	}
}

function voteCall3(){
	formObj = $('pollVote');
	if(voteCheck==false) {
		alert("You need to select an option before voting.");
	}
	else {
		ajaxUpdate($('pollPanel'),'poll_content_interim.jsp',"&"+formObj.serialize());
	}
}


function ajaxUpdate(panelObj,url,pars){var right_now=new Date();var noCache=right_now.getSeconds()+"_"+right_now.getMinutes()+"_"+right_now.getHours();var myAjax=new Ajax.Updater({success:panelObj},url,{method:'post',parameters:"noCache="+noCache+pars,onFailure:reportError,evalScripts:true});}
function reportError(err){}
function hasZero(value){if(value+0<10){return "0"+value;}else{return ""+value;}}  
function doNothing(){};

var flashplugin = 0;

function checkBrowser()
{
	this.isIE4=false;
	this.isIE5=false;
	this.isIE6=false
	
	this.isNS4=false;
	this.isNS6=false;
	this.isNS7=false;
	
	this.isMac=false;	
	this.isPC=false;
	this.isAOL=false;
	this.dom=document.getElementById?this.dom=true:this.dom=false;
	this.appName=navigator.appName;
	this.ver=navigator.appVersion;
	this.int_ver=parseInt(this.ver);
	this.navUser=navigator.userAgent;
	this.navMime=navigator.mimeTypes;
	this.navPlugs=navigator.plugins;
	this.appName.indexOf("Netscape")>=0&&this.int_ver==4?(this.isNS4=true):(this.isNS4=false);
	this.navUser.toLowerCase().indexOf('aol')!=-1?(this.isAOL=true):(this.isAOL=false);
	this.ver.indexOf('Mac')!=-1?(this.isMac=true):(this.isPC=true);
	this.navUser.indexOf('MSIE 4')>0?(this.isIE4=true):(this.isIE4=false);
	this.navUser.indexOf('MSIE 5')>0?(this.isIE5=true):(this.isIE5=false);
	this.navUser.indexOf('MSIE 6')>0?(this.isIE6=true):(this.isIE6=false);
	this.navUser.indexOf("Netscape6")>0?(this.isNS6=true):(this.isNS6=false);
	this.navUser.indexOf("Netscape/7.")>0?(this.isNS7=true):(this.isNS7=false);
	this.navUser.indexOf("Firefox")>0?(this.isNS7=true):(this.isNS7=false);
	this.navUser.indexOf("Mozilla/5")>-1?(this.isNS7=true):(this.isNS7=false);
	this.isNS = (this.isNS4 || this.isNS6 || this.isNS7);
	this.isIE = (this.isIE4 || this.isIE5 || this.isIE6);

return this;
}
msgBrowser=new checkBrowser();
/*Flash detect for Netscape and IE*/
//if(msgBrowser.navMime&&msgBrowser.navMime["application/x-shockwave-flash"]&&msgBrowser.navMime["application/x-shockwave-flash"].enabledPlugin){if (msgBrowser.navPlugs &&msgBrowser.navPlugs["Shockwave Flash"]){flashplugin = 1;}}
if(msgBrowser.navUser &&msgBrowser.navUser.indexOf("MSIE")>=0&&(msgBrowser.navUser.indexOf("Windows 95")>=0||msgBrowser.navUser.indexOf("Windows 98")>=0||msgBrowser.navUser.indexOf("Windows NT")>=0)){
document.write('<SCRIPT LANGUAGE=VBScript\> \n on error resume next \n\n flashplugin = (  IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5")))\n');
document.write('if ( flashplugin <= 0 ) then flashplugin = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")))\n </SCRIPT\> \n');}
/*Flash display*/


function NewWindow(pageURL,pageName,w,h,centered,scroll,resizable){
	LeftPosition	= (screen.width)?(screen.width-w)/2:0;
	TopPosition		= (screen.height)?(screen.height-h)/2:0;
	settings		= "height="+h+",width="+w;
	if(centered=="1"){
		settings += ",top="+TopPosition+",left="+LeftPosition;
	}
	settings += ",scrollbars="+scroll+",resizable="+resizable;
	nWindow			= window.open(pageURL,pageName,settings);
	nWindow.focus();
}



//from mookfpi
function detectFlashVersion() {  
  // If navigator.plugins exists...
  if (navigator.plugins) {  
    // ...then check for flash 2 or flash 3+.
    if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
		flashplugin=1;
      	// Some version of Flash was found. Time to figure out which.
      
      	// Set convenient references to flash 2 and the plugin description.
      	var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      	var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;

      	// DEBUGGING: uncomment next line to see the actual description.
       	//alert("Flash plugin description: " + flashDescription);
      
      	// A flash plugin-description looks like this: Shockwave Flash 4.0 r5
      	// We can get the major version by grabbing the character before the period
      	// note that we don't bother with minor version detection. 
      	// Do that in your movie with $version or getVersion().
      	flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
     
     	 // We found the version, now set appropriate version flags. Make sure
      	// to use >= on the highest version so we don't prevent future version
      	// users from entering the site.
      	flash2Installed = flashVersion == 2;    
      	flash3Installed = flashVersion == 3;
      	flash4Installed = flashVersion == 4;
      	flash5Installed = flashVersion == 5;
      	flash6Installed = flashVersion >= 6;
    }
	else flashVersion=0;
	}
else flashVersion=0;
}

function insertFlash(width,height,FlashSrc,ImageSrc,file_ID,color,fVer,autostart) {
	var classID = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
	var codebase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"; 
	var download = "http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash";
	FlashCode='';
	if(!fVer){fVer=3;}
	if(!width || !height){width=20;height=20;}
	if(!autostart){autostart=true;}
	if(!color){color="";}

	detectFlashVersion();
	if(msgBrowser.isIE) {
		if(msgBrowser.isPC) {
			FlashCode=('<OBJECT classid="'+classID+'" codebase="'+codebase+'" ID="'+file_ID+'" WIDTH="'+width+'" HEIGHT="'+height+'">\n');
			FlashCode+=('<PARAM NAME=movie VALUE="'+FlashSrc+'"> <PARAM NAME="quality" VALUE="high">\n<PARAM NAME="menu" VALUE="false"> \n');
			FlashCode+=('<PARAM NAME="AUTOSTART" VALUE="'+autostart+'">\n<PARAM NAME="bgcolor" VALUE="'+color+'">\n');
			if(ImageSrc!="") {
				FlashCode+=('<a href="'+download+'" target="_blank"><img src="'+ImageSrc+'" alt="'+file_ID+'" border="'+0+'" width="'+width+'" height="'+height+'"></a>');
			}
			else { 
				FlashCode += ('<a href="'+download+'" target="_blank"><img src="mediaStore/s/spacer.gif" alt="'+file_ID+'" border="'+0+'" width="'+width+'" height="'+height+'"></a>');
			}
			FlashCode+='</OBJECT>';
		}
		else {
			FlashCode=('<OBJECT classid="'+classID+'" codebase="'+codebase+'" ID="'+file_ID+'" WIDTH="'+width+'" HEIGHT="'+height+'">\n');
			FlashCode+=('<PARAM NAME=movie VALUE="'+FlashSrc+'"> <PARAM NAME="quality" VALUE="high">\n<PARAM NAME="menu" VALUE="false"> \n');
			FlashCode+=('<PARAM NAME="AUTOSTART" VALUE="'+autostart+'">\n<PARAM NAME="bgcolor" VALUE="'+color+'"><EMBED menu=false swLiveConnect="FALSE" src="'+FlashSrc+'" quality=high width='+width+' height='+height+' type="application/x-shockwave-flash" pluginspage="'+download+'" autostart="'+autostart+'" high bgcolor="'+color+'"></EMBED>\n');
			FlashCode+='</OBJECT>';
		}
	}
	else if(msgBrowser.isNS) {
		if(flashVersion >=fVer) {
			FlashCode+=('<EMBED menu=false swLiveConnect="FALSE" src="'+FlashSrc+'" quality=high width='+width+' height='+height+' type="application/x-shockwave-flash" pluginspage="'+download+'" autostart="'+autostart+'" high bgcolor="'+color+'"></EMBED>');
		}
		else {
			if(ImageSrc!="") {
				FlashCode+=('<a href="'+download+'" target="_blank"><img src="'+ImageSrc+'" alt="'+file_ID+'" border="'+0+'" width="'+width+'" height="'+height+'"></a>');
			}
			else {
				FlashCode = '<IMG alt="" src="mediaStore/s/spacer.gif" width=1 height=' + height + ' border=0>';
			}
		}	
	}
	else {
		if(ImageSrc!="") {
			FlashCode+=('<a href="'+download+'" target="_blank"><img src="'+ImageSrc+'" alt="'+file_ID+'" border="'+0+'" width="'+width+'" height="'+height+'"></a>');
		}
		else {
			FlashCode = '<IMG alt="" src="mediaStore/s/spacer.gif" width=1 height=' + height + ' border=0>';
		}
	}
	document.write(FlashCode);
}


function shwSponsor() {
	var iLib;
	if(pageSponsor=="noSponsor") {
		iLib	= imageName.substring(0,1);
		document.write("<img src=\"mediaStore/" + iLib + "/" + imageName + ".gif\"  border=\"0\"/>");
	}
	else
	{
		if(pageSponsor=="") {
			pageSponsor = "thegarden";
		}
		if(sponsorLink=="") {
			sponsorLink = pageSponsor;
		}
		if(sponsorLink=="powertolearn") {
		
		iLib	= pageSponsor.substring(0,1);
		document.write("<a href=\"http://powertolearn.com/school_to_career/liberty/index.shtml\" target=\"_new\"><img src=\"mediaStore/" + iLib + "/" + pageSponsor + ".gif\"  border=\"0\"/></a>");
		}
		else if(sponsorLink=="io_cable_ad") {
		
		iLib	= pageSponsor.substring(0,1);
		document.write("<a href=\"http://www.io.tv/index.jhtml?pageType=hdtv\" target=\"_new\"><img src=\"mediaStore/" + iLib + "/" + pageSponsor + ".gif\"  border=\"0\"/></a>");
		}
		else
		{
		iLib	= pageSponsor.substring(0,1);
		document.write("<a href=\"http://www." + sponsorLink + ".com\" target=\"_new\"><img src=\"mediaStore/" + iLib + "/" + pageSponsor + ".gif\"  border=\"0\"/></a>");
	}
	}
}
	

function shwHeader() {
	if(pageHeader=="") {
		pageHeader = "general_banner";
	}
	var iLib	= pageHeader.substring(0,1);
	document.write("<img src=\"mediaStore/" + iLib + "/" + pageHeader + ".jpg\" border=\"0\">");
}

function openSiteMap(site,name,width,height)
{
	var parameters = "toolbar=no,menubar=no,resizable=no,scrollbars=no,status=yes,width=" + width + ",height=" + height;
	window.open (site, name, parameters)
}

function checkForm()
	{
		if(checkFormInfo('lanzadores')==false)
		{
			return false;
		}
		else if(validate('relevista_1')==false)
		{
			alert("Seleccione un relevista");
			return false;
		}
		else if(validate('receptor')==false)
		{
			alert("Seleccione un receptor");
			return false;
		}
		else if(validate('primera')==false)
		{
			alert("Seleccione un primera base");
			return false;
		}
		else if(validate('segunda')==false)
		{
			alert("Seleccione un segunda base");
			return false;
		}
		else if(validate('campo')==false)
		{
			alert("Seleccione un campo corto");
			return false;
		}
		else if(validate('tercera')==false)
		{
			alert("Seleccione un tercera base");
			return false;
		}
		else if(checkFormInfo('jardineros')==false)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	
	function checkFormInfo(position)
	{
		var counter = 0;
		var counter2 = 1;
		var counter3 = 0; //number of total choices
		var counter4 = 0; //number of hidden/ number allowed to be checked
		
		for (var ii=0;ii<20;ii++)
		{
			fieldValue = eval("document.form1." + position + ii);
			fieldValue2 = eval("document.form1." + position + "_" + ii);
			if (fieldValue)
			{
				counter3++;
			}
			if (fieldValue2)
			{
				counter4++;
			}
		}
		
   	 	for (var i=1;i<counter3+1;i++)
		{
        	testValue = (eval("document.form1." + position + i + ".checked"));
			testValue2 = (eval("document.form1." + position + i + ".value"));
			if(testValue==true)
			{
				counter++;
				if(counter>=(counter4+1))
				{
					alert("Seleccione " + counter4 + " " + position);
					return false;
				}
				else
				{
					testValue3 = eval("document.form1." + position + "_" + counter2);
					testValue3.value = testValue2;
					counter2++;
				}
			}
	    }
		
		if(counter!=counter4)
		{
			alert("Seleccione " + counter4 + " " + position);
			return false;
		}
		else
		{
			return true;
		}
	}
	
	function validate(radioBoxName) {
	
	radioName = eval("document.form1." + radioBoxName);
    for (var i=0;i<radioName.length;i++) {
        if (radioName[i].checked)
            return true;
    }
    return false;
}

	function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
	}
	
	function isInteger(s) {
		var i;
    	for (i = 0; i < s.length; i++){   
        	// Check that current character is number.
        	var c = s.charAt(i);
        	if (((c < "0") || (c > "9"))) {
			 return false;
			}
    	}
    	// All characters are numbers.
   	 	return true;
	}
	function y2k(number) { return (number < 1000) ? number + 1900 : number; }


    function isDate(day,month,year) {
    var today = new Date();
    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);
    if (!day) return false
    var test = new Date(year,month,day);
    if ( (y2k(test.getYear()) == year) &&
    (month == test.getMonth()) &&
    (day == test.getDate()) )
    return true;
    else
    return false
}

	 function isDate(day,month,year) {
    var today = new Date();
    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);
    if (!day) return false
    var test = new Date(year,month,day);
    if ( (y2k(test.getYear()) == year) &&
    (month == test.getMonth()) &&
    (day == test.getDate()) )
    return true;
    else
    return false
}

function getMonthLength(month,year,julianFlag) {
    var ml;
    if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10||month==12) {
		ml = 31;
	}
	else {
		if(month==2) {
			ml = 28;
			if(!(year%4) && (julianFlag==1 || year%100 || !(year%400)))
            	ml++;
		}
		else
		{
			ml = 30;
		}
	}
return ml; 
}

	
	function checkAge() {
	
		var myLimit = 13;
		Today=new Date();
		var yd = Today.getYear();
        var md = Today.getMonth();
        var dd = Today.getDate();
			
		var mb = document.form1.month.options[document.form1.month.selectedIndex].value - 1;
		var db = document.form1.day.options[document.form1.day.selectedIndex].value;
		var yb = document.form1.year.value;
			
		if (isDate(db,mb,yb)==false) {
           	return false;
        }

		var mLength = 0;
        var isJulian = 1;
        var ma=0;
        var ya=0;
        var da = dd-db;
			 
		if(da<0) {
        	md--;
            if(md<1) {
            	yd--;
                if(mLength) {
					md=md+parseInt(365/mLength);
				}
                else{
					md=md+12;
				}
			}
				
			if(mLength==0) {
				ml=getMonthLength(md,yd,isJulian);
				da=da+ml;
			}
			else {
				da+=mLength;
			}
		}
			
			ma = md - mb;
			if(ma<0) {
		   		yd--;
				if(mLength!=0) {
					ma=ma+parseInt(365/mLength);
				}
				else {
					ma=ma+12;
				}
			}
			
			ya = yd - yb;
			if(ya>=myLimit) {
				return true;
			}
			else {
				return false
			}
		}
	
	function checkFormMets() {		
		document.form1.firstname.value = trim(document.form1.firstname.value);
		document.form1.lastname.value = trim(document.form1.lastname.value);
		document.form1.email.value = trim(document.form1.email.value);
		document.form1.number.value = trim(document.form1.number.value);
		document.form1.address.value = trim(document.form1.address.value);
		document.form1.city.value = trim(document.form1.city.value);
		document.form1.state.value = trim(document.form1.state.value);
		document.form1.year.value = trim(document.form1.year.value);
		document.form1.zip.value = trim(document.form1.zip.value);
		document.form1.msg.value = trim(document.form1.msg.value);
		
		if(document.form1.optin.checked==true)	{
			document.form1.optin.value="true";
		}
		else {
			document.form1.optin.value="";
		}
		
		if(document.form1.firstname.value=="") {
			alert("You must enter a first name.");
			return false;
		}
		else if(document.form1.lastname.value=="") {
			alert("You must enter a last name.");
			return false;
		}
		else if(document.form1.email.value=="" && document.form1.number.value=="") {
			alert("You must enter a Valid Email address or Wireless Number.");
			return false;
		}
		else if(document.form1.month.options[document.form1.month.selectedIndex].value=="") {
			alert("You must enter a month for your Date of Birth.");
			return false;
		}
		else if(document.form1.day.options[document.form1.day.selectedIndex].value=="") {
			alert("You must enter a day for your Date of Birth.");
			return false;
		}
		else if(document.form1.year.value=="") {
			alert("You must enter a year for your Date of Birth.");
			return false;
		}
		else if(isInteger(document.form1.year.value)==false) {
			alert("Please enter the proper year you were born.");
			return false;
		}
		else if(document.form1.msg.value=="") {
			alert("You must enter a question.");
			return false;
		}
		else if(document.form1.msg.value.length>140) {
			alert("You must enter a question that is not longer than 140 characters.");
			return false;
		}
		else if(checkAge() == false) {
			alert("You must be at least 13 years old to submit.")
			return false;
		}
		else {
			return true;
		}
	}
	
	function checkFormMets2() {		
		
		if(document.form1.optin.checked==true)	{
			document.form1.optin.value="false";
		}
		else {
			document.form1.optin.value="";
		}
		
		if(document.form1.email.value=="" && document.form1.number.value=="") {
			alert("You must enter a Valid Email address or Wireless Number.");
			return false;
		}
		else if (document.form1.email.value!="") {
			if ((document.form1.email.value.indexOf("@")==-1) || (document.form1.email.value.indexOf(".")==-1))
			{
				alert("Email address must be in the correct format i.e. example@example.com.");
				return false;
			}
		}
		else {
			return true;
		}
	}
	
	function checkFormMets3() {		
		
		
		if(document.form1.fromEmailAddr.value=="") {
			alert("You must enter a Valid Email address.");
			return false;
		}
		else if (document.form1.fromEmailAddr.value!="") {
			if ((document.form1.fromEmailAddr.value.indexOf("@")==-1) || (document.form1.fromEmailAddr.value.indexOf(".")==-1))
			{
				alert("Email address must be in the correct format i.e. example@example.com.");
				return false;
			}
		}
		else {
			return true;
		}
	}



