/* Clear  placeholding text in form text fields */

function isOkToProcess() {
	c = document.getElementById('tAndCsCheck').checked;
	if(c == false) {
		alert("Please read the terms and conditions.");
		return(false);
	}
	return(true);
}

function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else{
		var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
}


function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return(null);
}

function eraseCookie(name){
	createCookie(name,"",-1);
}

function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

function validateEmail(el) {
	strng = document.getElementById(el).value;
	var emailFilter = /^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) { 
		   alert("Please enter a valid email address.");
		   return(false);
	}
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	if (strng.match(illegalChars)) {
	   alert("The email address contains illegal characters.");
		return(false);
	}
	return(true);
}

/*  toggle layer visibility */


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	} else {
		el.style.display = '';
	}	
}


function swapImage(id, isrc) {
	document.getElementById(id).src = isrc;
}

// display decision alert box
function decision(message, url){
	if(confirm(message)) location.href = url;
}

// open browser window
function openPopUp(url, windowName, w, h, scrollbar) {

           
		   var winl = (screen.width - w) / 2;
           var wint = (screen.height - h) / 2;
           winprops = 'height=600,width=600,top='+wint+',left='+winl+',scrollbars=no,resizable=no';
		   win = window.open(url, windowName, winprops);
           if (parseInt(navigator.appVersion) >= 4) { 
              	win.window.focus(); 
           } 
}

function openPopUpResize(url, windowName, w, h, scrollbar) {

           
		   var winl = (screen.width - w) / 2;
           var wint = (screen.height - h) / 2;
           winprops = 'height=600,width=600,top='+wint+',left='+winl+',scrollbars=yes,resizable=yes';
		   win = window.open(url, windowName, winprops);
           if (parseInt(navigator.appVersion) >= 4) { 
              	win.window.focus(); 
           } 
}

function jumpMenu(target,object,restore){ 
  eval(target+".location='"+object.options[object.selectedIndex].value+"'");
  if (restore) object.selectedIndex=0;
}

function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); 
  return x;
}

function getImage(imageName)
{
		findObj('img').src = imageName;
}

function submitForm(el) {
	if(e = document.getElementById(el)) {
		e.submit;
	}
}

function submitDoc(formName) { 
  var obj;
 
	if (obj=findObj(formName)!=null) 
	{
		findObj(formName).submit(); 
	}
	else 
	{
		alert('The form you are attempting to submit called \'' + formName + '\' couldn\'t be found. Please make sure the submitDoc function has the correct id and name.');
	}

}
