// JavaScript Document
// Global variables
var active_div_replace=false;
var pageName;
var t;	//timeout for player
var firstUrlPart;
var lastUrlPart;

function DoNav(theUrl)
{
	document.location.href = theUrl;
}

function ChangeColor(tableRow, highLight)
{
	if (highLight)
	{
		tableRow.style.backgroundColor = '#cccccc';
	}
	else
	{
		tableRow.style.backgroundColor = 'white';
	}
}

function getDays(year,month)
{
	return 32 - new Date(year, month, 32).getDate();
}

function populateDay(year,month,spanName,selectName)
{
	document.getElementById(spanName).innerHTML = '';
	var myDate = new Date();
	var html = '';
	var getTodayDate = false;
	
	if(year == false || month == false)
		getTodayDate = true;
		
	if(year == false)
		year = myDate.getFullYear();
	if(month == false)
		month = myDate.getMonth();

	html = "<select name="+selectName+">";
	for(i=1;i<=getDays(year,month);i++)
	{
		if(i == myDate.getDate() && getTodayDate == true)
			html += "<option value='" + i + "' selected='selected'>" + i + "</option>"
		else
			html += "<option value='" + i + "'>" + i + "</option>"
	}
	html += '</select>'
	document.getElementById(spanName).innerHTML = html;
}

function projectLog(pURL,pNodeId)
{
	setTimeout("projectLog('"+pURL+"','"+ pNodeId +"')",60000);
	replace_content(pURL,pNodeId);
}

// Include the content of a given URL in a div
function replace_content(pURL, pNodeId) {

  if (!active_div_replace){
    active_div_replace=true;
    var url=pURL;
    if (arguments.length>=2) {
      rfNodeId=pNodeId;
    }
   	// empty the div
   	// document.getElementById(rfNodeId).innerHTML='';
   	//alert(pURL);
    
    if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc 
      xmlhttp=new XMLHttpRequest();
      xmlhttp.onreadystatechange=replace_div_HTML;
      xmlhttp.open("GET", pURL, true); // leave true for Gecko
      xmlhttp.send(null);
    } else if (window.ActiveXObject) { //IE 
      xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); 
      if (xmlhttp) {
        xmlhttp.onreadystatechange=replace_div_HTML;
        xmlhttp.open('GET', pURL, false);
        
        xmlhttp.send();
      }
    } else {
      alert('Your browser does not appear to support remote scripting.');
      xmlhttp=false;
      active_div_replace=false;
    }
    
    if ((typeof(xmlhttp))!='object') {
      document.write('You need to upgrade your browser to use this page.\r\nAs of March 2006 more than 98% of the web browsers in use support the remote scripting object. Either your browser does not support remote scripting or the support has been disabled.');
      active_div_replace=false;
    }
  }else{
    window.setTimeout("replace_content('"+pURL+"','"+pNodeId+"');",1);
  }
}

// function to replace the HTML of a div produced by the replace_content function
function replace_div_HTML(){
  if (xmlhttp.readyState==4) {
    if (xmlhttp.status==200) {
      if (rfNodeId=='') {
        document.write(xmlhttp.responseText);
        active_div_replace=false;
      }else{
        document.getElementById(rfNodeId).innerHTML=xmlhttp.responseText;
	active_div_replace=false;
      }
    }
  }
}

function daysInMonth(month,year) 
{
	var dd = new Date(year, month, 0);
	return dd.getDate();
}

function findDay(month,year)
{
	days = daysInMonth(month,year);
	for(i=29;i<=31;i++)
	{
		if(i<=days)
			document.getElementById('Day'+i).style.display = 'block';
		else
			document.getElementById('Day'+i).style.display = 'none';
	}
}

function checkFormValues(values,message)
{
	for(i=0;i<values.length;i++)
	{
		if(document.getElementById(values[i]).value == '')
		{
			alert('Please enter ' + message[i]);
			return false;
		}
		if(values[i] == 'email')
			return echeck(document.getElementById(values[i]).value);	
	}
	
	//alert('Please enter ');
	return true;
}

function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Please enter a valie E-mail address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please enter a valie E-mail address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please enter a valie E-mail address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please enter a valie E-mail address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please enter a valie E-mail address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please enter a valie E-mail address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please enter a valie E-mail address")
		    return false
		 }

 		 return true					
	}

