//optional parameters 1 - form.obj; 2 - min chars; 3 - max chars
function ValidateString() {
	l = arguments.length;
	obj = arguments[0];
	txt = Trim(obj.value);
	
	if (l > 1) {
		min = arguments[1];
		max = arguments[2];
		if ((min > 0 && txt.length < min) || (max > 0 && txt.length > max)) return false;
		else return true;
	} 
	else return ( txt != "" );
}

function ValidateEmail(obj) {
	rez =  ((obj.value.indexOf("@") != -1) && (obj.value.indexOf(" ") == -1) && ValidateString(obj));
	rez = rez && (obj.value.indexOf("@")+3 < obj.value.length);
	rez = rez && (obj.value.indexOf(".") != -1);
	rez = rez && (obj.value.indexOf(".")+2 < obj.value.length);
	rez = rez && !(obj.value.indexOf("www.") == 0);
	return rez;
}

function ValidateName(obj) {
	rez =  ValidateString(obj);
	rez = rez && (obj.value.indexOf("0") == -1);
	rez = rez && (obj.value.indexOf("1") == -1);
	rez = rez && (obj.value.indexOf("2") == -1);
	rez = rez && (obj.value.indexOf("3") == -1);
	rez = rez && (obj.value.indexOf("4") == -1);
	rez = rez && (obj.value.indexOf("5") == -1);
	rez = rez && (obj.value.indexOf("6") == -1);
	rez = rez && (obj.value.indexOf("7") == -1);
	rez = rez && (obj.value.indexOf("8") == -1);
	rez = rez && (obj.value.indexOf("9") == -1);
	return rez;
}

function ValidateOptionalEmail(obj) {
	if (ValidateString(obj)){
		return ((obj.value.indexOf("@") != -1));
	}
	return true;
}

function ValidateSelect(obj) {
	return (obj.options[obj.selectedIndex].value != "-99" && obj.options[obj.selectedIndex].value != "NULL" && obj.options[obj.selectedIndex].value != "");
}

function ValidateRadio(obj) {
	for (i=0; i< obj.length; i++) {
		if (obj[i].checked) {
			return true;
		}
	}
	return false;
}

function ValidateSelectMultiple(obj) {
	bool = false;
	for (i=0;i < obj.options.length;i++) {
		if (obj.options[i].selected) {
			bool = true;
		}
	}
	return bool;
}

function ValidateInteger(obj) {
	bool = (obj.value != "");
	if (bool) {
		if (isNaN(parseInt(obj.value))) {
			return false;
		}
		else {
			return true;
		}
	}
	else {
		return false;
	}
}

//returns false if there is a uppercase sequence
function ValidateNoUpperCase(str){
    for (i=0; i<str.length-4; i++){
        if ((str.substr(i,4))==(str.substr(i,4).toUpperCase())){

            return false;
        }
    }
    return true;
}

function SubmitUpSell(frm){
	frm.submit();
}

function AddToErrorList(strMsg) {
	if (strError == "") {
		//strError = "\nPlease fill correct the following fields:\n";
		strError = "";
	}
	strError = strError + "* " + strMsg + "\n";
}

//returns false if there is a uppercase sequence
function ValidateNoUpperCase(str){
    for (i=0; i<str.length-4; i++){
        if ((str.substr(i,4))==(str.substr(i,4).toUpperCase())){

            return false;
        }
    }
    return true;
}

function Trim(str) {
  str = str.replace(/^[ ]+/,"");return str.replace(/[ ]+$/,"");
}