// JavaScript Document
function validate_frm()
{	
	obj = document.frmquilt;
	
	if(document.getElementById('req_type').value == 'S'){
                        if(obj.txtfname.value == '')
			{
				alert("Please enter your first name");
		//		obj.txtfname.value = '';
				obj.txtfname.focus();
				return false;
			}
			else if(obj.txtlname.value == '')
			{
				alert("Please enter your last name");		
		//		obj.txtlname.value = '';
				obj.txtlname.focus();
				return false;
			}
			else if(obj.txtaddress.value == '')
			{
				alert("Please enter your address");	
		//		obj.txtaddress.value = '';
				obj.txtaddress.focus();
				return false;
			}
			else if(obj.txtcity.value == '')
			{
				alert("Please enter your city");	
		//		obj.txtcity.value = '';
				obj.txtcity.focus();
				return false;
			}	
			else if(document.getElementById('state').value == '0')
			{
				alert("Please select state");	
				obj.state.focus();
				return false;
			}
			else if(obj.txtzipcode.value == '')
			{
				alert("Please enter your zip code");	
		//		obj.txtzipcode.value = '';
				obj.txtzipcode.focus();
				return false;
			}
			else if(obj.txtstdcode.value.length != 3 || !isPositiveInteger(obj.txtstdcode.value))
			{
				alert("Please enter Valid Area code (xxx)");
				obj.txtstdcode.focus();
				return false;
			}
			else if(!valUsPhNumber(obj.txtphonenumber.value))
			{
				alert("Please enter your Valid phone number (xxx-xxxx)");
		//		obj.txtphonenumber.value = '';
				obj.txtphonenumber.focus();
				return false;
			}
			else if(obj.txtemail.value == '')
			{
				alert("Please enter your email address");	
		//		obj.txtemail.value = '';
				obj.txtemail.focus();
				return false;
			}else if(!checkEmail("txtemail")){
					alert("Please enter your valid email address");	
					obj.txtemail.focus();
					return false;
			}else if(obj.txtemailrepeat.value == '')
			{
				alert("Please enter your email address - Repeat");	
		//		obj.txtemailrepeat.value = '';
				obj.txtemailrepeat.focus();
				return false;
			}else if(!checkEmail("txtemailrepeat")){
					alert("Please enter your valid email address - Repeat");	
					obj.txtemailrepeat.focus();
					return false;
			}
			else if(obj.txtemail.value != obj.txtemailrepeat.value)
			{
				alert("Please enter same email");	
		//		obj.txtemailrepeat.value = '';
				obj.txtemailrepeat.focus();
				return false;		
			}
			else if(!multipleCheckboxValidation(obj, 'branch_served[]')) {
					alert("Please select Branch Served in");
					return false;
			}
			else if(!multipleCheckboxValidation(obj, 'deployment[]')) {
					alert("Please select Deployment");
					return false;
			}
			else if(document.getElementById('reason').value == '')
			{
				alert("Please enter Reason for Request");	
				obj.reason.focus();
				return false;
			}
	}
	
	if(document.getElementById('req_type').value == 'E'){
		
			if(obj.txtfname.value == '')
			{
				alert("Please enter your first name");
		//		obj.txtfname.value = '';
				obj.txtfname.focus();
				return false;
			}
			else if(obj.txtlname.value == '')
			{
				alert("Please enter your last name");		
		//		obj.txtlname.value = '';
				obj.txtlname.focus();
				return false;
			}
                        else if(obj.txtstdcode.value.length != 3 || !isPositiveInteger(obj.txtstdcode.value))
			{
				alert("Please enter Valid Area code (xxx)");
				obj.txtstdcode.focus();
				return false;
			}
			else if(!valUsPhNumber(obj.txtphonenumber.value))
			{
				alert("Please enter your Valid phone number (xxx-xxxx)");
		//		obj.txtphonenumber.value = '';
				obj.txtphonenumber.focus();
				return false;
			}
			else if(obj.txtemail.value == '')
			{
				alert("Please enter your email address");	
		//		obj.txtemail.value = '';
				obj.txtemail.focus();
				return false;
			}else if(!checkEmail("txtemail")){
					alert("Please enter your valid email address");	
					obj.txtemail.focus();
					return false;
			}else if(obj.txtemailrepeat.value == '')
			{
				alert("Please enter your email address - Repeat");	
		//		obj.txtemailrepeat.value = '';
				obj.txtemailrepeat.focus();
				return false;
			}else if(!checkEmail("txtemailrepeat")){
					alert("Please enter your valid email address - Repeat");	
					obj.txtemailrepeat.focus();
					return false;
			}
			else if(obj.txtemail.value != obj.txtemailrepeat.value)
			{
				alert("Please enter same email");	
		//		obj.txtemailrepeat.value = '';
				obj.txtemailrepeat.focus();
				return false;		
			}else if(document.getElementById('req_fname').value == '')
			{
				alert("Please enter First Name of Recipient ");	
				obj.req_fname.focus();
				return false;
			}else if(document.getElementById('req_lname').value == '')
			{
				alert("Please enter Last Name of Recipient ");	
				obj.req_lname.focus();
				return false;
			}
			else if(obj.txtaddress.value == '')
			{
				alert("Please enter Recipient's address");	
		//		obj.txtaddress.value = '';
				obj.txtaddress.focus();
				return false;
			}
			else if(obj.txtcity.value == '')
			{
				alert("Please enter Recipient's city");	
		//		obj.txtcity.value = '';
				obj.txtcity.focus();
				return false;
			}	
			else if(document.getElementById('state').value == '0')
			{
				alert("Please Recipient's state");	
				obj.state.focus();
				return false;
			}
			else if(obj.txtzipcode.value == '')
			{
				alert("Please enter Recipient's zip code");	
		//		obj.txtzipcode.value = '';
				obj.txtzipcode.focus();
				return false;
			}
			else if(!multipleCheckboxValidation(obj, 'branch_served[]')) {
					alert("Please select Branch Served in");
					return false;
			}
			else if(!multipleCheckboxValidation(obj, 'deployment[]')) {
					alert("Please select Deployment");
					return false;
			}
			else if(document.getElementById('reason').value == '')
			{
				alert("Please enter Reason for Request");	
				obj.reason.focus();
				return false;
			}
			
	}
	
	if(document.getElementById('req_type').value == 'G'){
		
			if(obj.txtfname.value == '')
			{
				alert("Please enter your first name");
		//		obj.txtfname.value = '';
				obj.txtfname.focus();
				return false;
			}
			else if(obj.txtlname.value == '')
			{
				alert("Please enter your last name");		
		//		obj.txtlname.value = '';
				obj.txtlname.focus();
				return false;
			}
                        else if(obj.txtstdcode.value.length != 3 || !isPositiveInteger(obj.txtstdcode.value))
			{
				alert("Please enter Valid Area code (xxx)");
				obj.txtstdcode.focus();
				return false;
			}
			else if(!valUsPhNumber(obj.txtphonenumber.value))
			{
				alert("Please enter your Valid phone number (xxx-xxxx)");
		//		obj.txtphonenumber.value = '';
				obj.txtphonenumber.focus();
				return false;
			}
			else if(obj.txtemail.value == '')
			{
				alert("Please enter your email address");	
		//		obj.txtemail.value = '';
				obj.txtemail.focus();
				return false;
			}else if(!checkEmail("txtemail")){
					alert("Please enter your valid email address");	
					obj.txtemail.focus();
					return false;
			}else if(obj.txtemailrepeat.value == '')
			{
				alert("Please enter your email address - Repeat");	
		//		obj.txtemailrepeat.value = '';
				obj.txtemailrepeat.focus();
				return false;
			}else if(!checkEmail("txtemailrepeat")){
					alert("Please enter your valid email address - Repeat");	
					obj.txtemailrepeat.focus();
					return false;
			}
			else if(obj.txtemail.value != obj.txtemailrepeat.value)
			{
				alert("Please enter same email");	
		//		obj.txtemailrepeat.value = '';
				obj.txtemailrepeat.focus();
				return false;		
			}
	}
		
	
return true;
}

function onlyNumber(objEvent) 
{
  if(objEvent.ctrlKey==true)
  	return false;
  var iKeyCode;  	
  browser=navigator.appName;
 
  if(browser.appName=="Netscape")
  {
	  iKeyCode = objEvent.which;  
  }
  else
  {
	  iKeyCode = objEvent.keyCode;
  }
  if(iKeyCode==8 || iKeyCode==9  || (iKeyCode>=48 && iKeyCode<=57) ||( iKeyCode>=96 && iKeyCode<=105) )
  	return true;
  else
	 return false;
}
function checkEmail(ctrlname)
{
	var obj = document.getElementById(ctrlname);
	//alert(obj) ; return false;
	if(obj.value != "")
	{
		if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.value))
		{	
			return true;
		}
		else
		{
			//alert("Please enter your valid email address.");
		//	obj.value = "";
			//obj.focus();
			return false;
		}
	}
}


function sumofPatriotic(m,f,o)
{
	if (m == 'select')	m = 0;
	if (f == 'select')	f = 0;
	if (o == 'select')	o = 0;
	
	var total_of_P = parseInt(m) + parseInt(f) + parseInt(o);
	document.getElementById("tot_pid").innerHTML = total_of_P;
	document.getElementById("tot_pid").value = total_of_P;
	
	var p = document.getElementById("tot_pid").value;
	var g = document.getElementById("tot_gid").value;
	var o = document.getElementById("tot_oid").value;
	var s = document.getElementById("tot_sid").value;
	
	//alert(p + "  " + g + "  " + o + "  " + s);
	if(p == null)	{p = 0;}
	if(g == null)	{g = 0;}
	if(o == null)	{o = 0;}
	if(s == null)	{s = 0;}
	
	document.getElementById("tot_id").innerHTML = parseInt(p) + parseInt(g) + parseInt(o) + parseInt(s);
	document.getElementById("tot_id").value = parseInt(p) + parseInt(g) + parseInt(o) + parseInt(s);
}

function sumofGeneric(m,f,o)
{
	if (m == 'select')	m = 0;
	if (f == 'select')	f = 0;
	if (o == 'select')	o = 0;

	var total_of_G = parseInt(m) + parseInt(f) + parseInt(o);
	document.getElementById("tot_gid").innerHTML = total_of_G;
	document.getElementById("tot_gid").value = total_of_G;

	var p = document.getElementById("tot_pid").value;
	var g = document.getElementById("tot_gid").value;
	var o = document.getElementById("tot_oid").value;
	var s = document.getElementById("tot_sid").value;
	
	if(p == null)	{p = 0;}
	if(g == null)	{g = 0;}
	if(o == null)	{o = 0;}
	if(s == null)	{s = 0;}		
	
	document.getElementById("tot_id").innerHTML = parseInt(p) + parseInt(g) + parseInt(o) + parseInt(s);
	document.getElementById("tot_id").value = parseInt(p) + parseInt(g) + parseInt(o) + parseInt(s);
}

function sumofOther(m,f,o)
{
	if (m == 'select')	m = 0;
	if (f == 'select')	f = 0;
	if (o == 'select')	o = 0;

	var total_of_O = parseInt(m) + parseInt(f) + parseInt(o);
	document.getElementById("tot_oid").innerHTML = total_of_O;
	document.getElementById("tot_oid").value = total_of_O;

	var p = document.getElementById("tot_pid").value;
	var g = document.getElementById("tot_gid").value;
	var o = document.getElementById("tot_oid").value;
	var s = document.getElementById("tot_sid").value;

	if(p == null)	{p = 0;}
	if(g == null)	{g = 0;}
	if(o == null)	{o = 0;}
	if(s == null)	{s = 0;}		
	
	document.getElementById("tot_id").innerHTML = parseInt(p) + parseInt(g) + parseInt(o) + parseInt(s);
	document.getElementById("tot_id").value = parseInt(p) + parseInt(g) + parseInt(o) + parseInt(s);
}

function sumofSpecialty(m,f,o)
{
	if (m == 'select')	m = 0;
	if (f == 'select')	f = 0;
	if (o == 'select')	o = 0;

	var total_of_S = parseInt(m) + parseInt(f) + parseInt(o);
	document.getElementById("tot_sid").innerHTML = total_of_S;
	document.getElementById("tot_sid").value = total_of_S;

	var p = document.getElementById("tot_pid").value;
	var g = document.getElementById("tot_gid").value;
	var o = document.getElementById("tot_oid").value;
	var s = document.getElementById("tot_sid").value;

	if(p == null)	{p = 0;}
	if(g == null)	{g = 0;}
	if(o == null)	{o = 0;}
	if(s == null)	{s = 0;}		
	
	document.getElementById("tot_id").innerHTML = parseInt(p) + parseInt(g) + parseInt(o) + parseInt(s);
	document.getElementById("tot_id").value = parseInt(p) + parseInt(g) + parseInt(o) + parseInt(s);
}

function valUsPhNumber(string) {
     if (string.length != 8) {
        return false;
     }

     for (var i = 0; i < string.length; i++) {
            var ch = string.charAt(i);
            if (i==3 && ch != '-') {
                return false;
            } else if (i!=3 && !isPositiveInteger(ch)) {
                return false;
            }
      }

      return true;
}

function multipleCheckboxValidation(frmObj, fieldName) {
    var totalCheckBoxCount = frmObj.elements[fieldName].length;
    var objCheckBox = frmObj.elements[fieldName];

    for (var cnt=0;cnt < totalCheckBoxCount;cnt++) {
        if (objCheckBox[cnt].checked == true) {
            return true;
        }
    }

    return false;
}
