// This is for disabling the Back functionality in the browser
history.forward(1);
document.oncontextmenu = new Function("return false");
//***************************************************************************************//
/* This function ensures that all the characters in the value passed are alphabhets and spaces */
function validEntryCheck(val)
{
	var lwr = 'abcdefghijklmnopqrstuvwxyz';
	var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var digits='0123456789';
	var splchars="_ .-";
	var string=lwr+upr+digits+splchars;
	var flag=0
	for(i=0;i<val.length;i++)
				{
				if(string.indexOf(val.charAt(i,0))==-1)
						{
							flag=1;
							return true;
						}
				}
	if(flag==0)
		return false;
}

function validCharsCheck(val)
{
	var lwr = 'abcdefghijklmnopqrstuvwxyz';
	var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var digits='0123456789';
	var splchars="_.-";
	var string=lwr+upr+digits+splchars;
	var flag=0
	for(i=0;i<val.length;i++)
		{
		if(string.indexOf(val.charAt(i,0))==-1)
			{
				flag=1;
				return true;
			}
		}
	if(flag==0)
		return false;
}

function validmailIdCheck(val)
{
	var lwr = 'abcdefghijklmnopqrstuvwxyz';
	var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var digits='0123456789';
	var splchars="_.-@";
	var string=lwr+upr+digits+splchars;
	var flag=0
	if((val.lastIndexOf('.')-val.indexOf('@')<3) || (val.indexOf('.') == -1)||(val.indexOf('@') == -1))
		return true;
	for(i=0;i<val.length;i++)
		{
		if(string.indexOf(val.charAt(i,0))==-1)
			{
				flag=1;
				return true;
			}
		}
	if(flag==0)
		return false;
}

function validBTEntryCheck(val)
{
	var lwr = 'abcdefghijklmnopqrstuvwxyz';
	var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var digits='0123456789';
	var splchars="_ .-@";
	var string=lwr+upr+digits+splchars;
	var flag=0
	for(i=0;i<val.length;i++)
	{
		if(string.indexOf(val.charAt(i,0))==-1)
		{
			flag=1;
			return true;
		}
	}
	if(flag==0)
		return false;
}

function isMacValid(val)
{
	if(val.length>17||val.length<17||val.indexOf(":")==-1)
		return true;
	var temp=val;
	if(temp.lastIndexOf(":")-temp.indexOf(":")!=12)
		return true;
	else
	{
		var temp1="";
		i=0;
		while(temp.indexOf(":")!=-1)
		{
			temp1=temp;
			temp=temp.substring(temp.indexOf(":")+1);
			i++;
			if(i<5)
			{
				if(temp.indexOf(":")-temp1.indexOf(":")!=0)
				{
					return true;
				}
			}
			else if(i>5)
				return true;
		}
		if(i<5)
			return true;
	}
	return false;		
}

//To check file upload path directory in advance configuration widject form...

function validpath(val)
{
	var lwr = 'abcdefghijklmnopqrstuvwxyz';
	var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var digits='0123456789';
	var splchars="_.\ /-";
	var string=lwr+upr+digits+splchars;
	var flag=0
	for(i=0;i<val.length;i++)
	{
		if(string.indexOf(val.charAt(i,0))==-1)
		{
			flag=1;
			return true;
		}
	}
	if(flag==0)
		return false;
}
////////////////////////////////////////////////////////////////////////////////////
function isIPValid(val)
{
	var str = val;
	
	var IPArray = str.split(".");
	var flag = 0;
	if(IPArray.length != 4)
	{
	  return false;
	}
	if (IPArray != null) {
		for (var i=0;i<=3;i++)
		{
			if (IPArray[i]>255 || IPArray[i].length == 0||IPArray[i].length>3) 
			{
				flag = 1;
			}
		}
	}
	if(flag == 0)
		return true;
	else
		return false;
}
/*function isIPValid(val)
{
	var chars="0123456789."
	for(i=0;i<val.length;i++)
	{
		if(chars.indexOf(val.charAt(i,0))==-1)
		{
			return false;
		}
	}
	return true;
}*/
//**************************************************************//

// Removes leading whitespaces
//************DOB Check *********************/
function isDob(dob)
{
if (!isValidDate(dob))
 	{
 		return true;
 	 }
 	 return true;
}

/***************DOB ************************/
function LTrim( value ) 
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) 
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function Trim( value ) 
{
	return LTrim(RTrim(value));
}
//***************************************************************************************//
//Function to count and disply  the character left on the screen 
function getcount(tid, c) {
  var el = document.getElementById(tid);
  var count = el.value.length;
  var max = el.getAttribute("maxlength") * 1;
  if(count > max) {
    el.value = el.value.substring(0, max);
    //alert("please XXXXXXXXXXXXXX");
    } else {
    //document.getElementById(c).innerHTML = (max - count);
    }
  }
//*****************************************************************************************//

//******************************************************************************************//
function isValidDate(dateStr1) {
// Checks for the following valid date formats:
// MM.DD.YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables


var datePat = /^(\d{2})(\.)(\d{2})\2(\d{4})$/;

// To require a 2 or 4 digit year entry, use this line instead:
// var datePat = /^(\d{1,2})(\.)(\d{1,2})\2(\d{2}|\d{4})$/;

var matchArray = dateStr1.match(datePat); // is the format ok?
if (matchArray == null) {
alert("Date is not in a valid format.")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
return false;
   }
}
if(year < 1900)
{
alert("Year must be greater than 1900");
return false;
}

return true;  // date is valid
}

//*****************************************************************************************//
//
//date and time

function showTime()
   {
    var now=new Date();
    var hour=now.getHours();
    var min=now.getMinutes();
    var sec=now.getSeconds();

    if (min<=9) { min="0"+min; }
    if (sec<=9) { sec="0"+sec; }
    if (hour<10) { hour="0"+hour; }        
   
    if (hour>12) 
     { hour1= hour - 12;}
    else
     hour1 = hour;
    if (hour1<10) { hour1=hour1; }  

    var ctime =  hour1 + ":" + min + ":" + sec;
    return ctime;
   
   }

// date time code ends here
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;
   
   }
   function IsNumericMob(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;
   
   }
   function IsEmpty(aTextField) {
      if ((aTextField.length==0) ||
      (aTextField==null)) {
         return true;
      }
      else { return false; }
}	

//This function allows numeric also..
function IsNonNumeric(sText)

{
   var str = val;
	if(str.search(/[^ _.�0123*$456789a-zA-Z�������]/) != -1)
	{
		 return false;
	}
	else
	{
	return true;
	}
   
   }


function emailCheck (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="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* 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. "jiminy 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. joe@[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 john.doe@somewhere.com, john and doe 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("Please enter a valid email address")
	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), 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;
}



///get ehe parameters from the url

function getURLParameters(paramName) 
{
	var sURL = window.document.URL.toString();
	
	if (sURL.indexOf("?") > 0)
	{
		var arrParams = sURL.split("?");
			
		var arrURLParams = arrParams[1].split("&");
		
		var arrParamNames = new Array(arrURLParams.length);
		var arrParamValues = new Array(arrURLParams.length);
		
		var i = 0;
		for (i=0;i<arrURLParams.length;i++)
		{
			var sParam =  arrURLParams[i].split("=");
			arrParamNames[i] = sParam[0];
			if (sParam[1] != "")
				arrParamValues[i] = unescape(sParam[1]);
			else
				arrParamValues[i] = "No Value";
		}
		
		for (i=0;i<arrURLParams.length;i++)
		{
		if(paramName==arrParamNames[i])
		  {
		  if(paramName=="userID")
		    {
		    if(arrParamValues[i].search(/[#]/) == -1)
		    {
			  	  var userId=arrParamValues[i].split("#");
				  return userId[0];
			  }
			  }
			  return arrParamValues[i];
			}
			
		}
	}
	else
	{
		alert("No parameters.");
	}
}

function getURL()
{
 var sURL = window.document.URL.toString();
 
 var arrParams = sURL.split("?");
 
return arrParams[0];
}


// active users parsing starts here
function getActvUserParams() 
{
	var sURL = window.document.URL.toString();	
	var arrURLParams=null;
	try {
			if (sURL.indexOf("?") > 0)
			{
				var arrParams = sURL.split("?");			
				arrURLParams = arrParams[1].split("&");	
			}
			else
			{
				alert("No parameters.");
			}
		}catch(eActvUsers) {  }
	return arrURLParams; 
}

function fillCombo(cmbName,arrayParams)
{
	
}


/* ********************************Age Check************** */
   function ageCheck(age)
   {
  	 if(!IsEmpty(age))
   	 {
   		if (age<18 || age>100)
 	 	return false;
 	 }
   }

/* *********************** 'images' folder path finder ***** */
function imagePath()
{
	var path=""+window.location;
	return path.substring(0,path.lastIndexOf('/'))+"/images";
}
   
