// JavaScript Document | Bookmark this page | Copyright 12th February, 2005 
// Stephen Chapman, http://javascript.about.com 
// You have permission to copy and use this javascript provided that 
// the copyright notice is included with the script 

var chr = 'CTRL-D'; 
var agt=navigator.userAgent.toLowerCase(); 

if(agt.indexOf("opera")!= -1) 
	chr = 'CTRL-T'; 

if (window.external) 
	document.write('<a href="javascript:window.external.addFavorite(self.location,document.title)">Add to favorites&nbsp;<\/a>'); 
	else 
	document.write('Press '+chr+' to bookmark this page.');
	
///////////////////////////////////////////////////////////////////////////	
//sub function called by submit_validate() 
//function written just below this function
function validate_required(field,alerttxt)
{
	with (field)
	{
		if (value==null||value==""||value=="0")
		{
			alert(alerttxt);
			return false;
		}
		else 
			return true;
	}
}
//function to open school roll number slips in new window after validation
function submit_validate_school_emiscode(thisform)
{
    windowName = "school_window";
    windowURL = thisform.action + '?';
    windowURL = windowURL + 'grade=' + thisform.school_grade_emiscode.value + '&';
    windowURL = windowURL + 'emiscode=' + thisform.school_emiscode.value;
	with (thisform)
	{
		if (validate_required(school_grade_emiscode,"Please select any grade!")==false)
		{
			school_grade_emiscode.focus();
			return false;
		}
		if (validate_required(school_emiscode,"Please enter correct EMIS code of your school!")==false)
		{
			school_emiscode.focus();
			return false;
		}
	}
	result_window = window.open(windowURL, windowName, 'width=550,height=540,scrollbars=yes');
	result_window.moveTo(0,0);
	result_window.focus();
}
//function to open list of schools roll in new window after validation
function submit_validate_school_registration(thisform)
{
    windowName = "school_window";
    windowURL = "find_school.jsp" + '?';
    windowURL = windowURL + 'school_grade=' + thisform.school_grade_adv.value + '&';
    windowURL = windowURL + 'school_district=' + thisform.school_district_adv.value + '&';
    windowURL = windowURL + 'school_tehsil=' + thisform.school_tehsil_adv.value + '&';
    windowURL = windowURL + 'school_type=' + thisform.school_type_adv.value;
	with (thisform)
	{
		if (validate_required(school_grade_adv,"Please select a grade!")==false)
		{
			school_grade_adv.focus();
			return false;
		}
		if (validate_required(school_district_adv,"Please select a district!")==false)
		{
			school_district_adv.focus();
			return false;
		}
		if (validate_required(school_tehsil_adv,"Please select a tehsil!")==false)
		{
			school_tehsil_adv.focus();
			return false;
		}
		if (validate_required(school_type_adv,"Please select a school type!")==false)
		{
			school_type_adv.focus();
			return false;
		}
	}
	result_window = window.open(windowURL, windowName, 'width=550,height=540,scrollbars=yes');
	result_window.moveTo(0,0);
	result_window.focus();
}
//function to open student result in new window after validation
function submit_validate_result(thisform)
{
    windowName = "result_window";
    windowURL = thisform.action + '?';
    windowURL = windowURL + 'rollno=' + thisform.rollno.value + '&';
    windowURL = windowURL + 'district=' + thisform.district.value + '&';
	windowURL = windowURL + 'grade=' + thisform.grade.value;
	with (thisform)
	{
		if (validate_required(rollno,"Please enter your Roll Number!")==false)
		{
			rollno.focus();
			return false;
		}
		if (validate_required(grade,"Please select your grade!")==false)
		{
			grade.focus();
			return false;
		}
		if (validate_required(district,"Please select your district!")==false)
		{
			district.focus();
			return false;
		}
	}
	result_window = window.open(windowURL, windowName, 'width=510,height=570');
	result_window.moveTo(0,0);
	result_window.focus();
}
//function to open student registration in new window after validation
function submit_validate_registration(thisform)
{
    windowName = "reg_window";
    windowURL = thisform.action + '?';
    windowURL = windowURL + 'grade=' + thisform.reg_grade.value+'&';
    windowURL = windowURL + 'district=' + thisform.reg_district.value+'&';
	windowURL = windowURL + 'type=' + thisform.reg_type.value+'&';
	windowURL = windowURL + 'student_name=' + thisform.reg_student_name.value+'&';
	windowURL = windowURL + 'father_name=' + thisform.reg_father_name.value;
	with (thisform)
	{
		if (validate_required(reg_grade,"Please select your grade!")==false)
		{
			reg_grade.focus();
			return false;
		}
		if (validate_required(reg_district,"Please select your district!")==false)
		{
			reg_district.focus();
			return false;
		}
		if (validate_required(reg_type,"Please select your registration type!")==false)
		{
			reg_type.focus();
			return false;
		}
		if (validate_required(reg_student_name,"Please enter your name!")==false)
		{
			reg_student_name.focus();
			return false;
		}
		if (validate_required(reg_father_name,"Please enter your father's name!")==false)
		{
			reg_father_name.focus();
			return false;
		}
	}
	reg_window = window.open(windowURL, windowName, 'width=550,height=560,scrollbars=yes');
	reg_window.moveTo(0,0);
	reg_window.focus();
}
//Function to display registration slip based on entry of roll number and district.
function submit_validate_registration_roll_no(thisform){
    windowName = "reg_window";
    windowURL = thisform.action + '?';
    windowURL = windowURL + 'grade=' + thisform.reg_grade_roll_no.value+'&';
    windowURL = windowURL + 'district=' + thisform.reg_district_roll_no.value+'&';
	windowURL = windowURL + 'roll_no=' + thisform.student_roll_no.value;
	with (thisform)
	{
		if (validate_required(reg_grade_roll_no,"Please select your grade!")==false)
		{
			reg_grade_roll_no.focus();
			return false;
		}
		if (validate_required(reg_district_roll_no,"Please select your district!")==false)
		{
			reg_district_roll_no.focus();
			return false;
		}
		if (validate_required(student_roll_no,"Please enter your correct Roll Number!")==false)
		{
			student_roll_no.focus();
			return false;
		}
	}
	reg_window = window.open(windowURL, windowName, 'width=550,height=560,scrollbars=yes');
	reg_window.moveTo(0,0);
	reg_window.focus();
}
//Disabling the Enter Key to avoid form submission without hitting the Button
function stopRKey(evt) { 
  var evt = (evt) ? evt : ((event) ? event : null); 
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;} 
} 
document.onkeypress = stopRKey; 

//Email form and Contact form validation routine
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("Please enter your correct email");
		   return false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please enter your correct email");
		   return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please enter your correct email");
		    return false;
		}
		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please enter your correct email");
		    return false;
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please enter your correct email");
		    return false;
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please enter your correct email");
		    return false;
		 }
		 if (str.indexOf(" ")!=-1){
		    alert("Please enter your correct email");
		    return false;
		 }
 		 return true;
	}
function ValidateContactForm(){
	var name=document.contact_form.name;
	var email=document.contact_form.from;
	var subject=document.contact_form.subject;
	var inquiry=document.contact_form.inquiry;
	if((name.value==null)||(name.value == ""))
	{
		alert("Please enter your name");
		name.focus();
		return false;
	}
	else if ((email.value==null)||(email.value=="")){
		alert("Please enter your email");
		email.focus();
		return false;
	}
	else if (echeck(email.value)==false){
		email.value="";
		email.focus();
		return false;
	}
	else if((subject.value==null)||(subject.value == ""))
	{
		alert("Please enter subject of your inquiry");
		subject.focus();
		return false;
	}
	else if((inquiry.value==null)||(inquiry.value == ""))
	{
		alert("Please enter your inquiry");
		inquiry.focus();
		return false;
	}
	return true
 }
 function ValidateFeedbackForm(){
	var feedback=document.feedback_form.feedback;
	if((feedback.value==null)||(feedback.value == ""))
	{
		alert("Please enter your feedback");
		feedback.focus();
		return false;
	}
	return true
 }
