/*	Copyright © 2003- 	Gemini Software Solutions Pvt Ltd.
All rights reserved.  No part of this program or publication may be reproduced,
transcribed, stored in a retrieval system, or translated into any language or computer
language, or in any form or by any means, electronic, mechanical, magnetic, optical,
chemical, biological or otherwise, without the prior written permission of :

      GEMINI SOFTWARE SOLUTIONS PRIVATE LTD.,
      NILA, TECHNOPARK CAMPUS, TRIVANDRUM, INDIA.

      - - - - - - - - - - - - - - - - - - - - -
      File Name : Common.cs
      - - - - - - - - - - - - - - - - - - - - -

      System				:  	AgencyWorld
      Module				:  	General
      Author				:	Agency World Team
      Date					:	
      Function				:	A form which has all the common functions required in the system
      Modification History	:       

      Label		Date		Name		Change description
      - - - - -	- - - - 	- - - - - 	- - - - - - - - - - - - - - - -
	  M001		13/04/2005	Karthik		To include the PageQuery and queryString function as the
										value in the string should be obtained from the client itself.
	  M002		27/04/2005	Karthik		To make the the checkbox select function a common one.
										It is moved from UserAdmin form.
	  M003		29/04/2005	Karthik		To get the month number from the month name which is 'mmm'.
	  M004		01/05/2005	Karthik		To include a function for maximizing the form of login page.
	  M005		05/05/2005	Karthik		To disable the right click in all the web pages.
	  M006		11/06/2008	Smitha SG   To enable the right click in all the web pages.
*/

/* ++++++++++++++++++++++++++++++++ ACTIVE CLOCK FUNCTION STARTS HERE +++++++++++++++++++++++++++ */

var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
var arrMonthName = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function getthedate(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()
var dn="AM"
if (hours>=12)
dn="PM"
if (hours>12){
hours=hours-12
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
//change font size here
var cdate="<font color='#ffffff' face='Arial' size='1'>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+" "+hours+":"+minutes+":"+seconds+" "+dn
+"</font>"
if (document.all)
document.all.clock.innerHTML=cdate
else if (document.getElementById)
document.getElementById("clock").innerHTML=cdate
else
document.write(cdate)
}
if (!document.all&&!document.getElementById)
getthedate()

function activeClock(){
if (document.all||document.getElementById)
setInterval("getthedate()",1000)
}

/**
		* DHTML date validation script for dd/mm/yyyy. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
		*/
		// Declaring valid date character, minimum year and maximum year
		var dtCh= "/";
		var minYear=1900;
		var maxYear=2100;

		function isInteger(s){
			var i;
    		for (i = 0; i < s.length; i++){   
   				// Check that current character is number.
				var c = s.charAt(i);
				if (((c < "0") || (c > "9"))) return false;
			}
			// All characters are numbers.
			return true;
		}

		function stripCharsInBag(s, bag){
			var i;
			var returnString = "";
			// Search through string's characters one by one.
			// If character is not in bag, append to returnString.
			for (i = 0; i < s.length; i++){   
				var c = s.charAt(i);
				if (bag.indexOf(c) == -1) returnString += c;
			}
			return returnString;
		}
		
		

		function daysInFebruary (year){
			// February has 29 days in any year evenly divisible by four,
			// EXCEPT for centurial years which are not also divisible by 400.
			return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
		}

		function DaysArray(n) {
			for (var i = 1; i <= n; i++) {
				this[i] = 31
				if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
				if (i==2) {this[i] = 29}
			} 
			return this
		}

		function isDate(dtStr){
			if (dtStr == "") return false;//Added by prisy
			var daysInMonth = DaysArray(12)
			var pos1=dtStr.indexOf(dtCh)
			var pos2=dtStr.indexOf(dtCh,pos1+1)
			var strDay=dtStr.substring(0,pos1)
			var strMonth=dtStr.substring(pos1+1,pos2)
			var strYear=dtStr.substring(pos2+1)
			strYr=strYear
			if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
			if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
			for (var i = 1; i <= 3; i++) {
				if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
			}
			//month=parseInt(strMonth)
			//M003
			month = parseInt(GetMonthFromString(strMonth))
			day=parseInt(strDay)
			year=parseInt(strYr)
			dtStr = day + "/" + month + "/" + year
			//End of M003		
						
			if (pos1==-1 || pos2==-1){
				//var str="Alerts.aspx?errorCode=The date format should be : dd/mm/yyyy &iCon=images/alerts/Error.gif&button1=images/alerts/plainspacer.gif&button2=images/alerts/ok.gif&heading=images/alerts/heading_errs.gif";
				alert("The date format should be : dd/mm/yyyy");
				//open_Frameless(str);	
				return false
			}
			if (strMonth.length<1 || month<1 || month>12){
			alert("Please enter a valid month");
				//var str="Alerts.aspx?errorCode= Please enter a valid month &iCon=images/alerts/Error.gif&button1=images/alerts/plainspacer.gif&button2=images/alerts/ok.gif&heading=images/alerts/heading_errs.gif";
				//open_Frameless(str);	
				//alert("")
				return false
			}
			if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
				alert("errorCode= Please enter a valid day");
				//var str="Alerts.aspx?errorCode= Please enter a valid day &iCon=images/alerts/Error.gif&button1=images/alerts/plainspacer.gif&button2=images/alerts/ok.gif&heading=images/alerts/heading_errs.gif";
				//open_Frameless(str);	
				//alert("")
				return false
			}
			if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
			alert("Please enter a valid 4 digit year");
				//var str="Alerts.aspx?errorCode= Please enter a valid 4 digit year between" + minYear + " and " + maxYear + " &iCon=images/alerts/Error.gif&button1=images/alerts/plainspacer.gif&button2=images/alerts/ok.gif&heading=images/alerts/heading_errs.gif";
				//open_Frameless(str);	
				//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
				return false
			}
			if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
				alert("Please enter a valid date");
				//var str="Alerts.aspx?errorCode= Please enter a valid date &iCon=images/alerts/Error.gif&button1=images/alerts/plainspacer.gif&button2=images/alerts/ok.gif&heading=images/alerts/heading_errs.gif";
				//open_Frameless(str);	
				//alert("Please enter a valid date")
				return false
			}
		return true
		}
		
//M003
function GetMonthFromString(AMonthName)
{
	for(intLoop = 0; intLoop < arrMonthName.length; intLoop++)
	{
		if (arrMonthName[intLoop] == AMonthName)
			return (intLoop + 1);
	}
}
//End of M003

function CheckMustEntry(source, arguments)
{
	arguments.IsValid = false;
	var hdnTemp = document.all.item("hdnFormName")
	var oObject = document.all.item(hdnTemp.value)
	if (oObject != null)
	{
		if (oObject.length != null)
		{
			for (i = 0; i < oObject.length; i++)
			{
				if (oObject(i).id != "")
				{
					var strName =oObject(i).id;
					var strTemp = strName.split("_");
					
					//---Changed by Mohan				
					var strFlag = strTemp[0]; 
					var strFlagPlc = strTemp[4]; 
					var strFlagPlcTemp = strTemp[2]; // by Pramod (Feedback)
							
						
					if( ((oObject(i).disabled == false) &&
						((strFlag == "m") || (strFlag == "n") 
						|| (strFlag == "d") || (strFlag == "c")) || (strFlag == "i") )
						||((oObject(i).disabled == false) &&
						((strFlagPlcTemp == "m") || (strFlagPlcTemp == "n") 
						|| (strFlagPlcTemp == "d") || (strFlagPlcTemp == "c")) || (strFlagPlcTemp == "i") )
						|| ((oObject(i).disabled == false) &&
						((strFlagPlc == "m") || (strFlagPlc == "n") 
						|| (strFlagPlc == "d") || (strFlagPlc == "c")) || (strFlagPlc == "i")))						
					 
					
					{					
						if (hdnTemp.value != "frmEnquirySearch")
						{
							if ((oObject(i).value == " | ") || (oObject(i).value==null)||(oObject(i).value==""))
							{
								alert("Please enter "+oObject(i).title);										
								if (oObject(i) == null)
									return;										
								else
								{
									document.getElementById(oObject(i).id).focus();									
									return;	
								}																		
							}
						}
					}
					
					//---Changed by Mohan
					if ((oObject(i).disabled == false) && (strFlagPlc == "d"))
					{
					  if (hdnTemp.value == "frmMain")
					  {
						var strLength = oObject(i).value;
						if (strLength.length > 0)
						{
							if (isDate(oObject(i).value) == false)
							{
								document.getElementById(oObject(i).id).focus(); 
								return;
							}
						}					
					  }
					
					  if (hdnTemp.value != "frmMain")
					  {
						if (isDate(oObject(i).value) == false)
						{
							document.getElementById(oObject(i).id).focus(); 
							return;
						}
					  }
								
					}//end if for date check
					
					if ((oObject(i).disabled == false) && (strFlagPlc == "n"))
					{
						if (hdnTemp.value == "frmEnquirySearch")
						{
							var strLength = oObject(i).value;
							if (strLength.length > 0)
							{
								if (ValidateNumeric(oObject(i)) == false) 
								{
									return;
								}
							}							
						}
						
						if (hdnTemp.value != "frmEnquirySearch")
						{
							if (ValidateNumeric(oObject(i)) == false) 
							{
								return;
							}	
						}							
					} //if for numeric check
				
					if ((oObject(i).disabled == false) && (strFlag == "i"))
					{
						if (hdnTemp.value == "frmEnquirySearch")
						{
							var strLength = oObject(i).value;
							if (strLength.length > 0)
							{
								if (ValidateNumericForIntegerOnly(oObject(i)) == false) 
								{
									return;
								}
							}								
						}
						
						if (hdnTemp.value != "frmEnquirySearch")
						{
							if (ValidateNumericForIntegerOnly(oObject(i)) == false) 
							{
								return;
							}	
						}
					}//if for integer check		
				}
			}
		}
	}
	arguments.IsValid = true;
}//end of checkmust entry 
		
		
		
function ValidateNumericForIntegerOnly(field) 
{
	var valid = "0123456789,"
	var temp;
	if (field.value.length == 0) return false; 
	if (field.value == 0) return false;
	for (var i=0; i<field.value.length; i++) 
	{
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") 
		{
			alert("Please enter only integer values");
			return false;
		}
	}
}

function Upper(TextField) 
{
	document.getElementById(TextField).value = document.getElementById(TextField).value.toUpperCase();
								
}
	
function ValidateNumeric(field) 
{
	var valid = "0123456789,"
	var temp;

	if (field.value.length == 0) return false; 
	if (field.value == 0) 
	{
		alert("Zero not allowed for " + field.title);
		return false;
	}
		for (var i=0; i<field.value.length; i++) 
		{
			temp = "" + field.value.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") 
			{
				alert("Invalid entry!  Only numbers are accepted!");
				field.focus();
				return false;
			}
		}
			
		var Count = 0;
		var strTemp;
		valid = ".";
		for (var i=field.value.length - 1; i>=0; i--) 
		{
			Count += 1;
			strTemp = field.value.charAt(i);
			if (valid.indexOf(strTemp) != -1) 
			{
				if (Count > 3)
				{
					alert("Invalid entry!  Decimal places cannot be more than 2!");
					field.focus();			
					return false;	
				}
				else return true;
			}
		}
		return true;
}


/*****************************************************************************/
//added by bindu on 21/10/2003 to validate email format
			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("Invalid E-mail ID")
					return false
				}
			

				if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
				{
				alert("Invalid E-mail ID")
				return false
				}

				if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==(lstr-1) || str.indexOf(dot)==lstr)
				{
					alert("Invalid E-mail ID")
					return false
				}

				if (str.indexOf(at,(lat+1))!=-1)
				{
					alert("Invalid E-mail ID")
					return false
				}

				if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
				{
					alert("Invalid E-mail ID")
					return false
				}

				if (str.indexOf(dot,(lat+2))==-1)
				{
					alert("Invalid E-mail ID")
					return false
				}
				
				if (str.indexOf(" ")!=-1)
				{
					alert("Invalid E-mail ID")
					return false
				}

 				return true					
			}

			function ValidateForm(id)
			{
				
				//var emailID=document.frmCreateUser.m_txt_Email				
				var emailID=document.getElementById(id)
				if ((emailID.value==null)||(emailID.value=="")){
					//alert("Please Enter your Email ID")
					//emailID.focus()
					return true;
				}
				if (echeck(emailID.value)==false){
					emailID.value=""
					emailID.focus()
					return false
				}
				return true
			}
			
			/*PRASEETHA BEGIN - 19/MAR/2007
			Function to validate the password entered by the user. It should be at least 6 chars in length.
			*/
			
			function ValidatePassword(pwd)
			{
				var strpwd = document.getElementById(pwd);
				if((strpwd.value == null)||(strpwd.value==""))
					return true;
				if(strpwd.value.length < 6)
				{
					alert("The password must be atleast 6 characters long");
					strpwd.value = "";
					strpwd.focus();
					return false;
				}
				return true;
				
			}
			/*PRASEETHA END   - 19/MAR/2007*/
			
			//------for confirmation before delete-----added by bindu
			/*function ConfirmDeletion(txt_Name) 
			{	
				if(document.getElementById(txt_Name).value == "") 
					return;
				else
					return confirm('Are you sure you want to delete?');			
				
				
			}	*/
			
			function ConfirmDeletion(txt_Name) 
			{	
				if(txt_Name == "grd_deletion")
					return confirm('Are you sure you want to delete?');
				else
				{
					if(document.getElementById(txt_Name).value == "") 
						return;
					else					
						return confirm('Are you sure you want to delete?');
				}			
			}	
			
//M001			
function PageQuery(q) 
{
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) 
	{
		for(var i=0; i < this.q.split("&").length; i++) 
		{
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
		}
		this.getKeyValuePairs = function() { return this.keyValuePairs; 
		}
		this.getValue = function(s) 
	{
	for(var j=0; j < this.keyValuePairs.length; j++) 
		{
		if(this.keyValuePairs[j].split("=")[0] == s)
		return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function() 
	{
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) 
		{
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; } 
	
}			
			
function queryString(key)
{
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key)); 
}
//End of M001

//M002
function chk_Main(name,count,mainname)
{
	arrNames = name.split(",");
	arrCount = count.split(",");
	
	for(j=0;j<=arrCount.length;j++)
	{
		for (i=0; i<=arrCount[j]; i++)
		{			
			if( document.getElementById('_ctl0__ctl0_'+mainname).checked == false)
			{  		
				document.getElementById('_ctl0__ctl0_'+arrNames[j]+'_'+i).checked = false;				
			}
			else
				document.getElementById('_ctl0__ctl0_'+arrNames[j]+'_'+i).checked = true;							
		}
	}
}
//End of M002

//M004
function MaximizePage()
{
	top.window.moveTo(0,0);
	if (document.all) 
	{
		top.window.resizeTo(screen.availWidth,screen.availHeight);
	}
	else if (document.layers||document.getElementById) 
	{
		if (top.window.outerHeight < screen.availHeight||top.window.outerWidth < screen.availWidth)
		{
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
		}
	}
}
//End of M004

//M005
//This is used to DISABLE the right click of the mouse
//on the WEB PAGE.(For Development this can be commented)
//document.oncontextmenu = new Function("return false")	//commented by M006
//End of M005
			 
 
 /*****************************************************************************/
 