var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
return true
}
////// end date stuff


// emw 090814
function TextAreaRequired(field) 
{
with (field)
{
//alert(length);
itemLength = length;
}
if (itemLength == 0) {
return false;
} else {
return true;
}
} 

function MultiSelectRequired(field) 
{
with (field)
{
	count= 0;
	for(var i=0;i<options.length;i++){
		//alert(options[i].selected);
       if(options[i].selected)
             count++;
      } 
//alert(count);
//count= 0;
}
if (count < 1) {
return false;
} else {
return true;
}
} 


function SingleSelectRequired(field) 
{
with (field)
{
	itemSelected = selectedIndex;
}
if (itemSelected == 0) {
return false;
} else {
return true;
}
} 
function SingleSelectRequired1(field,var1) 
{
with (field)
{
	itemSelected = selectedIndex;
}
if (itemSelected == var1) {
return false;
} else {
return true;
}
} 

function RadioValue(field,msg,index) 
{
with (field)
{
	if(field[index].checked) {
		return true;
		}
		else {
		return false;
	}
}

}

function SingleSelectValue(field,field2) 
{
with (field)
{
//alert(value);
itemSelected = value;
}
if (itemSelected != field2) {
return false;
} else {
return true;
}
}    

function validate_numeric(field,alerttxt)
{
with (field)
{
var strValidChars = "0123456789";
var strChar;
var blnResult = true;
//if (length == 0) return false;
//alert(value.length);
for (i = 0; i < value.length && blnResult == true; i++)
      {
		x = value;  
		strChar = x.charAt(i);
	  //alert(strChar);
		if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
	  //alert(value);
	  // set optional range here
	  if (value < 1 ) 
	  {
		  blnResult = false;
		  }
   return blnResult;
}
}

   
   
   
   

function validate_TextAreaRequired(field,alerttxt) 
		{
		with (field)
		{
		itemLength = value.length;
		}
		if (itemLength == 0) {
		return false;
		} else {
		return true;
		}
		} 
     
     
function validate_required(field,alerttxt) 	{
		
		with (field)
		{
		if (value==null ||value=="")
		   {return false;}
		else {return true;}
			}
		}
	
	
	function validate_url(field,alerttxt) {
		with (field)
		{
		
		var pattern = /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;

		 if (!pattern.test(value.toLowerCase())) 
		  {return false;}
		else {return true;}
			}
		}	
		
function validate_email(field,alerttxt) {
		with (field)
		{
		
		var pattern = /^[a-z0-9]+[-._a-z0-9]*@([a-z0-9]+[-a-z0-9]*\.)+[a-z]{2,}$/;
		 if (!pattern.test(value.toLowerCase())) 
		  {return false;}
		else {return true;}
			}
		}
function validate_siebelphone(field,alerttxt)
{ 
with (field)
{
var strValidChars = "0123456789+()- ";
var strChar;
var blnResult = true;
var cntr=0;


//if (value.length < 10 || value.length > 40) return false;

for (i = 0; i < value.length && blnResult == true; i++)
      {
		x = value;  
		strChar = x.charAt(i);
	 	
		if(strChar!='(' && strChar!=')' && strChar!='-') cntr++;
			
		if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }// for loop
	if(cntr < 10 || cntr > 40) {blnResult = false;}
   return blnResult;
} // with
} // end function



function validate_postal(field,co) {
		switch(co)
			{
			case 'United States':
			  var Pattern = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
			  break;
			case 'United Kingdom':
			  var Pattern = /^(GIR|[A-Z]\d[A-Z\d]??|[A-Z]{2}\d[A-Z\d]??)[ ]??(\d[A-Z]{2})$/;
			  break;
			case 'Spain':
			   var Pattern = /^([1-9]{2}|[0-9][1-9]|[1-9][0-9])[0-9]{3}$/;
			  break;
			case 'Italy':
			  var Pattern =/^(V-|I-)?[0-9]{4}$/;
			  break;
			case 'France':
				var Pattern = /((^[0-9]*).?((BIS)|(TER)|(QUATER))?)?((\W+)|(^))(([a-z]+.)*)([0-9]{5})?.(([a-z\'']+.)*)$/;
				break;
		case 'Germany':
			   var Pattern =/\b((?:0[1-46-9]\d{3})|(?:[1-357-9]\d{4})|(?:[4][0-24-9]\d{3})|(?:[6][013-9]\d{3}))\b/ ;
			  break;
			case 'Canada':
			  var Pattern =/^[ABCEGHJKLMNPRSTVXYabceghjklmnprstvxy]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$/;
			  break;
		 	default:
			  var Pattern=0;
			}
		with (field)
		{
		
		if (Pattern ==0) // assume good zip since there is no reg exp for country selected
		return true;
		
		 if (!Pattern.test(value.toLowerCase())) 
		  {return false;}
		else {return true;}
			}
		}