// javascript file

// these control how the div's open/close
var divh;
var elemDiv;
var elemStatus;
var delay = 2;
var inc = 12;
var max = 98;
var statDiv = self.document.getElementById('status');
var isIE = (navigator.userAgent.toLowerCase().indexOf("msie")>=0)

function popup(x) {
	alert(x);
}

function setFocus(ctl){
	//popup(ctl);
	document.getElementById(ctl).focus()
}

function IsNumeric(strString)

   //  check for valid numeric strings	
   {
 //  alert("in: " + strString);
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   if (blnResult == false) alert("Not a valid UPC value.\nIt must be numeric.");
   return blnResult;
   }

function ShrinkDiv() {
    divh = divh-inc;
    if (divh < 1) { divh = 1; }
    elemDiv.style.height = divh + '%';
    if (divh == 1) { return false; }
    setTimeout("ShrinkDiv()",delay) 
}
function GrowDiv() {
    divh = divh+inc;
    if (divh > (max-1)) { divh = max; }
    elemDiv.style.height = divh + '%';
    if (divh == max) { return false; }
    setTimeout("GrowDiv()",delay)   
}

function SignClick(id) {
	// user clicked the +/- sign next to a section header

	elemSign = document.getElementById("sign" + id);
	elemDiv = document.getElementById("div" + id);
	elemStatus = document.getElementById("pnlstatus" + id);
	
	if (isIE) {
    	
	    divh = parseInt(elemDiv.style.height);
	    if (!divh) { divh = max; }
    	
    	
	    if (divh == 1) { 
            elemSign.src = "images/tree_minus.gif";
			elemStatus.value="closed";
	        setTimeout("GrowDiv()",delay); 
	    }
	    else { 
            elemSign.src = "images/tree_plus.gif";
			elemStatus.value="open";
	        setTimeout("ShrinkDiv()",delay); 
	    }
	}
	else {
	    // change visibility of div
        elemDiv.style.display = (elemDiv.style.display == "none" ) ? "" : "none";
        // change the +/- sign
        elemSign.src = (elemDiv.style.display == "none" ) ? "images/tree_plus.gif" : "images/tree_minus.gif";
	}
}

function ShowMe(id) {
	if (id=="encoder") {	self.document.location.href = "[url goes here]"; return false; }
	
	elemDiv = document.getElementById("pic" + id);
	elemDiv.style.display = (elemDiv.style.display == "none" ) ? "" : "none";	
}

function BoxSet(id, value) {
	// set the status for a box to value="open" or "close".
	// show/hide the div as needed.
	
    elemSign = document.getElementById("sign" + id);
    elemDiv = document.getElementById("div" + id);

	if (isIE) {
	    divh = parseInt(elemDiv.style.height);
    	
	    if (value == "open") { 
            elemSign.src = "images/tree_minus.gif";
            elemDiv.style.height = max + '%'; 
        }
        else {
            elemSign.src = "images/tree_plus.gif";
            elemDiv.style.height = '1%'; 
        }
	}
	else {
	    if (value == "open") { 
            elemSign.src = "images/tree_minus.gif";
            elemDiv.style.display = '';
        }
        else {
            elemSign.src = "images/tree_plus.gif";
            elemDiv.style.display = 'none';
        }
	}
}

function AdRedirect(url) {
	alert("got here");
	window.location='ad_redirect.php?page=url';
}

function checkMandSU(){
	email = document.getElementById("email");
	fname = document.getElementById("fname");
	lname = document.getElementById("lname");
	password1 = document.getElementById("password1");
	password2 = document.getElementById("password2");
	pw_hint_answer = document.getElementById("pw_hint_answer");
		
	msg="";
	if (email.value=="") {
		msg += "E-mail is a required field\n";
	} else {
		if (!echeck(email.value)) {
			msg += "E-mail format is not valid\n";
		}
	}
	if (password1.value=="") msg += "Password is a required field\n";
	if (password2.value =="") msg += "You must confirm the password\n";
	if (password1.value != password2.value) msg += "Passwords do not match\n";	
	if (fname.value=="") msg += "First Name is a required field\n";
	if (lname.value=="") msg += "Last Name is a required field\n";
	if (pw_hint_answer.value =="") msg += "Password hint answer is a required field\n";
	
	if (msg !="") {
		alert(msg);
		return false;
	} else {
		return true;
	}
}

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 ID")
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}
		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
 		 return true					
	}


function checkMandClub(){
	name1 = document.getElementById("name");
	password1 = document.getElementById("password1");
	
	msg="";
	if (name1.value=="") msg += "Name is a required fieled\n";
	if (password1.value=="") msg += "Password is a required field\n";
	
	if (msg !="") {
		alert (msg);
		return false;
	} else {
		return true;
	}
}

function checkMandBook(){
	title = document.getElementById("title");
	
	msg="";
	if (title.value=="") msg+= "Title is a required field\n";
	
	if (msg!="") {
		alert(msg);
		return false;
	} else {
		return true;
	}
	return false;
}
function checkMandClubMemb() {
	club_id = document.getElementById("club_id");
	password1 = document.getElementById("password1");
	
	msg="";
	if (club_id.value=="") msg+= "Club number is a required entry\n";
	if (password1.value=="") msg+= "Password is a required entry\n";
	
	if (msg!=""){
		alert(msg);
		return false;
	} else {
		return true;
	}
}
