
var isNS4 = (navigator.appName=="Netscape")?1:0;

function checkemail(){
var str=document.form_collaboration.frm_email.value
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
return 0
else{
alert("Your email is not valid.")
return 1
}

}


// function to trim string input
function trimString (str) {
	while (true) {
		if (str.charAt(0) == ' ') {
       		str = str.substr(1)
       	} else {
       		break;
       	}
    }

    while (true) {
       	if (str.charAt(str.length - 1) == ' ') {
       		str = str.substr(0, str.length - 1)
       	} else {
       		break
       	}
    }

	return(str);

}

// function to validate input radio
function validateRadio (form) {

	for (var i = 0; i < form.length; i++) {
		if (form[i].checked) {
    		break;
		}
	}

	if (i == form.length) {
		return false;
	} else {
		return true;
	}
}


// function to get validate input radio value
function getRadioValue (form) {

	for (var i = 0; i < form.length; i++) {
		if (form[i].checked) {    		
			return form[i].value		
		}
	}	
	
}


// function to check input
function checkItem (strItemCaption, strItemName, intMinLength, strType) {

	 var warn = 'Please field: '
	 var warn2 = ' Please fix it!'
	 var warn3 =  ' your enter is too short! minimum '
	 var warn4 = ' character'
	 
	if (strType == undefined) {
		strType = 'input'
	}

	
	if (strType == 'radio') {
		if (validateRadio(strItemName) == false) {
			alert(warn + ' "' + strItemCaption + '". ' + warn2)
			return 1
		}
	} else 
	
	if (strType == 'select') {
		
		if (trimString(strItemName.value) == '') {
			alert(warn + ' "' + strItemCaption + '". ' + warn2)
			strItemName.value = ''
			strItemName.focus()
			return 1
		}
		
	} else 
	
	if (strType == 'input') {

		if (trimString(strItemName.value) == '') {
			alert(warn + ' "' + strItemCaption + '". ' + warn2)
			strItemName.value = ''
			strItemName.focus()
			return 1
		}
		
		if (intMinLength > 0) {
			
			if (strItemName.value.length < intMinLength) {
				alert(strItemCaption + ' ' + warn3 + ' ' + intMinLength + ' ' + warn4)
				strItemName.focus()
				return 1
			}
		
		}

	}
}


// funtion to validate form
function validateForm (form) {

	if (checkItem ('Company Name', form.frm_company_name, 3) > 0) { return false }
	if (checkItem ('Email', form.frm_email, 3) > 0) { return false }		
	if (checkItem ('Country', form.frm_country, 5) > 0) { return false }	
	if (checkItem ('Contact Person Name', form.frm_contact_person_name, 5) > 0) { return false }	
	
	if (checkemail()>0) { return false }

}
