
var imagefolder;

function menuselect()
{
if (document.jump.mainmenu.options[document.jump.mainmenu.selectedIndex].value != "##")
	{
	document.jump.action="../../admin/" + document.jump.mainmenu.options[document.jump.mainmenu.selectedIndex].value + "/search.cfm";
	document.jump.submit();
	}
else
	{
	document.jump.mainmenu[0].selected="1";
	}
}

function popup(url,title,w,h) {
	showcenteredpopup(url,title,w,h,'yes','yes','yes','no','no');
}

function showcenteredpopup(url,title,wsize,hsize,rsize,scroll,status,toolbar,location)
{
var leftpos;
var toppos;
// get top and left positions based on user's resolution so hint window is centered.
leftpos = (window.screen.width/2) - ((wsize/2) + 10); // half the screen width minus half the new window width (plus 5 pixel borders).
toppos = (window.screen.height/2) - ((hsize/2) + 50); // half the screen height minus half the new window height (plus title and status bars).
var newpopup=window.open(url,title,'height=' + hsize + ',width=' + wsize + ',left=' + leftpos + ',top=' + toppos + ',screenX=' + leftpos + ',screenY=' + toppos + ',resizable=' + rsize + ',scrollbars=' + scroll + ',status=' + status + ',toolbar=' + toolbar + ',location=' + location);
} 

function preview()
{
showcenteredpopup('../incl/previewloader.cfm','PreviewWindow','800','600','yes','yes','yes','no','no');
setTimeout("submitform('preview=yes','PreviewWindow');",500);
}

function showselectorpopup(url,title,wsize,hsize,rsize,scroll,status,toolbar,location,id,idfield,restriction,showidlist,deadlink)
{
if (deadlink == 'yes'){return} 
var leftpos;
var toppos;
// get top and left positions based on user's resolution so hint window is centered.
leftpos = (window.screen.width/2) - ((wsize/2) + 10); // half the screen width minus half the new window width (plus 5 pixel borders).
toppos = (window.screen.height/2) - ((hsize/2) + 50); // half the screen height minus half the new window height (plus title and status bars).
var popup=window.open(url + '?recordID=' + id + '&' + idfield + '=' + eval('document.editform.' + idfield + '.value') + '&restriction='+ restriction +  '&showidlist=' + showidlist + '&deadlink=' + deadlink,title,'height=' + hsize + ',width=' + wsize + ',left=' + leftpos + ',top=' + toppos + ',screenX=' + leftpos + ',screenY=' + toppos + ',resizable=' + rsize + ',scrollbars=' + scroll + ',status=' + status + ',toolbar=' + toolbar + ',location=' + location);
} 

function submitform(params,newtarget)
{
if (params != null)
	{document.editform.action=document.editform.action + "?" + params;}

if (newtarget != null)
	{document.editform.target=newtarget;}
else
	{document.editform.target="_self";}

if (notblank(document.editform.articlename) && checkSelector(document.editform.articletypeid))
	{
	//soEditor.updateFormField();
	document.editform.submit();
	}
else
	{alert("Please complete the Article name field and choose a type!");}
}

function checkSelector(field) {
	if (field.value.length > 0 && field.value > 0)
		return true;
	return false;
}

function actionitem(message,action,confirmation)
{
if (confirmation != null)
	{
	if (confirmation == 'yes')
		{
		if (confirm(message)) //display confirmation dialog box
			{
			submitform('action=' + action);
			}
		}
	else //do not confirm
		{
		submitform('action=' + action);
		}
	}
else //confirmation not specified so confirm by default
	{
	if (confirm(message))
			{
			submitform('action=' + action);
			}
	}
}

function notblank(field1)
{
if (field1 != null)
	{
	if (field1.value == "")
		{
		return false;
		}
	return true; 
	}	
}

function setdates()
{
if (document.editform.onedayevent.checked==true)
	{
	document.editform.enddate.value=document.editform.startdate.value;
	document.editform.enddate_year.options[0].selected=1;
	document.editform.enddate_month.options[0].selected=1;
	document.editform.enddate_day.options[0].selected=1;
	}
}
function nodate(frm,name) {
	eval(frm+"."+name+".value=''");
	eval(frm+"."+name+"_day").selectedIndex=0;
	eval(frm+"."+name+"_month").selectedIndex=0;
	eval(frm+"."+name+"_year").selectedIndex=0;
}

function showhide(element){
	if (document.getElementById(element).style.display != "block") {
		document.getElementById(element).style.display = "block";
	} else {
		document.getElementById(element).style.display = "none";
	}
}

function show(element){
	document.getElementById(element).style.display = "block";
}

function hide(element){
	document.getElementById(element).style.display = "none";
}

/*
son of suckerfish menu script from:
http://www.htmldog.com/articles/suckerfish/dropdowns/
 */
 
 sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
			this.style.zIndex=200; //this line added to force flyout to be above relatively positioned stuff in IE
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

/*
form validation, field element requires title to validate
email address validation needs title of "email"
*/

function checkFrm(frmObj,termCheck){
	var errMessage = "The following errors occurred:";
	var frmLength = frmObj.length;
	
	//make sure we have terms and conditions
	if (termCheck == 1 && document.getElementById('termsCheck').checked == false){
		//alert(document.getElementById('termsCheck').checked);
		errMessage = errMessage + "\n" + "You must have checked the terms and conditions to receive the Risk Report";
	}
	for (i=0; i<frmLength;i++){
		if(frmObj[i].value == "" && frmObj[i].id != "" && (frmObj[i].type == "text"||frmObj[i].type == "textarea")){
			errMessage = errMessage + "\n" + frmObj[i].id + " needs to be completed"
		} else if (frmObj[i].id == "password" && frmObj[i].value !=  document.getElementById('conf_password').value){
				errMessage = errMessage + "\n" + " please make sure that your passwords match";
			} else if (frmObj[i].id == "Email"){	//validate email
			//get value of email field
			strEmail = document.getElementById(frmObj[i].id).value;
			//call check email function
			if (isEmail(strEmail)){
				//all OK
			} else {
				errMessage = errMessage + "\n" + " please enter a valid email address";
			}
			
		} else if (frmObj[i].type == "select-one" && frmObj[i].id != "" && frmObj[i].options[frmObj[i].selectedIndex].value == ""){
			errMessage = errMessage + "\n" + frmObj[i].id + " needs to be completed";
		}
	}

	if (errMessage != "The following errors occurred:"){
		alert(errMessage);
	} else {
		frmObj.submit();
	}
}

function isEmail(strValue){
  var objRE = /^[\w-\.\']{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,}$/;
  return (strValue != '' && objRE.test(strValue));
}

/*//custom checks

	//only check passwords on registration
	if (frmObj.id == "frmRegistration"){
		if (document.getElementById('password').value !=  document.getElementById('conf_password').value){
			errMessage = errMessage + "\n" + " please make sure that your passwords match";
		}
	}*/