function Validate(form) 
{
    var v = new RegExp();
    v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
    if (!v.test(form.value)) {
        alert("You must supply a valid URL.");
        return false;
    }
}

function checkURLNew(sUrl)
	{
		var url = false ;
		var isNot = "`!@$^*()[{]}\|;'',<> " ;
		if (sUrl.length != 0 )
		{
			if (sUrl.indexOf('://') != -1)
			{
				if(sUrl.indexOf('www.') != -1)
				{
				if (sUrl.indexOf('"') == -1)
				{
					url = true ;
					if (sUrl.length <= 7 )
					{
						url = false ;	
					}
					for (i=0;i!=sUrl.length;++i)
					{
						if (isNot.indexOf(sUrl.substring(i,i+1)) != -1)
						{
							url = false ;	
						}
					}
					//Checking for .com, .co, .net, .org	in the URL				
					if (sUrl.indexOf('.com') != -1)
					{
						url = true ;						
					}
					else
					{
						if (sUrl.indexOf('.co') != -1)
						{
							url = true ;						
						}
						else
						{	
							if (sUrl.indexOf('.net') != -1)
							{
								url = true ;
							}
							else
							{
								if(sUrl.indexOf('.org') != -1)
								{
									url = true ;
								}
								else
								{
									url = false ;
								}
							}
						}
					}
					//
				}
			}
		}
	}
		else{
			url=true;
		}	
		if (url == false )
		{
			//alert('In valid URL') ;
			return false;
		}
		else
		{
			//checkURLNew = true ;
			return true ;
		}	
	}

function isNum(Num) {
        var charpos = Num.search("[^0-9]"); 
        if(Num.length > 0 &&  charpos >= 0) 
              { 
                return false; 
              }
        else
			  { 
                return true; 
              }
    }	

function isDate(strDate)
{
	var datePattern = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = strDate.match(datePattern); //check the date format ok?.
	var blnIsDate = true;

	if (matchArray == null)
	{
		//alert("Please enter date as mm/dd/yyyy");
		return false;
		blnIsDate=false;
	}

	month=matchArray[1];
	day=matchArray[3];
	year=matchArray[5];

	if (month <1 || month > 12)
	{
		//alert("Month must be between 1 and 12");
		return false;
		blnIsDate=false;
	}

	if (day <1 || day > 31)
	{
		//alert("Day must be between 1 and 31");
		return false;
		blnIsDate=false;
	}

	if ((month ==4 || month == 6 || month==9 || month==11) && day==31)
	{
		alert("Month "+month+" doesn't have 31 days!");
		return false;
		blnIsDate=false;
	}

	if (month ==2)
	{
		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;
			blnIsDate=false;
		}

	}

	return true;
}

function isFloat (s)
{   var i;
	var seenDecimalPoint = false;
	var decimalPointDelimiter = "."
	var defaultEmptyOK = true
	if (isEmpty(s)) 
	   if (isFloat.arguments.length == 1) return defaultEmptyOK;
	   else return (isFloat.arguments[1] == true);

	if (s == decimalPointDelimiter) return false;

	// Search through string's characters one by one
	// until we find a non-numeric character.
	// When we do, return false; if we don't, return true.

	for (i = 0; i < s.length; i++)
	{   
		// Check that current character is number.
		var c = s.charAt(i);

		if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
		else if (!isDigit(c)) return false;
	}

// All characters are numbers.
return true;
}
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isEmpty(s)
{	return ((s == null) || (s.length == 0))
}

function checkMoney(ctl,msgName){
  if(isFloat(ctl.value)==false)	
    {
      alert('"'+msgName+'"' + " is Invalid. \nPlease Enter only Numeric Data. \nDo not use any characters like ','");
      ctl.focus();
      return (false);
    }
  else
    {
    	return (true);
    }
}

function checkBlank(ctl,msgName){
	if(trimme(ctl.value)=="")	
    {
      alert('"'+msgName+'"' + " Can not be blank");
      ctl.focus();
      return (false);
    }
  else
    {
    	return (true);
    }
}

/*function checkSelect(ctl){
  if(ctl.selectedIndex>=0)	
    {
      alert('Please Select state from dropdown');
      ctl.focus();
      return (false);
    }
  else
    {
    	return (true);
    }
}*/

function checkSelect(ctl,msgName){	
  if(ctl.selectedIndex<=0)	
    {	
       alert('Please Select '+msgName);
       ctl.focus();
      return false;
    }
  else
    {
    	return true;
    }
	
}

/*function getSelectedOption(frmName,srcListName)
{
	var form = eval( 'document.' + frmshipper );
	var srcList = eval( 'frmshipper.' + srcListName );

	i = srcList.selectedIndex;
	if (i != null && i > -1) {
		return srcList.options[i];
	} else {
		return null;
	}
}*/


function ValidateEmail(ctl)
	{
    var id=ctl;
	var at=id.value.indexOf('@');
	var lastat=id.value.lastIndexOf('@');
	var dot=id.value.indexOf('.');
	lastdot=id.value.lastIndexOf('.')
	if ( !( (0 < at) && (at < (lastdot-1)) && (lastdot < (id.value.length-1)) && (at == lastat) ) )
	{
	  error = 1;
	  alert("Email address is not formatted properly.");
	  ctl.focus();
	
	  return (false);
	}
	var str_referral=id.value.length;
	var ch_referral=id.value;
	for(i=0;i<str_referral;i++)
	{
		ch_referral1=ch_referral.substring(i,i+1);

		if(ch_referral1==" ")
		{
			alert("Please Enter Valid Email address Id need not content any space.");
			ctl.focus();
			return (false);
		}
	}
}
function ValidateEmailSend(ctl)
{
	var emesage;
	if(ctl==frm.to_email)
	{
		emesage=":- Recipient E-Mail";
	}
	else
	{
		emesage=":- Your E-Mail";
	}

    var id=ctl;
	var at=id.value.indexOf('@');
	var lastat=id.value.lastIndexOf('@');
	var dot=id.value.indexOf('.');
	lastdot=id.value.lastIndexOf('.')
	if ( !( (0 < at) && (at < (lastdot-1)) && (lastdot < (id.value.length-1)) && (at == lastat) ) )
	{
	  error = 1;
	  alert("Email address"+emesage+" is not formatted properly.");
	  ctl.focus();
	  return (false);
	}
	var str_referral=id.value.length;
	var ch_referral=id.value;
	for(i=0;i<str_referral;i++)
	{
		ch_referral1=ch_referral.substring(i,i+1);

		if(ch_referral1==" ")
		{
			alert("Please Enter Valid Email address Id"+emesage+" need not content any space.");
			ctl.focus();
			return (false);
		}
	}
	
}

function confirmPassword(ctl1,ctl2){
   if(ctl1.value != ctl2.value){
   	alert("Password and Confirm Password do not match");
   	ctl1.focus();
   	return(false);
   }
}


function deleteitem(theMessage,theTarget)
{	
	var theRadio=form1.item_nbr;
	var strRadio;
	if (theRadio.length)
	{
		for (var i = 0; i < theRadio.length; i++)
		{   if (theRadio[i].checked)
			{
				strRadio=theRadio[i].value;
			}
		}
	}else
	{
		strRadio=theRadio.value;
	}
		if (strRadio > 0)
	{
		var blnConfirm;
		blnConfirm = confirm("Are you sure?");
		if (blnConfirm)
		{
			form1.action=theTarget+'?item_nbr='+strRadio
			form1.submit();
		}
	}else
	{
		alert ("Select "+ theMessage + " To Delete");
	}
}

function radio_validate(formObj) {
    var isOK = false;
    for (i=0;i<formObj.elements.length;i++) {
	currElem = formObj.elements[i]
        if (currElem.type == "radio"  &&  currElem.checked) {
            isOK=true;
	    break;
        }
    }
    if (!isOK) alert("You need to select a option !");
    
    return isOK;
}

function findObj(n, d)
{ 
  var p,i,x;  
  if(!d) d=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length)
{
  d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function showHideLayers()
{ 
  var i,p,v,obj,args=showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  if ((obj=findObj(args[i]))!=null) 
	{ 
	  v=args[i+2];
		if (obj.style) 
		{ 
			obj=obj.style; 
			v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
		}
		obj.visibility=v;
	}
}
function jumpMenu(targ,selObj,restore)
{ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function NNKeyCap(thisOne) 
{
    if (thisOne.which <48 || thisOne.which >57)
       {
	   if(thisOne.which !=46)
	   	{
		   alert('Only numeric (1,2,3..) and Dot \".\" are allowed')
		   return false;
		}
	   }
}

function IEKeyCap() 
{
	alert(window.event.keyCode);
    if (window.event.keyCode <48 || window.event.keyCode >57)
       {
	   if(window.event.keyCode ==46)
	   	{
		   alert('This key is not valid .Please Enter The Quantity In Number.')
		   return false;
		}
	   }
}
if (navigator.appName == 'Netscape') {
window.captureEvents(Event.KEYPRESS);
window.onKeyPress = NNKeyCap;
}

function numbersonly(myfield, e, dec)
{
	var key;
	var keychar;
	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;
	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
		return true;
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
		return true;
	// decimal point jump
	else if (dec && (keychar == "."))
	{
		
		myfield.form.elements[dec].focus();
		return false;
	}
	else
	{
		alert('This key is not valid .Please Enter The Quantity In Number.')	
		return false;
	}
}

function getExtension (filename)
{
	//alert(filename);
	filename = filename.toLowerCase();
	
	fileArr = filename.split("\\");
	
	//alert("length " + fileArr.length);
	
	fname = fileArr[fileArr.length-1];
	
	fnameArr = fname.split(".");
	
	ext = fnameArr[fnameArr.length-1];
	
	//alert(ext);
	
	return ext;
}

function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* 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("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}
// 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.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

