/*************************************************************************
*Author		: Vipin Kumar
*FileName	: Common.js
*Purpose	: Global form validation functions file
*Created	: 07/09/2001
*Revision	: added a dateDiff function
				12/08/2002 : dateDiff - changed the computation of date 
				difference using Math.abs (date1- date2) to
				eval(date2 - date1) - to get tbe actual difference.
				13/12/2002 : fnchangestyle function added to give mouseover effect
*************************************************************************/
//variable declaration

var inHH,inMM,inSS;
var stDefRowColor;
function mouseover(){
	event.srcElement.style.cursor="hand";
}
//checks whether there is an option selected in the combo box
//Usage : fnIsComboBoxSelected(document.frm.combo,"Locations")
function fnIsComboBoxSelected(varCtrl,stCtrlName){
	if (varCtrl.selectedIndex==0){
		alert(stCtrlName +  "Please select an option");
		varCtrl.focus();
		return false;
	}
	return true;
}
//checks whether a text box contains null values
//Usage : fnIsTextNull("User name",document.frm.txt)
function fnIsTextNull(strMsg,varCtrl){
	var blnValid;
	var strVal;
	blnValid = true;
	//check for blank text field
	if (varCtrl.value==""){
		blnValid = false;
	}
	if (!blnValid) {
		//alert(strMsg + " Cannot be left blank");
		varCtrl.select();
		varCtrl.focus();
		return false;
	}
	return true;
}

//checks whether year entered is greater than 1900
//Usage : fnIsValidYear("Year ",document.frm.txt)
function fnIsValidYear(strMsg,varCtrl){
	if (varCtrl.value<1900){
		alert(strMsg + " Cannot be less than 1900");
		varCtrl.select();
		varCtrl.focus();
		return false;
	}
	return true;
}


	//fills the days in the combo
	function fillDay(varDayCtrl,varMonthCtrl,varYearCtrl){
		var inLimit;
		var inMonth;
		
		inMonth = getMonth(varMonthCtrl);
		
		//check for month = 2
		if (inMonth==2){
			//check for year
			if (fnCheckYear(varYearCtrl)==1) {
				inLimit = 29;	
			}else{
				inLimit = 28;
			}
		}else{
			if  ((inMonth==1) || 
					(inMonth==3) ||
					(inMonth==5) ||
					(inMonth==7) ||
					(inMonth==8) ||	 
					(inMonth==10) ||
					(inMonth==12)){
					inLimit = 31;
			}else{
				inLimit = 30;
			}
		}
		//clear the list
		varDayCtrl.options.length = 0;
		//add a blank option
		varDayCtrl.options.length++;
		varDayCtrl(varDayCtrl.options.length - 1).value='';
		varDayCtrl(varDayCtrl.options.length - 1).text='---';
		//fill the day combo
		for(i=1;i<=inLimit;i++){
			varDayCtrl.options.length++;
			varDayCtrl(varDayCtrl.options.length - 1).value=i;
			varDayCtrl(varDayCtrl.options.length - 1).text=i;
		}
	}
	//fills the months
	function fillMonth(varCtrl){
		varCtrl.options.length++;
		varCtrl(varCtrl.options.length - 1).value='';
		varCtrl(varCtrl.options.length - 1).text='-----';

		varCtrl.options.length++;
		varCtrl(varCtrl.options.length - 1).value='1';
		varCtrl(varCtrl.options.length - 1).text='Jan';
		
		varCtrl.options.length++;
		varCtrl(varCtrl.options.length - 1).value='2';
		varCtrl(varCtrl.options.length - 1).text='Feb';
		
		varCtrl.options.length++;
		varCtrl(varCtrl.options.length - 1).value='3';
		varCtrl(varCtrl.options.length - 1).text='Mar';
		
		varCtrl.options.length++;
		varCtrl(varCtrl.options.length - 1).value='4';
		varCtrl(varCtrl.options.length - 1).text='Apr';
		
		varCtrl.options.length++;
		varCtrl(varCtrl.options.length - 1).value='5';
		varCtrl(varCtrl.options.length - 1).text='May';
		
		varCtrl.options.length++;
		varCtrl(varCtrl.options.length - 1).value='6';
		varCtrl(varCtrl.options.length - 1).text='Jun';
		
		varCtrl.options.length++;
		varCtrl(varCtrl.options.length - 1).value='7';
		varCtrl(varCtrl.options.length - 1).text='Jul';
		
		varCtrl.options.length++;
		varCtrl(varCtrl.options.length - 1).value='8';
		varCtrl(varCtrl.options.length - 1).text='Aug';
		
		varCtrl.options.length++;
		varCtrl(varCtrl.options.length - 1).value='9';
		varCtrl(varCtrl.options.length - 1).text='Sept';
		
		varCtrl.options.length++;
		varCtrl(varCtrl.options.length - 1).value='10';
		varCtrl(varCtrl.options.length - 1).text='Oct';
		
		varCtrl.options.length++;
		varCtrl(varCtrl.options.length - 1).value='11';
		varCtrl(varCtrl.options.length - 1).text='Nov';
		
		varCtrl.options.length++;
		varCtrl(varCtrl.options.length - 1).value='12';
		varCtrl(varCtrl.options.length - 1).text='Dec';
		
	}
	//fills combo box between given lower and upper limits in reverse order
	function fillCombo(varCtrl,inLower,inUpper){
		var i;
		//var inLower = 1950;
		//var dt = new Date();
		//var inUpper = dt.getYear();
		//add a blank option

		varCtrl.options.length++;
		varCtrl(varCtrl.options.length - 1).value='';
		varCtrl(varCtrl.options.length - 1).text='-----';
		for(i=inUpper;i>=inLower;i--){
			varCtrl.options.length++;
			varCtrl(varCtrl.options.length - 1).value=i;
			varCtrl(varCtrl.options.length - 1).text=i;
		}
	}
	
	//fills combo box between given lower and upper limits
	function fillCombo1(varCtrl,inLower,inUpper){
		var i;
		//var inLower = 1950;
		//var dt = new Date();
		//var inUpper = dt.getYear();
		//add a blank option
		varCtrl.options.length++;
		varCtrl(varCtrl.options.length - 1).value='';
		varCtrl(varCtrl.options.length - 1).text='-----';
		for(i=inLower;i<=inUpper;i++){
			varCtrl.options.length++;
			varCtrl(varCtrl.options.length - 1).value=i;
			varCtrl(varCtrl.options.length - 1).text=i;
		}
	}
	
	
	//check for a leap year
	//returns 1 for leap year , 0 for normal year
	function fnCheckYear(varCtrl){
		var inYY;
		inYY = varCtrl.value;
		return (((inYY % 4 == 0) && (inYY % 100 != 0)) || (inYY % 400 == 0)) ? 1 : 0;
	}
	//returns the value of the selected month
	function getMonth(varCtrl){
		return varCtrl.value;
	}
	
	
function MM_preloadImages() { //v3.0 
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); 
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) 
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} 
} 


//adds a new item to a list box
//usage : fnAddList(document.frm.lst,"VALUE","TEXT") 
function fnAddList(varCtrl,stValue,stText){
	if (fnCheckDuplicate(varCtrl,stValue)){
		varCtrl.options.length++;
		varCtrl.options[varCtrl.options.length - 1].value=stValue;
		varCtrl.options[varCtrl.options.length - 1].text=stText;
		return true;
	}else{
		//alert('This item already exists in the list');
		return false;
	}
}
//deletes the selcted item from the list box
//usage : fnDelList(document.frm.lst)
function fnDelList(varCtrl)
{
	var selIndex,i;
/*
	if (varCtrl.value != "")
	{
		varCtrl.options[varCtrl.options.selectedIndex].value="";
		varCtrl.options[varCtrl.options.selectedIndex].text="";
		selIndex = varCtrl.options.selectedIndex;
		alert(selIndex);
	}*/
	selIndex = varCtrl.options.selectedIndex;

	for(i=selIndex;i<varCtrl.options.length-1;i++)
	{

		varCtrl.options[i].value = varCtrl.options[i+1].value;
		varCtrl.options[i].text = varCtrl.options[i+1].text;
	}

	 varCtrl.options.length--;
}

function fnCheckDuplicate(varCtrl,stValue){
	var i;
	for (i=0;i<varCtrl.options.length;i++){
		if (stValue == varCtrl.options[i].value)
			return false;
	}
	return true;
}

//File Filter
	function fnCheckFile(file){
		var extArray = new Array(".bmp",".jpg",".jpeg",".gif",".tga");
		//permit image files only.
		var allowSubmit;
		allowSubmit = false;
		if (!file) return;
		while (file.indexOf("\\") != -1)
			file = file.slice(file.indexOf("\\") + 1);
			ext = file.slice(file.indexOf(".")).toLowerCase();
			for (var i = 0; i < extArray.length; i++) {
				if (extArray[i] == ext) { 
					allowSubmit = true; 
					break; 
				}
			}
		if (allowSubmit){
			return true;
		}else{
			alert("Please only upload files that end in types:  " 
			+ (extArray.join("  ")) + "\nPlease select another "
			+ "file to upload.");
			return false;
		}	
	}

//this function provides index search feature to the page
//can be used to search for a matching item in a list box
//usage : fnListSearch('NAME|...|...|...',Value to be searched,document.frm.combo,true/false - for deselecting)
//return : the value of selected item in the combo
	function fnListSearch(stKey,stValue,varCtrl,blnDeSelect){
		var i;
		var stListVal;
		var stVal;
		if (blnDeSelect){
			for (i=0;i<varCtrl.length;i++){
				varCtrl.options[i].selected = false;
			}
		}
		for (i=0;i<varCtrl.length;i++){
			if (stKey.toUpperCase() == "NAME")
				stListVal =  varCtrl.options[i].text;
			else
				stListVal =  varCtrl.options[i].value;
			
			stListVal = stListVal.toUpperCase();
			stValue = stValue.toUpperCase();
			//if (stListVal.search(stValue) != -1){
			if (stListVal.search(stValue) == 0){
				varCtrl.options[i].selected = true;
				stVal = varCtrl.options(varCtrl.selectedIndex).value;
				return stVal;
				break; 
			}
		}
	}

//this function provides index search feature to the page
//can be used to search for a matching item in a list box
//usage : fnListSearch('NAME|...|...|...',Value to be searched,document.frm.combo,true/false - for deselecting)
//return : the value of selected item in the combo
	function fnListSearch2(stKey,stValue,varCtrl,blnDeSelect){
		var i;
		var stListVal;
		var stVal;
		if (blnDeSelect){
			for (i=0;i<varCtrl.length;i++){
				varCtrl.options[i].selected = false;
			}
		}
		for (i=0;i<varCtrl.length;i++){
			stValue = stValue.toUpperCase();
			if ((varCtrl.options[i].value.toString().toUpperCase().search(stValue) != -1) || (varCtrl.options[i].text.toString().toUpperCase().search(stValue) != -1)) {
				varCtrl.options[i].selected = true;
				stVal = varCtrl.options(varCtrl.selectedIndex).value;
				return stVal;
				break; 
			}
		}
	}



function fnValidAlpha(strMsg,varCtrl)
{
	var i;
	var flag;
	var stValue = varCtrl.value;
	for (i=0;i<stValue.length;i++)
	{
		if (((stValue.charAt(i)>="A") && (stValue.charAt(i)<="Z")) || ((stValue.charAt(i)>="a") && (stValue.charAt(i)<="z")))
			{	
			flag = 0;	
		}else{
			flag = 1;
			break;
		}
	}
	if (flag == 1){
		alert('Invalid characters in ' + strMsg + '. Please enter valid characters.');
		varCtrl.select();
		varCtrl.focus();
		return false;	
	}
	return true;
}


var oPopUp;
	function fnPopUpAlert(strMessage){
		var strHTML = '<html>' +
					  '<table border="1" height="100%" bgcolor="333333" width="100%" cellpadding="0" cellspacing="0" bordercolor="#FFAF00">' +
					  '<tr>' +
						'<td height="10" bgcolor="FFAF00" width="95%">'+
							'<font face="Arial Narrow" size="3" color="000000">'+
								'<b><i>On-Air Logger</i></b>'+
							'</font>'+
						 '</td>'+
						'<td bgcolor="FFAF00">'+
							'<a href="javascript:parent.fnClosePopUp();"><img src="../images/cross1.gif" onclick="javascript:parent.fnClosePopUp();" border="0"></a>'+
						 '</td>'+
					   '</tr>'+
					   '<tr>'+
						  '<td colspan="2" align="center">'+
							'<font face="Arial Narrow" size="3" color="ffffff">'+
								strMessage+
							 '</font>'+
						  '</td>'+
					   '</tr>'+
					   '</table>'+
					   '</html>'
		oPopUp = window.createPopup();
		var oPopUpBody = oPopUp.document.body;
		oPopUpBody.innerHTML = strHTML;
		oPopUp.show(screen.width/2 - 150,screen.height/2 - 50,300,100);
	}
	
	function fnPopUpAlert1(strMessage){
		var strHTML = '<html>' +
					  '<table border="1" height="100%" bgcolor="333333" width="100%" cellpadding="0" cellspacing="0" bordercolor="#FFAF00">' +
					  '<tr>' +
						'<td height="10" bgcolor="FFAF00" width="95%">'+
							'<font face="Arial Narrow" size="3" color="000000">'+
								'<b><i>On-Air Logger</i></b>'+
							'</font>'+
						 '</td>'+
						'<td bgcolor="FFAF00">'+
							'<a href="javascript:parent.fnClosePopUp();"><img src="images/cross1.gif" onclick="javascript:parent.fnClosePopUp();" border="0"></a>'+
						 '</td>'+
					   '</tr>'+
					   '<tr>'+
						  '<td colspan="2" align="center">'+
							'<font face="Arial Narrow" size="3" color="ffffff">'+
								strMessage+
							 '</font>'+
						  '</td>'+
					   '</tr>'+
					   '</table>'+
					   '</html>'
		oPopUp = window.createPopup();
		var oPopUpBody = oPopUp.document.body;
		oPopUpBody.innerHTML = strHTML;
		oPopUp.show(screen.width/2 - 150,screen.height/2 - 50,300,100);
	}
	
	function fnClosePopUp(){
		oPopUp.hide(); 
	}
	
	
		function isValidTime(timeCtrl) {
			var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
			var timeStr = timeCtrl.value;
			var matchArray = timeStr.match(timePat);
			if (matchArray == null) {
				fnPopUpAlert("Time is not in a valid format.");
				return false;
			}
			hour = matchArray[1];
			minute = matchArray[2];
			second = matchArray[4];
			ampm = matchArray[6];
			
			inHH = hour;
			inMM = minute;
			inSS = second;

			if (second=="") { second = null; }
			if (ampm=="") { ampm = null }

			if (hour < 0  || hour > 23) {
				fnPopUpAlert("Hour must be between 0 and 23");
				timeCtrl.select();
				timeCtrl.focus();
				return false;
			}
			if  (hour > 12 && ampm != null) {
				fnPopUpAlert("You can't specify AM or PM for military time.");
				timeCtrl.select();
				timeCtrl.focus();
				return false;
			}
			if (minute < 0 || minute > 59) {
				fnPopUpAlert ("Minute must be between 0 and 59.");
				timeCtrl.select();
				timeCtrl.focus();
				return false;
			}
			if (second != null && (second < 0 || second > 59)) {
				fnPopUpAlert ("Second must be between 0 and 59.");
				timeCtrl.select();
				timeCtrl.focus();
				return false;
			}
			return true;
		}

		function dateDiff(varCtrlInTime,varCtrlOutTime,flgAlert) {
			var date1 = new Date();
			var date2 = new Date();
			var diff  = new Date();
			var timediff = new Date();
			var secs = 0;
			
			
			if (isValidTime(varCtrlInTime)) { // Validates first date 
				date1temp = new Date(date1.getYear(),date1.getMonth(),date1.getDate(),inHH,inMM,inSS);
				date1.setTime(date1temp.getTime());
			}
			else return false; // otherwise exits
				
			
			if (isValidTime(varCtrlOutTime)) { // Validates second date 
				date2temp = new Date(date2.getYear(),date2.getMonth(),date2.getDate(),inHH,inMM,inSS);
				date2.setTime(date2temp.getTime());
			}
			else return false; // otherwise exits
			

			// sets difference date to difference of first date and second date
			//diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
			
			
			timediff = eval(date2.getTime() - date1.getTime());  //diff.getTime();
			//secs = Math.floor(timediff / 1000); 
			//timediff -= secs * 1000;
			//timediff = secs;
			
			if (timediff > 0){
				return true;
			}else if(flgAlert == 1){
				fnPopUpAlert("Invalid Times are entered");
				varCtrlInTime.select();
				varCtrlInTime.focus();
				return false; 
			}
		}

		
	
	
/*
//function to check if the field has only alphanumeric characters
//A-Z and a-z
//Usage : fnIsValidAlpha("User name",document.frm.txt)
function fnIsValidAlpha(strMsg,varCtrl){
	var Field;
	var strVal;
	var ct;
	Field = varCtrl;
	strVal = Field.value;
	Field.value = strVal.trim();
	var length = Field.value.length;
	if (!fnIsCharacter(Field)){
		alert("First letter should be an alphabet");
		varCtrl.select();
		varCtrl.focus();
		return false;
	}
	for(ct=0;ct<Field.value.length;ct++){
		var Validchar = Field.value.substring(ct,ct+1);
		var character = 0;
		if ((Validchar>="A") && (Validchar<="Z")) || ((Validchar>="a") && (Validchar<="z")) || ((Validchar >="0") && (Validchar <= "9") || (Validchar == " ") || (Validchar == "_" ) || (Validchar == "-")){
			character = 1;//valid character
		}else{
			character = 0;//invalid character
			alert("Enter a valid " + strMsg + " [Valid character set A-Z,a-z,.,_,-,0-9]");
			varCtrl.select();
			varCtrl.focus();
			return false;
		}
		//generate an error message is not a valid character
		if (character==0){
			alert("Must have valid characters in " +  strMsg);
			varCtrl.select();
			varCtrl.focus();
			return false;
		}
	}
	return true;
}
*/


/* function for the giving mouseover effect for buttons*/

function fnChangeStyle(varCtrl,flag)
{
	if(flag==0)
	{
		varCtrl.style.backgroundColor = "#ffffff";
		varCtrl.style.color = "#000000";
	}

	if(flag==1)
	{
		varCtrl.style.backgroundColor = "#A1BDEA";
		//varCtrl.style.color = "#ffffff";
		varCtrl.style.color = "#000000";
	}
}

/*
|-------------------------------------------------------------------|
Functions for changing images on rollover and showing the roll over 
menu. Added by Vipin
|-------------------------------------------------------------------|
*/
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; 
  if(d.images){
   if(!d.MM_p) d.MM_p=new Array();
  var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
   for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){
     d.MM_p[j]=new Image;
     d.MM_p[j++].src=a[i];
    }
  }
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  
  if(!d) d=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length){
    d=parent.frames[n.substring(p+1)].document; 
    n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n]; 
  for (i=0;!x&&i<d.forms.length;i++)
   x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++)
   x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById)
   x=document.getElementById(n);
  return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; 
	document.MM_sr=new Array; 
	for(i=0;i<(a.length-2);i+=3)
		if ((x=MM_findObj(a[i]))!=null){
			document.MM_sr[j++]=x;
			if(!x.oSrc) 
			x.oSrc=x.src;
			x.src=a[i+2];
		}
}

/*
|-------------------------------------------------------------------|
Function Name: fnRollOverMenu(iShow)
Purpose:This function is to make the sublevel menu visible to the 
		user on moving the mouse over the specified tab using 
		variables iShow and iMenuOption	variables.
|-------------------------------------------------------------------|
*/
function fnRollOverMenu(iShow){
	if(iShow==1){
	 document.getElementById("Submenu").style.visibility = "visible";
	 document.getElementById("Submenu").style.display = "block";
	}else{
	 document.getElementById("Submenu").style.visibility = "hidden";
	 document.getElementById("Submenu").style.display = "none";
	}
}

/*
|-------------------------------------------------------------------|
Function Name: fnChangeLayer(itoShow)
Purpose: This function is for changing between layer in the page it
		takes parameter itoShow that describes which layer has to be
		made visible. For example fnChangeLayer(2)would make 2nd 
		layer that you define visible and all the other layers visible.
Constarint: Name's and Id's of layers should be in following
	 format layer1,layer2,...
|-------------------------------------------------------------------|
*/
function fnChangeLayer(itoShow,layers){
	var iCtr;
	for(iCtr=1;iCtr<=layers;iCtr++)	{
		if(iCtr==itoShow) {
			document.getElementById("layer" + iCtr).style.visibility= "visible";
			document.getElementById("layer" + iCtr).style.display= "";
		}else{
			document.getElementById("layer" + iCtr).style.visibility= "hidden";
			document.getElementById("layer" + iCtr).style.display= "none";
		}
	}
	fnChangeColor(itoShow,layers);
}/*
|-------------------------------------------------------------------|
Function Name: fnChangeColor(itoShow,layers)
Purpose: This function is for changing color of the tab according 
		the the selected layer itoShow that describes column to 
		highlight.
Constarint: Name's and Id's of layers should be in following format
		col1,col2,...
|-------------------------------------------------------------------|
*/
function fnChangeColor(itoShow)
{
	var iCtr;
	for(iCtr=1;iCtr<=layers;iCtr++)
	{
		if(iCtr==itoShow)
		{
			document.getElementById("col" + iCtr).style.backgroundColor  = "#cccccc";
			document.getElementById("col" + iCtr).style.color = "gray";
		}
		else
		{
			document.getElementById("col" + iCtr).style.backgroundColor = "gray";
			document.getElementById("col" + iCtr).style.color = "#cccccc";
		}
	}
}


/*
|-------------------------------------------------------------------|
  Number to words converter code
	Takes two parameters to validate function input tat is to be
	converted and id of div where the result is to be displayed
|-------------------------------------------------------------------|
*/
var n = "";

//validating the input
function validate(input,divname) {
	if (input.length == 0) {
		alert ('Please Enter A Number.');
		return true;
	}else{
	 convert(input,divname);
	}
}

// single digit terms
function d1(x) { 
	switch(x) {
		case '0': n= ""; break;
		case '1': n= " One "; break;
		case '2': n= " Two "; break;
		case '3': n= " Three "; break;
		case '4': n= " Four "; break;
		case '5': n= " Five "; break;
		case '6': n= " Six "; break;
		case '7': n= " Seven "; break;
		case '8': n= " Eight "; break;
		case '9': n= " Nine "; break;
		default: n = "Not a Number";
	}
	return n;
}

// 10x digit terms
function d2(x) { 
	switch(x) {
		case '0': n= ""; break;
		case '1': n= ""; break;
		case '2': n= " Twenty "; break;
		case '3': n= " Thirty "; break;
		case '4': n= " Forty "; break;
		case '5': n= " Fifty "; break;
		case '6': n= " Sixty "; break;
		case '7': n= " Seventy "; break;
		case '8': n= " Eighty "; break;
		case '9': n= " Ninety "; break;
		default: n = "Not a Number";
	}
	return n;
}

// teen digit terms
function d3(x) {
	switch(x) {
		case '0': n= " Ten "; break;
		case '1': n= " Eleven "; break;
		case '2': n= " Twelve "; break;
		case '3': n= " Thirteen "; break;
		case '4': n= " Fourteen "; break;
		case '5': n= " Fifteen "; break;
		case '6': n= " Sixteen "; break;
		case '7': n= " Seventeen "; break;
		case '8': n= " Eighteen "; break;
		case '9': n= " Nineteen "; break;
		default: n=  "Not a Number";
	}
	return n;
}

//Converting the input to words
function convert(input,divname) {
	//Declaration
	var inputlength = input.length;
	var x = 0;
	var teen1 = "";
	var teen2 = "";
	var teen3 = "";
	var numName = "";
	var invalidNum = "";
	var a1 = ""; // for insertion of million, thousand, hundred 
	var a2 = "";
	var a3 = "";
	var a4 = "";
	var a5 = "";
	
	digit = new Array(inputlength); // stores output
		
	for (i = 0; i < inputlength; i++)  {
	// puts digits into array
	digit[inputlength - i] = input.charAt(i)};
	store = new Array(9); // store output
	for (i = 0; i < inputlength; i++) {
	x= inputlength - i;
	switch (x) { // assign text to each digit
		case x=9: d1(digit[x]); store[x] = n; break;
		case x=8: if (digit[x] == "1") {teen3 = "yes"}
		          else {teen3 = ""}; d2(digit[x]); store[x] = n; break;
		case x=7: if (teen3 == "yes") {teen3 = ""; d3(digit[x])}
		          else {d1(digit[x])}; store[x] = n; break;
		case x=6: d1(digit[x]); store[x] = n; break;
		case x=5: if (digit[x] == "1") {teen2 = "yes"}
		          else {teen2 = ""}; d2(digit[x]); store[x] = n; break;
		case x=4: if (teen2 == "yes") {teen2 = ""; d3(digit[x])}    
		          else {d1(digit[x])}; store[x] = n; break;
		case x=3: d1(digit[x]); store[x] = n; break;
		case x=2: if (digit[x] == "1") {teen1 = "yes"}
		          else {teen1 = ""}; d2(digit[x]); store[x] = n; break;
		case x=1: if (teen1 == "yes") {teen1 = "";d3(digit[x])}     
		          else {d1(digit[x])}; store[x] = n; break;
	}
	if (store[x] == "Not a Number"){invalidNum = "yes"};
	switch (inputlength){
		case 1:   store[2] = ""; 
		case 2:   store[3] = ""; 
		case 3:   store[4] = ""; 
		case 4:   store[5] = "";
		case 5:   store[6] = "";
		case 6:   store[7] = "";
		case 7:   store[8] = "";
		case 8:   store[9] = "";
	}
	if (store[9] != "") { a1 =" Hundred "} else {a1 = ""};
	if ((store[9] != "")||(store[8] != "")||(store[7] != ""))
	{ a2 =" Million "} else {a2 = ""};
	if (store[6] != "") { a3 =" Hundred "} else {a3 = ""};
	if ((store[6] != "")||(store[5] != "")||(store[4] != ""))
	{ a4 =" Thousand "} else {a4 = ""};
	if (store[3] != "") { a5 =" Hundred "} else {a5 = ""};
	}
	// add up text, cancel if invalid input found
	if (invalidNum == "yes"){numName = "Invalid Input"}
	else {
	numName = "Rupees " + store[9] + a1 + store[8] + store[7] 
	+ a2 + store[6] + a3 + store[5] + store[4] 
	+ a4 + store[3] + a5 + store[2] + store[1]+" Only";
	}
	store[1] = ""; store[2] = ""; store[3] = ""; 
	store[4] = ""; store[5] = ""; store[6] = "";
	store[7] = ""; store[8] = ""; store[9] = "";
	if (numName == ""){numName = "Zero"};
	//document.myform.textver.value = numName;
	document.getElementById(divname).innerHTML="<b>"+numName+"</b>";
	return true;
}

function fnSetRowColorSel(trID){
	stDefRowColor = document.getElementById(trID).style.backgroundColor;
	document.getElementById(trID).style.backgroundColor = "#b6bdd2";
}

function fnSetRowColorNormal(trID){
	document.getElementById(trID).style.backgroundColor = stDefRowColor;
}

function fnDivString(str){
	return (str.replace(/\r\n|\r|\n/g,"<br>"));
}


/*
-----------------------------------------------------------
Functions for form validation and email validation.
Takes form control  as parameter.
-----------------------------------------------------------
*/

/*

function fnEmailCheck(str){
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1) return false;
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
	if (str.indexOf(at,(lat+1))!=-1) return false;
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
	if (str.indexOf(dot,(lat+2))==-1) return false;
	if (str.indexOf(" ")!=-1) return false;
 	return true;
}
*/

function fnEmailCheck(str){
	/*
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1) return false;
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
	if (str.indexOf(at,(lat+1))!=-1) return false;
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
	if (str.indexOf(dot,(lat+2))==-1) return false;
	if (str.indexOf(" ")!=-1) return false;
	*/
	//done by S.Srinivas
	var reEMail=/^\w[\w\-\.]+\@\w[\w\-]+(\.[\w\-]+)+$/;
	if (!reEMail.test(str)) {
	 return false;
	}
 	return true;
 	
}

function fnCheckMailids(strMailIds)
{
	var strTemp;
	strTemp=strMailIds;
	if (strTemp.indexOf(",")==-1) 
	{
		return fnEmailCheck(stripSpaces(strTemp));	
	}
	var arrTemp=new Array();
	arrTemp=strTemp.split(",");
	
	for (var i=0;i<arrTemp.length;i++)
	{
	
		if(arrTemp[i].length!=0 && fnEmailCheck(stripSpaces(arrTemp[i]))==false  )
		{
			return false;
			break;
		}
		
	}
	return true;
}

function stripSpaces(x) { 
	if (x.charCodeAt(0)==13)
	{
		x = x.substring(1); 
		x = x.substring(1); 
	}
	while (x.substring(0,1) == ' ') 
	    x = x.substring(1); 
	while (x.substring(x.length-1,x.length) == ' ') 
	    x = x.substring(0,x.length-1); 
	return x; 
} 


function validateForm(fctrl){
	var j,i,ftype,flen,fval,flag,fctrl;
	flag=0;
		flen=fctrl.length;
		for(i=0 ; i<flen ; i++ ){
			ftype = fctrl[i].type;
			fval = fctrl[i].value;

			switch(ftype){
				case "text":
					if (fctrl[i].name == "txtEmail"){
						if (fval == "" || fval==null){
						//	alert("Please Enter the Email ID");
							flag=1;
						}else{
							if(fnEmailCheck(fval)== false){
								fctrl[i].value="";
						//		alert('Please enter valid email ID');
								flag=1;
							}
						}
					}else{
						if (fval == "" || fval==null){
						//	alert(fctrl[i].name+' needs to be filled');
							flag=1;
						}
					}
					break;
				case "select-one":
					if (fval == "" || fval==null){
						//alert(fctrl[i].name+' needs to be selected');
						flag=1;
					}	
					break;
				case "textarea":
					if (fval == "" || fval==null){
						flag=1;
					}	
					break;
				case "hidden":
					break;
				default:
					if (fval == "" || fval==null){
						flag=1;
					}	
					break;
	//				alert('defaut action');
	//				break;
			}
			if (flag==1){
				alert('You have missed a field. Please enter a value.');
				fctrl[i].focus();
				if (ftype=="select-one"){
					fctrl[i].options[0].selected = true;
				}
				break;
			}
		}
	if (flag==1)
		return false;
	else
		return true;
}


//////-------------------------------------------------------------
////// function to open a new window to show the circular
//////
//////-------------------------------------------------------------
function fnOpenCircular(stURL){	
	window.open(stURL,'Details','width=600,height=500,scrollbars=1,toolbar=no,top=0,left=0');
}
  
  
//fUNCTION TO CHECK IF THE DATES ARE VALID OR NOT 

function fnChkDate1(){
	if(document.frmOvrEdu.cmbToYr.value!="" && document.frmOvrEdu.cmbFrmYr.value != ""){
		if(document.frmOvrEdu.cmbToYr.value < document.frmOvrEdu.cmbFrmYr.value){
			alert("The FROM year can not be greater than TO year");
			return false;
		}else{
			if(document.frmOvrEdu.cmbToYr.value == document.frmOvrEdu.cmbFrmYr.value){
				if(document.frmOvrEdu.cmbToMon.value!="" && document.frmOvrEdu.cmbFrmMon.value != ""){
					if(document.frmOvrEdu.cmbToMon.value < document.frmOvrEdu.cmbFrmMon.value){
						alert("The FROM month can not be greater than TO month");
						return false;
					}else{
						if(document.frmOvrEdu.cmbToMon.value == document.frmOvrEdu.cmbFrmMon.value){
							alert("The FROM month can not be equal than TO month");
							return false;
						}
					}
				}
			}
		}
	}
	return true;
}

function fnCheckDate(){
	if(document.frmOvrEdu.cmbToYr.value!="" && document.frmOvrEdu.cmbFrmYr.value != ""){
		if(document.frmOvrEdu.cmbToYr.value < document.frmOvrEdu.cmbFrmYr.value){
			alert("The FROM year can not be greater than TO year");
			return false;
		}else{
			if(document.frmOvrEdu.cmbToYr.value == document.frmOvrEdu.cmbFrmYr.value){
				if(document.frmOvrEdu.cmbToMon.value!="" && document.frmOvrEdu.cmbFrmMon.value != ""){
					if(document.frmOvrEdu.cmbToMon.value < document.frmOvrEdu.cmbFrmMon.value){
						alert("The FROM month can not be greater than TO month");
						return false;
					}else{
						if(document.frmOvrEdu.cmbToMon.value == document.frmOvrEdu.cmbFrmMon.value){
							alert("The FROM month can not be equal than TO month");
							return false;
						}
					}
				}
			}
		}
	}
	return true;
}

//======================================================================
function fnchkSpace(ctr)
{
var len,i;
var str1;

len=ctr.length;
i=ctr.indexOf(" ");
if(i>0)
	return false;
else
	return true;
}

//========================================================================

function hideAll()
{
	var whichbrowser;

    if(document.layers)	{
       whichbrowser="NN4";
    }
    if(document.all){
       whichbrowser="ie";
    }
    if(!document.all && document.getElementById){
       whichbrowser="NN6";
    }

	if(whichbrowser=='ie')
		{
			document.all.Menu.style.visibility= "hidden";
			document.all.Menu1.style.visibility= "hidden";
			document.all.Menu.style.display= "none" ;
			document.all.Menu1.style.display= "none" ;
			document.all.Menu2.style.visibility= "hidden";
			document.all.Menu2.style.display= "none" ;	
			document.all.Menu3.style.visibility= "hidden";
			document.all.Menu3.style.display= "none" ;
			document.all.Menu4.style.visibility= "hidden";
			document.all.Menu4.style.display= "none" ;			
		}
		else if(whichbrowser=='NN4')
		{
			document.Menu.visibility="hidden";
			document.Menu1.visibility="hidden";
			document.Menu.display= "none" ;
			document.Menu1.display= "none" ;
			document.Menu2.visibility="hidden";
			document.Menu2.display= "none" ;	
			document.Menu3.visibility="hidden";
			document.Menu3.display= "none" ;
			document.Menu4.visibility="hidden";
			document.Menu4.display= "none" ;			
		}
		else if(whichbrowser=='NN6')
		{
			document.getElementByID("Menu").style.visibility= "hidden";
			document.getElementByID("Menu").style.display= "none" ;
			document.getElementByID("Menu1").style.visibility= "hidden";
			document.getElementByID("Menu1").style.display= "none" ;
			document.getElementByID("Menu2").style.visibility= "hidden";
			document.getElementByID("Menu2").style.display= "none" ;		
			document.getElementByID("Menu3").style.visibility= "hidden";
			document.getElementByID("Menu3").style.display= "none" ;
			document.getElementByID("Menu4").style.visibility= "hidden";
			document.getElementByID("Menu4").style.display= "none" ;			
		}

}

var count;
count=1;
function show(strMenu)
{
	//declaring variables
	
	var n;
	var thisbrowser;

	//initiailizing and reinitializing the variable n which will keep the counter to let user show and hide layer
	n=count%2;
	//code for detecting the browser
        if(document.layers)
	{
            thisbrowser="NN4";
        }
        if(document.all)
	{
             thisbrowser="ie";
        }
        if(!document.all && document.getElementById)
	{
             thisbrowser="NN6";
        }

	if(n!=0)
	{
    	if(thisbrowser=='ie')
		{
			if(strMenu=="Menu")
			{
				document.all.Menu.style.visibility= "visible";
				document.all.Menu.style.display= "block" ;
			}
			if(strMenu=="Menu1")
			{
				document.all.Menu1.style.visibility= "visible";
				document.all.Menu1.style.display= "block" ;
			}
			if(strMenu=="Menu2")
			{
				document.all.Menu2.style.visibility= "visible";
				document.all.Menu2.style.display= "block" ;
			}	
			if(strMenu=="Menu3")
			{
				document.all.Menu3.style.visibility= "visible";
				document.all.Menu3.style.display= "block" ;
			}
			if(strMenu=="Menu4")
			{
				document.all.Menu4.style.visibility= "visible";
				document.all.Menu4.style.display= "block" ;
			}			
		}
		else if(thisbrowser=='NN4')
		{
			if(strMenu=="Menu")
			{
				document.Menu.visibility="visible";
				document.Menu.display = "block";
			}
			if(strMenu=="Menu1")
			{
				document.Menu1.visibility="visible";
				document.Menu1.display = "block";
			}
			if(strMenu=="Menu2")
			{
				document.Menu2.visibility="visible";
				document.Menu2.display = "block";
			}	
			if(strMenu=="Menu3")
			{
				document.Menu3.visibility="visible";
				document.Menu3.display = "block";
			}
			if(strMenu=="Menu4")
			{
				document.Menu4.visibility="visible";
				document.Menu4.display = "block";
			}			
			
		}
		else if(thisbrowser=='NN6')
		{
			if(strMenu=="Menu")
			{
				document.getElementByID("Menu").style.visibility= "visible";
				document.getElementByID("Menu").style.display= "block" ;
			}
			if(strMenu=="Menu1")
			{
				document.getElementByID("Menu1").style.visibility= "visible";
				document.getElementByID("Menu1").style.display= "block" ;
			}
			if(strMenu=="Menu2")
			{
				document.getElementByID("Menu2").style.visibility= "visible";
				document.getElementByID("Menu2").style.display= "block" ;
			}
			if(strMenu=="Menu3")
			{
				document.getElementByID("Menu3").style.visibility= "visible";
				document.getElementByID("Menu3").style.display= "block" ;
			}
			if(strMenu=="Menu4")
			{
				document.getElementByID("Menu4").style.visibility= "visible";
				document.getElementByID("Menu4").style.display= "block" ;
			}			
		}
		count=count+1;
	}
	else
	{
	if(thisbrowser=='ie')
		{
			if(strMenu=="Menu")
			{
				document.all.Menu.style.visibility= "hidden";
				document.all.Menu.style.display= "none" ;
			}
			if(strMenu=="Menu1")
			{
				document.all.Menu1.style.visibility= "hidden";
				document.all.Menu1.style.display= "none" ;
			}
			if(strMenu=="Menu2")
			{
				document.all.Menu2.style.visibility= "hidden";
				document.all.Menu2.style.display= "none" ;
			}	
			if(strMenu=="Menu3")
			{
				document.all.Menu3.style.visibility= "hidden";
				document.all.Menu3.style.display= "none" ;
			}
			if(strMenu=="Menu4")
			{
				document.all.Menu4.style.visibility= "hidden";
				document.all.Menu4.style.display= "none" ;
			}			
		}
		else if(thisbrowser=='NN4')
		{
			if(strMenu=="Menu")
			{
				document.Menu.visibility="hidden";
				document.Menu.display= "none" ;
			}
			if(strMenu=="Menu1")
			{
				document.Menu1.visibility="hidden";
				document.Menu1.display= "none" ;
			}
			if(strMenu=="Menu2")
			{
				document.Menu2.visibility="hidden";
				document.Menu2.display= "none" ;
			}
			if(strMenu=="Menu3")
			{
				document.Menu3.visibility="hidden";
				document.Menu3.display= "none" ;
			}
			if(strMenu=="Menu4")
			{
				document.Menu4.visibility="hidden";
				document.Menu4.display= "none" ;
			}				
		}
		else if(thisbrowser=='NN6')
		{
			if(strMenu=="Menu")
			{
				document.getElementByID("Menu").style.visibility= "hidden";
				document.getElementByID("Menu").style.display= "none" ;
			}
			if(strMenu=="Menu1")
			{
				document.getElementByID("Menu1").style.visibility= "hidden";
				document.getElementByID("Menu1").style.display= "none" ;
			}
			if(strMenu=="Menu2")
			{
				document.getElementByID("Menu2").style.visibility= "hidden";
				document.getElementByID("Menu2").style.display= "none" ;
			}			
			if(strMenu=="Menu3")
			{
				document.getElementByID("Menu3").style.visibility= "hidden";
				document.getElementByID("Menu3").style.display= "none" ;
			}
			if(strMenu=="Menu4")
			{
				document.getElementByID("Menu4").style.visibility= "hidden";
				document.getElementByID("Menu4").style.display= "none" ;
			}	
		}
		count=count+1;
	}
}


function hideAllMenu()
{
	var whichbrowser;

    if(document.layers)	{
       whichbrowser="NN4";
    }
    if(document.all){
       whichbrowser="ie";
    }
    if(!document.all && document.getElementById){
       whichbrowser="NN6";
    }
	if(whichbrowser=='ie')
		{
			document.all.Menu2.style.visibility= "hidden";
			document.all.Menu2.style.display= "none" ;
			document.all.Menu1.style.visibility= "hidden";
			document.all.Menu1.style.display= "none" ;			
		}
		else if(whichbrowser=='NN4')
		{
			document.Menu2.visibility="hidden";
			document.Menu2.display= "none" ;
			document.Menu1.visibility="hidden";
			document.Menu1.display= "none" ;			
		}
		else if(whichbrowser=='NN6')
		{
			document.getElementByID("Menu2").style.visibility= "hidden";
			document.getElementByID("Menu2").style.display= "none" ;
			document.getElementByID("Menu1").style.visibility= "hidden";
			document.getElementByID("Menu1").style.display= "none" ;			
		}

}
