
// HELP STUFF  //////////////////////////////////////////////////////////////////////

var tooltips_enabled = true;

function showhelp(help_page) {

	  helpwindow = window.open(help_page,"HELP","height=400,width=400,resizable,scrollbars");
		helpwindow.focus();
		
	}	  // endof showhelp	
 
  function showtooltip(tooltip_id) {
	  if(tooltips_enabled){
	  	document.getElementById(tooltip_id).style.visibility = "visible" ;
	  }
  }	  // endof showtooltip	

  function hidetooltip(tooltip_id) {

	   document.getElementById(tooltip_id).style.visibility = "hidden" ;
  }	  // endof hidetooltip	
 
 
 
 
 
 
// WINDOW CONTROL  //////////////////////////////////////////////////////////////////////

	var close_subwindows_ok = "true"; //the default is to close subwindows see close_all_subwindows()

	var current_location = window.location.href; //capture current document location

	var temp_win = "";

	var subwindow_list = new  Array();

		//bring window to front when contents change

	window.onload=bring_to_front;

  function bring_to_front(){self.focus();}

	function new_subwindow(comandline, windowname, attributes){

		temp_win = window.open(comandline,windowname,attributes);

		if(temp_win && ! temp_win.closed){subwindow_list.push(temp_win);}

	}

	

	

	function reload_page_now(){

		close_subwindows_ok = "false"; //don't auto close subwindows on an auto reload

		location.reload();

	}

	function auto_reload_page(time_interval){ //reloads document after a given time interval in millisecs

		setTimeout('reload_page_now()', time_interval);

	}//eof auto_reload_page

	

	function close_all_subwindows(){

		if(close_subwindows_ok == "true"){//only close subwindows if document is NOT auto reloading

			while(subwindow_list.length > 0){

				temp_win = subwindow_list.pop();

				if(temp_win && ! temp_win.closed){temp_win.close();}

			}

		}

	}	//eof close subwindows

	

	

	function close_named_parent(name){

		if(self.name == name){ //if this is the window 'name' close it

			window.close();

		}

		else{

			opener.window.close_named_parent(name); //pass it back up the tree

		}

	}	//eof close_named_parent

	



	function reload_named_parent(name){

		if(self.name == name){ //if this is the window 'name' refresh it

			window.location.reload(self);

		}

		else{

			opener.window.reload_named_parent(name); //pass it back up the tree

		}

	}	//eof reload_named_parent

		

// EOF WINDOW CONTROL ///////////////////////////////////////////////////////////////////////////////////



 
 
 
function JS_is_websafe_password(password_input){
    var test_password = password_input.toString();
    var regex2 = new RegExp(/[^\d\w#*,.:_!\-%&\/?{}\[\])|(=]/);
    if(test_password.length < 8 ) { 
    	alert('Password is too short. Minimum 8 characters.');
      return false;
    }
    if(test_password.length > 24 ) { 
    	alert('Password is too long. Maximum 24 characters.');
      return false;
    }
   if(regex2.test(test_password)){
      alert('Password contains illegal characters.');
      return false; 
    } 
    return true;
}// eof JS_is_websafe_password




function isTelNo(inputVal) {
		inputStr = inputVal.toString()
      if (inputStr.length <= 6) {	//if telno less than 7 characters
		  return false }		
		for (var i = 0; i < inputStr.length; i++) {
	   	var oneChar = inputStr.charAt(i)
      	if (oneChar < '0' || oneChar > '9' )   {
			  if (oneChar != ' ') {//if not number or space character
		      return false }
	   	}
	   	}
		  return true
		  } // endof isTelNo


function resize_window(new_width,new_height){
  // resizes the current window. Doesn't work with all browsers but seems OK with Firefox and IE  
  if (window.outerWidth) {
    window.outerWidth = new_width;
		window.outerHeight = new_height;
	}
	else if (window.resizeTo) {
		window.resizeTo(new_width,new_height);
	}
}//eof resize_window

function loadpage(page_url,page_title,page_width,page_height,page_topbars){
    if(page_topbars){
      page_topbars = ",resizable,scrollbars," + page_topbars;
    }
    else{
        page_topbars = ",resizable,scrollbars";
    }
    // internet explorer requires double quotes on page title or it errors
    mywindow = window.open(page_url, "page_title", "width=" + page_width + ",height=" + page_height + page_topbars);
		mywindow.focus();
} // EOF LOADPAGE

  
function isEmail(inputVal) {
	 if(inputVal == null){return false;}
	 inputStr = inputVal.toString();
	 var regex3 = new RegExp(/[^\d\w!#\$\@%&'\*\+-\/=?\^_`\{|\}~\.]/);
   if(inputStr.length < 6) { // if email too short
	   return false; }
   if(inputStr.length > 70) { //email too long to be believable though not strictly illegal
	   return false; }	 
	 if(inputStr.indexOf(" ") != -1) { // if it contains a space
	   return false ;}  
   if(inputStr.indexOf("@") == -1) { // if no @ character
	   return false;}	
	 if(inputStr.indexOf(".") == -1) { // if no period character
	   return false; }	  
   if (inputStr.indexOf("@") != inputStr.lastIndexOf("@")) { // if multiple @ characters
	   return false; }	
	 if(inputStr.indexOf("@") < 1) { // if @ in wrong place
	   return false; }
	 if(inputStr.indexOf("@") >= (inputStr.lastIndexOf(".") -1) ) { // if last period not to right of @
	   return false ;}
	 if(inputStr.lastIndexOf(".") >= (inputStr.length -2) ) { // if last period in wrong place
	   return false; }
	 if(regex3.test(inputStr)){ // email contains illegal characters
      return false; }  
		  
	 return true
} // endof validate email	  
  
  
  

  
function validate_card_details(){
    /* validates standard payment card entry fields. Element names must be correct or it will error
     Can only be used to validate static html pages, ie doesn't work with programatically generated html
		 
		 
     Returns true if card data is valid, false if not.
		 Card details MUST be contained within a form called "account_form" ie <form name="account_form" ...
		 */
    
 			var cardnumber = document.account_form.card_number.value;
 
              if((document.account_form.cardholder_name__.value.length < 4) ){			
                alert('Please enter a valid card holder name');
                return false;
              }
              if((cardnumber.length < 13)||(cardnumber.length > 19) ){	
                alert('Please enter a valid card number');
                return false;
              }
              if(isNaN(cardnumber)){
                alert('Please enter a valid card number');
                return false;
              }
              if((document.account_form.card_type.selectedIndex == 0) ){	
                alert('Please select a card type');
                return false;
              }            
              if((document.account_form.card_type.selectedIndex == 1) || (document.account_form.card_type.selectedIndex == 2) ){
                //If its a credit card
                if(isNaN(document.account_form.security_code.value)){
                  alert('Please enter a numeric security code');
                  return false;
                }
                if(document.account_form.security_code.value.length != 3 ){
                  alert('Security code must be 3 digits');
                  return false;
                }
                if(document.account_form.card_expmonth.selectedIndex == 0 ){
                  alert('Please select an expiry month');
                  return false;
                } 
                if(document.account_form.card_expyear.selectedIndex == 0 ){
                  alert('Please select an expiry year');
                  return false;
                }
              }   
              if((document.account_form.card_type.selectedIndex == 3)){
                //If its a debit card
                if( isNaN(document.account_form.card_issue.value) && (document.account_form.card_startmonth.selectedIndex == 0 ) ){
                  alert('Debit card payment requires either an issue number or a start date.');
                  return false;
                }
                if(document.account_form.card_issue.value.length > 0 ){ // issue number is entered so check it
                  if(isNaN(document.account_form.card_issue.value)){
                    alert('Please enter a numeric issue number');
                    return false;
                  }
                  if(document.account_form.card_issue.value.length != 2 ){
                    alert('Issue number must be 2 digits');
                    return false;
                  }
                }
                else{ // no issue number so there should be a start date
                  if(document.account_form.card_startmonth.selectedIndex == 0 ){
                    alert('Please select a start month');
                    return false;
                  } 
                  if(document.account_form.card_startyear.selectedIndex == 0 ){
                    alert('Please select a start year');
                    return false;
                  }
                }
              }   

    return true;

} //eof validate card details










// VERTICAL MENU /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function show_dropbox(vm_base,vm_dropbox){
	document.getElementById(vm_base).style.backgroundColor='#3770A3';
	if( vm_dropbox != ""){
		document.getElementById(vm_dropbox).style.visibility='visible';
	}
}

function hide_dropbox(vm_base,vm_dropbox){
	document.getElementById(vm_base).style.backgroundColor='#3770A3';
	if( vm_dropbox != ""){
		document.getElementById(vm_dropbox).style.visibility='hidden';
	}
}





// HORIZONTAL MENU /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function show_dropbox_h(hm_base,hm_dropbox,background_image_url){
	//document.getElementById(hm_base).style.backgroundImage='url(' + background_image_url + ')';
	if( hm_dropbox != ""){
		document.getElementById(hm_dropbox).style.visibility='visible';
	}
}

function hide_dropbox_h(hm_base,hm_dropbox){
	//document.getElementById(hm_base).style.backgroundImage='';
	if( hm_dropbox != ""){
		document.getElementById(hm_dropbox).style.visibility='hidden';
	}
}















  
  
