//this file contains code used by the web pages for various functions 
//including opening new web pages and data validation

var whitespace = " \t\n\r";

function newwindow(url,wt,ht){ 
windowprops="directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,width="+wt+",height="+ht+",left=200,top=0";
preview=window.open(url,"Questions",windowprops);
} 
function newwindow2(url,wt,ht){ 
windowprops="directories=no,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,width="+wt+",height="+ht+",left=200,top=0";
preview=window.open(url,"Questions",windowprops);
} 
function newwindow3(url){ 
windowprops="directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,height="+screen.height+", width="+790+", left=0,top=0";
preview=window.open(url,"Questions",windowprops);
} 

function checkEmpty(elem,elem2){
var s = elem.value;
var s2 = elem2.value;
//alert("size option " + size);
if((s == null) || (s.length == 0) || (s2 == null) || (s2.length == 0) ) {
alert("Please enter all fileds marked with an *");
return false;
}
else {
//alert("size of greeting!" + s.length);
return true;
}
}

function checkform(elem,elem2,elem3,elem4,elem5,elem6,elem7,elem8){
var msg ="Please enter all fields marked with an *.";
var s = elem.value;
var s2 = elem2.value;
var s3 = elem3.value;
var s4 = elem4.value;
var s5 = elem5.value;
var s6 = elem6.value;
var s7 = elem7.value;
var s8 = elem8.checked;
//alert(s8);
//check emails
if(isEmail(s6)==false || isEmail(s7)==false){
alert("Please enter a valid email");
return false;
}
//compare emails
if (s6.toUpperCase() != s7.toUpperCase()) {
     alert("Emails are not equal not equal. Please correct."); 
	 return false;
     }

//alert(isEmail(s6));
//alert(isEmail(s7)); 
if((s == null) || (s.length == 0) || (s2 == null) || (s2.length == 0)|| (s3 == null) || (s3.length == 0)|| (s4 == null) || (s4.length == 0) || (s5 == null) || (s5.length == 0)|| (s8 == false)  ) {
if(s8==false)msg ="This form can not proceed unless you aggree with the terms and conditions.";
alert(msg);
return false;
}
else {
//alert("size of greeting!" + s.length);
return true;
}
}

function checkform2(elem,elem2,elem3,elem4,elem5,elem6,elem7,elem8){
var msg ="Please enter all fields marked with an *.";
var s = elem.value;
var s2 = elem2.value;
var s3 = elem3.value;
var s4 = elem4.value;
var s5 = elem5.value;
var s6 = elem6.value;
var s7 = elem7.value;
var s8 = elem8.checked;
//alert(s8);

//check first field is a number not word
//var numcheck =parseInt(s);
//alert(typeof(s));
//alert(parseInt(s));
//alert(numcheck);
if(!checkIsNumber(s)){
//alert("Please enter a number to repsond to.");
return false;
}

//check emails
if(!isEmail(s6) || !isEmail(s7)){
alert("Please enter a valid email");
return false;
}
//compare emails
if (s6.toUpperCase() != s7.toUpperCase()) {
     alert("Emails are not equal not equal. Please correct."); 
	 return false;
     }

//alert(isEmail(s6));
//alert(isEmail(s7)); 
if((s == null) || (s.length == 0) || (s2 == null) || (s2.length == 0)|| (s3 == null) || (s3.length == 0)|| (s4 == null) || (s4.length == 0) || (s5 == null) || (s5.length == 0)|| (s8 == false)  ) {
if(s8==false)msg ="This form can not proceed unless you aggree with the terms and conditions.";
alert(msg);
return false;
}
else {
//alert("size of greeting!" + s.length);
return true;
}
}

function checkform3(elem,elem2,elem3,elem4,elem5){
var msg ="Please enter all fields marked with an *.";
var s = elem.value;
var s2 = elem2.value;
var s3 = elem3.value;
var s4 = elem4.value;
var s5 = elem5.value;

//check first field is a number not word

//if(!checkIsNumber(s4)){
//alert("Please enter a number to repsond to.");
//return false;
//}

//check emails
if(!isEmail(s2) || !isEmail(s3)){
alert("Please enter two correct valid emails");
return false;
}
//compare emails
if (s2.toUpperCase() != s3.toUpperCase()) {
     alert("Emails are not equal not equal. Please correct."); 
	 return false;
     }

//alert(isEmail(s6));
//alert(isEmail(s7)); 
if((s == null) || (s.length == 0) || (s2 == null) || (s2.length == 0)|| (s3 == null) || (s3.length == 0)|| (s4 == null) || (s4.length == 0) || (s5 == null) || (s5.length == 0)  ) {
//if(s8==false)msg ="This form can not proceed unless you aggree with the terms and conditions.";
alert(msg);
return false;
}
else {
//alert("size of greeting!" + s.length);
return true;
}
}

function checkform4(elem,elem2,elem3,elem4,elem5,elem6,elem7,elem8){
var msg ="Please enter all fields marked with an *.";
var s = elem.value;
var s2 = elem2.value;
var s3 = elem3.value;
var s4 = elem4.value;
var s5 = elem5.value;
var s6 = elem6.value;
var s7 = elem7.checked;
//var s8 = elem8[1].checked;


//check radio buttons
//alert(elem8.length);
// set var radio_choice to false
var radio_choice = false;
// Loop from zero to the one minus the number of radio button selections
for (counter = 0; counter < elem8.length; counter++){
// If a radio button has been selected it will return true
// (If not it will return false)
if (elem8[counter].checked)
radio_choice = true; 
}
if (!radio_choice){
// If there were no selections made display an alert box 
alert("Please select a topic.")
return (false);
}
//end check radio buttons

//check emails
if(isEmail(s5)==false || isEmail(s6)==false){
alert("Please enter a valid email");
return false;
}
//compare emails
if (s5.toUpperCase() != s6.toUpperCase()) {
     alert("Emails are not equal not equal. Please correct."); 
	 return false;
     }

//alert(isEmail(s6));
//alert(isEmail(s7)); 
if((s == null) || (s.length == 0) || (s2 == null) || (s2.length == 0)|| (s3 == null) || (s3.length == 0)|| (s4 == null) || (s4.length == 0) || (s7 == false)  ) {
if(s7==false)msg ="This form can not proceed unless you aggree with the terms and conditions.";
alert(msg);
return false;
}
else {
//alert("size of greeting!" + s.length);
return true;
}
}

function checkform5(elem,elem2,elem3,elem4,elem5,elem6,elem7,elem8){
var msg ="Please enter all fields marked with an *.";
var s = elem.value;
var s2 = elem2.value;
var s3 = elem3.value;
var s4 = elem4.value;
var s5 = elem5.value;
var s6 = elem6.value;
var s7 = elem7.value;
var s8 = elem8.checked;
//alert(s8);
//check emails
if(isEmail(s4)==false || isEmail(s5)==false){
alert("Please enter a valid email");
return false;
}
//compare emails
if (s4.toUpperCase() != s5.toUpperCase()) {
     alert("Emails are not equal not equal. Please correct."); 
	 return false;
     }

//alert(isEmail(s6));
//alert(isEmail(s7)); 
if((s == null) || (s.length == 0) || (s2 == null) || (s2.length == 0)|| (s3 == null) || (s3.length == 0)|| (s4 == null) || (s4.length == 0) || (s5 == null) || (s5.length == 0)|| (s6 == false)|| (s7.length == 0)|| (s8 == false)  ) {
if(s8==false)msg ="This form can not proceed unless you aggree with the terms and conditions.";
alert(msg);
return false;
}
else {
//alert("size of greeting!" + s.length);
return true;
}
}

function checkform5b(elemb,elem,elem2,elem3,elem4,elem5,elem6,elem7,elem8){
var msg ="Please enter all fields marked with an *.";
var sb= elemb.value;
var s = elem.value;
var s2 = elem2.value;
var s3 = elem3.value;
var s4 = elem4.value;
var s5 = elem5.value;
var s6 = elem6.value;
var s7 = elem7.value;
var s8 = elem8.checked;
//alert(s8);
//check emails
if(isEmail(s4)==false || isEmail(s5)==false){
alert("Please enter a valid email");
return false;
}
//compare emails
if (s4.toUpperCase() != s5.toUpperCase()) {
     alert("Emails are not equal not equal. Please correct."); 
	 return false;
     }

//alert(isEmail(s6));
//alert(isEmail(s7)); 
if((sb == null) || (sb.length == 0)||(s == null) || (s.length == 0) || (s2 == null) || (s2.length == 0)|| (s3 == null) || (s3.length == 0)|| (s4 == null) || (s4.length == 0) || (s5 == null) || (s5.length == 0)|| (s6 == false)|| (s7.length == 0)|| (s8 == false)  ) {
if(s8==false)msg ="This form can not proceed unless you aggree with the terms and conditions.";
alert(msg);
return false;
}
else {
//alert("size of greeting!" + s.length);
return true;
}
}

function checkform6(elem,elem2,elem4,elem5,elem6,elem7,elem8){
var msg ="Please enter all fields marked with an *.";
var s = elem.value;
var s2 = elem2.value;
var s4 = elem4.value;
var s5 = elem5.value;
var s6 = elem6.value;
var s7 = elem7.value;
var s8 = elem8.checked;
//alert(s8);
//check emails
if(isEmail(s6)==false || isEmail(s7)==false){
alert("Please enter a valid email");
return false;
}
//compare emails
if (s6.toUpperCase() != s7.toUpperCase()) {
     alert("Emails are not equal not equal. Please correct."); 
	 return false;
     }

//alert(isEmail(s6));
//alert(isEmail(s7)); 
if((s == null) || (s.length == 0) || (s2 == null) || (s2.length == 0)|| (s4 == null) || (s4.length == 0) || (s5 == null) || (s5.length == 0)|| (s8 == false)  ) {
if(s8==false)msg ="This form can not proceed unless you aggree with the terms and conditions.";
alert(msg);
return false;
}
else {
//alert("size of greeting!" + s.length);
return true;
}
}

function checkform7(elem,elem2,elem3){
var msg ="Please enter all fields marked with an *.";
var s = elem.value;
var s2 = elem2.value;
var s3 = elem3.value;

if((s == null) || (s.length == 0) || (s2 == null) || (s2.length == 0)|| (s3 == null) || (s3.length == 0) ) {
//if(s8==false)msg ="This form can not proceed unless you aggree with the terms and conditions.";
alert(msg);
return false;
}
else {
//alert("size of greeting!" + s.length);
return true;
}
}

function checkform8(elem,elem2,elem3){
var msg ="Please enter all fields marked with an *.";
var s = elem.value;
var s2 = elem2.value;
var s3 = elem3.value;

//check emails
if(isEmail(s2)==false || isEmail(s3)==false){
alert("Please enter two valid emails");
return false;
}
//compare emails
if (s2.toUpperCase() != s3.toUpperCase()) {
     alert("Emails are not equal not equal. Please correct."); 
	 return false;
     }
if((s == null) || (s.length == 0) || (s2 == null) || (s2.length == 0)|| (s3 == null) || (s3.length == 0) ) {
//if(s8==false)msg ="This form can not proceed unless you aggree with the terms and conditions.";
alert(msg);
return false;
}
else {
//alert("size of greeting!" + s.length);
return true;
}
}

//shared functions
function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return false;//defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
	// Check that current character isn't whitespace.
	var c = s.charAt(i);

	if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

// Check whether string s is empty.
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function checkIsNumber(field)
{
	var strField = new String(field);//.value);
	//alert(strField);
	if (isWhitespace(strField)) return true;

	var i = 0;

	for (i = 0; i < strField.length; i++)
		if (strField.charAt(i) < '0' || strField.charAt(i) > '9') {
			alert("Please enter a question number to respond to. Please do not use words or any non-numeric symbols.");
			//objField.focus();
			return false;
		}

	return true;
}

function Minimize() 
{
window.innerWidth = 100;
window.innerHeight = 100;
window.screenX = screen.width;
window.screenY = screen.height;
alwaysLowered = true;
}

function Maximize() 
{
window.innerWidth = screen.width;
window.innerHeight = screen.height;
window.screenX = 0;
window.screenY = 0;
alwaysLowered = false;
}

//end shared functions