﻿var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

function checkmail(e){
var returnval=emailfilter.test(e.value)
if (returnval==false){
//alert("Please enter a valid email address.")
//e.select()
}
return returnval
}

function Focus(objname, waterMarkText) {
            obj = objname;
            if (obj.value == waterMarkText) {
                obj.value = "";
                obj.className = "NormalTextBox";
                if (obj.value == "User ID" || obj.value == "" || obj.value == null) {
                    obj.style.color = "#c1c1c1";
                }
            }
        }
 function Blur(objname, waterMarkText) {
            obj = objname;
            if (obj.value == "") {
                obj.value = waterMarkText;
                if (objname != "txtPwd") {
                    //obj.className = "WaterMarkedTextBox";
                    obj.className = "NormalTextBox";
                }
                else {
                    //obj.className = "WaterMarkedTextBoxPSW";
                    obj.className = "NormalTextBox";
                }
            }
            else {
                obj.className = "NormalTextBox";
            }

            if (obj.value == "User ID" || obj.value == "" || obj.value == null) {
                obj.style.color = "gray";
            }
            
        }


function formCheck(formobj){
	// Enter name of mandatory fields
	var fieldRequired = Array("Name", "Company" , "Contact", "Email", "Requirements");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("Name", "Company" , "Contact", "Email", "Requirements");
	// dialog message
	var alertMsg = "All the fields are mandatory. Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == "" || obj.value == obj.name){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
				if (obj.value == "" || obj.value == null || obj.value == obj.name){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "textarea":
				if (obj.value == "" || obj.value == null || obj.value == obj.name){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			
			if(obj.name == "Email")
			{
				if(!checkmail(obj))
				{
					alertMsg += " - " + "Please enter a valid email address." + "\n";
				}
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}
	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}