//function to automatically find the first field on a form and focus on it...
function formFocus() {
	//default to selecting the first form on the page
	if(document.forms[0]){
		//alert("Reached here..");
		for(var i=0; i < document.forms[0].elements.length; i++) {
			currentElement = document.forms[0].elements[i];
			// Debugging...alert(currentElement.type);
			if(currentElement.disabled == false && (currentElement.type == "select-one" || currentElement.type == "submit" || (currentElement.readOnly == false && currentElement.type == "text") || currentElement.type == "textarea")) {
				currentElement.focus();
				break;
			}
		}
	}
}

/* Nav History Functions */
//Show the Nav History!
function showHistory()
{
	document.all["historyDropDown"].style.visibility="visible";
	//hide all select boxes so they don't overlap the menu...
	var ids = Array();
	ids = document.getElementsByTagName("select");
	for (j=0; j<ids.length; ++j) {
	  ids[j].style.visibility = "hidden";
	}
}

//Hide the Nav History!
function hideHistory()
{
	document.all["historyDropDown"].style.visibility="hidden"
	//show all select boxes again...
	var ids = Array();
	ids = document.getElementsByTagName("select");
	for (j=0; j<ids.length; ++j) {
	  ids[j].style.visibility = "visible";
	}
}
/* End Nav History Functions */

/* Menu Functions */
//Show the popup menu!!!
function showmenu(elmnt)
{
	document.all(elmnt).style.visibility="visible";
	//hide all select boxes so they don't overlap the menu...
	var ids = Array();
	ids = document.getElementsByTagName("select");
	for (j=0; j<ids.length; ++j) {
	  ids[j].style.visibility = "hidden";
	}
	//remove focus from any input box
	this.focus();
}

//Hide the popup menu!!!
function hidemenu(elmnt)
{
	document.all(elmnt).style.visibility="hidden"
	//show all select boxes again...
	var ids = Array();
	ids = document.getElementsByTagName("select");
	for (j=0; j<ids.length; ++j) {
	  ids[j].style.visibility = "visible";
	}
}

//Show - Hide the info in tha browser ststus bar
function setStatbar(stxt){
	window.status = stxt;
}
/* End Menu Functions */

/* Some form validation function */
function isEmailAddr(email) {

				  var result = false
				  var index = email.value.indexOf("@");
				  var fieldFocus = window.event.srcElement;
				  if (email.value.length == 0)
				  {
				  	result = true;
				  } 
				  else if (index > 0)
				  {
				  	var pindex = email.value.indexOf(".",index);
				    if ((pindex > index+1) && (email.value.length > pindex+1))
					{
						result = true;
					}
				  }
				  if (result == false)
				  {
				  	alert('Invalid email address');
					fieldFocus.focus();
				  }			
				  return result;
}

/* Affiliate cookie functions */
function SetCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+ ";path=/" +
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
/* old code */
//function SetCookie (name, value) {
//        var argv = SetCookie.arguments;
//        var argc = SetCookie.arguments.length;
//        var expires = (argc > 2) ? argv[2] : null;       
//        var path = (argc > 3) ? argv[3] : null;
//        var domain = (argc > 4) ? argv[4] : null;
//        var secure = (argc > 5) ? argv[5] : false;
//        document.cookie = name + "=" + escape (value) +
//                ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
//                ((path == null) ? "" : ("; path=" + path)) +
//                ((domain == null) ? "" : ("; domain=" + domain)) +
//                ((secure == true) ? "; secure" : "");
//}
function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {		
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
                var j = i + alen;
                if (document.cookie.substring(i, j) == arg)
                        return getCookieVal (j);
                i = document.cookie.indexOf(" ", i) + 1;
                        if (i == 0)
                                break;
                }
   return null;
}
