<!--
var CR= unescape("%0D");		// The carriage return
var ErrEncountered = false
var ErrMesg = "";

function checknull(obj,text)

// Check for Null value & add proper message in the variable ErrMesg.
/* 
	Pass the parameters - 
						1.	Field object name
						2.  Text for field to be displayed in the alert message
						
							Eg. checknull(document.form1.txtName,'State Name')
*/
					 
{
var i = 0;
	for(i=0;(i < obj.value.length &&  obj.value.charAt(i) == ' ');i++);
	if (i == obj.value.length) 
		{
			ErrMesg+= "* "+text+" can not be blank"+CR;
			ErrEncountered = true;
		}
}		// EOFn

function checknull2(obj)
// Check for null value & return - true/false
/*		Function checknull2 
			Pass the parameter(s) - 
			   			   1.	Field object name
			   			   
			Return Value - True/False (True, if the value of object is null. False, if the value of object is not null.			 
			Eg. if (checknull2(document.form1.txtAddress)==false) alert('xxxx') else alert('yyyy');
*/
			
{
var i = 0;
	for(i=0;(i < obj.value.length &&  obj.value.charAt(i) == ' ');i++);
	if (i == obj.value.length) 
		return true;
	else
		return false;	
}		// EOFn

function checklength(obj,text)
// Check the length
/*	Function checklength
			Pass the parameter(s) - 
						 1.	Field object name
						 2.	Text for field to be displayed in the alert message
						 
						 Note : In this case maxlength of the object must be defined.
						 Eg. checklength(document.form1.txtAddress,'Street Address')
*/

{
	if (parseInt(obj.value.length,10) > parseInt(obj.maxlength,10))
	{
		ErrMesg+= "* Value of "+text+" can not be more than "+obj.maxlength+" characters"+CR;
		ErrEncountered = true;
	}
}	// EOFn

function checkcombo(obj,val,text)

// Check for value in the dropdown.
/*		Function checkcombo
			Pass the parameter(s) - 
						 1.	Field object name
						 2.	Value of the dropdown which is to be checked.
						 3.	Text for field to be displayed in the alert message
						 
						 Eg. checkcombo(document.form1.txtEmail,'X','City')
*/

{
	if (obj.options[obj.selectedIndex].value==val)
	{
		ErrMesg+= "* "+text+" must be selected"+CR;
		ErrEncountered=true;
	}
}	// EOFn

function checknum(obj,text,minvalue)

// Check for numeric value, if its numeric - should be greater than/equal to given value.
/*		Function checknum
			Pass the parameter(s) - 
						 1.	Field object name
						 2.	Text for field to be displayed in the alert message
						 3.	Minimum value i.e. the value entered in the object should be greater than/equal to minimum value.
						 
						 Eg. checknum(document.form1.txtArea,'Area',0)
*/
						 
{
	if (isNaN(obj.value))
	{
		ErrMesg+= "* "+text+" should be numeric"+CR;
		ErrEncountered=true;
	}
	else
	{
		if (parseInt(obj.value,10) < minvalue)
		{
			ErrMesg+= "* Value of "+text+" should be greater than/equal to "+minvalue+CR;
			ErrEncountered=true;
		}
	}
}	// EOFn

function checkimg(obj,text)

// Check image extension & return extension.
/*		Function checkimg 
			Pass the parameter(s) - 
			   			   1.	Field object name
			   			   2.	Text for field to be displayed in the alert message
			   			   
			Return Value - Extension of the image.
			Eg. var extnsmallimg =  checkimg(document.form1.txtImage,"Image");
*/

{
	var extn = '';
	var pos = obj.value.lastIndexOf(".");
	
	if (pos != -1)
		extn = obj.value.substring(pos+1);
	
	if (extn=='')
	{
		ErrMesg+= "* "+text+" can't be without an Extension"+CR;
		ErrEncountered = true;
	}
	else
	{
		extn = extn.toUpperCase();
		if (!(extn=="JPG" || extn=="JPEG" || extn=="GIF"))
		{
			ErrMesg+= "* "+text+" Extension should be 'JPG', 'JPEG' or 'GIF' only"+CR;
			ErrEncountered = true;
		}
	}
	return extn;	
}	// EOFn

//-->

function checkemail(obj,text)
// Check for valid email addresses
/*		Function checkemail
			Pass the parameter(s) - 
						 1.	Field object name
						 2.	Text for field to be displayed in the alert message
						 
						 Eg. checkemail(document.form1.txtEmail,'Email Id')
*/

{
emailexp1 = /([a-zA-Z0-9_]+)(@)([a-zA-Z0-9]+)([\.])([a-zA-Z]){2,}/   
emailexp2 = /([a-zA-Z0-9_]+)(@)([a-zA-Z0-9]+)([\.])([a-zA-Z]){4,}/   

	if ((obj.value.search(emailexp1) == - 1) || (obj.value.search(emailexp2) != - 1))
	{
		ErrMesg+= "* Invalid "+text+" !!"+CR;
		ErrEncountered = true;
	}
}	// EOFn

function checkdaterange(fromdt,todt,fromdttext,todttext)

// Check whether From date > To date.
/*		Function checkdaterange
			 Pass the parameters - 
						1.	value of From Date field in the format(mm/dd/yyyy)
						2.  value of To Date field in the format(mm/dd/yyyy)
						3.  Text for From Date to be displayed in the alert message
						4.  Text for To Date to be displayed in the alert message 
						
						 Eg. checkdaterange('12/1/2001','12/31/2001','From Date','To Date')
*/

{
var fromdtnum = Date.parse(fromdt);
var todtnum = Date.parse(todt);

	if (todtnum < fromdtnum)
	{
			ErrMesg+= "* "+fromdttext+" can not be greater than "+todttext+CR;
			ErrEncountered = true;
	}
}	// EOFn

function checkphone(obj,text)

// Check for valid phone numbers
/* Pass the parameters - 
						1.	Field object name
						2.  Text for field to be displayed in the alert message
						
							Eg. checkphone(document.form1.txtPhone,'Phone No.')
*/

{
var expphno = /([^0-9\,\-\(\)]){1,}/;
	if (obj.value.search(expphno)!= -1)
	{
		ErrMesg+= "* "+text+" is invalid !!"+CR;
		ErrEncountered = true;
	}
}	// EOFn

function checkchkboxsingle(obj,text,option)

// Check whether a checkbox is checked/unchecked.
/* Pass the parameters - 
						1.	Field object name
						2.  Text for field to be displayed in the alert message
						3.	The text 'checked' or 'unchecked' based on examples below						
							Eg. 
							If checkbox has to be checked - 
							checkchkboxsingle(document.form1.chkDisplay,'Display on web','checked');
							
							If checkbox has to be unchecked - 
							checkchkboxsingle(document.form1.chkDisplay,'Display on web','unchecked');
*/

{
	option = option.toLowerCase();
	
	if (option=='checked')
	{
		if(obj.checked==false)
		{
				ErrMesg+= "* "+text+" must be "+option+CR;
				ErrEncountered = true;
		}
	}
	
	if (option=='unchecked')
	{
		if(obj.checked==true)
		{
				ErrMesg+= "* "+text+" must be "+option+CR;
				ErrEncountered = true;
		}
	}	
}	// EOFn

function checkoptions(arroptions,text,obj)

// Check whether one of the radio buttons/checkboxes of a group is checked or not
/* Pass the parameters - 
						1.	Array of radio buttons/checkboxes (In this case the whole group of radio buttons/checkboxes should have same id)
						2.  Text for field to be displayed in the alert message
						3.  Field object name
						Eg. First create the array of radio buttons/checkboxes & then pass it to the function.
						var arropt = document.all("optAvailable");		Here optAvailable is the id given to all radio buttons/checkboxes of the group.
						checkoptions(arropt,'Available Options',document.form1.optAvailable);
*/

{
var cntr=0;

	if (arroptions.length)
	{
		for (var i=0;i<arroptions.length;i++)
		{
			if (arroptions[i].checked==true)
				cntr+= 1;
		}
	}
	else
	{
		if (obj.checked==true)
			cntr+= 1;
	}
	
	if (cntr==0)
	{
		ErrMesg+= "* Atleast one option of "+text+" must be selected"+CR;
		ErrEncountered = true;
	}
}	// EOFn

function previewimage(obj,text)
{
// Preview An Image(GIF/JPG/SWF)
/* Pass the parameters - 
						1.	Field Object Name (A Text Field or File Type Field)
						2.  Text for field to be displayed in the alert message
						Eg. previewimage(document.form1.flUploadImage,'Image Path');
*/
	if (checknull2(obj)==true)
	{
			alert (" First select image !!");
			return;
	}
	else
	{
		var imgpath = obj.value;
		var extn = '';
		var pos = obj.value.lastIndexOf(".");
	
		if (pos != -1)
			extn = obj.value.substring(pos+1);
	
		if (extn=='')
		{
			ErrMesg+= "* "+text+" can't be without an Extension"+CR;
			ErrEncountered = true;
		}
		else
		{
			extn = extn.toUpperCase();
			var newwin;
			newwin=window.open ("","previewwin","width=400,height=300");
			
			if ((extn=='JPG') || (extn=='JPEG') || (extn=='GIF'))
				newwin.document.write ('<img border=0 src='+ imgpath +'>');
			
			if (extn=='SWF')
				newwin.document.write ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" border=0 width=100% height=100%><param name=_cx value=4895><param name=_cy value=3969><param name=Movie value='+ imgpath +'><param name=Src value='+ imgpath +'><param name=WMode value=Window><param name=Play value=-1><param name=Loop value=-1><param name=Quality value=High><param name=SAlign value><param name=Menu value=-1><param name=Base value><param name=Scale value=ShowAll><param name=DeviceFont value=0><param name=EmbedMovie value=-1><param name=BGColor value><param name=SWRemote value><embed src='+ imgpath +' quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width=100% height=100%></object>');	
		}
	}			
}

function changeday(objyear,objmonth,objday) // will populate day dropdown 
{
// Fill day dropdown according to selected year & month.
/* Pass the parameters - 
						1.	Year dropdown object name
						2.  Month dropdown object name
						3.  Day dropdown object name
						Eg. changeday(document.form1.selYear,document.form1.selMonth,document.form1.selDay);
*/

	var month,year;
	var dayarr = new Array(31,28,31,30,31,30,31,31,30,31,30,31); 
	month = parseInt(objmonth.value);
	year = parseInt(objyear.value);
	if ( month == 0 || year == 0)
		return ;
	if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0  ))
		dayarr[1]= 29;
	objday.length =dayarr[month-1]+1;
	for(i=29;i<=dayarr[month-1];i++)
	{
		objday.options[i].text = i;
	    objday.options[i].value = i;
	}
}   // EOFn

function checklength1(obj,text,lengthtocheck)
// Check the length

{
	if (parseInt(obj.value.length,10) > parseInt(lengthtocheck,10))
	{
		ErrMesg+= "* Value of "+text+" can not be more than "+lengthtocheck+" characters"+CR;
		ErrEncountered = true;
	}
}	// EOFn

function checktext(obj,text)

// Check for text only value, it should not be numeric
/*		Function checktext
			Pass the parameter(s) - 
						 1.	Field object name
						 2.	Text for field to be displayed in the alert message
						 
						 Eg. checktext(document.form1.txtArea,"First Name")
*/
						 
{
	if (obj.value > 0 || obj.value < 0)
	{
		ErrMesg+= "* "+text+": only numeric data is not allowed. "+CR;
		ErrEncountered=true;
	}
}	// EOFn
