/* OMG make javascript functions returned by ajax parse-able by adding them to the DOM! */
function parseScript(_source) {
	var source = _source;
	var scripts = new Array();
	
	// Strip out tags
	while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
		var s = source.indexOf("<script");
		var s_e = source.indexOf(">", s);
		var e = source.indexOf("</script", s);
		var e_e = source.indexOf(">", e);
		
		// Add to scripts array
		scripts.push(source.substring(s_e+1, e));
		// Strip from source
		source = source.substring(0, s) + source.substring(e_e+1);
	}
	
	// Loop through every script collected and eval it
	for(var i=0; i<scripts.length; i++) {
		try {
			eval(scripts[i]);
		}
		catch(ex) {
			// do what you want here when a script fails
		}
	}
	
	// Return the cleaned source
	return source;
	
	alert('source')
}


function MM_jumpMenu(targ,selObj,restore){ //v3.0
  // eval(targ+".location.href='http://dna.asteriks-dev.co.uk/"+selObj.options[selObj.selectedIndex].value+"'");
  eval(targ+".location.href='http://www.dnakids.co.uk/"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function showpuzzle(thetype){
	if (window.XMLHttpRequest) {
		liveSearchReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var thetime= "&thetime="+new Date().getTime();
	liveSearchReq.open("GET","getpuzzlee.html?flashsrc="+thetype+thetime,false);
	liveSearchReq.send(null);

	if (liveSearchReq.readyState == 4) {
		var  res = document.getElementById("puzzlediv");
		res.innerHTML = parseScript(liveSearchReq.responseText);
	}
}

/* for the region map */
var startzindex = '2';

function resetto(targetName)
{
	document.getElementById(targetName).style.zIndex = startzindex;
	startzindex++;
}


function validate_form(theform)
{
	if(Trim(document.getElementById("fullname").value)=="") {
					alert("Please enter your full name");
					document.getElementById("fullname").focus();
					return false;
	}
	if(Trim(document.getElementById("mobtel").value)=="") {
					alert("Please enter a contact telephone number");
					document.getElementById("mobtel").focus();
					return false;
	}
	if(Trim(document.getElementById("email").value)=="") {
					alert("Please enter an email address");
					document.getElementById("email").focus();
					return false;
	}
	if(Trim(document.getElementById("dateob").value)=="") {
					alert("Please enter your date of birth");
					document.getElementById("dateob").focus();
					return false;
	}
	if(Trim(document.getElementById("makemodel").value)=="") {
					alert("Please enter your vehicle make and model");
					document.getElementById("makemodel").focus();
					return false;
	}
	if(Trim(document.getElementById("own_vehicle").value)=="") {
					alert("Please state whether you own your vehicle");
					document.getElementById("own_vehicle").focus();
					return false;
	}
	if(Trim(document.getElementById("purchase").value)=="") {
					alert("Please state if you are in a position to purchase your own disco equipment in the near future");
					document.getElementById("purchase").focus();
					return false;
	}

	return true;
}

function Trim(myval)
{
                var chklen=myval.length; 
                var pos=0;
                mychar = myval.charAt(0);

                while(pos>=0 || lstpos >=0)
                {
                                pos=myval.indexOf(" ");
                                if (pos==0)
                                {
                                                myval=myval.substring(1,chklen);
                                                chklen = myval.length;
                                                mychar = myval.charAt(0);
                                }
                                lstpos=myval.lastIndexOf(" ");

                                if (lstpos==chklen-1)
                                {               
                                                myval=myval.substring(0,chklen-1);
                                                chklen=myval.length;
                                                mychar = myval.charAt(chklen-1);
                                }
                                
                                if(mychar!=" ")
                                                break;

                }
                return myval;                                        
}