/************************************************************************
Validation funcs written by arv@10aug2k3
************************************************************************

--------GUIDELINES FOR USAGE OF FUNCTIONS ----------------------
set the id of form elements as directed here and 
call the CheckEntireForm(objForm) in the form submit evet
i.e. <form onSubmit = "return CheckEntireForm(MyFormName)" ... >

RQ-Y/N REQUIRED(SHOULD NOT BE BLANK)
NM-Y/N NAME
NU-Y/N NUMERIC
FN-Y/N FLOAT NUMERIC
NUR-Y/N NUMERIC RANGE
NURMX-n MAX NUMERIC RANGE
NURMN-n MIN NUMERIC RANGE
NRC-Y/N CHECK NUMEIC RANGE
PH-Y/N PHONE
EM-Y/N EMAIL
CMX-n CONTROL HAS n AS MAX RANGE
CMN-n CONTROL HAS n AS MIN RANGE
CRC - Y/N CHECK CONTROL LENGTH RANGE
LBC-Y/N- CONTROL IS A LIST BOX CONTROL AND CHECK THAT A SELECTON IS MADE
MSS - XYZ... MESSAGE TO THROW IF VALIDATION FAILED
SPA - Y/N space is not allowed
FUP - Y/N if a file upload comp
TFP - P/C p=picture ; c = cv

A SAMPLE ID IS SHOWN HERE
RQ-Y|NU-Y|CMN-3|CMX-8|MSS-EMPLYOEE_INCOME_LEVEL
this field is a required field, it can only accept
numeric data and can contain only 3 to 8 char length number
it is EMPLYOEE INCOME LEVEL (notice underscore as space is not allowwd)
***********************************************************************************
*/
//this code is copyied from calender file

var NUM_CENTYEAR = 30;
var BUL_TIMECOMPONENT = false;
var BUL_YEARSCROLL = true;
var LEFT_POS=0
var TOP_POS=0
var calendars = [];
var RE_NUM = /^\-?\d+$/;

var Left
var Bottom

var IE = document.all?true:false

if (!IE) document.captureEvents(Event.MOUSEMOVE)


document.onmouseup = getMouseXY;
var tempX = 0
var tempY = 0

//////////////////////////////////////////
//Global constants for message throwing
var MESS_BLANK = new String("Please specify a value for the field: ")
var MESS_RANGE = new String("Please specify a value in the valid range for the field: ")
var MESS_NUMERIC = new String("Please specify a valid numeric value for the field: ")
var MESS_NAME = new String("Please specify a valid name for the field: ")
var MESS_NUMERIC_RANGE = new String("Please specify a numeric value in the given range for the field: ")
var MESS_PHONE = new String("Please specify a valid phone number in the format xxx-xxx-xxxxxxxx for the field: ")
var MESS_EMAIL = new String("Please specify a valid Email address in the form of foo@bar.com for the field: ")
var MESS_CHAR_DATA = new String("Please specify a value with the specified min/max length for the field: ")
var MESS_LIST = new String("Please select an option from the list : ")
var MESS_START =new String("PLEASE FILL THIS FORM AS SPECIFIED HERE :\n--------------------------------------------------------------------")
var MESS_FUP=new String("The file you have selected for upload is not a valid file for the field: ")
var MESS_STRICTNUMERIC = new String("Please enter a whole number for the field : ")
var MESS_PASSWORD = new String("Please enter a valid value (Alphabets,numbers, _ are allowed) for the field :")
//x



//Function to search  through an entire select list and highlight a specific option value based on passed arguement ObjList = Name of select list
function SelectListOption(ObjList,StrOptionValue)
{
	for(i=0;i<ObjList.length;i++)
	{
		if (ObjList.options[i].text==StrOptionValue)
		{
			ObjList.options[i].selected="1";
			return true;
		}
	}
	return false;		
}

//Function to check / uncheck checkbox form control
function SelectCheckBox(ObjCheckBox,boolCheck)
{
	if(boolCheck){
		ObjCheckBox.checked=true;
		return true;
		}
	else
	{
		ObjCheckBox.checked=false;
		return false;
	}
}

//get ascii char code of arg
function GetAsciiCode(argChar)
{
	var s = new String(argChar);
	return parseInt(s.charCodeAt(0));
}

//check if arg is pure numeric and a +ive whole number 
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}
//check valid password
//check if arg is pure numeric and a +ive whole number 
function IsPassword(sText)
{
   var ValidChars = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm0123456789_";
   var ret=true;
   var Char;
 
   for (i = 0; i < sText.length && ret == true; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         ret= false;
         }
   }
   return ret;
}
//check if arg is pure numeric and a +ive whole number 
function IsStrictNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}
//func for char checking 
function IsValid(argValue,argValidChars)
{
   var ValidChars = argValidChars;
   var ret=true;
   var Char;
 
   for (i = 0; i < argValue.length && ret == true; i++) 
      { 
      Char = argValue.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         ret = false;
         }
      }
   return ret;
}
//check if arg is  numeric and a +ive decimal number
function IsFloatOrNumeric(argStr)
{
	var s = new String(argStr);
	var cnt=0;
	len = s.length;
	if (IsBlank(argStr)) { return false;}
	for(i=0;i<len;i++)
	{
		intCh = GetAsciiCode(s.charAt(i));
		
		if (intCh==46) //there can't be more than one decimal
		{
			cnt++;
			if(cnt>1)
				return false;
		}
		
		if (intCh==46&&(i==0||i==len-1))//first char and last char cannot be decimal
		{
			 return false;
		}
		
		if(!((intCh>=48&&intCh<=57)||(intCh==46)))
		{
			return false;
		}
	}
	return true;
}

//check if a string contains whitespaces or nothing ...
function IsBlank(argStr)
{
	var s = new String(argStr);
	var cnt=0;
	len = s.length;
	
	for(i=0;i<len;i++)
	{
		intCh = GetAsciiCode(s.charAt(i));
		if(intCh==32)
		{
			cnt++;
		}
	}
	if ((cnt==len)||(cnt==0&&len==0))
	{
		return true;
	}
	return false;
}

//check if a string contains special characters
function IsSpecialCharacter(argStr)
{
	var s = new String(argStr);
	var cnt=0;
	len = s.length;
	if (IsBlank(argStr)) { return false;}
	
	for(i=0;i<len;i++)
	{
		intCh = GetAsciiCode(s.charAt(i));
		if ((intCh>=0&&intCh<=31) || (intCh>=127&&intCh<=255))
		{
			return true;
		}
	}
	return false;
}

//check if a string abides to a min , max range rule for an input field
function IsLengthBetweenRange(argStr,MIN,MAX)
{
	var s = new String(argStr)
	len = s.length;
	if (len<MIN||len>MAX)
	{
		return false;
	}
	return true;
}

//check valid international phone number xxx-xxx-xxxxxxxx
function IsValidInternationalPhoneFaxNumber(argStr)
{
	var s = new String(argStr);
	var cnt=0;
	len = s.length;
	
	if (IsThereAnyWhiteSpace(argStr)==true)
	{
		return false;
	}
		
	if (!(s.indexOf("-")>=0))
	{
		return false;
	}
		
	arr = s.split("-")
	
	if (arr.length!=3)
	{
		return false;
	}
	
	var countrycode=new String(arr[0]);
	var statecode=new String(arr[1]);
	var localcode=new String(arr[2]);
	
	if (IsNumeric(countrycode)==false||IsNumeric(statecode)==false||IsNumeric(localcode)==false)
	{
	return false;
	}
	
	if (IsLengthBetweenRange(countrycode,2,3)==false||IsLengthBetweenRange(statecode,2,3)==false||IsLengthBetweenRange(localcode,4,8)==false)
	{
		return false;
	}
	
	return true;
}

//check if arg contains no white spaces
function IsThereAnyWhiteSpace(argStr)
{
	var s = new String(argStr);
	var cnt=0;
	len = s.length;
	if (IsBlank(argStr))
	{
	return false;
	}
	
	if(s.indexOf(" ")>=0)
	{
		return true;
	}
	return false;
}
//check if number is between given range
function CheckNumericRange(argStr,MIN,MAX)
{
	if (IsNumeric(argStr)==true)
	{
		var n = new Number(argStr);
		
		if (n<MIN||n>MAX)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return false;
	}
}
function IsValidName(argStr)
{
	var s = new String(argStr);
	var cnt=0;
	len = s.length;
	
	for(i=0;i<len;i++)
	{
		intCh = GetAsciiCode(s.charAt(i));
		if(!((intCh==32)||(intCh>=65&&intCh<=90)||(intCh>=97&&intCh<=122)||(intCh==46)||(intCh==39)))
		{
			return false;
		}	
	}
	return true;
}
function IsValidEmail(argStr)
{
	var s = new String(argStr)
	
	if(IsBlank(s)==true) {return false;}
	if(IsThereAnyWhiteSpace(s)==true) { return false;}
	if(IsValid(s,"qwertyuiopasdfghjklzxcvbnm0123456789-@.QWERTYUIOPASDFGHJKLZXCVBNM")==false) return false;
	if(s.indexOf('@')<1) { return false;}
	
	var dotCount;
	var id = new String();
	var dom = new String();
	
	arr=s.split('@')
	
	id  = arr[0];
	dom = arr[1];
	
	
	
	if (id.length<1) { return false;}
	if (dom.length<4) { return false;}
	if (dom.indexOf('.')<1) { return false;}
	return true;
}
function IsListBoxSelected(objListBox)
{
	
	/*var strText = new String(objListBox.options[objListBox.selectedIndex].text)
	if (strText.toUpperCase()=='SELECT') return false;*/
	
	if (objListBox.options[objListBox.selectedIndex].value==0)
	{
		return false;
	}
	return true;
}
//resolve extra data passed with a control to the form and get name - value pairs 
function GetCommand(CONTROL_DATA,MKEY)
{	
	arr = CONTROL_DATA.split("|")
	for(i=0;i<arr.length;i++)
	{
		arr2=arr[i].split("-");
		if (arr2[0]==MKEY)
		{
			return arr2[1];
		}
	}
}
/*fn :: restrict the user to select only gif,jpe,png files for photo uploading */
function IsValidFile(argStr,type)
{
	var fileExt=new Array();
	if(type.toUpperCase()=='P')//picture
	{
		fileExt[0]="GIF";
		fileExt[1]="JPEG";
		fileExt[2]="PNG";
		fileExt[3]="JPG";
	}
	if(type.toUpperCase()=='C')//cv
	{
		fileExt[0]="TXT";
		fileExt[1]="DOC";
		fileExt[2]="XLS";
		fileExt[3]="ZIP";
		fileExt[4]="HTM";
		fileExt[5]="HTML";
	}

	dt=argStr;
	if(dt.length>0)
	{
		dotpos = dt.lastIndexOf(".");
		ext = dt.substr(dotpos+1);
		for(i=0;i<fileExt.length;i++)
		{
			if (ext.toUpperCase()==fileExt[i])
			{
				return true;				
			}
		}
	return false;
	}
	else
	{
		//if no file is selected then return true as there is nothin to check
		return true;
	}
	return false;
}
//***********************************************************************************************
//This function takes the form obj as arg and processes all it's elements by the ids passed to it
//***********************************************************************************************

function CheckEntireForm(objForm)
{
	var intFormElements=new Number();		//number of form elements
	var obj;								//pointer to particular object of form
	var i;									//loop var
	var COMMAND_STRING = new String();		//command string of form control
	var FINAL_MESSAGE = new String();		//message to throw if validation fails
	
	
	var RQ;									//required field
	var NM;									//name field
	var NU;									//numeric fiels
	var FN;									//float numeric
	var NUR;								//numeric range
	var NURMX;								//if nur then max numeric range
	var NURMN;								//if nur then min numeric range
	var PH;									//phone field
	var EM;									//email field
	
	var CMX;								//field max length
	var CMN;								//field min length
	var LBC;								//control is a list box select
	var MSS_CONTROL;						//mss associated with a control(message)
	var SPA;								//spaces not allowed
	
	var NRC;
	var CRC;
	var FUP;
	var TFP;
	var STN;								//STRICT NUMERIC NO DECIMALS
	var PWD;								//password field
	
	var YES="Y";							//constants for the ease of distinguishing
	var NO="N";								//constants for the ease of distinguishing
	
	var CONTROL_VALUE;
	var m;
	
	//get number of form elements
	intFormElements= objForm.elements.length;
	
	//seperate messages for all elements
	var MESSAGE_ARRAY = new Array(intFormElements)
	
	//loop through all elements
	for(i=0;i<intFormElements;i++)
	{
		obj = objForm.elements[i]
		
		COMMAND_STRING = obj.lang;
		//alert(COMMAND_STRING);
		COMMAND_STRING = COMMAND_STRING.toUpperCase();
		
		//get custom validation
	
		RQ			= GetCommand(COMMAND_STRING,"RQ");
		NM			= GetCommand(COMMAND_STRING,"NM");
		NU			= GetCommand(COMMAND_STRING,"NU");
		FN			= GetCommand(COMMAND_STRING,"FN");
		NUR			= GetCommand(COMMAND_STRING,"NUR");
		NURMX		= GetCommand(COMMAND_STRING,"NURMX");
		NURMN		= GetCommand(COMMAND_STRING,"NURMN");
		PH			= GetCommand(COMMAND_STRING,"PH");
		EM			= GetCommand(COMMAND_STRING,"EM");
		CMX			= GetCommand(COMMAND_STRING,"CMX");
		CMN			= GetCommand(COMMAND_STRING,"CMN");
		LBC			= GetCommand(COMMAND_STRING,"LBC");
		MSS_CONTROL = GetCommand(COMMAND_STRING,"MSS");
		SPA			= GetCommand(COMMAND_STRING,"SPA");
		NRC			= GetCommand(COMMAND_STRING,"NRC");
		CRC			= GetCommand(COMMAND_STRING,"CRC");
		FUP			= GetCommand(COMMAND_STRING,"FUP")
		TFP			= GetCommand(COMMAND_STRING,"TFP")
		STN			= GetCommand(COMMAND_STRING,"STN")
		PWD			= GetCommand(COMMAND_STRING,"PWD")
		
		CONTROL_VALUE = obj.value
		MESSAGE_ARRAY[i]=""
		
		//check required
		if (RQ==YES)
		{
			
			if (IsBlank(CONTROL_VALUE)==true)
			{
				MESSAGE_ARRAY[i] = MESS_BLANK+MSS_CONTROL
			}
		}
		//check name
		if (NM==YES)
		{
			if (IsValidName(CONTROL_VALUE)==false&&MESSAGE_ARRAY[i].length==0)
			{
				MESSAGE_ARRAY[i] = MESS_NAME+MSS_CONTROL;
			}
		}
		//check strict numeric
		if (STN==YES)
		{
			if (IsStrictNumeric(CONTROL_VALUE)==false&&MESSAGE_ARRAY[i].length==0)
			{
				MESSAGE_ARRAY[i] = MESS_STRICTNUMERIC+MSS_CONTROL;
			}
		}
		//check numeric
		if (NU==YES)
		{
			if (IsNumeric(CONTROL_VALUE)==false&&MESSAGE_ARRAY[i].length==0)
			{
				MESSAGE_ARRAY[i] = MESS_NUMERIC+MSS_CONTROL;
			}
		}
		//check float numeric
		if (FN==YES)
		{
			if (IsFloatOrNumeric(CONTROL_VALUE)==false&&MESSAGE_ARRAY[i].length==0)
			{
				MESSAGE_ARRAY[i] = MESS_NUMERIC+MSS_CONTROL;
			}
		}
		//check password
		if (PWD==YES)
		{
			if (IsPassword(CONTROL_VALUE)==false&&MESSAGE_ARRAY[i].length==0)
			{
				MESSAGE_ARRAY[i] = MESS_PASSWORD+MSS_CONTROL;
			}
		}
		//check numeric with range
		if (NUR==YES)
		{
			if(STN==YES)
			{
				if (IsStrictNumeric(CONTROL_VALUE)==false&&MESSAGE_ARRAY[i].length==0)
				{
					MESSAGE_ARRAY[i] = MESS_NUMERIC+MSS_CONTROL;
				}		
			}
			else
			{
				if (IsNumeric(CONTROL_VALUE)==false&&MESSAGE_ARRAY[i].length==0)
				{
					MESSAGE_ARRAY[i] = MESS_NUMERIC+MSS_CONTROL;
				}
			}
		}
		
		if (NRC==YES&&MESSAGE_ARRAY[i].length==0)
		{
			if (CheckNumericRange(CONTROL_VALUE,NURMN,NURMX)==false&&MESSAGE_ARRAY[i].length==0)
			{
				MESSAGE_ARRAY[i] = MESS_NUMERIC_RANGE+MSS_CONTROL+"[Range: "+NURMN+" to "+NURMX+ " ]";
			}
		}
		
		//check phone number
		if (PH==YES&&MESSAGE_ARRAY[i].length==0)
		{
			if (IsValidInternationalPhoneFaxNumber(CONTROL_VALUE)==false&&MESSAGE_ARRAY[i].length==0)
			{
				MESSAGE_ARRAY[i] = MESS_PHONE+MSS_CONTROL;
			}
		}
		
		//check email
		if (EM==YES&&MESSAGE_ARRAY[i].length==0)
		{
			if (IsValidEmail(CONTROL_VALUE)==false&&MESSAGE_ARRAY[i].length==0)
			{
				MESSAGE_ARRAY[i] = MESS_EMAIL+MSS_CONTROL;
			}
		}
		//check length for character data
		if (CRC==YES&&MESSAGE_ARRAY[i].length==0)
		{
			if (IsLengthBetweenRange(CONTROL_VALUE,parseInt(CMN),parseInt(CMX))==false&&MESSAGE_ARRAY[i].length==0)
			{
				MESSAGE_ARRAY[i] = MESS_CHAR_DATA+MSS_CONTROL+ " Range ("+CMN + " to " + CMX+ " )";
			}
		}
		//check if value  from a list is selectd
		if (LBC==YES&&MESSAGE_ARRAY[i].length==0)
		{
			if(IsListBoxSelected(obj)==false&&MESSAGE_ARRAY[i].length==0)
			{
				MESSAGE_ARRAY[i] = MESS_LIST+MSS_CONTROL;
			}
		}
		//check file upload is havin a valid file upload
		
		if (FUP==YES&&MESSAGE_ARRAY[i].length==0)
		{
			if (IsValidFile(CONTROL_VALUE,TFP)==false)
			{
				if (TFP=='P') { var e = new String("GIF,JPG,PNG")}
				if (TFP=='C') { var e = new String("TXT,DOC,HTM,HTML,ZIP,XLS")}
				MESSAGE_ARRAY[i] = MESS_FUP+MSS_CONTROL+" Valid file formats are : " + e;
			}
		}
		
	}
	
	//end checking form controls
	m="";
	for(i=0;i<intFormElements;i++)
	{
		m+=MESSAGE_ARRAY[i];
	}
	
	if(m!="")
	{
		FINAL_MESSAGE+=MESS_START + "\n\n"
		
		for(i=0;i<intFormElements;i++)
		{
			if (MESSAGE_ARRAY[i]!="")
			{
				//FINAL_MESSAGE+="("+parseInt(i+1)+") "+MESSAGE_ARRAY[i]+"\n";
				FINAL_MESSAGE+='» '+MESSAGE_ARRAY[i]+"\n";
			}
		}
		alert(FINAL_MESSAGE);
		return false;
	}
	else
	{
		return true;
	}
}
// function to fill list box 

function copyToList(from,to,sMethod,bSelectList,MaxToSize)
{

	if(document.getElementById)
	{
			fromList = document.getElementById(from);
				toList = document.getElementById(to);
			
			selection = fromList.selectedIndex;

			if(selection == -1)
			{
				alert('You have not selected any country to Add or Remove!\n\nSelect an option in one of the lists first.  ');
				return;
			}
			var current = fromList.options[selection];		
			
			if (current.value == "")
			{
				alert('You cannot move this country!');
				return;
			}
			
			if(sMethod == "delete")
			{
				fromList.options[selection] = null;
				if(fromList.options.length < 1)
				{document.getElementById(from+"Values").value = "";}
				else
				{setValues(bSelectList, to, from);}
				return;
			}
		
			if (toList.options.length > 0 && toList.options[0].value == '')
			{
				toList.options.length = 0;
			}
			if(sMethod == "copy" || sMethod == "move")
			{
				bMove = true;
						
				if(toList.options.length < MaxToSize && toList.options.length > 0)
				{
						for (i=0;i<toList.options.length; i++)
						{
							if(current.value == toList.options[i].value)
								{
									alert('You have already selected this country');
									bMove = false;
								}
						}
				}
				else
				{
				if (bSelectList == false && toList.options.length != 0 )
					{
						alert('You have already selected '+MaxToSize+' items');
						bMove = false;
					}
				 }
				if(bMove == true)
				{
					if(sMethod=="copy")
						{toList.options[toList.length] = new Option(current.text,current.value);}
					else
						{toList.options[toList.length] = new Option(current.text,current.value);
							fromList.options[selection] = null;
						}
				}
			}
			setValues(bSelectList, to, from);
			}
	
}

// function to set the values of list
function setValues(bSelectList,to,from)
{


		if(bSelectList == false)
		{
			hiddenvalues = document.getElementById(to+"Values");
			optionslist = toList;
			//alert(to+"Values")
		}			
		else
		{
			hiddenvalues = document.getElementById(from+"Values");
			optionslist = fromList;
		}	
			
			hiddenvalues.value = "";
			for(i=0;i<optionslist.options.length;i++)
			{
			hiddenvalues.value = hiddenvalues.value + optionslist.options[i].value + ",";
			}
			
			
}
////////////////////////////////calender javascript//////////////

function getMouseXY(e) 
{
	if (IE) 
		{ // grab the x-y pos.s if browser is IE
			tempX = event.clientX + document.body.scrollLeft
			tempY = event.clientY + document.body.scrollTop
		} 
		else
		{  // grab the x-y pos.s if browser is NS
			tempX = e.pageX
			tempY = e.pageY
		}  
	// catch possible negative values in NS4
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}  
	// show the position values in the form named Show
	// in the text fields named MouseX and MouseY
	//document.Show.MouseX.value = tempX
	//document.Show.MouseY.value = tempY
	Left= tempX
	Bottom= tempY
	return true
	
}
function calendar2(obj_target) {

	// assigning methods
	this.gen_date = cal_gen_date2;
	this.gen_time = cal_gen_time2;
	this.gen_tsmp = cal_gen_tsmp2;
	this.prs_date = cal_prs_date2;
	this.prs_time = cal_prs_time2;
	this.prs_tsmp = cal_prs_tsmp2;
	this.popup    = cal_popup2;
	this.top_pos  = TOP_POS;
	this.left_pos = LEFT_POS

	// validate input parameters
	if (!obj_target)
		return cal_error("Error calling the calendar: no target control specified");
	if (obj_target.value == null)
		return cal_error("Error calling the calendar: parameter specified is not valid target control");
	this.target      = obj_target;
	this.time_comp   = BUL_TIMECOMPONENT;
	this.year_scroll = BUL_YEARSCROLL;
	
	// register in global collections
	this.id = calendars.length;
	calendars[this.id] = this;
}

function cal_popup2 (str_datetime,caltop,calleft,path) {

    if(path=="root")
        path = "calendar";
    else
        path = "../calendar";
        
	this.dt_current = this.prs_tsmp(str_datetime ? str_datetime : this.target.value);
	if (!this.dt_current) return;
	if(this.top_pos >450) this.top_pos = 300;
	var obj_calwindow = window.open(
		path + '/calendar.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,
		'Calendar', 'width=200,height='+(this.time_comp ? 215 : 190)+
		',status=no,resizable=no,top=' + caltop + ',left=' + calleft + ',dependent=yes,alwaysRaised=yes'
	);
	obj_calwindow.opener = window;
	obj_calwindow.focus();
}


// timestamp generating function
function cal_gen_tsmp2 (dt_datetime) {
	return(this.gen_date(dt_datetime) + ' ' + this.gen_time(dt_datetime));
}

// date generating function
function cal_gen_date2 (dt_datetime) {
	return (
		(dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate() + "/"
		+ (dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "/"
		+ dt_datetime.getFullYear()
	);
}
// time generating function
function cal_gen_time2 (dt_datetime) {
	return (
		(dt_datetime.getHours() < 10 ? '0' : '') + dt_datetime.getHours() + ":"
		+ (dt_datetime.getMinutes() < 10 ? '0' : '') + (dt_datetime.getMinutes()) + ":"
		+ (dt_datetime.getSeconds() < 10 ? '0' : '') + (dt_datetime.getSeconds())
	);
}

// timestamp parsing function
function cal_prs_tsmp2 (str_datetime) {
	// if no parameter specified return current timestamp
	if (!str_datetime)
		return (new Date());

	// if positive integer treat as milliseconds from epoch
	if (RE_NUM.exec(str_datetime))
		return new Date(str_datetime);
		
	// else treat as date in string format
	var arr_datetime = str_datetime.split(' ');
	return this.prs_time(arr_datetime[1], this.prs_date(arr_datetime[0]));
}

function validateDate(ctrl)
{
    if(cal_prs_date2(ctrl.value)==null)
    {
        ctrl.focus();
    }
}

// date parsing function
function cal_prs_date2 (str_date) {

    if(str_date=="")
        return "" ;
        
    var arr_date = str_date.split('/');

    if (arr_date.length != 3) return alert ("Invalid date format: '" + str_date + "'.\nFormat accepted is dd/mm/yyyy.");
    if (!arr_date[0]) return alert ("Invalid date format: '" + str_date + "'.\nNo day of month value can be found.");
    if (!RE_NUM.exec(arr_date[0])) return alert ("Invalid day of month value: '" + arr_date[0] + "'.\nAllowed values are unsigned integers.");
    if (!arr_date[1]) return alert ("Invalid date format: '" + str_date + "'.\nNo month value can be found.");
    if (!RE_NUM.exec(arr_date[1])) return alert ("Invalid month value: '" + arr_date[1] + "'.\nAllowed values are unsigned integers.");
    if (!arr_date[2]) return alert ("Invalid date format: '" + str_date + "'.\nNo year value can be found.");
    if (!RE_NUM.exec(arr_date[2])) return alert ("Invalid year value: '" + arr_date[2] + "'.\nAllowed values are unsigned integers.");

    var dt_date = new Date();
    dt_date.setDate(1);

    if (arr_date[1] < 1 || arr_date[1] > 12) return alert ("Invalid month value: '" + arr_date[1] + "'.\nAllowed range is 01-12.");
    dt_date.setMonth(arr_date[1]-1);
	 
    if (arr_date[2] < 100) arr_date[2] = Number(arr_date[2]) + (arr_date[2] < NUM_CENTYEAR ? 2000 : 1900);
    dt_date.setFullYear(arr_date[2]);

    var dt_numdays = new Date(arr_date[2], arr_date[1], 0);
    dt_date.setDate(arr_date[0]);
	
    if (dt_date.getMonth() != (arr_date[1]-1)) return alert ("Invalid day of month value: '" + arr_date[0] + "'.\nAllowed range is 01-"+dt_numdays.getDate()+".");

    return (dt_date)
	
}



// time parsing function
function cal_prs_time2 (str_time, dt_date) {

	if (!dt_date) return null;
	var arr_time = String(str_time ? str_time : '').split(':');

	if (!arr_time[0]) dt_date.setHours(0);
	else if (RE_NUM.exec(arr_time[0])) 
		if (arr_time[0] < 24) dt_date.setHours(arr_time[0]);
		else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed range is 00-23.");
	else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed values are unsigned integers.");
	
	if (!arr_time[1]) dt_date.setMinutes(0);
	else if (RE_NUM.exec(arr_time[1]))
		if (arr_time[1] < 60) dt_date.setMinutes(arr_time[1]);
		else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed values are unsigned integers.");

	if (!arr_time[2]) dt_date.setSeconds(0);
	else if (RE_NUM.exec(arr_time[2]))
		if (arr_time[2] < 60) dt_date.setSeconds(arr_time[2]);
		else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed values are unsigned integers.");

	dt_date.setMilliseconds(0);
	return dt_date;
}

function cal_error (str_message) {
	alert (str_message);
	return null;
}
