/*****************************************************
** Last Updated: April 30, 2007
** 
** This page contains JAVASCRIPT functions common to 
** all jznetwork sites.
**
** A. JavaScript FUNCTIONS
**		1. placeFocus()
**		2. getAnOptionValue(source)
**		3. getAnOptionText(source)
**		4. getATextBoxValue(source)
**		5. getATextBoxLength(source)
**
** B. Other FUNCTIONS
**		1. disableEnterKey()
**		2. addslashes()
**		3. stripslashes()
**		4. encryptPassword()
**		5. addEvent()
**		6. jzAddListeners()
**
*****************************************************/ 

/*****************************************************
** --------------------------------------------------
** 
** A. AJAX Functions --------------------------------
*****************************************************/ 


/*****************************************************
** 1. PLACE FOCUS
*****************************************************/ 

<!-- Original:  Tom Khoury (twaks@yahoo.com) -->
function placeFocus() {
if (document.forms.length > 0) {
var field = document.forms[0];
for (i = 0; i < field.length; i++) {
if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
document.forms[0].elements[i].focus();
break;
         }
      }
   }
}


/*****************************************************
** 2. GET AN OPTION BOX VALUE
*****************************************************/ 

function getAnOptionValue(source) {
	return document.getElementById(source).options[document.getElementById(source).selectedIndex].value;
}


/*****************************************************
** 3. GET A TEXT BOX VALUE LENGTH
*****************************************************/ 

function getAnOptionText(source) {
	return document.getElementById(source).options[document.getElementById(source).selectedIndex].text;
}


/*****************************************************
** 4. GET A TEXT BOX VALUE
*****************************************************/ 

function getATextBoxValue(source) {
	return document.getElementById(source).value;
}





/*****************************************************
** 5. GET A TEXT BOX VALUE LENGTH
*****************************************************/ 

function getATextBoxLength(source) {
	return document.getElementById(source).value.length;
}



/*****************************************************
** --------------------------------------------------
** 
** B. Other Functions --------------------------------
*****************************************************/ 


/*****************************************************
** 1. Disable Enter Key on Forms
*****************************************************/ 

/*
To USE
<input type='text' name='mytext' onKeyPress='return disableEnterKey(event)'>
 
 OR
 
or you can use one line:
onkeypress='return event.keyCode!=13'

 added to  FORM element
*/

function disableEnterKey(e)
{
     var key;
     if(window.event.keyCode) {
         key = window.event.keyCode;     //IE
	 } else {
		 key = e.keyCode;     //firefox
	 } 
	 
	 if(key == 13) {
          return false;
	 } else {
          return true;
	 }
}




/*****************************************************
** 2. addslashes()
*****************************************************/ 

function addslashes(str) {
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\0/g,'\\0');
return str;
}

/*****************************************************
** 3. stripslashes()
*****************************************************/ 

function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\\\/g,'\\');
str=str.replace(/\\0/g,'\0');
return str;
}


/*****************************************************
** 4. encryptPassword()
*****************************************************/ 

function encryptPassword(f, password_id) {
	var password = f.password_id.value;
	var salt = f. salt.value;
	var encrypted1 = hex_md5(password);
	var encrypted2 = hex_md5(encrypted1 + salt);
	f.password_id.value = encrypted2;

}


/*****************************************************
** 5. addEvent()
*****************************************************/ 

function addEvent(elm, evType, fn, useCapture) {
  // cross-browser event handling for IE5+, NS6 and Mozilla 
  // By Scott Andrew 
  if (elm.addEventListener) { 
    elm.addEventListener(evType, fn, useCapture); 
    return true; 
  } else if (elm.attachEvent) { 
    var r = elm.attachEvent('on' + evType, fn); 
    return r; 
  } else {
    elm['on' + evType] = fn;
  }
}

/*****************************************************
** 6. jzAddListeners()
*****************************************************/ 
// here's the bit that installs the listeners to all
// JZ Network Sites

function addListeners_jz(e) {
  
  // A. Place Focus on first item of the form
  	placeFocus();
  
  // B. disable the 'Enter' Key
	//var formo = document.getElementsByTagName('form');
	/*
	var target = 'formo';
	var obj = document.getElementById(target);

	addEvent(obj,'keyup', disableEnterKey ,false);
	*/
}