 //  check for valid numeric strings	
function IsNumeric(strString) {
   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;
}


function check_details() {
	jsCrLf = String.fromCharCode(10,13);
	var error='';
	var error_msg = 'Please complete the following before continuing:'+jsCrLf;
	var error_found='';

	if (document.newtalent.M_fname.value == '') {
		error=error+' - First Name'+jsCrLf; error_found ='found';}
				
	if (document.newtalent.M_lname.value == '') {
		error=error+' - Last Name'+jsCrLf; error_found ='found';}

	if (document.newtalent.M_dob_day.value == '' || document.newtalent.M_dob_month.value == '' || document.newtalent.M_dob_year.value == '') {
		error=error+' - Date of Birth'+jsCrLf; error_found ='found';
	} else if (!IsNumeric(document.newtalent.M_dob_day.value) || !IsNumeric(document.newtalent.M_dob_month.value) || !IsNumeric(document.newtalent.M_dob_year.value)) {	
		error=error+' - Date of Birth'+jsCrLf; error_found ='found';
	}

	if (document.newtalent.email.value == '') {
		error=error+' - Email Address'+jsCrLf; error_found ='found';}
		
	if (document.newtalent.tel.value == '') {
		error=error+' - Telephone Number'+jsCrLf; error_found ='found';}
	
	if (document.newtalent.M_address_old.value == '') {
		error=error+' - Address'+jsCrLf; error_found ='found';}	
		
	if (document.newtalent.M_city.value == '') {
		error=error+' - City / Town'+jsCrLf; error_found ='found';}		

	if (document.newtalent.postcode.value == '') {
		error=error+' - Postcode'+jsCrLf; error_found ='found';}	
		
	if (document.newtalent.M_referal.value == '') {
		error=error+' - Where did you hear about StartinTV?'+jsCrLf; error_found ='found';}

	if (document.newtalent.M_password1.value == '') {
		error=error+' - Password'+jsCrLf; error_found ='found';}

	if (document.newtalent.M_password1.value != document.newtalent.M_password2.value) {
		error=error+' - Passwords need to match'+jsCrLf; error_found ='found';}

		if (typeof(document.newtalent.alreadyThere)!='undefined'){
			if (document.newtalent.alreadyThere.value == '1') {
				error=error+' - This email exists - either use a different one, or tick the renew subscription box'+jsCrLf; error_found ='found';}
		}


	/* remove when NUS format confirmed */
	if (!document.newtalent.M_nus.value.length==0) {
		document.newtalent.amount.value = '35.00';
		document.newtalent.desc.value = 'NUS New Talent Registration';
	}

	/* reuse when NUS format confirmed
	if (!document.newtalent.M_nus.value.length==0){
		if (document.newtalent.M_nus.value.length!=18) {
			error=error+' - NUS Number needs to be valid'+jsCrLf; error_found ='found';}
		else {
			document.newtalent.amount.value = '35.00';
			document.newtalent.desc.value = 'NUS New Talent Registration';
		}
	}
	*/
	

	document.newtalent.name.value=document.newtalent.M_fname.value+' '+document.newtalent.M_lname.value;
	if (error_found == 'found') {window.alert(error_msg+error);return false;} 
	
	if (!document.newtalent.email.value.match(/^(.+)@(.+)$/)) {
		error='Please enter a valid email address';window.alert(error);return false;}

	if (document.newtalent.terms.checked == false) {
		error=error+'Please Agree to Terms and Conditions.'+jsCrLf;window.alert(error);return false;}
	
	document.newtalent.address.value = document.newtalent.M_address_old.value+', '+document.newtalent.M_city.value;
	
		
}








//-----------------------------------------------------------------------------------------------------------------------------------------------------------
function ajax(resultSpaceId,ajaxURL){


	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		xmlHttpReq = new XMLHttpRequest();
		xmlHttpReq.overrideMimeType('text/xml');
	}
	// IE
	else if (window.ActiveXObject) {
		xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlHttpReq.open('POST', ajaxURL, true);
	
	xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttpReq.onreadystatechange = function() {
		if (xmlHttpReq.readyState == 4) {

			outnode=document.getElementById(resultSpaceId);
			outnode.innerHTML=xmlHttpReq.responseText;

		}
	}
	xmlHttpReq.send('');	
}



