function validate_login_form(thisform)
{
	if (validate_required(thisform.elements['EMAIL_ADDRESS'],"Please enter your email address")==false)
	{
		thisform.elements['EMAIL_ADDRESS'].focus();
	  	return false;
	}
	if (validate_email(thisform.elements['EMAIL_ADDRESS'],"Please enter a valid email address")==false)
	{
		thisform.elements['EMAIL_ADDRESS'].focus();
	  	return false;
	}
	if (validate_required(thisform.elements['PASSWORD'],"Please enter your password")==false)
	  {thisform.elements['PASSWORD'].focus();return false;}
	 thisform.submit();
}
function validate_forgot_password_form(thisform)
{
	if (validate_required(thisform.elements['EMAIL_ADDRESS'],"Please enter your email address")==false)
	{
		thisform.elements['EMAIL_ADDRESS'].focus();
	  	return false;
	}
	if (validate_email(thisform.elements['EMAIL_ADDRESS'],"Please enter a valid email address")==false)
	{
		thisform.elements['EMAIL_ADDRESS'].focus();
	  	return false;
	}
}
function validate_site_registration_form(thisform)
{
	if (validate_required(thisform.elements['EMAIL_ADDRESS'],"Please enter your email address")==false)
	{
		thisform.elements['EMAIL_ADDRESS'].focus();
	  	return false;
	}
	if (validate_email(thisform.elements['EMAIL_ADDRESS'],"Please enter a valid email address")==false)
	{
		thisform.elements['EMAIL_ADDRESS'].focus();
	  	return false;
	}
	if (validate_required(thisform.elements['FNAME'],"Please enter your first name")==false)
	{
		thisform.elements['FNAME'].focus();
	  	return false;
	}
	if (validate_required(thisform.elements['LNAME'],"Please enter your last name")==false)
	{
		thisform.elements['LNAME'].focus();
	  	return false;
	}
	if (validate_required(thisform.elements['WEB_TITLE'],"Please enter your business title")==false)
	{
		thisform.elements['WEB_TITLE'].focus();
	  	return false;
	}
	if (validate_required(thisform.elements['USERNAME'],"Please enter a user name")==false)
	{
		thisform.elements['USERNAME'].focus();
	  	return false;
	}
	if (validate_required(thisform.elements['PASSWORD'],"Please enter a password")==false)
	{
		thisform.elements['PASSWORD'].focus();
	  	return false;
	}
	if (thisform.elements['PASSWORD']!= thisform.elements['CONFIRM_PASSWORD'])
	{
		alert("The passwords you entered do not match");
		thisform.elements['PASSWORD'].focus();
	  	return false;
	}
}
function validate_required(field,alerttxt)
{
	  if (field==null||field.value=="")
	  {
	  alert(alerttxt);return false;
	  }
	  else
	  {
	  return true;
	}
}
function validate_email(field,alerttxt)
{
	apos=field.value.indexOf("@");
	dotpos=field.value.lastIndexOf(".");
	if (apos<1||dotpos-apos<2) 
	  {alert(alerttxt);return false;}
	else {return true;}
}
function setFocus(form,field)
{
//Need to use this silly setTimeout to get this to work in Firefox.
	setTimeout("document."+form+"."+field+".focus()", 50);
}
function hideId(id){
	document.getElementById(id).style.visibility="hidden"
}	
function showId(id){
	document.getElementById(id).style.visibility="visible"
}	
function RightslinkPopUp(title, date, author, contentID)
	{	
		var url = "https://s100.copyright.com/servlet/DispatchServlet"; 
		var location = url 
			+ "?PublisherName=" + escape("Putman Media, Inc.")
			+ "&Publication=" + escape("Chemical Processing")
			+ "&Title=" + escape(title)
			+ "&PublicationDate=" + escape(date)
			+ "&Author=" + escape(author)
			+ "&Install=S"
			+ "&ContentID=" + escape(contentID);
		PopUp = window.open( location,  'Rightslink', 
			'location=no,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=650,height=550');
	}

function OpenBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

var displayed;
displayed = '';
function toggle(divid){
	if(displayed != '') {
	  document.getElementById(displayed).style.display = 'none';
	}	
	if(displayed != divid){
		if(document.getElementById(divid).style.display == 'none'){
			document.getElementById(divid).style.display = 'block';
		}else{
			document.getElementById(divid).style.display = 'none';
		}
	}	
	displayed = divid;
}

/* Deal with IE problems on hover for left nav*/


startList = function() {

	startListLeft();
	startListTop();
}

startListLeft = function() {

if (document.all&&document.getElementById) {
navRoot = document.getElementById("leftnav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}

/* Deal with IE problems on hover for top nav*/
startListTop = function() {

if (document.all&&document.getElementById) {
navRoot = document.getElementById("topnav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}

// window.onload=startList;

// set up axel and ord for DART
var axel = Math.random() + "";
var ord = axel * 1000000000000000000;

var lastkctab = 'kctab1';
function toggletabs(kind,num) {
	var divid = kind+num;
	if (divid != 'lastkctab') {
		document.getElementById(lastkctab+"a").className = "";
		document.getElementById(lastkctab+"li").className = "";
		document.getElementById(lastkctab).style.display = "none";		
		document.getElementById(divid+"a").className = "current";
		document.getElementById(divid+"li").className = "active";
		document.getElementById(divid).style.display = "block";
		lastkctab = divid;		
	}		
}

function jumpMenu(targ,selObj,restore){
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function refreshPopular() {
	(new Ajax()).doGet('/services/most_popular_processor.html');
}

function createCookie(name,value,days,host,path) {
	var expires = "";
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	
	var domain = '';
	if (host) {
		domain = "; domain="+host;
	}

	var folder = '';
	if (path) {
		folder = "; path="+path;
	}
	document.cookie = name+"="+value+expires+domain+folder;
}

function handle_validate_data(data)
{
	switch(data['status']) {
	case('success'):
		createCookie(data['name'], data['value'], 23, data['cookie_domain']);
		location.replace('/member/manage_account.html?q=user/' + data['uid'] + '/edit');
		break;
	case('expired'):
		param = '/member/register.php?status=expired';
		modalwindow();
		$('#modal_wrap').jqmShow();
		break;
	case('used'):
		param = '/member/login.php?status=used';
		modalwindow();
		$('#modal_wrap').jqmShow();
		break;
	}
}

// Modal functions
var fade_close=function(hash){ hash.w.fadeOut('350',function(){ hash.o.remove(); }); };
var fade_open=function(hash) { hash.w.fadeIn('350'); };

function modalwindow()
{
	$('#modal_wrap').jqm({
		ajax: param,
		ajaxText: '<img id="ajax_loading" src="http://www.chemicalprocessing.com/images/user/ajax_loading.gif" height="100" width="100">',
		closeClass: 'modal_close',
		onHide: fade_close,
		onShow: fade_open,
		overlay: 80,
		overlayClass: 'modal_overlay',
		toTop: true,
		trigger: '.modal_trigger'
	});
}

// Manage Account -- focus form fields

var field = '';
var lasthash = '';

var onshow = function(){
		doshow();
};

function doshow() {
		if(field != '') {
				var selector = 'input#' + field;
				if(field == 'edit-pass-pass1') {
						var selector = 'input#' + field + ', input#edit-pass-pass2'; 
				}
				$(selector).addClass('highlight');
		}
		var focusid = field;
		if(focusid != '') {
				document.getElementById(focusid).focus();
		}
}

// initialize the variable everywhere
var put_registered = false;
