///***********************************************************************///
///***<!-- Contains Copyrighted Materials by (c) ISPRODUCTIONS 2006 -->***///
///***********************************************************************///

// Extend the string object to include a trim function
String.prototype.Trim = trim_string;
// Extend the date object to include a simple form string conversion
Date.prototype.toSimpleForm = date_toSimpleForm;

function isNonBlank(value)
{
	var strErrorMsg = "This field must have a non-blank value";
	if(value.length == 0)
	{
		alert(strErrorMsg);
		return false;
	}
	return true;
}

function isItemSelected(selectedIndex)
{
	var strErrorMsg = "This field must have a valid selection";
	if(selectedIndex == 0)
	{
		alert(strErrorMsg);
		return false;
	}	
	return true;
}

function isValidIntNumber(value)
{
	var strErrorMsg = "This field must be a valid positive integer number";
	var strDefault = default_value(value);
	
	value=value.Trim();
	if (value.length==0)
		value=strDefault;
	var num = "0123456789";
	for (var intLoop = 0; intLoop < value.length; intLoop++) {
		if (num.indexOf(value.charAt(intLoop)) == -1) {
			alert(strErrorMsg);
			return false;
		}
	}
	if (value.length > 1 && parseFloat(value) <= 0) {
        alert(strErrorMsg);
		return false;
	}
	return true;
}

function isValidNumber(value) {
	var strErrorMsg = "This field must be a valid numeric";
	var strDefault = default_value(value);
	
	value=value.Trim();
	if (value.length==0)
		value=strDefault;
	var num = ".0123456789";
	for (var intLoop = 0; intLoop < value.length; intLoop++) {
		if (num.indexOf(value.charAt(intLoop)) == -1) {
			alert(strErrorMsg);
			return false;
		}
	}
	if (value.indexOf(".")!= value.lastIndexOf(".")) {
		alert(strErrorMsg);
		return false;
	}	
	return true;
}

function isValidEmail(value) {
	var strErrorMsg = "This field is not a valid Email";
	value=value.Trim();
	if (value.length == 0)   return true;
	
	if (!(/^([a-zA-Z0-9]+([_-]+[a-zA-Z0-9]+)*\.)*[a-zA-Z0-9_-]+([_-]+[a-zA-Z0-9]+)*@([a-zA-Z0-9]+([-]+[a-zA-Z0-9]+)*\.)+[a-zA-Z]{2,4}$/.test(value))) { 
		alert(strErrorMsg);
		return false;
	}
	return true;
}

function isValidDomainName(value) {
	var strErrorMsg = "This field is not a valid Domain Name";
	value=value.Trim();
	if (value.length == 0)   return true;
	if (!(/^\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(value))) { 
		alert(strErrorMsg);
		return false;
	}
	return true;
}

function isValidDomainName2(value) {
	var strErrorMsg = value + " is not a valid Domain Name";
	value = value.toLowerCase().Trim();
	if (value.length == 0)   return true;
	var filter = /^(([1-9][0-9]{0,2})|0)\.(([1-9][0-9]{0,2})|0)\.(([1-9][0-9]{0,2})|0)\.(([1-9][0-9]{0,2})|0)$/;
	
	if (!(/^\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(value)) || filter.test(value) || value == 'ssl.folioarchive.com' || value == 'wf.folioarchive.com') { 
		alert(strErrorMsg);
		return false;
	}
	return true;
}

function isValidDateWithoutAlert(value) {
    var s;        
    value = value.Trim();

	s = value;		
	if(s.indexOf("/") == -1) {
	   return false;
	}
	ss = s.split("/");
	var intM = new Number(ss[0]);
	if ( intM < 1 || intM > 12 ) {
		return false;
	}
	var intD = new Number(ss[1]);
	if ( intD < 1 || intD > 31 ) {
		return false;
	}
	var intY = new Number(ss[2]);
	if ( intY < 2000 || intY > 2500 ) {
		return false;
	}
	if (isNaN(Date.parse(value))) {
		return false;
	}
	var dtItem = new Date(Date.parse(value));
	value = dtItem.toSimpleForm();
	return true;
}

function isValidDate(value) {
    var strErrorMsg = "This field is not a valid Date 'MM/DD/YYYY'";
    var s;        
    value = value.Trim();

	s = value;		
	if(s.indexOf("/") == -1) {
	    alert(strErrorMsg);
	    return false;
	}
	ss = s.split("/");
	var intM = new Number(ss[0]);
	if ( intM < 1 || intM > 12 ) {
		alert( strErrorMsg + " wrong month -"+ss[1]+"-");
		return false;
	}
	var intD = new Number(ss[1]);
	if ( intD < 1 || intD > 31 ) {
		alert( strErrorMsg + " wrong day -"+ss[0]+"-");
		return false;
	}
	var intY = new Number(ss[2]);
	if ( intY < 2000 || intY > 2500 ) {
		alert( strErrorMsg + " wrong year -"+ss[2]+"-");
		return false;
	}
	if (isNaN(Date.parse(value))) {
		alert(strErrorMsg + " wrong date -"+ value+"-");
		return false;
	}
	var dtItem = new Date(Date.parse(value));
	value = dtItem.toSimpleForm();
	return true;
}

function default_value(value) {
	var strDefault = value.defaultValue;
	if (strDefault== "undefined" || strDefault=="")
		strDefault="";
	return strDefault;
}

function trim_string() {
	var ichar, icount;
	var strValue = this;
	ichar = strValue.length - 1;
	icount = -1;
	while (strValue.charAt(ichar)==' ' && ichar > icount)
		--ichar;
	if (ichar!=(strValue.length-1))
		strValue = strValue.slice(0,ichar+1);
	ichar = 0;
	icount = strValue.length - 1;
	while (strValue.charAt(ichar)==' ' && ichar < icount)
		++ichar;
	if (ichar!=0)
		strValue = strValue.slice(ichar,strValue.length);
	return strValue;
}

function date_toSimpleForm() {
	var toSimpleForm = new String;
	toSimpleForm = this.toLocaleString();
	toSimpleForm = toSimpleForm.substring(0,toSimpleForm.indexOf(' '));
	return toSimpleForm;
}
