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;
    }
}

//Launches the Image Preview pop up window in the maximised mode.
//Author : Johnson P Thomas
function pic(Id)
{
	var wid = screen.width - 100;
	var hei = screen.height - 150;
	var txtwid = screen.width;
	var txthei = screen.height;
	var loc = document.location;
	loc = loc.toString();
	loc = loc.substring(0,loc.indexOf("?"));
	path = "http://www.worldimages.com";
	//path = "http://65.36.160.29";
	//path = "http://192.168.10.120";
	window.open(path+"/imgshow.php?loc="+loc+"&txtwidth="+txtwid+"&txtheight="+txthei+"&table=g&imgId=" + Id,"_blank","width="+wid+",height="+hei+",toolbars=no,scrollbars=yes,menubars=no,resizable=yes,left=0,top=0,status=yes");
}
function pic_search(Id)
{
	var wid = screen.width - 100;
	var hei = screen.height - 150;
	var txtwid = screen.width;
	var txthei = screen.height;
	var loc = document.location;
	loc = loc.toString();
	loc = loc.substring(0,loc.indexOf("?"));
	path = "http://www.worldimages.com";
	//path = "http://65.36.160.29";
	//path = "http://192.168.10.120";
	
	window.open(path+"/imgshow_search.php?loc="+loc+"&txtwidth="+txtwid+"&txtheight="+txthei+"&table=g&imgId=" + Id,"_blank","width="+wid+",height="+hei+",toolbars=no,scrollbars=yes,menubars=no,resizable=yes,left=0,top=0,status=yes");
}

function isImage(path)
{
	var imageDelimiters="_\\- .:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

	if (isWhitespace(path)) return false;

	var j=0;

	var pathLength = path.length;
	while ((j < pathLength) && (imageDelimiters.indexOf(path.charAt(j)) != -1))
	{ j++ }

	if (j < pathLength) return false;
	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 (!isEmpty(theField.value)) 
	 {
    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,"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 isPhoneNumber (s) //valid only numers ,spaces , - , (,)
{
    var i,c;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( !(((c >= "0") && (c <= "9")) || (c==" ") || (c=="-")|| (c=="(") || (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 >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || ((c >= "0") && (c <= "9")) || (c == "_") ))
        {
                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;
		}
	}
}
 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) == ".") )
			{		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;
}

//check whether start date is greater than end date
//returns tru if greater , else false
function isGreaterDate(strDay,strMon,strYear,endDay,endMon,endYear)
{
	var strDt,endDt;
	if(strDay.length<2)
		strDay = "0" + strDay;
	if(strMon.length<2)
		strMon = "0" + strMon;
	if(endDay.length<2)
		endDay = "0" + endDay;
	if(endMon.length<2)
		endMon = "0" + endMon;
	strDt = "" + strYear + strMon + strDay;
	endDt = "" + endYear + endMon + endDay; 
	if(strDt > endDt)
		return true;
	else
	 	return false;
}	

function isInt (s)

{   var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    return reInteger.test(s)
}

function isFloat (s)

{   if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    return reFloat.test(s)
}
//For checking gallery name
function checkGalleryName(strString) {
   var strValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
   var strChar;
   var blnResult = true;
  for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
	  if (strString.charAt(0) == "-") {
		  blnResult = false;
	  }
   return blnResult;
}

