// js form validation stuff
var errorMsg0   = 'Missing value in the form !';
var errorMsg1   = 'This is not a number!';
var errorMsg2   = ' is not a valid row number!';
var noDropDbMsg = '"DROP DATABASE" statements are disabled.';
var confirmMsg  = 'Do you really want to ';


function small_window(myurl, dest) {
    var newWindow;
    var props = 'scrollBars=yes,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,width=400,height=110,alwaysRaised=yes,dependent=yes';

    newWindow = window.open(myurl, "Add_from_Src_to_Dest", props);
    // Global var as the destination entry field;
    destination = dest;
    newWindow.focus ();
}

// Adds the list of selected items selected in the child
// window to its list. It is called by child window to do so.
function addToParent(source) {
    if (source.value != null) {
        with ( window.document.forms[0] )
            destination.value = source.value;
    }
}

// Add the selected items in the parent by calling method of parent
function addSelectedItemToParent() {
    self.opener.addToParent(window.document.forms[0].itemList);
    window.close();
}


// Use the array of required_fields and parse for errors
function verify(form_name) {
	var themessage = "";
	
	if (submitcount == 0) {
		submitcount++;
	} else {
		alert("This form has already been submitted.\nPlease Wait. Thanks!");
		return false;
	}

	with (document.forms[form_name]) {
		if (dest1.value=="") {
			themessage = themessage + " - First Name\n";
		}
		if (dest2.value=="") {
			themessage = themessage + " -  Last Name\n";
		}
		// alert if fields are empty and cancel form submit
		if (themessage == "") {
			// All OK, so submit form
			submit();
		} else {
			alert ("You are required to complete the following fields\n" 
				+ themessage);
			submitcount = 0;
			return false;
		}
	}
}

function goSPG() {
	location.href="http://www.spgindia.org";
}


var submitcount = 0;

for(iFormsCount=0;iFormsCount < document.forms.length;iFormsCount++) {
	for(iElementsCount=0; iElementsCount < document.forms[iFormsCount].elements.length; iElementsCount++) {
		strCookieName = document.forms[iFormsCount].elements[iElementsCount].name;
		strCookieVal = getCookie(strCookieName);
		if (strCookieVal != null && !(isNaN(strCookieVal)) && strCookieVal != '') {
			document.forms[iFormsCount].elements[iElementsCount].selectedIndex = strCookieVal;
		}
	}
}

