var newwindow = '';
var Today=new Date();
var ThisDay=Today.getDay();
var ThisDate=Today.getDate();
var ThisMonth=Today.getMonth()+1;
var ThisYear=Today.getFullYear();  //included if you wish to insert the year
var DayName=DayTxt(ThisDay);

function DayTxt (DayNumber) 
{
	var Day=new Array();
	Day[0]="Sunday";
	Day[1]="Monday";
	Day[2]="Tuesday";
	Day[3]="Wednesday";
	Day[4]="Thursday";
	Day[5]="Friday";
	Day[6]="Saturday";
	return Day[DayNumber];
}


function MonthDays (MonthNumber, year) 
{
	var Month=new Array();
	Month[1]=31;
	Month[2]=28;
	Month[3]=31;
	Month[4]=30;
	Month[5]=31;
	Month[6]=30;
	Month[7]=31;
	Month[8]=31;
	Month[9]=30;
	Month[10]=31;
	Month[11]=30;
	Month[12]=31;
	
	var	extraDays = 0;
	
	if (year % 100 == 0 ) 
	{
		if (year % 400 == 0) extraDays = 1;
	}
	else if (year % 4 == 0) extraDays = 1;
		
	return Month[MonthNumber] + extraDays;
}

function MonthTxt (MonthNumber) 
{
	var Month=new Array();
	Month[1]="January";
	Month[2]="February";
	Month[3]="March";
	Month[4]="April";
	Month[5]="May";
	Month[6]="June";
	Month[7]="July";
	Month[8]="August";
	Month[9]="September";
	Month[10]="October";
	Month[11]="November";
	Month[12]="December";
	return Month[MonthNumber];
}

function GetGreeting()
{
	var MonthName=MonthTxt(ThisMonth);
	var d = new Date();
	var h = d.getHours();
	var greetingString = "";
	
	if (h < 3) greetingString = "Good morning! Up early or working late?";
	else if (h < 7) greetingString = "Good morning! Up bright and early!";
	else if (h < 12) greetingString = "Good morning!";
	else if (h < 17) greetingString = "Good afternoon!";
	else if (h < 23) greetingString = "Good evening!";
	else greetingString = "A late good evening! Not much left of it now.";
	
	return greetingString;
}


function colorRows(tableId) 
{

	var myTable = document.getElementById(tableId);	

	var myTR = myTable.getElementsByTagName('tr');

	
	for (var i=0;i<myTR.length;i++) 
	{
		if (i%2) 
		{
			myTR[i].className = 'tintRow';
	    }
  	}
 	 
}

function clock() 
{
	if (!document.layers && !document.all) return;
	
	var digital = new Date();
	var hours = digital.getHours();
	var minutes = digital.getMinutes();
	var seconds = digital.getSeconds();
	var amOrPm = "AM";
	if (hours > 11) amOrPm = "PM";
	if (hours > 12) hours = hours - 12;
	if (hours == 0) hours = 12;
	if (minutes <= 9) minutes = "0" + minutes;
	if (seconds <= 9) seconds = "0" + seconds;
	dispTime = 	digital.toDateString() + " " + hours + ":" + minutes + ":" + seconds + " " + amOrPm;
	
	if (document.layers) 
	{
		document.layers.clockSpan.document.write(dispTime);
		document.layers.clockSpan.document.close();
	}
	else if (document.all) clockSpan.innerHTML = dispTime;
	
	setTimeout("clock()", 1000);
}

function MainLoad()
{
	clock();
	greetingSpan.innerHTML = GetGreeting();
	scrollit(100);
	PerformSpecialFunction();	
}

function MainLoadWithoutSpecial()
{
	clock();
	greetingSpan.innerHTML = GetGreeting();
	scrollit(100);	
}

function scrollit(seed) 
{
	var msg="Fines Management System for Placement Committe 2007";
	var out = " ";
	var c   = 1;
	if (seed > 100) 
	{
		seed--;
		cmd="scrollit("+seed+")";
		timerTwo=window.setTimeout(cmd,100);
	}
	else if (seed <= 100 && seed > 0) 
	{
		for (c=0 ; c < seed ; c++) { out+=" "; }
		out+=msg;
		seed--;
		window.status=out;
		cmd="scrollit("+seed+")";
		timerTwo=window.setTimeout(cmd,100);
	}
	else if (seed <= 0) 
	{
		if (-seed < msg.length) 
		{
			out+=msg.substring(-seed,msg.length);
			seed--;
			window.status=out;
			cmd="scrollit("+seed+")";
			timerTwo=window.setTimeout(cmd,100);
		}
		else 
		{
			window.status=" ";
			timerTwo=window.setTimeout("scrollit(100)",75);
      	}
   	}
}

function ltrim(str)
{
	return str.replace(/^[ ]+/,'');	
}

function rtrim(str)
{
	return str.replace(/^[ ]+$/,'');	
}

function trim(str)
{
	return ltrim(rtrim(str));
}


function validateDate(inputDate) 
{
    var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
    
    if ((trim(inputDate).match(RegExPattern)) && (trim(inputDate)!='')) 
    {
  		return 0;
    } 
    else 
    {
  		return 1;  
    } 
}

function disableselect(e)
{
	return false;
} 
function reEnable()
{
	return true;
} 
function SetSelectDisable()
{
	//if IE4+
	document.onselectstart=new Function ("return false") 
	//if NS6
	if (window.sidebar)
	{
		document.onmousedown=disableselect
		document.onclick=reEnable
	}
}

function clickIE() 
{
	if (document.all) 
	{
		return false;
	}
} 

function clickNS(e) 
{
	if (document.layers||(document.getElementById&&!document.all)) 
	{ 
		if (e.which==2||e.which==3) 
		{
			return false;
		}
	} 
}

function DisableRightClick()
{
	if (document.layers) 
	{
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown=clickNS;
	} 
	else
	{
		document.onmouseup=clickNS;
		document.oncontextmenu=clickIE;
	} 
	document.oncontextmenu=new Function("return false") 
	
}

function OpenExplanationWindow(testId,id,questionNumber)
{
	urlString = "ShowExplanation.asp?test=" + testId + "&id=" + id + "&question=" + questionNumber;

	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = urlString ;
	}
	else {
		newwindow=window.open(urlString ,null,"height=600,width=650,status=no,scrollbars=yes,toolbar=no,menubar=no,location=no,left=100,top=100");
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}
function OpenExplanationWindowX(testId, id, questionNumber) {
    urlString = "ShowExplanationX.asp?test=" + testId + "&id=" + id + "&question=" + questionNumber;

    if (!newwindow.closed && newwindow.location) {
        newwindow.location.href = urlString;
    }
    else {
        newwindow = window.open(urlString, null, "height=600,width=650,status=no,scrollbars=yes,toolbar=no,menubar=no,location=no,left=100,top=100");
        if (!newwindow.opener) newwindow.opener = self;
    }
    if (window.focus) { newwindow.focus() }
    return false;
}
function OpenTenCATExplanation(testId,id,questionNumber)
{
	urlString = "ShowTenCATExplanation.asp?test=" + testId + "&id=" + id + "&question=" + questionNumber;

	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = urlString ;
	}
	else {
		newwindow=window.open(urlString ,null,"height=400,width=400,status=no,scrollbars=yes,toolbar=no,menubar=no,location=no,left=10,top=10");
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}

function OpenCETWindow(testId,questionNumber)
{
	urlString = "ShowCETExplanation.asp?test=" + testId +  "&question=" + questionNumber;

	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = urlString ;
	}
	else {
		newwindow=window.open(urlString ,null,"height=600,width=650,status=no,scrollbars=yes,toolbar=no,menubar=no,location=no,left=100,top=100");
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}

function popitup(url) {
}



function toggleLayer( whichLayer ,what)
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  if (what == 1) vis.display = 'block';
  else vis.display = 'none';
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function checkMail(whichLayer )
{
var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
    
	var x = elem.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return 0;
	else return 1;
}
