//Form validation
function checkform(of)
		{
		// Test if DOM is available and there is an element called required
			if(!document.getElementById || !document.createTextNode){return;}
			if(!document.getElementById('required')){return;}

		// Define error messages and split the required fields
			var errorID='errormsg';
			var errorClass='error'
			var errorMsg='Please enter or change the fields marked with a ';
			var privacyMsg='Before continuing please indicate that you have	read and accepted our privacy Policy by clicking the checkbox above';
			var errorAlt='Error';
			var errorTitle='This field has an error!';
			var reqfields=document.getElementById('required').value.split(',');

		// Cleanup old mess
			// if there is an old errormessage field, delete it
			if(document.getElementById(errorID))
			{
				var em=document.getElementById(errorID);
				em.parentNode.removeChild(em);
			}
			// remove old images and classes from the required fields
			for(var i=0;i<reqfields.length;i++)
			{
				var f=document.getElementById(reqfields[i]);
				if(!f){continue;}
				if(f.previousSibling && /img/i.test(f.previousSibling.nodeName))
				{
					f.parentNode.removeChild(f.previousSibling);
				}
				f.className='';
			}
		// loop over required fields
			for(var i=0;i<reqfields.length;i++)
			{
		// check if required field is there
				var f=document.getElementById(reqfields[i]);
				var fc=document.getElementById('email1');
				if(!f){continue;}
		// test if the required field has an error, 
		// according to its type
				switch(f.type.toLowerCase())
				{
					case 'text':
						if(f.value=='' && f.id!='email1' && f.id!='email1_confirm'){cf_adderr(f)}							
		// email is a special field and needs checking
						if(f.id=='email1' && !cf_isEmailAddr(f.value)) {cf_adderr(f)}
						if(f.id=='email1_confirm')
							{
							if (f.value=='' || f.value != fc.value || !cf_isEmailAddr(f.value))
								{cf_adderr(f)}
						   }
					break;
					case 'textarea':
						if(f.value==''){cf_adderr(f)}							
					break;
					case 'checkbox':
						if(!f.checked){
							cf_adderr(f)}							
					break;
					case 'select-one':
						if(!f.selectedIndex && f.selectedIndex==0 && f.value==''){cf_adderr(f)}							
					break;
				}
			}
			return !document.getElementById(errorID);

			/* Tool methods */
			function cf_adderr(o)
			{
				// create image, add to and colourise the error fields
				var errorIndicator=document.createElement('img');
				errorIndicator.alt=errorAlt;
				errorIndicator.src=errorImg;
				errorIndicator.title=errorTitle;
				o.className=errorClass;
				o.parentNode.insertBefore(errorIndicator,o);

			// Check if there is no error message
				if(!document.getElementById(errorID))
				{
				// create errormessage and insert before submit button
					var em=document.createElement('div');
					em.id=errorID;
					var newp=document.createElement('p');
					newp.appendChild(document.createTextNode(errorMsg))
					// clone and insert the error image
					newp.appendChild(errorIndicator.cloneNode(true));
					em.appendChild(newp);
					// find the submit button 
					for(var i=0;i<of.getElementsByTagName('input').length;i++)
					{
						if(/submit/i.test(of.getElementsByTagName('input')[i].type))
						{
							var sb=of.getElementsByTagName('input')[i];
							break;
						}
					}
					if(sb)
					{
						sb.parentNode.insertBefore(em,sb);
					}	
				} 
			}
			function cf_isEmailAddr(str) 
			{
			    return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
			}
		}
function popUp(strURL,strType,strHeight,strWidth) {
var strOptions="";
var winl = (screen.width - strWidth) / 2;
var wint = (screen.height - strHeight) / 2;
if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth+",top="+wint+",left="+winl;
if (strType=="semiconsole") strOptions="resizable,scrollbars,height="+strHeight+",width="+strWidth+",top="+wint+",left="+winl;
//if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth+",top="+wint+",left="+winl;
if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth+",top="+wint+",left="+winl;
window.open(strURL, 'newWin', strOptions);
}
//
window.onload = function()
/* - this tells the browser to load the new table class from the CSS, namely “.hover” - */
{
  var table = document.getElementsByTagName("table");
  for(var t = 0; t < table.length; t++){
   table[t].onmouseover = function(){
    this.className += " hover";
   }
   table[t].onmouseout = function(){
    this.className = this.className.replace("hover", "");
   }
  }
/* - same as above, except this gets the class, of the same name, assigned to tr or table row  - */
{
  var tr = document.getElementsByTagName("tr");
  for(var r = 0; r < tr.length; r++){
   tr[r].onmouseover = function(){
    this.className += " hover";
   }
   tr[r].onmouseout = function(){
    this.className = this.className.replace("hover", "");
   }
  }
}
/* - same as above, for Input Buttons - */
 var zinput = document.getElementsByTagName("input");
  for(var t = 0; t < zinput.length; t++){
   zinput[t].onmouseover = function(){
    this.className += " hover";
   }
   zinput[t].onmouseout = function(){
    this.className = this.className.replace("hover", "");
   }
  }
}

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=/";
}
createCookie("tst_c","123",1);