var defaultEmptyOK = false;
var nameDelimiters = "-. ";
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz";
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var whitespace = " \t\n\r";
var validDomainNameChars = digits + uppercaseLetters + lowercaseLetters + "-_.";

function checkEmail (theField, emptyOK){
	if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else {
      emailStatus = isEmail(theField.value, false)
      if (emailStatus != true) return warnInvalid (theField, "Invalid email address");
      else return true;
    }
}

function isEmail (s){
	 if (isEmpty(s)) {
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true); }
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++ }
    if ((i >= sLength) || (s.charAt(i) != "@")) return ("no @ sign");
    else atloc = i;
    j = i+1;
    i += 1;
    while ((j < sLength) && (validDomainNameChars.indexOf(s.charAt(j)) != -1))
    { j++ }
    if (j < sLength) return("invalid character in domain name: "+s.charAt(j));
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++ }
    if (i == sLength) return("no . in domain name");
    if (i == (atloc +1)) return("not enough space between @ and .");
    k = atloc+1;
    while (k < sLength){
      if ((s.charAt(k) == ".") && (s.charAt(k+1) == ".")) return("too many .'s");
      k++
    }
    l = sLength;
    while ((i < sLength -2) && (l != i) && (s.charAt(l) != "."))
    { l = l-1 }
    if ((i >= sLength - 2) || (s.charAt(i) != ".") || (l >= sLength - 2)) return("not enough chars after .");
    else return true;
}

function checkURL (theField, emptyOK){
    if (checkURL.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else {
      var tempURL = theField.value;
      if ((tempURL.indexOf("http://") >= 0) && (tempURL.indexOf("http://") < tempURL.length)) theField.value = tempURL.substring(tempURL.indexOf("http://")+7,tempURL.length);
      URLStatus = isURL(theField.value, false)
      if (URLStatus != true) return warnInvalid (theField, "Invalid URL");
      else {
        theField.value = reformatWebURL(theField.value);
        return true;
      }
    }
}

function isURL (s)
{   if (isEmpty(s)) 
       if (isURL.arguments.length == 1) return defaultEmptyOK;
       else return (isURL.arguments[1] == true);
    if (isWhitespace(s)) return false;
    var i = 0;
    var j = 0;
    var URLstart = 0;
    var sLength = s.length;
    while ((j < sLength) && (validDomainNameChars.indexOf(s.charAt(j)) != -1))
    { j++ }
    if (j < sLength) return("invalid character in domain name: "+s.charAt(j));
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++ }
    if (i == sLength) return("no . in domain name");
    if (i == (URLstart)) return("not enough space before first .");
    k = URLstart+1;
    while (k < sLength)
    {
      if ((s.charAt(k) == ".") && (s.charAt(k+1) == ".")) return("too many .'s");
      k++
    }
    l = sLength;
    while ((i < sLength -2) && (l != i) && (s.charAt(l) != "."))
    { l = l-1 }
    if ((i >= sLength - 2) || (s.charAt(i) != ".") || (l >= sLength - 2)) return("not enough chars after .");
    else return true;
}

function reformatWebURL(s) {
  if (isEmpty(s)) 
     if (reformatWebURL.arguments.length == 1) return defaultEmptyOK;
     else return (reformatWebURL.arguments[1] == true);
  return ("http://"+s);
}

function checkName(theField,emptyOK){
    if (checkName.arguments.length == 1) emptyOK = defaultEmptyOK;
    if (isEmpty(theField.value)) return emptyOK;
    else {
        if (!isAlphabetic(stripCharsInBag(theField.value,nameDelimiters))){
          
          //warnInvalid(theField,msgArray(152));
          warnInvalid(theField,"Text  contains invalid Name");
          //alert("Field contains invalid characters");
          //theField.focus();
          return false;
         }
        else {
          theField.value = makeTitleCase(theField.value);
          return true;
        }
    }
}

//no alert
function isName(theField){
    if (isEmpty(theField.value)) return true;
    else {
        if (!isAlphabetic(stripCharsInBag(theField.value,nameDelimiters))){
            return false;
         }
        else {
            return true;
        }
    }
	return true;
}

//for checkname
function stripCharsInBag (s, bag){
    var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function isAlphabetic (s){
    var i;
    if (isEmpty(s)) 
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!isLetter(c))
        return false;
    }
    return true;
}

function isLetter (c){
   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function warnInvalid (theField,s){
//    theField.focus()
    theField.select()
    alert(s)
    return false
}

function makeTitleCase(s){
  if (isEmpty(s)) 
     if (makeTitleCase.arguments.length == 1) return defaultEmptyOK;
     else return (makeTitleCase.arguments[1] == true);
  count = 1;
  ws = 0;
  s = s.charAt(0).toUpperCase()+s.substring(1,s.length);
  while (count < s.length){
    if (isWhitespace(s.charAt(count)) || (s.charAt(count) == ".") || (s.charAt(count) == "-")) ws = 1;
    else if ((ws == 1) && (isLetter(s.charAt(count)))){
      s = s.substring(0,count)+s.charAt(count).toUpperCase()+s.substring(count+1,s.length);
      ws = 0;
    }
    count++;
  }
  return s;
}

function isWhitespace(s) {
    var i;

    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false; // not whitespace
    }
    return true;
}

function isEmpty(s) {
    return ((s == null) || (s.length == 0))
}


//line-187
//My own functions

//to remove double space to single
function rmspace(form)
		{
			var i; 
			i=0;
			//Remove space from begining
			while (form.value.substr(i,1) == " ") { i=i+1 ; }
			form.value=form.value.substr(i);

			//remove space from end
			i=1;
			while (form.value.substr(form.value.length - i,1) == " ") { i=i+1 ; }
			form.value=form.value.substr(0,form.value.length - (i-1));

			//remove double spaces between
			i=0;
			var space=0;
			while((form.value.length-1)>=i)
			{
				if(form.value.substr(i,1) == " ")
						space=space+1;
		
				else
						space=0;
	
				if (space==2)
				{       form.value=form.value.substr(0,i) + form.value.substr(i+1);
						i=i-1;
                		space=0;
		         }
				else
						i=i+1;
			}
		} 
		function nospace(form)
		{
			 var i=0;
			while((form.value.length-1)>=i)
			{
			     if(form.value.substr(i,1) == " ")
		    		     form.value=form.value.substr(0,i) + form.value.substr(i+1);
			     else
				         i=i+1;
			}
		}

function checkyear(field)
{	nospace(field);
	if (isEmpty(field.value))
		return false;
	var cdt = new Date();
	if (isinteger(field))
	{
		if (field.value.length <4 )
			alert("Year should be four digit");
		else if(field.value > cdt.getYear())
		{
			alert("Year of established is not a valid year");
		}
	 }
field.focus();
}
		
	
function isCharText (s) //valid only alphabets and space 
{
    var i,c;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( !(((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || (c ==' ')))
        {
                return false;
		}
    }
    return true;
}	
	
function isAlphaNumeric (s) //valid only alphabets and numers
{
    var i,c;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( !(((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || ((c >= "0") && (c <= "9")) ))
        {
                return false;
		}
    }
    return true;
}	
function isUserName(s) //valid only alphabets and numers
{
    var i,c;
	for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( !( (c == ".") || (c == ",") || (c == ' ') || (c == ";") || (c == ":") || (c == "-") || ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || ((c >= "0") && (c <= "9")) || (c == "_") ))
        {
               return false;
		}
    }
	if(isWhitespace(s)==true)
	{
		return false;
	}
	return true;
}
	 
 function isinteger(field)
{	
	nospace(field);
     if (field.value != "")
	 {
	  	//return ((c >= "0") && (c <= "9"))
	  	var i=0;
	  	while(i < field.value.length)
	  	{
	  		if (field.value.charAt(i)>="0" && field.value.charAt(i)<="9" )
					i++;
			else
				break;
		  }
		if (i== field.value.length)  
			return true;
		else
		{
			//alert("Only Integers allowed");
			alert("Please enter a number ");
			field.select();
			return false;
		}
	}
}
 
 function checkInteger(value)
{	
	//nospace(field);
     if (value != "")
	 {
	  	//return ((c >= "0") && (c <= "9"))
	  	var i=0;
	  	while(i < value.length)
	  	{
	  		if (value.charAt(i)>="0" && value.charAt(i)<="9" )
					i++;
			else
				break;
		  }
		if (i== value.length)  
			return true;
		else
		{
			return false;
		}
	}
	else
		return true;
}
 function isdigit(field)
{
     nospace(field);
	 if (field.value != "")
	 {
	  	//return ((c >= "0") && (c <= "9"))
	  	var i=0;
	  	var digitcount =0;
		while(i < field.value.length)
	  	{
	  		if ((field.value.charAt(i)>="0" && field.value.charAt(i)<="9") || (field.value.charAt(i) == ".") || (field.value.charAt(i) == "-"))
			{		if(field.value.charAt(i) ==".")
						digitcount = (digitcount + 1)- 0 ;
					if (digitcount == 2)
						break; 
				i++;
			}
			else
				break;
		  }
		if (i== field.value.length)  
			return true;
		else
		{
			alert("Please enter a number");
			field.select();
			return false;
		}
	}
}

function checkisdigit(field)
{	
	nospace(field);	
     if (field.value != "")
	 {
	  	var i=0;
	  	var digitcount =0;
		while(i < field.value.length)
	  	{
	  		if ((field.value.charAt(i)>="0" && field.value.charAt(i)<="9") || (field.value.charAt(i)==".") )
			{		if(field.value.charAt(i) == ".")
						digitcount = digitcount + 1;
					if (digitcount == 2)
						break; 
				i++;
			}
			else
				break;
		  }
		if (i== field.value.length)  
			return true;
		else
		{
			field.focus();
			return false;
		}
	}
	return true;
}

//Check whether in hh:mm format
function IsTime(field)
{
     nospace(field);
	 if (field.value != "")
	 {
	  	//return ((c >= "0") && (c <= "9"))
	  	var i=0;
	  	var digitcount =0;
		while(i < field.value.length)
	  	{
	  		if ((field.value.charAt(i)>="0" && field.value.charAt(i)<="9") || (field.value.charAt(i) == ":") )
			{		if(field.value.charAt(i) ==":")
						digitcount = (digitcount + 1)- 0 ;
					if (digitcount == 2)
						break; 
				i++;
			}
			else
				break;
		  }
		if (i== field.value.length)  
			return true;
		else
			return false;
	}
}



function loginadd(lgid,pswd,psqst,psans)
{
	regform.loginid.value=lgid;
	regform.password.value=pswd;
	regform.passwordqst.value=psqst;
	regform.passwordans.value=psans;
}



// Bid Form Functions

function checkdate(field)
	{
		var ln,temp="",mm=false,dd=false,yyyy=false;
		var i=0;
		ln=field.value.length;
		nospace(field);
		while ( i< ln)
		{
			if((field.value.substr(i,1)>="0") && (field.value.substr(i,1)<="9") )
			{	temp=temp+field.value.substr(i,1);
				//alert(temp);
				if ((dd==false) && (temp.length > 2) )
				{
					alert("Invalid Date*");
					field.focus();
					return ;
				}
				else if(temp.length >4 )
				{
					alert("Invalid Year");
					field.focus();
					return;
				}
				
				if(i==ln-1)
				{
					if(temp.length==3 || temp.length==1)
					{
						alert("Year shold be 2 Or 4 digit")
						field.focus();
						return;
					}
					else if(temp.length == 2)
					{
						field.value=field.value.substr(0,i-1) + "20" +field.value.substr(i-1);
						year=true;				
					}				
				}
			
			
			}	
			else
			{
				if (temp=="")
				{
					alert("Invalid date**");
					field.focus();
					return;
				}
				if(mm == false)
				{	
					if(temp >12 || temp==0)
					{
						alert("Invalid Month")
						field.focus();
						return;
					}
					field.value=field.value.substr(0,i) + "/" +field.value.substr(i+1);
					mm=true;				
				}
				
				else if(dd == false)
				{
					if(temp >31 || temp==0)
					{
						alert("Invalid Day")
						field.focus();
						return;
					}
					field.value=field.value.substr(0,i) + "/" +field.value.substr(i+1);
					dd=true;				
				}
				else if(yyyy == false)
				{
					alert("Invalid characters in year");
					field.focus();
					return;				
				}
				
				temp="";
			}
		i=i+1;
		}
	}

	function ListDay(lstname)
		{		
				var i ;	
				document.write("<SELECT NAME=" + lstname + "> <OPTION VALUE='' SELECTED>-Day-</OPTION> ");
				for (i=1; i<=31; i++)
				{
					document.write(" <OPTION VALUE="+ i + ">" + i +"</OPTION>");
				}
				document.write("</SELECT>");
		}
	
	function ListMonth(lstname)
		{		
				var i ;	
				document.write("<SELECT NAME=" + lstname + "> <OPTION VALUE='' SELECTED>-Month-</OPTION> ");
				for (i=1; i<=12; i++)
				{
					document.write(" <OPTION VALUE="+ i + ">" + i +"</OPTION>");
				}
				document.write("</SELECT>");
		}
		
	function ListYear(lstname)
		{		
				var dt = new Date();
				var i;
				var CurrYr=dt.getFullYear();
				document.write("<SELECT NAME=" + lstname + "> <OPTION VALUE='' SELECTED>-Year-</OPTION> ");
				for (i=0; i<=110; i++)
				{
					document.write(" <OPTION VALUE="+ (CurrYr) + ">" + (CurrYr--) +"</OPTION>");
				}
				document.write("</SELECT>");	
		}
		
	function SelectVal(lstname,lstvalue)
	{
		var len=lstname.options.length;
		for(i=0;i<len;i++)
		{
			if(lstname.options[i].value==lstvalue)
			{
				//lstname.selectedIndex=i;
				lstname.options[i].selected = true;
				break;
			}
		}
	}
	function SelectRad(lstname,lstvalue) // to select a radio
	{
		var len=lstname.length;
		if(len==null) // only one radio
		{
			if(lstname.value==lstvalue)
				lstname.checked=true;
		}
		else
		{
			for(i=0;i<len;i++)
			{
				if(lstname[i].value==lstvalue)
				{
					lstname[i].checked=true;
					break;
				}
			}
		}
	}
	function isValidDate(v_day,v_mon,v_yr){
		var v_arr=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
		if (v_mon==2 && v_day>28){
			if((v_yr%4==0 && v_yr%100!=0)||(v_yr%400==0))
				v_arr[1]=29;
		}
		if (v_arr[v_mon-1]>=v_day)
			return(1);
		else
			return(0);
	}
	/*End*/
	
	
//myfoodeu functions

function putData(fromField ,toField )
	{
		if(toField.value == "")
		toField.value = fromField.value;
	}
	
	
function chkEmail(eml) {
	emailad=eml.value
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;

	if(((emailad.search(exclude) != -1) || (emailad.search(check)) == -1)|| (emailad.search(checkend) == -1)){
	//alert("Incorrect email address!");
	//eml.select();
	//eml.focus();
	return false;
	}
	else {
	return true;
	}
	return true;
}	

function checkdate(objName) {
var datefield = objName;
if (chkdate(objName) == false) {
datefield.select();
alert("That date is invalid.  Please try again.");
datefield.focus();
return false;
}
else {
return true;
   }
}

//added by karan for date validation (mm/dd/yyyy)
// The following functions were written by Tom Wittbrodt
// Copyright (c) 1998, 1999 Tom Wittbrodt
// License is granted if and only if this entire 
// copyright notice is included. 
function validate_date(date_field, desc) {
        if (!date_field.value)  
                return true;
        var in_date = stripCharString(date_field.value," ");
        in_date = in_date.toUpperCase();
        var date_is_bad = 0;  
        if (!allowInString(in_date,"/0123456789T+-"))
                date_is_bad = 1; // invalid characters in date
        if (!date_is_bad) { 
                var has_rdi = 0;
                if (in_date.indexOf("T") >= 0){ 
                        has_rdi = 1;
                }
                if (!date_is_bad && has_rdi && (in_date.indexOf("T") != 0)) { 
                        date_is_bad = 2; // relative date index character is not in first position
                }
                if (!date_is_bad && has_rdi && (in_date.length == 1)) { 
                        var d = new Date();
						var return_month = parseInt(d.getMonth() + 1).toString();
						return_month = (return_month.length==1 ? "0" : "") + return_month; 
						var return_date =  parseInt(d.getDate()).toString();
						return_date = (return_date.length==1 ? "0" : "") + return_date; 
				        in_date = return_month + "/" + return_date + "/" + get_full_year(d);		
                        has_rdi = 0; // date doesn't have rdi char anymore (will also cause failure of add'l rdi checks, which is a good thing)
                }
                if (!date_is_bad && has_rdi && (in_date.length > 1) && !(in_date.charAt(1) == "+" || in_date.charAt(1) == "-")) {
                        date_is_bad = 3; // length of rdi string is greater than 1 but second char is not "+" or "-"
                }
                if (!date_is_bad && has_rdi && isNaN(parseInt(in_date.substring(2,in_date.length),10))) {
                        date_is_bad = 4; // rdi value is not a number
                }
                if (!date_is_bad && has_rdi && (parseInt(in_date.substring(2,in_date.length),10) < 0)) {
                        date_is_bad = 5; // rdi value is not a positive integer
                }
                if (!date_is_bad && has_rdi) {
                        var d = new Date();
                        ms = d.getTime();
                        offset = parseInt(in_date.substring(2,in_date.length),10);
                        if(in_date.charAt(1) == "+") {
                                ms += (86400000 * offset);
                        } else {
                                ms -= (86400000 * offset);
                        }
                        d.setTime(ms);
						var return_month = parseInt(d.getMonth() + 1).toString();
						return_month = (return_month.length==1 ? "0" : "") + return_month; 
						var return_date =  parseInt(d.getDate()).toString();
						return_date = (return_date.length==1 ? "0" : "") + return_date; 
				        in_date = return_month + "/" + return_date + "/" + get_full_year(d);	
                        has_rdi = 0;
                }
        } 
        if (!date_is_bad) {
                var date_pieces = new Array();
                date_pieces = in_date.split("/");
                if (date_pieces.length == 2) {
                        var d = new Date();
                        in_date = in_date + "/" + get_full_year(d);
                        date_pieces = in_date.split("/");
                }
                if (date_pieces.length != 3 || parseInt(date_pieces[0],10) < 1 || parseInt(date_pieces[0],10) > 12 
                                || parseInt(date_pieces[1],10) < 1 || parseInt(date_pieces[1],10) > 31 
                                || (date_pieces[2].length != 2 && date_pieces[2].length != 4)) {
                        date_is_bad = 6;  // date is not in format of m[m]/d[d]/yy[yy]
                }
        }
        if (date_is_bad) {
                alert(desc + " must be in the format of mm/dd/yy or mm/dd/yyyy");
                date_field.focus();
                return (false);
        }
        
        var ms = Date.parse(in_date);
        var d = new Date();
        d.setTime(ms);
		var return_date = d.toLocaleString();
		var return_month = parseInt(d.getMonth() + 1).toString();
		return_month = (return_month.length==1 ? "0" : "") + return_month; 
		var return_date =  parseInt(d.getDate()).toString();
		return_date = (return_date.length==1 ? "0" : "") + return_date; 
        return_date = return_month + "/" + return_date + "/" + get_full_year(d);
        date_field.value = return_date;
        return true;
}       // normalize the year to yyyy
function get_full_year(d) {
		var y = ""
		if (d.getFullYear() != null)
		{
			y = d.getFullYear();
			if (y < 1970) y+= 100;		
		} else
		{	
	        y = d.getYear();
	        if (y > 69  && y < 100) y += 1900;
	        if (y < 1000) y += 2000;
		}
        return y;
}
// The following functions were written by Gordon McComb
// More information can be found here: http://www.javaworld.com/javaworld/jw-02-1997/jw-02-javascript.html
function stripCharString(InString, CharString)  {
        var OutString="";
   for (var Count=0; Count < InString.length; Count++)  {
        var TempChar=InString.substring (Count, Count+1);
      var Strip = false;
      for (var Countx = 0; Countx < CharString.length; Countx++) {
        var StripThis = CharString.substring(Countx, Countx+1)
         if (TempChar == StripThis) {
                Strip = true;
            break;
         }
      }
      if (!Strip)
        OutString=OutString+TempChar;
   }
        return (OutString);
}
function allowInString(InString, RefString)  {
        if(InString.length==0) return (false);
        for (var Count=0; Count < InString.length; Count++)  {
        var TempChar= InString.substring (Count, Count+1);
      if (RefString.indexOf (TempChar, 0)==-1)  
        return (false);
   }
   return (true);
}

//function added by karan
//check for phone numbers, e.g. 123-456-789
/*function isPhone(s) 
{
	alert(s)
    var i,c;
	var str;
	str=new String(s);
    for (i = 0; i < str.length; i++)
    {   
        var c = str.charAt(i);
        if( !((c=="-") || ((c >= "0") && (c <= "9")) ))
        {
                return false;
		}
    }
    return true;
} 
 
*/
<!-- 
-->