<!--  hide script from old browsers 

function Form_Validator(theForm)
// used by web editor to capture content
{
	if (document.getElementById('editor1')) {
		document.getElementById('editor1').EscapeUNICODE = true;
		document.getElementById('xhtml1').value = document.getElementById('editor1').value;
	} else {
		document.getElementById('xhtml1').value = document.getElementById('alternate1').value;
	}
  return (true);
}

function buyvalidate(theForm) 
{
	if(theForm.getElementsByTagName('select').length>0)
	{
		selects=theForm.getElementsByTagName('select')
		for(i=0;i<selects.length;i++)
		{
		var mess = selects[i][selects[i].selectedIndex].text.toLowerCase()
		//var temp = selects[i].value.toLowerCase()
		if (mess.indexOf("select")>-1||mess.indexOf("choose")>-1)
			{
			alert("Please "+mess+" to continue");
			selects[i].focus();
			return false;
			}
		}
return true;
	}
}

function trimAll(sString) 
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}
// validates form puts error in buttonholder if it exists exist it
// writes the error before the submit button
function checkform(of)
{
	var checkarray,em,i,f,ty;
	/* Changes from form example */
	// reading all the labels and placing them in an associative 
	// array
	var labels,fieldnames;
	fieldnames=new Array();
	if(document.getElementsByTagName('label').length>0)
	{
		labels=document.getElementsByTagName('label');
		for(i=0;i<labels.length;i++)
		{
			fieldnames[labels[i].htmlFor]=labels[i].firstChild.nodeValue;
		}
	}
	
	/* reset hilighted fields */
	for(var i=0;i<document.getElementsByTagName('input').length;i++)
		{
		document.getElementsByTagName('input')[i].className='notselected';
		}

	/* if old error message exists remove it */
	if(document.getElementById('errormsg')){
		em=document.getElementById('errormsg');
		em.parentNode.removeChild(em);
	}
	
	if(document.getElementById('required'))
	{
		checkarray=document.getElementById('required').value.split(',');
		for(i=0;i<checkarray.length;i++)
		{
			f=document.getElementById(checkarray[i]);
			if(f){
				ty=f.type.toLowerCase();
				switch(ty)
				{
					case 'text':
						if(f.value==''){adderr(f.id,fieldnames[f.id]+' is required',of)}							
					break;
					case 'file':
						if(f.value==''){adderr(f.id,fieldnames[f.id]+' is required',of)}							
					break;
					case 'password':
						if(f.value==''){adderr(f.id,fieldnames[f.id]+' is required',of)}							
					break;
					case 'textarea':
						if(f.value==''){adderr(f.id,fieldnames[f.id]+' is required',of)}							
					break;
					case 'checkbox':
						if(!f.checked){adderr(f.id,fieldnames[f.id]+' must be checked',of)}							
					break;
					case 'select-one':
		//document.getElementById('keywords').appendChild(document.createTextNode(f.value+" "));
						if(!f.value!=''){adderr(f.id,fieldnames[f.id]+' must be selected',of)}							
					break;
					/* extend as needed */
				}
			}
			}
			

			if(document.getElementById('requiredradios'))	{
			checkarray=document.getElementById('requiredradios').value.split(',');
			for(i=0;i<checkarray.length;i++){
			f=document.getElementById(checkarray[i]);
			if(!getRadioValue(checkarray[i])){
				adderr(f.id,fieldnames[checkarray[i]]+' is required!',of)
			}
			}
			}
			
			if(document.getElementById('maxchar'))	{
			checkarray=document.getElementById('maxchar').value.split(',');
			for(i=0;i<checkarray.length;i++){
			f=document.getElementById(checkarray[i].split('=')[0]);
			if (f.value.length > checkarray[i].split('=')[1]) {
				adderr(f.id,fieldnames[f.id]+' has too many characters max.='+checkarray[i].split('=')[1],of)
				break;
				}
			}
			}
			
			if(document.getElementById('minchar'))	{
			checkarray=document.getElementById('minchar').value.split(',');
			for(i=0;i<checkarray.length;i++){
			f=document.getElementById(checkarray[i].split('=')[0]);
			if (f.value.length < checkarray[i].split('=')[1] && f.value.length != 0) {
				adderr(f.id,fieldnames[f.id]+' has too few characters min.='+checkarray[i].split('=')[1],of)
				break;
				}
			}
			}
			
			if(document.getElementById('valemail'))	{
			checkarray=document.getElementById('valemail').value.split(',');
			for(i=0;i<checkarray.length;i++){
			f=document.getElementById(checkarray[i]);
			if(f.value.length > 0 && !isEmailAddr(trimAll(document.getElementById(f.id).value))){
				adderr(f.id,fieldnames[f.id]+' is not a valid email address',of)
				break;
				}
			}
			}
			
			if(document.getElementById('valnumber'))	{
			checkarray=document.getElementById('valnumber').value.split(',');
			for(i=0;i<checkarray.length;i++){
			f=document.getElementById(checkarray[i]);
			if(f.value.length > 0 && !IsNumeric(document.getElementById(f.id).value)){
				adderr(f.id,fieldnames[f.id]+' is not a number',of)
				break;
				}
			}
			}
			
			if(document.getElementById('valdate'))	{
			checkarray=document.getElementById('valdate').value.split(',');
			for(i=0;i<checkarray.length;i++){
			f=document.getElementById(checkarray[i]);
			if(f.value.length > 0 && !isDate(document.getElementById(f.id).value)){
				adderr(f.id,fieldnames[f.id]+' is not a valid date',of)
				break;
				}
			}
			}

			if(document.getElementById('valccnum'))	{
			checkarray=document.getElementById('valccnum').value.split(',');
			for(i=0;i<checkarray.length;i++){
			f=document.getElementById(checkarray[i]);
			if(f.value.length > 0 && !mod10(f.value)){
				adderr(f.id,fieldnames[f.id]+' is not a valid card number',of)
				break;
				}
			}
			}
			
			if(document.getElementById('sameinput'))	{
			checkarray=document.getElementById('sameinput').value.split(',');
			var mymatch = document.getElementById(checkarray[0]).value;
			for(i=0;i<checkarray.length;i++){
			f=document.getElementById(checkarray[i]);
			if(f.value!=mymatch){
				adderr(f.id,fieldnames[f.id]+' is not exactly the same',of)
				break;
				}
			}
			}

	}
	
	if(document.getElementById('errormsg'))
	{
	document.getElementById('errormsg').focus();
	return false;
		
		
	}
}

function getRadioValue(RadioName)
{
var colRadio = document.getElementsByName(RadioName);
var blnResult = false;
for (var i = 0; i < colRadio.length; i++)
{
if (colRadio[i].checked){blnResult = true;}
}
return blnResult;
}


function adderr(id,name,of)
{
 	var se,i,nli,na,newli;
	//i=document.createElement('img');
	//i.src='/creation/images/alert.gif';
	//i.alt='Error';
	//i.title='This field has an error!';
	se=document.getElementById(id);
	//se.parentNode.insertBefore(i,se)
	se.className='selected';
	
	if(!document.getElementById('errormsg')){
		var he=document.createElement('h3');
		he.id='errorhead';
		he.appendChild(document.createTextNode('Slight Problem'))
		var em=document.createElement('p');
		em.appendChild(he);
		em.id='errormsg';
		em.appendChild(document.createTextNode('The form could not be sent because: '))
	/* Changes from form example */
		ul=document.createElement('ul');
		ul.id='errorlist';
		em.appendChild(ul);
	/* end Changes from form example */
	
		if (document.getElementById('buttonholder')) {
				document.getElementById('buttonholder').parentNode.insertBefore(em,document.getElementById('buttonholder'));

		}
		else
		{
			for(var i=0;i<of.getElementsByTagName('input').length;i++)
			{
				if(/submit/i.test(of.getElementsByTagName('input')[i].getAttribute('type')))
				{
					var sb=of.getElementsByTagName('input')[i];
					break;
				}
			}
			sb.parentNode.insertBefore(em,sb);
		}
	}
	/* create problem list */
	newli=document.createElement('li');
	newa=document.createElement('a');
	newa.appendChild(document.createTextNode(name));
	newa.href='#'+id;
	newa.isid=id;
	newa.onclick=function()
	{
		document.getElementById(this.isid).focus();
		return false;
	}
	newli.appendChild(newa)
/* Changes end */
	
	document.getElementById('errorlist').appendChild(newli);
	
	/* end Changes from form example */
}

function isEmailAddr(str) 
{
    return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function mod10( cardNumber ) { // LUHN Formula for validation of credit card numbers.
	var ar = new Array( cardNumber.length );
	var i = 0,sum = 0;

   	for( i = 0; i < cardNumber.length; ++i ) {
   		ar[i] = parseInt(cardNumber.charAt(i));
   	}
   	for( i = ar.length -2; i >= 0; i-=2 ) { // you have to start from the right, and work back.
   		ar[i] *= 2;							 // every second digit starting with the right most (check digit)
   		if( ar[i] > 9 ) ar[i]-=9;			 // will be doubled, and summed with the skipped digits.
   	}										 // if the double digit is > 9, ADD those individual digits together 


       	for( i = 0; i < ar.length; ++i ) {
       		sum += ar[i];						 // if the sum is divisible by 10 mod10 succeeds
       	}
       	return (((sum%10)==0)?true:false);	 	
}

function expired( month, year ) {
	var now = new Date();							// this function is designed to be Y2K compliant.
	var expiresIn = new Date(year,month,0,0,0);		// create an expired on date object with valid thru expiration date
	expiresIn.setMonth(expiresIn.getMonth()+1);		// adjust the month, to first day, hour, minute & second of expired month
	if( now.getTime() < expiresIn.getTime() ) return false;
	return true;									// then we get the miliseconds, and do a long integer comparison
}

		
function update_frame(myoptions) 
{
        destination = myoptions[myoptions.selectedIndex].value;
        if (destination == "null")
        {
                return true;
        }
		
		window.open(destination, '_self');
        myoptions.selectedIndex = 0;

        return true;
}

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		 if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "external"){
		anchor.target = "_blank";
		anchor.title = "Opens in a new window"; 
    	anchor.className = 'external'; 
		}
		else if (anchor.getAttribute("href") &&
		anchor.getAttribute("href").indexOf(".asp")!=-1)
		{

		}
		else if (anchor.getAttribute("href") &&
		anchor.getAttribute("href").indexOf(".pdf")!=-1 | anchor.getAttribute("href").indexOf(".ppt")!=-1 | anchor.getAttribute("href").indexOf(".doc")!=-1 | anchor.getAttribute("href").indexOf(".jpg")!=-1 | anchor.getAttribute("href").indexOf(".gif")!=-1){
		anchor.target = "_blank";
		anchor.title = "Opens in a new window"; 
    	anchor.className = 'external'; 
		}
	}
}
function popupwindow_setup()
{
	for (alink in document.links)
	{
		if (document.links[alink].href)
		{
			if (document.links[alink].className == 'popup')
			{
				document.links[alink].onclick = function(){popupwindow_open(this.href);return false;};
			}
		}
	}
}

function popupwindow_open(theurl)
{
	window.open(theurl, 'InfoPopupWindow', 'width=600,height=400,scrollbars=1', false);
}

function addMyScriptsEvent(elm, evType, fn, useCapture)
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
// By Scott Andrew
{
  if (elm.addEventListener){
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent){
    var r = elm.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
} 

addMyScriptsEvent(window, "load", externalLinks);
addMyScriptsEvent(window, "load", popupwindow_setup);
// end hiding script from old browsers -->

