	// JavaScript Document
	function checkMail(val)
	{
		var x = val;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(x)) return true;
		else return false;
	}

	function checkForInvalidCharsAtStart(strToTst, bypassMsg)
	{
		//this function tests for any of the following special characters in the entire
		//passed string! and in the firsst instance it returns false!
		
		var invalidChars = "~!@#$%^&*()_+|{}:<>?`-=\[];',./";
		var fStr;
		var i;		//this is just a simple counter!
		//we are doing this trick because " cannot be incorporated between " "...
		invalidChars = invalidChars + '"';
		//check for space char
		invalidChars = invalidChars + " ";

		//stuff the first character into the variable!
		/*alert ("Getting into it!");
		alert (invalidChars);*/
		fStr = strToTst.substring(0,1);
		for(i = 0; i < invalidChars.length; i++)
		{
			if(invalidChars.substring(i,i + 1) != "_")
			{
				//Now chek for the entire passed string!
				for(j = 0; j < strToTst.length; j++)
				{
					//alert(strToTst.substring(j,j + 1) + " and " + invalidChars.substring(i,i + 1));
					if(strToTst.substring(j,j + 1) == invalidChars.substring(i,i + 1))
					{
						if(bypassMsg == false)
						{
							alert ("EparOpar ID cannot have '" + invalidChars.substring(i,i + 1) + "' character!");
						}
						return false;
					}
				}			 
			}
			else
			{
				if(fStr == invalidChars.substring(i,i + 1))
				 {
					if(bypassMsg == false)
					{
						alert ("EparOpar ID cannot start with '" + invalidChars.substring(i,i + 1) + "' character!");
					}
					user_login.user_id.focus();
					return false;
				 }
			}
		}
		return true;		
	}
	
	
	function IsNumeric(sText)
	{
		var ValidChars = "0123456789.";
		var IsNumber=true;
		var Char;
		if(sText != "")
		{
			for (i = 0; i < sText.length && IsNumber == true; i++) 
			{ 
				Char = sText.charAt(i); 
				if (ValidChars.indexOf(Char) == -1) 
				{
					IsNumber = false;
				}
			}
		}
		else
		{
			IsNumber=false;
		}
		return IsNumber;	
	}
	
	function isPhone(num)
	{
		var isPhone=true;
		var reg2 = /[0-9\-\.\,\ ]$/; // valid
		if(!reg2.test(num))
		{
			alert("Invalid Number!");
			isPhone=false;
		}
		return isPhone;
	}
	
	function validDays()
	{
		//validate only for feb...
		if(user_login.month.value=="February")
		{
			//Chk if the selected year is a leap year!v
			if(user_login.year.value%4 == 0)
			{
				//we are into leap year! Day can be upto 29.
				//if(user_login.day.value "30" || user_login.day.value=="31")
				if(user_login.day.value <= 29)
				{
					return true;
				}
				else
				{
					alert("Please select valid date! You have chosen a leap year!");
					user_login.day.focus();
					return false;
				}
			}
			else
			{
				// we are into any non-leap year!
				if(user_login.day.value <= 28)
				{
					return true;
				}
				else
				{
					alert("Please select valid date!");
					user_login.day.focus();
					return false;
				}
			}
		}
		else
		{
			//for any non feb months! First lets check for 30 days month!
			if(user_login.month.value=="April" || user_login.month.value=="June" || user_login.month.value=="September" || user_login.month.value=="November")
			{
				if(user_login.day.value <= 30)
				{
					return true;
				}
				else
				{
					alert("Please select valid date!");
					user_login.day.focus();
					return false;
				}
			}
		}
	}

	function validateEmail(email)
	{
		var i, ctr, j, dot;
		ctr = 0;
		//chk if it is comprising of atleaset 9 characaters!
		if(email.length < 9)
		{
			alert ("Your email doesnt seem to be a real one! Please re-check!");
			return false;
		}
		else
		{
			//check if there is a '@' in it!
			for(i = 0; i <= email.length; i++)
			{
				if(email.substring(i, i+1) == "@")
				{
					ctr++;
				}				
			}
			if(ctr <= 0 || ctr > 1)
			{
				alert ("Your email doesnt seem to be a real one! Please re-check!");
				return false;
			}
			else
			{
				//@ found, check if it is in the very first position!
				if(email.substring(0,1) == '@')
				{
					alert ("Your email doesnt seem to be a real one! Please re-check!");
					return false;
				}
				else
				{
					//chk for existance of '.'
					//reset the counter var first!
					ctr = 0;
					for(i = 0; i <= email.length; i++)
					{
						if(email.substring(i, i+1) == ".")
						{
							ctr++;
						}				
					}
					if(ctr <= 0)
					{
						alert ("Your email doesnt seem to be a real one! Please re-check!");
						return false;
					}
					else
					{
						//next check if atleast one dot appears after the @ char!
						var gotAtTheRate;
						//init it to 'false'
						gotAtTheRate = false;
						//next reset the counter var!
						ctr=0;
						for(i = 0; i <= email.length; i++)
						{
							//chk only if '@' is not found!
							if(gotAtTheRate == false)
							{
								if(email.substring(i, i+1) == "@")
								{
									//found the '@', toggle the var!
									gotAtTheRate = true;
								}
							}
							else
							{
								//chk if the character is "."
								if(email.substring(i, i+1) == ".")
								{
									//found the '.', increase the counter var!
									ctr++;
									gotAtTheRate = true;
								}
							}
						}
						//at last decide if a dot is found after the '@' or not!
						if(ctr <= 0)
						{
							alert ("Your email doesnt seem to be a real one! Please re-check!");
							return false;
						}
						else
						{
							//next check if "@" and '.' coexists! i.e like "@."...
							if(email.indexOf('@.') > -1)
							{
								//found, unfavourable!
								alert ("Your email doesnt seem to be a real one! Please re-check!");
								return false;
							}
							else if(email.indexOf('.@') > -1)
							{
								//again found, unfavpourable!
								alert ("Your email doesnt seem to be a real one! Please re-check!");
								return false;
							}
							else
							{
								//not found, data OKay!
								return true;
							}
							return true;
						}
					}
				}
			}
		}
	}
	
	function isPassword(pass)
	{
			var aflag=false;
			var nflag=false;
			var validcharsA='abcdefghijklmnopqrstuvwxyz';
			var validcharsN='1234567890';
			if(pass.length<6)
			{
					alert("Password must be of atleast 6 characters.");
					return false;
			}
			
			for(i = 0; i < pass.length; i++)
			{
					
				if(pass.substring(i, i+1) == " ")
				{
					alert("Blank space is not allowed here.");
					return false;
					break;
				}
				keychar=pass.substring(i, i+1);
				keychar = keychar.toLowerCase();
				if(!nflag)
				{
					if (validcharsN.indexOf(keychar) != -1)
					{
						nflag=true;
					}
				}
				if(!aflag)
				{
					if (validcharsA.indexOf(keychar) != -1)
					{
						aflag=true;
					}
				}
			}
			if(!aflag)
			{
				alert("Password should contain atleast one alphabet.");
				return false;
			}
			if(!nflag)
			{
				alert("Password should contain atleast one number.");
				return false;
			}
			return true;
	}
	
	function isIndianPIN(pin)
	{
		var res;
		//First chk if its not empty!
		if(pin == "")
		{
			alert("Pin left empty!");
			res = false;
		}
		else
		{
			//Chk if its in numeric format!
			if(IsNumeric(pin) == false)
			{
				alert("PIN should only contain numbers!");
				res = false;
			}
			else
			{
				if(pin.length != 6)
				{
					alert("Invalid PIN, please check!");
					res = false;
				}
				else
				{
					res = true;
				}
			}
		}
		return res;
	}
	
	function isUSAPIN(pin)
	{
		var regexp=/(^\d{5}$)/;
		return regexp.test(pin);
	}
	
	function isUSAPhone(phone)
	{
		var regexp = /^\d{3}\-\d{3}\-\d{4}$/;
		return regexp.test(phone);
	}
	
	function isUSAFax(fax)
	{
		var regexp = /^\+\d{2}\-\d{4}\-\d{7}$/;
		return regexp.test(fax);
	}
	
	
	
	function isEmpty(value)
	{
		if(value.search(/\S/)==-1)
		{
	   		return true;
	  	}  
	  	return false; 
	}
	
	function getKeyCode(e)
	{
		if (window.event)
			return window.event.keyCode;
		else if (e)
			return e.which;
		else
			return null;
	}
	
	function keyRestrict(e, validchars) 
	{
		var key='', keychar='';
		key = getKeyCode(e);
		if (key == null) return true;
		keychar = String.fromCharCode(key);
		keychar = keychar.toLowerCase();
		validchars = validchars.toLowerCase();
		if (validchars.indexOf(keychar) != -1)
			return true;
		if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
			return true;
		//alert("Plese enter a valid character.");
		return false;
	}
	
	// Functions for trailing spaces.
function trim(strText) { 
		// this will get rid of leading spaces
		while (strText.substring(0,1) == ' ')
			strText = strText.substring(1, strText.length);

		// this will get rid of trailing spaces
		while (strText.substring(strText.length-1,strText.length) == ' ')
			strText = strText.substring(0, strText.length-1);
		var pos=0
		var tevePos=0
		while(strText.indexOf("\n",pos)>-1)
		{
			tevePos=strText.indexOf("\n",pos)
			pos=tevePos+1
		}
		
	   return strText;
}
	var win = null;
	function NewWindow(mypage,myname,w,h,scroll){
	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	var settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
	}
	
	function openwin(url,w,h,scrollyes){
		var top = (screen.height-h)/2;
		var left = (screen.width-w)/2;
		var customize = "toolbar=no,menubar=no,resizable=yes,scrollbars="+scrollyes+",width="+w+",height="+h+",top="+top+",left="+left;
		window.open(url,'_blank',customize)
	}
	
	function IsInFormat(val,format)
	{
		if(!(val==""))
		{
			var reg2 = format; 
			if(!reg2.test(val))
			{
				alert("Not in valid format!");
				return false;
			}
		}
			return true;
			
	}
	
	function daysInMonth(iMonth, iYear)
	{
		return 32 - new Date(iYear, iMonth, 32).getDate();
	}
	
	///change value into currency format
	function CurrencyFormatted(amount)
	{
		var i = parseFloat(amount);
		if(isNaN(i)) { i = 0.00; }
		var minus = '';
		if(i < 0) { minus = '-'; }
		i = Math.abs(i);
		i = parseInt((i + .005) * 100);
		i = i / 100;
		s = new String(i);
		if(s.indexOf('.') < 0) { s += '.00'; }
		if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
		s = minus + s;
		return s;
	}
	// end of function CurrencyFormatted()
	
	
	//credit card verification function
	//return true if information right else return false
	function validatecardfunc (cc_number,cc_type) {
	validcard = false;
	ret = stripNonNumbers(cc_number);
	result = cc_type;
	if (result == "Mastercard") {
	if (ret.length == 16)
	validcard = true;
	if ((ret.substring (0, 2) >= "51") &&
	(ret.substring (0, 2) <= "55"))
	validcard = true;
	else
	validcard = false;
	}
	if (result == "Visa") {
	if ((ret.length == 16) || (ret.length ==13))
	validcard = true;
	if (ret.substring (0, 1) != "4")
	validcard = false;
	}
	if (result == "American Express") {
	if (ret.length == 15)
	validcard = true;
	if ((ret.substring (0, 2) != "34") &&
	(ret.substring (0, 2) != "37"))
	validcard = false;
	}
	if (result == "Discover") {
	if (ret.length == 16)
	validcard = true;
	if (ret.substring (0, 4) != "6011")
	validcard = false;
	}
	return (validcard);
	}
	
	function stripNonNumbers (InString) {
	OutString="";
	InString=InString.toString();
	for (Count=0; Count < InString.length; Count++) {
	TempChar=InString.substring (Count, Count+1);
	Strip = false;
	CharString="0123456789";
	for (Countx = 0; Countx < CharString.length; Countx++) {
	StripThis = CharString.substring(Countx, Countx+1)
	if (TempChar == StripThis) {
	Strip = true;
	break;
	}
	}
	if (Strip)
	OutString=OutString+TempChar;
	}
	return (OutString);
	}
	
	function isExpYearValid(expYear,expMonth,curYear,curMonth)
    {

  // Use this if you do not have access to the servers system date.
  // Get current year from client machine
   myDate = new Date();
  myYear = parseInt(curYear);
  myMonth = parseInt(curMonth); 
  // Remember that JavaScript getMonth will return a number between 00 and 11
  // alert(myYear);

  // Get current year from server
  //myYear = (:sYear);
  //myMonth = (:sMonth);
  
	theirYear=parseInt(expYear);
	theirMonth=parseInt(expMonth);
  // Find out if the year they gave is equal or greater or less than currentyear
    if (theirYear > myYear)
        {
        return true;
        }
  else if (myYear > theirYear)
    {
        alert("Your credit card seems to have expired .");
        return false;
    }
  else
    {
        // it is equal, check the month.
    if (myMonth > theirMonth || parseInt(myMonth)==parseInt(theirMonth))
      {
      alert("Your credit card seems to have expired");
	  /*\n(You entered " +
theirMonth + ", " + theirYear + ". It is now " + myMonth + ", " + myYear +
".)\nPlease enter a updated expiration or try another credit card.*/
      return false;
      }
    }
  return true;
    }
	
	function isUrl(s) {
	var regexp = /^[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_%&\?\/.=]+$/
	return regexp.test(s);
}

function getfileextension(filename) 
{ 
	
	 if( filename.length == 0 ) return ""; 
	 var dot = filename.lastIndexOf("."); 
	 if( dot == -1 ) return ""; 
	 var extension = filename.substr(dot,filename.length); 
	 return extension.toLowerCase(); 
} 
