// JavaScript Document
function Close()
{
window.close();
}
function nuevoAjax(){
	var xmlhttp=false;
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E){
			xmlhttp = false;
		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	
	return xmlhttp;
}

function check_form()
{
			student_1=document.form.student.value ;
		  	email_1=document.form.email.value ;
			//message_1=document.form.message.value ;
			 
			 if(student_1=='' || empty(student_1) == false) 
				{
				alert("Enter student's name");
				document.form.student.focus();
				return false;
				}
				
			 if(email_1=='' || empty(email_1) == false) 
				{
				alert("Enter a email");
				document.form.email.focus();
				return false;
				}
			if (EsEmail(email_1) == false)
				{
				alert("write the email correctly !");							
				document.form.email.focus();
				return false;
				}
			 /*if(message_1=='' || empty(message_1) == false) 
				{
				alert("Enter a message");
				document.form.message.focus();
				return false;
				}*/
				return true ;
				
}
function empty(q) 
	{   
	    
        
		for ( i = 0; i < q.length; i++ ) {   
                if ( q.charAt(i) != " " ) {   
                        return true   
                }   
        }   
        return false
	}
function EsEmail(sText) {
  
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(sText)){
      return (true);
  } else {
      return (false);
  }
 }	

function selectAllBoxes(chkObj, classNameFlag)
{
	var formObj = chkObj.form;
	
	for(var i=0; i<formObj.elements.length; i++)
	{
		if(formObj.elements[i].type.toLowerCase() == "checkbox")
		{
			if(formObj.elements[i].className.toLowerCase() == classNameFlag.toLowerCase())
			{
				formObj.elements[i].checked = chkObj.checked;
			}
		}
	}
}

function validate_form(){ 
var pepez=0; 
for(i=0; ele=document.form.elements[i]; i++){ 
if (ele.type=='checkbox') 
if (ele.checked){pepez=1;break;}} 
if (pepez==1){document.form.submit();}else{ 
alert('You must tick 2 or more codes');return false;} 
} 
function validate_form_student_()
{
				
			first_name_1=document.form.first_name.value ;
		  	last_name_1=document.form.last_name.value ;			
			post_code_1=document.form.post_code.value ;
			email_1=document.form.email.value ;
			username=document.form.user_name.value ;
			passw=document.form.password.value ;
			code_1=document.form.code.value ;
			type_payment=document.form.payment ;		
			type_gender=document.form.gender ;
			
			gender_=getRadioButtonSelectedValue(type_gender);
						
			payment_1=getRadioButtonSelectedValue(type_payment);
			
				
			 if(first_name_1=='' || empty(first_name_1) == false) 
				{
				alert("Enter your first name");
				document.form.first_name.focus();
				return false;
				
				}
			if(last_name_1=='' || empty(last_name_1) == false) 
				{
				alert("Enter your last name");
				document.form.last_name.focus();
				return false;
				
				}
					
			if(gender_ !='f' && gender_ !='m')
				{				
					
					alert("Select a gender");
				
					return false;																
				}
			
			
			if(post_code_1=='' || empty(post_code_1) == false) 
				{
				alert("Enter your post code");
				document.form.post_code.focus();
				return false;
				
				}
			if(email_1=='' || empty(email_1) == false) 
				{
				alert("Enter your email");
				document.form.email.focus();
				return false;
				
				}
			
			if(email_1 !='')
				{
					if (EsEmail(email_1) == false)
						{
							alert("write the email correctly !");							
							document.form.email.focus();
							return false;
						}
				}
			
					
			if(username=='' || empty(username) == false) 
				{
				alert("Enter your username");
				document.form.user_name.focus();
				return false;
				
				}
					
			if(passw=='') 
				{
				alert("Enter your password");
				document.form.password.focus();
				return false;
				
				}
				
			if(payment_1=="code")
				{
				if(code_1=='' || empty(code_1) == false) 
					{
						alert("Enter your code");
						document.form.code.focus();
						return false;
					}				
								
				}
				
			if(payment_1 !='code' && (email_1=='' || empty(email_1) == false ))	
				{
				
				alert("You must enter your email !");	
				return false;
					
				}
				
			if( form.agree.checked ==false)
				{		
				form.agree.focus();
				alert("Tick on terms and conditions");	
				return false;
				}
			
															
             return true ;


}

function removespace(cad)
{
	while (cad.indexOf(' ')==0)
	{
		cad=cad.substr(1,cad.length-1);
	}
	return cad
}
 function getRadioButtonSelectedValue(ctrl)
{
    for(i=0;i<ctrl.length;i++)
        if(ctrl[i].checked) return ctrl[i].value;
} 