// JavaScript Document

function CalculateTotal(frm) {
    var order_total = 0

    for (var i=0; i < frm.elements.length; ++i) {

        form_field = frm.elements[i]

        form_name = form_field.name

        if (form_name.substring(0,1) == "s") {

            item_quantity = parseInt(form_field.value)

            if (item_quantity >= 0) {
                order_total += item_quantity 
            }
        }
    }

    frm.final_score.value = order_total
}


function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
        // otherwise, update 'characters left' counter
    else
        countfield.value = maxlimit - field.value.length;
}

function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='?cat=' + val ;
}


function checkFormRegister()  {
	
	if(ValidateForm()){
	
		if((document.content_form.first_name.value == "") || 
			(document.content_form.last_name.value == "") || 
			(document.content_form.cat.value == "") || 
			(document.content_form.subcat.value == "") || 
			  (document.content_form.email.value == "") || 
			  (document.content_form.username.value == "") || 
			  (document.content_form.password.value == "")){
			alert("You must complete all the required (*) fields.");
		}else{
			document.content_form.submit();	
		}
		
	}
}

function checkForgotForm()  {
	
	
	
		if(document.content_form.email.value == ""){
			alert("You must enter an e-mail address.");
		}else{
			document.content_form.submit();	
		}
	
}

function alertDatasheet()  {
	
			alert("You have not yet submitted a Chapter Data Sheet. You must submit a Chapter Data Sheet in order to complete the program report process. Please select 'Chapter Data Sheet' in the navigation on the next page.");
		
			document.content_form.submit();	
		
		
	
}

function checkFormApplication()  {
	if((document.content_form.org_name.value == "") || 
		(document.content_form.org_address.value == "") || 
		(document.content_form.org_city.value == "") || 
		(document.content_form.org_state.value == "") || 
		(document.content_form.org_zip.value == "") || 
		(document.content_form.org_telephone.value == "") || 
		(document.content_form.org_exec_name.value == "") || 
		(document.content_form.org_exec_email.value == "") || 
		(document.content_form.org_proj_name.value == "") || 
		(document.content_form.org_proj_email.value == "") ||
		(document.content_form.proposal_title.value == "") ||
		(document.content_form.proposal_amt.value == "") ||
		(document.content_form.proposal_period.value == "") || 
		(document.content_form.proposal_target.value == "")){
		alert("You must complete all the required (*) fields.");
	}else{
		document.content_form.submit();	
	}
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

 		 return true					
	}

function ValidateForm(){
	var emailID=document.content_form.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function clearemail()  {
	document.email.email.value="";	
}

function checkForm()  {
	if((document.agreement.certify.checked) && (document.agreement.proposal_official.value != "") && (document.agreement.proposal_official_title.value != "")){
		document.agreement.submit();	
	}else{
		alert("You must certify the application by checking the box and completing all fields.");
	}
}


function enableButton() {

	if(document.getElementById('checkboxSubmit').checked){
		document.getElementById('btnSubmit').disabled='';
		document.getElementById('btnSubmit').style.backgroundColor="#336633";
	} else {
		document.getElementById('btnSubmit').disabled='true';
		
		document.getElementById('btnSubmit').style.backgroundColor="#c0dfc0";
	}

}

sfHover = function() {
	var sfEls = document.getElementById("navbar").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" hover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" hover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


