var	whitespace =" \t\n\r ";

// function for checking empty filed
function isEmpty(str)
{
	return ((str == null) || (str.length == 0))
}
// end of function

// function to check the whitespace
function isWhitespace(str)
{	 var i;
	 var flag

	  // Is s empty?
	  if (isEmpty(str)) return true;
	   // Search through string's characters one by one
	   // until we find a non-whitespace character.
	   // When we do, return false; if we don't, return true.
	   for (i = 0; i < str.length; i++)
	   {
		   // Check that current character isn't whitespace.
		   var c = str.charAt(i);

		   if (whitespace.indexOf(c) == -1)
				return false
	   }
	   // All characters are whitespace.
			return true;
}
// end of function

// function to check the maxlength of the textarea
function checkMaxLength(val,maxlength)
{
	var val1
	val1 = val.length
	if (parseInt(val1)>parseInt(maxlength))
	{
		lflag=false
		return lflag;
		//return true;
	}
	else
	{
		lflag=true
		return lflag;
		//return false;
	}
}
// end of function

// function for special charachteres (",%)
	function isSpecialCharPresnt(objValue)
	{
		var characters="%'"
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if(characters.indexOf(tmp)>=0)
			{
				lTag = 1
				break;
			}
		}
		if(lTag == 1)
			return true
		else
			return false
	}
// end of function

// function for checking if inputed value is a valid number
// @param objValue - string
function isAllNumeric(objValue)
{
			lTempLength = objValue.length
			lTempCounter = 0
			lTempString = trim(objValue)
			flag = false

			do
			{
			if(lTempString.charAt(lTempCounter) == " ")
			{
				flag = false
				break
			}
			else if(lTempString.charAt(lTempCounter) > 0 || lTempString.charAt(lTempCounter) < 9 || lTempString.charAt(lTempCounter)=='-')
				flag = true
			else
				{
					flag = false
					break
				}
				lTempCounter = lTempCounter + 1
			}
			while(lTempCounter <= lTempLength)

			if(flag == true)
				return true
			else
				return false
}
// end of function

// function for checking all entered valuea are numbers only with decimal values
function isWholePositiveNumber(obj)
{
		flag = 0
		if(isNaN(obj))
		{
			flag=1;
		}

		if(flag==0)
		{
			for(i=0;i<obj.length;i++)
			{
				//if(obj.charAt(i)=="-" || obj.charAt(i)==".")
				if(obj.charAt(i)=="-")
				{
					flag=1;
					break;
				}
			}
		}

		if(flag==1)
		{
			return false
		}
		else if(flag==0)
		{
			return true
		}
}
// end of function

// function for checking all entered valuea are numbers only with decimal values
function isNegativeNumber(obj)
{
		flag = 0
		if(isNaN(obj))
		{
			flag=1;
		}

		if(flag==0)
		{
			for(i=0;i<obj.length;i++)
			{
				//if(obj.charAt(i)=="-" || obj.charAt(i)==".")
				if(obj.charAt(i)==".")
				{
					flag=1;
					break;
				}
			}
		}

		if(flag==1)
		{
			return false
		}
		else if(flag==0)
		{
			return true
		}
}
// end of function

// function to check all the entered values are characters only
function isAllCharacters(objValue)
{
		var characters="' -abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ."
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
				break;
			}
		}
		if(lTag == 1)
			return false
		else
			return true
}
// end of function


function specialnum(field,name,R)
{
	missinginfo = ""	;
	if(R=="R")
	{
	if(field.value==""){
	missinginfo+="\n"+name+" må fylles ut";
	return missinginfo;
	 }
	}

	var valid = "0123456789";
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++)
	{
	temp = "" + field.value.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if (ok == "no")
	{
	missinginfo += "\n"+ name + "(Bare tall er tillatt)";
	return missinginfo;
	field.focus();
	field.select();
	}
	else return "";
  }

// function to check all the entered values are characters only
function isAlphaNumeric(objValue)
{
			var characters="'-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
			var tmp
			var lTag
			lTag = 0
			temp = (objValue.length)
			for (var i=0;i<temp;i++)
			{
				tmp=objValue.substring(i,i+1)
				if (characters.indexOf(tmp)==-1)
				{
					lTag = 1
					break;
				}
			}
			if(lTag == 1)
				return false
			else
				return true

}
// end of function

function isalphaNumericSpace(objValue){
	var characters="'-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	var tmp
	var lTag
	lTag = 0
	temp = (objValue.length)
	for (var i=0;i<temp;i++){
		tmp=objValue.substring(i,i+1)
		if (characters.indexOf(tmp)==-1){
			if ( tmp != " " ){
				lTag = 1
				break;
			}
		}
	}
	return (lTag == 1)? false : true;
}

// function for checking blank value as wee as white space but allowes space between two characters
function checkEmpty(objValue){
	if(isWhitespace(objValue)==true){
		return(true);
	}else{
		return(false);
	}
}
// end of function

// check alpha numeric
function checkAlphaNumeric(objValue,objName,checkForNull)
{
	err=""

	if (checkForNull.toUpperCase()=="Y")
	{

		if (checkEmpty(objValue)==true)
		{
			err =objName +" can not contain only space or can not be blank"

		}
	}
	else
	{
			var characters="-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
			var tmp
			var lTag
			lTag = 0
			temp = (objValue.length)
			for (var i=0;i<temp;i++)
			{
				tmp=objValue.substring(i,i+1)
				if (characters.indexOf(tmp)==-1)
				{
					err = objName+"Can not contains special characters"

				}
			}

	}
	return err
}

// end of function

// check alpha numeric punctuation
function checkAlphaNumericPunct(objValue, objName){	
	var characters="-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,'@#*\"";
	var tmp
	var lTag
	lTag = 0
	temp = (objValue.length)
	for (var i=0;i<temp;i++)
	{
		tmp=objValue.substring(i,i+1)
		if (characters.indexOf(tmp)==-1)
		{
			return false;
		}
	}	
	return true;
}
// end of function

// function for triming
function trim(pstrString)
{
	var intLoop=0;

	for(intLoop=0; intLoop<pstrString.length; )
	{
		if(pstrString.charAt(intLoop)==" ")
			pstrString=pstrString.substring(intLoop+1, pstrString.length);
		else
			break;
	}

	for(intLoop=pstrString.length-1; intLoop>=0; intLoop=pstrString.length-1)
	{
		if(pstrString.charAt(intLoop)==" ")
			pstrString=pstrString.substring(0,intLoop);
		else
			break;
	}
	return pstrString;
}

// function for valid file to be upload
// @ param : val = value , msg = for which, typ = for which type - A = All files(.htm,.html,.jpg,.gif,.bmp,.jpeg)
// H - .htm, .html
// I - .jpg, .jpeg, .gif, .bmp
// Att - all fileas are valid and only length is validated for 50 characters

function IsValidFile(val,msg,typ)
{
		val = trim(val)
		strlen = val.length
		strcnt = val.lastIndexOf("\\")
		newstr = val.substr(strcnt+1,strlen)
		tempval = val.toUpperCase()
		val = tempval.substr(val.lastIndexOf("."),val.length)
		var flg= 0
		var err = ""


		if( (typ=='A')&&( ( ((val.length==5)&&((val!='.JPEG')&&(val!='.HTML')))|| ((val.length==4)&&((val!='.HTM')&&(val!='.JPG')&&(val!='.GIF')&&(val!='.BMP')&&(val!='.TXT'))))||(val.length>5) ))
		{
			err = "Only .gif/.jpg/.jpeg/.bmp/.html/.htm/.txt can be selected for "+msg+".<br>"
		}
		else if( (typ=='H')&&( ( ((val.length==5)&&(val!='.HTML'))|| ((val.length==4)&&(val!='.HTM')))||(val.length>5) ))
		{
			err = "Only .html/.htm files can be selected for "+msg+".<br>"
		}
		else if( (typ=='I')&&( ( ((val.length==5)&&(val!='.JPEG'))|| ((val.length==4)&&((val!='.JPG')&&(val!='.GIF')&&(val!='.BMP'))))||(val.length>5) ))
		{
			err = "Only .gif/.jpg/.jpeg/.bmp files can be selected for "+msg+".<br>"
		}
		/*
		else if((typ=='T')&&(((val.length==4)&&(val!='.TXT'))))
		{
			err = "Only .txt file can be selected for "+msg+".<br>"
		}
		*/
		else if ( (newstr.indexOf(".") == 0)|| (val.indexOf('.') == -1) || (val.length <4) )
			err = "File selected for "+msg+" is invalid.<br>"
		else if(newstr.indexOf("'") != -1)
			err = "File selected for "+msg+" contains invalid character.<br>"
		else if (newstr.length > 50)
			err = "Length of file name selected for "+msg+" must be less then or equal to 50.<br>"

		return err
}
// end of function

// this is the same function for checking the valid file extension except it returns true or false
function isInValidFile(val,msg,typ)
{
		val = trim(val)
		strlen = val.length
		strcnt = val.lastIndexOf("\\")
		newstr = val.substr(strcnt+1,strlen)
		tempval = val.toUpperCase()
		val = tempval.substr(val.lastIndexOf("."),val.length)
		var flg= 0
		var err = ""

		if( (typ=='A')&&( ( ((val.length==5)&&((val!='.JPEG')&&(val!='.HTML')))|| ((val.length==4)&&((val!='.HTM')&&(val!='.JPG')&&(val!='.GIF')&&(val!='.TXT'))))||(val.length>5) ))
		{
			return true;
		}
		else if( (typ=='H')&&( ( ((val.length==5)&&(val!='.HTML'))|| ((val.length==4)&&(val!='.HTM')))||(val.length>5) ))
		{
			return true;
		}
		else if( (typ=='I')&&( ( ((val.length==5)&&(val!='.JPEG'))|| ((val.length==4)&&((val!='.JPG')&&(val!='.GIF'))))||(val.length>5) ))
		{
			return true;
		}
		if( (typ=='HI')&&( ( ((val.length==5)&&((val!='.JPEG')&&(val!='.HTML')))|| ((val.length==4)&&((val!='.HTM')&&(val!='.JPG')&&(val!='.GIF'))))||(val.length>5) ))
		{
			return true;
		}
		/*
		else if((typ=='T')&&(((val.length==4)&&(val!='.TXT'))))
		{
			err = "Only .txt file can be selected for "+msg+".<br>"
		}
		*/
		else if((typ=='X')&&(((val.length==4)&&(val!='.XLS'))))
		{
			return true;
		}
		else if((typ=='K')&&((((val.length==3)&&((val!='.KW')))||(val.length>3))))
		{
			return true;
		}
		else if ( (newstr.indexOf(".") == 0)|| (val.indexOf('.') == -1) || (val.length <4) )
			return true;
		else if(newstr.indexOf("'") != -1)
			return true;
		else if (newstr.length > 50)
			return true;

}
// end of function

// function to put the comma in between the validation fileds
function putcomma(msg)
{
	if((msg!=""))
	{
		msg = msg+"," ;
	}
	return (msg);
}
// end of function


//checking whether date is valid or not ie no of days are correct or not as per the month
function isValidDate(tempDate, tempMonth, tempYear)
{
		// check weather the date is selected or not
		if ((tempDate =="Day") || (tempMonth == "Month") || (tempYear == "Year" ))
		{
		 return false;
		}
		else if((tempDate !="") && (tempMonth != "") && (tempYear != "" ))
		{

			var tempNoOfDays
			var lArrMonthDays = new Array(2)
			var dateFlag

			dateFlag = false

			lArrMonthDays[0] = new Array(12)
			lArrMonthDays[1] = new Array(12)

			lArrMonthDays[0][0] = "1"
			lArrMonthDays[1][0] = "31"

			lArrMonthDays[0][1] = "2"
			lArrMonthDays[1][1] = "28"

			lArrMonthDays[0][2] = "3"
			lArrMonthDays[1][2] = "31"

			lArrMonthDays[0][3] = "4"
			lArrMonthDays[1][3] = "30"

			lArrMonthDays[0][4] = "5"
			lArrMonthDays[1][4] = "31"

			lArrMonthDays[0][5] = "6"
			lArrMonthDays[1][5] = "30"

			lArrMonthDays[0][6] = "7"
			lArrMonthDays[1][6] = "31"

			lArrMonthDays[0][7] = "8"
			lArrMonthDays[1][7] = "31"

			lArrMonthDays[0][8] = "9"
			lArrMonthDays[1][8] = "30"

			lArrMonthDays[0][9] = "10"
			lArrMonthDays[1][9] = "31"

			lArrMonthDays[0][10] = "11"
			lArrMonthDays[1][10] = "30"

			lArrMonthDays[0][11] = "12"
			lArrMonthDays[1][11] = "31"

			if(tempMonth == 2)
			{
				if(tempYear % 4 == 0 || tempYear % 400 == 0)
				{
					//change the days of Feb to 29 b'coz LEAP YEAR
					lArrMonthDays[1][1] = "29"
				}
			}

			tempNoOfDays = lArrMonthDays[1][tempMonth-1]

			// check for the no of days for the selected month
			if(parseInt(tempDate) > parseInt(tempNoOfDays))
			{
				dateFlag = false
			}
			else
			{
				dateFlag = true
			}

			return dateFlag
		}
		else
		{
			return false;
		}
}
// end of function

// function for comparison of date
function fnDateComp(frmNm,Day1,Month1,Year1,Day2,Month2,Year2)
{

	var Day1	=	eval("document."+frmNm+"."+Day1+"[document."+frmNm+"."+Day1+".selectedIndex].value")
	var Day2	=	eval("document."+frmNm+"."+Day2+"[document."+frmNm+"."+Day2+".selectedIndex].value")
	var Month1	=	eval("document."+frmNm+"."+Month1+"[document."+frmNm+"."+Month1+".selectedIndex].value")
	var Month2	=	eval("document."+frmNm+"."+Month2+"[document."+frmNm+"."+Month2+".selectedIndex].value")
	var Year1	=	eval("document."+frmNm+"."+Year1+"[document."+frmNm+"."+Year1+".selectedIndex].value")
	var Year2	=	eval("document."+frmNm+"."+Year2+"[document."+frmNm+"."+Year2+".selectedIndex].value")

	if(parseFloat(Year1) > parseFloat(Year2))
	{
		return true;
	}

	if(parseFloat(Year1)==parseFloat(Year2))
	{
		if(parseFloat(Month1) > parseFloat(Month2))
		{

			return true;
		}
		else if(parseFloat(Month1)==parseFloat(Month2))
		{
			if((parseFloat(Day1)>parseFloat(Day2)))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}

	if (parseFloat(Year1) < parseFloat(Year2))
	{
		return false;
	}
}
// end of function



//function for email validation
function isValidEmail(emailStr)
{
			/* The following pattern is used to check if the entered e-mail address
			   fits the user@domain format.  It also is used to separate the username
			   from the domain. */
			var emailPat=/^(.+)@(.+)$/
			/* The following string represents the pattern for matching all special
			   characters.  We don't want to allow special characters in the address.
			   These characters include ( ) < > @ , ; : \ " . [ ]    */
			//var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
			var specialChars="\\(\\)<>@,`';:~!#$%^&*+=|{}?\\\\\\\"\\.\\[\\]"

			/* The following string represents the range of characters allowed in a
			   username or domainname.  It really states which chars aren't allowed. */
			var validChars="\[^\\s" + specialChars + "\]"
			/* The following pattern applies if the "user" is a quoted string (in
			   which case, there are no rules about which characters are allowed
			   and which aren't; anything goes).  E.g. "sg cricket"@disney.com
			   is a legal e-mail address. */
			var quotedUser="(\"[^\"]*\")"
			/* The following pattern applies for domains that are IP addresses,
			   rather than symbolic names.  E.g. sg@[123.124.233.4] is a legal
			   e-mail address. NOTE: The square brackets are required. */
			var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
			/* The following string represents an atom (basically a series of
			   non-special characters.) */
			var atom=validChars + '+'
			/* The following string represents one word in the typical username.
			   For example, in sg.sg@somewhere.com, sg and sg are words.
			   Basically, a word is either an atom or quoted string. */
			var word="(" + atom + "|" + quotedUser + ")"
			// The following pattern describes the structure of the user
			var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
			/* The following pattern describes the structure of a normal symbolic
			   domain, as opposed to ipDomainPat, shown above. */
			var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


			/* Finally, let's start trying to figure out if the supplied address is
			   valid. */

			/* Begin with the coarse pattern to simply break up user@domain into
			   different pieces that are easy to analyze. */
			var matchArray=emailStr.match(emailPat)
			if (matchArray==null) {
			  /* Too many/few @'s or something; basically, this address doesn't
				 even fit the general mould of a valid e-mail address. */
				//alert("Email address seems incorrect (check @ and .'s)")
				return false
			}
			var user=matchArray[1]
			var domain=matchArray[2]

			// See if "user" is valid
			if (user.match(userPat)==null) {
				// user is not valid
				//alert("The username doesn't seem to be valid.")
				return false
			}

			/* if the e-mail address is at an IP address (as opposed to a symbolic
			   host name) make sure the IP address is valid. */
			var IPArray=domain.match(ipDomainPat)
			if (IPArray!=null) {
				// this is an IP address
				  for (var i=1;i<=4;i++) {
					if (IPArray[i]>255) {
						//alert("Destination IP address is invalid!")
					return false
					}
				}
				return true
			}

			// Domain is symbolic name
			var domainArray=domain.match(domainPat)
			if (domainArray==null) {
			//alert("The domain name doesn't seem to be valid.")
				return false
			}

			/* domain name seems valid, but now make sure that it ends in a
			   three-letter word (like com, edu, gov) or a two-letter word,
			   representing country (uk, nl, no), and that there's a hostname preceding
			   the domain or country. */

			/* Now we need to break up the domain to get a count of how many atoms
			   it consists of. */
			var atomPat=new RegExp(atom,"g")
			var domArr=domain.match(atomPat)
			var len=domArr.length
			if (domArr[domArr.length-1].length<2 ||
				domArr[domArr.length-1].length>3) {
			   // the address must end in a two letter or three letter word.
			   //alert("The address must end in a three-letter domain, or two letter country.")
			   return false
			}

			// Make sure there's a host name preceding the domain.
			if (len<2) {
			   var errStr="This address is missing a hostname!"
			   //alert(errStr)
			   return false
			}

			// If we've gotten this far, everything's valid!
			return true;
}
// end of function


// function to get the file name
function getFileName(fileName)
{
	// get the file name

	// find the length
	strlen = fileName.length;
	// find out the location of last back slash(\)
	strcnt =fileName.lastIndexOf("\\");
	// find the name of the file
	nameOfFile = fileName.substr(strcnt+1,strlen)
	// return the file name
	return nameOfFile;

}
//end function


//************code for validation of same file name not allowed for  Left Column and reading reference

function isDuplicatFileNameCheck(fileName,fileControlName,formName)
{
	tempflag = true
	errMsg =""

	if(tempflag==true)
	{
		val = fileName

			if (trim(val) != "")
			{
					// assign the file to variable which will check for duplicate
					FixedFileName = fileName

					// loop through the form elements for checking all the file elements
					for(i=1;i<=eval("document."+formName+".elements.length") - 1;i++)
					{
						// get the currnet control name
						CurControlname= eval("document."+formName+".elements["+i+"].name")

						// compare the current control name with the passed control name if not equal then
						// check for the duplicate name
						if (fileControlName.toUpperCase() != CurControlname.toUpperCase())
						{
							// check form element of type "FILE"
							if (eval("document."+formName+".elements["+i+"].type.toUpperCase()")=="FILE")
							{
								// get the current form control file value
								CurControlValue = getFileName("document."+formName+".elements["+i+"].value")

								// comapre the Fixed file name with the others
								if (FixedFileName.toUpperCase() == CurControlValue.toUpperCase())
								{
									tempflag=false
									break;

								}
							}
						}
					}
			}
			if(tempflag==false)
			{
				errMsg = errMsg  + "Please select different files/fine name for uploading"
				return errMsg;
			}
			else
			{
				return errMsg + "File  is not duplicate"
			}
	}
}

// function for combo box selectd
function isComboSelected(frmNm,objName,valueForCompare)
{
	var objName	=	eval("document."+frmNm+"."+objName+"[document."+frmNm+"."+objName+".selectedIndex].value")

	if (objName.toUpperCase() == valueForCompare.toUpperCase())
	  return true
	else
	  return false
}
//end function

// function to check special characters in course Id
function isSpecialCharactersCourseId(objValue)
	{
		tmp = 0
		var characters="`<>?/,.=~!@$%^[]{}&*\;+|\'\"\\"
		ltag = false
		temp = characters.length

		for (var i=0;i<temp;i++)
		{
			tmp=characters.substring(i,i+1)
			if (objValue.indexOf(tmp) != -1)
			{
				ltag = true
				break
			}
		}
		return ltag
	}
//end function

//Function to check Code eg:- Course Code
function isAlphaNumericSpecialCharsForCourse(objValue)
{
			var characters="-_()#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
			var tmp
			var lTag
			lTag = 0
			temp = (objValue.length)
			for (var i=0;i<temp;i++)
			{
				tmp=objValue.substring(i,i+1)
				if (characters.indexOf(tmp)==-1)
				{
					lTag = 1
					break;
				}
			}
			if(lTag == 1)
				return true
			else
				return false

}
//end of function

//Function to check Code eg:- Subject Code and Class Code
function isAlphaNumericSpecialChars(objValue)
{
			var characters="-'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789&()"
			var tmp
			var lTag
			lTag = 0
			temp = (objValue.length)
			for (var i=0;i<temp;i++)
			{
				tmp=objValue.substring(i,i+1)
				if (characters.indexOf(tmp)==-1)
				{
					lTag = 1
					break;
				}
			}
			if(lTag == 1)
				return true
			else
				return false

}
//end of function

//function to validate city,state
function fnIsAlphaNumericSpecial(objValue)
{
	var characters=" -abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789&'()[]+"
	var tmp
	var lTag
	lTag = 0
	temp = (objValue.length)
	for (var i=0;i<temp;i++)
	{
		tmp=objValue.substring(i,i+1)
		if (characters.indexOf(tmp)==-1)
		{
			lTag = 1
			break;
		}
	}
	if(lTag == 1)
		return false
	else
		return true
}
//end function

// function to reset the form values
 function fnReset(frmName)
 {
	eval("document."+frmName+".reset()")
 }
// end function

// #region Phone Number mask
// #region Persistent fold region

//function to mask the htmlInputbox
/* The scripts on this page was produced by mordechai Sandhaus - 52action.com,
 and is copyrighted . If you like this script, we encourage you to use it,
 provided that  include this note, and link to 52action.com. */

/* script explanation for dummies */

/* NOTE: THE FIRST 2 ARGUMENTS SHOULD ALWAYS REMAIN THE SAME - this.value, this */
// the first argument in the function, accepts the "value" of the textbox to be masked
// the second argument is the name of the textbox
//although the first 2 could have been done in 1 argument I did it in 2
// to make it easier to understand

//the third argument holds the locations of the separator,
// each location should be separated by a comma - (going from lower numbers to higher)

//the fourth holds the delimiter (or separator) character.

/*	nothing in the function should be edited,
	to change a delimiter or character location,
	change it in the calling script
	- the following code should be inserted into the field(s) to be masked - */

/*	replace 'location1,location2' with the locations where you want the delimiter
	replace the 'delimiter' with the separating character you would like */

// javascript:return mask(this.value,this,'location1,location2','delimiter')

//-there is no limit to the amount of delimiters you can have added
// #endregion

function mask(str,textbox,loc,delim){
var	locs = loc.split(',');
for	(var i = 0; i <= locs.length; i++){
	for (var k = 0; k <= str.length; k++){
		if (k == locs[i]){if (str.substring(k, k+1) != delim){	str = str.substring(0,k) + delim + str.substring(k,str.length)}}
	}
 }
textbox.value = str
}
var	isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
			if(arr[index] == ele)
				found = true;
			else
				index++;
		return found;
	}
	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
			if (input.form[i] == input)index = i;
			else i++;
		return index;
	}
return true;
}
// #endregion

// #region scaletofit region


// use only scaletofit function. Other function is supplimentory to scaletofit function
var speed = 5; // Delay between increments.
var inc = 30; // Increment amount -- also changes speed
var ih = "";
function ScaleToFit(id) {
	var obj= document.getElementById(id);
	var dw=obj.scrollWidth;
	var dh=obj.scrollHeight;
// 	alert(dh + ' x ' + dw);
	ih = obj.innerHTML;
	obj.innerHTML="";
	resize(dw, dh, 0, id);
}
function resize(width, height, current, id) {
	var obj = document.getElementById(id);
	obj.style.border="1px solid #000000"; 
	if (current <= width) {i = current + inc;obj.style.width = i;}
	if (current <= height) {	i = current + inc;obj.style.height = i;}
	if (current <= width || current <= height) {	var t = window.setTimeout("resize("+width+", "+height+", "+i+", '"+id+"')", speed);}
	else { obj.style.height = height; obj.style.width = width; obj.innerHTML=ih;ih=""; obj.style.border=""; }
}
///end region
// #endregion

// #region Validation Engine

var flgCompulsary = "1";
var flgNullAllowed = "0";

var allNum = "2";
var allChar = "3";
var alphaNumeric = "4";
var allCharSpace = "5";
var alphaNumericSpace = "6";
var email = "7";
var password = "8";
var allFloat = "9";

function validate(arrValidation){
	var tagName = "";
	var control;
	var validControl = true;
	var validForm = true;
	var msg="";
	
	for(var i=0;i<arrValidation.length;i++)
	{	
		tagName = "";
		validControl = true;
		control = document.getElementById(arrValidation[i][0])
		if ( control != null || control != undefined ){
			switch (control.tagName){
				case "INPUT":
					if (arrValidation[i][2] == flgCompulsary){
						
						if (isWhitespace(control.value)){validControl=false;}
						if (control.value.length <= 0) {validControl=false;}
						if (!validControl){msg+= "Enter " + arrValidation[i][3] + "\n";}
						
						switch(arrValidation[i][1]){
							case allNum : if (!isAllNumeric(control.value)){ validControl = validControl && false; msg+=  arrValidation[i][3] + " must be Numeric."+ "\n";}
							break;
							case allChar : if (!(isAllCharacters(control.value))){ validControl = validControl && false; msg+=  arrValidation[i][3] + " must be Alphabetic."+ "\n";}
								break;
							case alphaNumeric :if (!(isAlphaNumeric(control.value))){ validControl = validControl && false; msg+=  arrValidation[i][3] + " must be alphanumeric."+ "\n";}
								break;
							case email :if (!(isValidEmail(control.value))){ validControl = validControl && false; msg+=  arrValidation[i][3] + " is invalid."+ "\n";}
								break;
							case password :if ( control.value.length<6 ){ validControl = validControl && false; msg+=  arrValidation[i][3] + " shold have atleast 6 characters."+ "\n";}
								break;
							case alphaNumericSpace : if (!(isalphaNumericSpace(control.value))){ validControl = validControl && false; msg+=  arrValidation[i][3] + " must be alphanumeric."+ "\n";}
								break;
							
						}
						
					}
					
				break;
				case "SELECT" : 
					if (arrValidation[i][2] == flgCompulsary ){
						if(control.selectedIndex==0){validControl=false;}
					}
					if (!validControl){msg+= "Please Select " + arrValidation[i][3]+ "\n";}
				break;				
			}
			if (! validControl){
			}
		}
		validForm = validForm && validControl;
	}
	if (!(validForm)){
		alert(msg);
		return false;
	}else{
		return true;
	}
}

// #endregion

var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
var px = document.layers ? "" : "px";
var ffx = (navigator.userAgent.indexOf("Firefox") != -1);

function el(id){
	return d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
}
0
function JSFX_FloatDiv1(id, sx, sy)
{
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
	el.flt=function()
	{
		var pX, pY;
		
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : d.documentElement && d.documentElement.clientWidth ? d.documentElement.clientWidth : d.body.clientWidth;
		pY = ns ? pageYOffset : d.documentElement && d.documentElement.scrollTop ? d.documentElement.scrollTop : d.body.scrollTop;
		
		if(this.sy<0) 
			pY += ns ? innerHeight : d.documentElement && d.documentElement.clientHeight ? d.documentElement.clientHeight : d.body.clientHeight;
			
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.flt()", 40);
		
	}
	return el;
}
function JSFX_FloatDiv(id){
	var ele=el(id);
	window[id + "_obj"] = ele;
	if(d.layers)ele.style=ele;
	//ele.cx = ele.sx = sx;ele.cy = ele.sy = sy;
	ele.getMousePos=function(e){
		var TheEventObject; 
		if(e) 
		{ 
			TheEventObject = e; 
		} 
		else if(window.event) 
		{ 
			TheEventObject = window.event; 
		} 
		else 
		{ 
			TheEventObject = null; 
		}

		if( 'undefined' != typeof e.pageX) 	{ 
			ele.cx = e.pageX; 
			ele.cy = e.pageY; 
		} 
		else { 
			ele.cx = e.clientX + document.body.scrollLeft; 
			ele.cy = e.clientY + document.body.scrollTop; 
		}
	 }
	ele.sP=function(x,y){
		this.style.left=(ffx)?parseInt(x+7)+px:x+px;this.style.top=(ffx)?parseInt(y-16)+px:y+px;
		}; // Set Position
	ele.flt=function(){
		this.sP(this.sx, this.sy);
		}
	return ele;
}

function fnValFileNm(field) {		  
	var sFile = document.getElementById(field).value;
	var flag = true;
	var chkflag = false;
	var strErr = ""
	
	if(sFile != "") { 
		sStrLen    = sFile.length;
		sPosition  = sFile.lastIndexOf(".");
		sSubString = sFile.substring(sPosition+1, sStrLen);
		if ((sSubString!="pdf")&&(sSubString!="PDF")) {
			flag = false;
			alert("- Only PDF files are allowed.\n\n");
			return false;
		}else{
			return true;
		}
	}
	else{
		alert("- File required. \n\n");
		return false;
	}
}  


function fnValFileNm2(field) {		
	var sFile = document.getElementById(field).value;
	var flag = true;
	var chkflag = false;
	var strErr = ""
	
	if(sFile != "") { 
		sStrLen    = sFile.length;
		sPosition  = sFile.lastIndexOf(".");
		sSubString = sFile.substring(sPosition+1, sStrLen);
		if ((sSubString!="pdf")&&(sSubString!="PDF")) {
			flag = false;
			alert("- Only PDF files are allowed.\n\n");
			return false;
		}else{
			return true;
		}
	}
} 