/*
Required field(s) validation- By NavSurf
Visit NavSurf.com at http://navsurf.com
Visit http://www.dynamicdrive.com for this script
*/
function isEmail( str )
{
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function formCheck(formobj){
	//1) Enter name of mandatory fields
	var fieldRequired = Array("title","forename", "surname","email", "email_duplicate","institution", "confirmation");
	//2) Enter field description to appear in the dialog box
		var fieldDescription = Array("Title","Forename", "Surname","Email", "Confirmation Email", "Institution","Confirmation Check");
	//3) Enter dialog message
	var alertMsg = "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 (fieldRequired[i]== "email" && obj)
		{
			
			if(formobj.elements["email"].value != "" && !isEmail(formobj.elements["email"].value)){
				alertMsg += " - Not a Valid Email Address \n";			
			}
			else if(formobj.elements["email"].value != formobj.elements["email_duplicate"].value){
					alertMsg += " - E-Mail Address and Confirm E-Mail must be same. \n";	
			}
		}
		if (fieldRequired[i]== "institution" && obj)
		{
			
			if (formobj.elements["institution_other"].value=="" && (obj.selectedIndex < 1 || obj.options[obj.selectedIndex].text == 0))
			{
				alertMsg += " - " + fieldDescription[i] + "\n";
			}
		}
		
		else if (obj){

			switch(obj.type){
			case "select-one":
			
			if (obj.selectedIndex < 1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "checkbox":
				if (obj.checked == false){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}


	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

function checkPType(formobj){
var ptype = formobj.ptype.value;

if (ptype=="CHECK")
{
	formobj.exp_month.disabled = true;
	formobj.exp_year.disabled = true;
	formobj.cc_cvv.disabled = true;
}
else{
	formobj.exp_month.disabled = false;
	formobj.exp_year.disabled = false;
	formobj.cc_cvv.disabled = false;
}
}

function CVVPopUpWindow(url) {
window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=630,height=300,screenX=150,screenY=30,top=30,left=150')
}

