function isnumber(arg){	
	var oldstring = arg; 
	var newstring = parseFloat(arg).toString();
		
	if(oldstring.length == newstring.length && newstring != "NaN")
	{
		return 1;
	}
	else
	{
		return 0;
	}	
}

//Sets the current address to the permanent address
function set(){
	if(document.app.padd.checked==true)
	{
		document.app.cstreet.value=document.app.pstreet.value;      				
		document.app.capt.value=document.app.papt.value;    				
		document.app.ccity.value=document.app.pcity.value;					
		document.app.cstate.value=document.app.pstate.value;					
		document.app.czip.value=document.app.pzip.value;    				
		document.app.cctry.value=document.app.pctry.value;					
		document.app.cphone.value=document.app.pphone.value;					
	}
	else
	{
		document.app.cstreet.value="";      				
		document.app.capt.value="";    				
		document.app.ccity.value="";					
		document.app.cstate.value="";					
		document.app.czip.value="";    				
		document.app.cctry.value="";					
		document.app.cphone.value="";	
	}
}
		
function enable_citizen(){			
	if(document.app.citizen.value=="No")
	{
		document.app.per_resident.disabled=false;
		enable_per_resident();
	}
	else
	{
		document.app.per_resident.disabled=true;
		document.app.alien_no.disabled=true;
	}
}
function enable_per_resident(){
	if(document.app.per_resident.value=="Yes")
		document.app.alien_no.disabled=false;
	if(document.app.per_resident.value=="No")
		document.app.alien_no.disabled=true;
}

// Changes the page to the selected school's UGR application
function change_page(arg){
	switch(arg){
		case 0:
		   	window.location="?school=TAMU";
		   	break;
		case 1:
		   	window.location="?school=TAMUCC";
		  	break;
		case 2:
		   	window.location="?school=PVAMU";
		  	break;
	}
}	
		
function tamu_validation(){
		
	var check = 0; //Used for other required fields
	var check2 = 0; //Used for UIN checks
	
	if(
		document.app.uin.value=='' || document.app.fname.value=='' || document.app.lname.value=='' || 
		document.app.bmonth.value=='' || document.app.bday.value=='' || document.app.byear.value=='' || document.app.gender.value=='' || document.app.race.value=='' || 
		document.app.pstreet.value=='' || document.app.pcity.value=='' || document.app.pstate.value=='' || document.app.pzip.value=='' || document.app.pctry.value=='' || 
		document.app.cstreet.value=='' || document.app.ccity.value=='' || document.app.cstate.value=='' || document.app.czip.value=='' || document.app.cctry.value=='' || 
		document.app.cell.value=='' || document.app.email.value=='' || document.app.pers_email.value=='' || 
		document.app.gpa.value=='' || document.app.major.value=='' || document.app.mentor.value=='' || document.app.pers_stat.value=='' || document.app.agree.value==''
	)
	{
		check = check + 1;
	}		
	if(document.app.per_resident.value == "Yes" && document.app.citizen.value == "No"){
		if(document.app.alien_no.value == ''){
			check = check + 1;
		}
	}
	if(isnumber(document.app.uin.value) == 0){				
		check2 = check2 + 1;
	}
	
	if(check2 != 0){
		alert("The UIN that you entered is not valid.");
	}
	else if(check != 0){
		alert("You must fill out all required fields before proceeding.");
	}			
	else{
		check_conf();						
	}
	
}		
		
function tamucc_validation(){

	var check = 0;
	
	if(
		document.app.uin.value=='' || document.app.fname.value=='' || document.app.lname.value=='' || 
		document.app.bmonth.value=='' || document.app.bday.value=='' || document.app.byear.value=='' || document.app.gender.value=='' || document.app.race.value=='' || document.app.citizen.value=='' || 
		document.app.pstreet.value=='' || document.app.pcity.value=='' || document.app.pstate.value=='' || document.app.pzip.value=='' || document.app.pctry.value=='' || 
		document.app.cstreet.value=='' || document.app.ccity.value=='' || document.app.cstate.value=='' || document.app.czip.value=='' || document.app.cctry.value=='' || 
		document.app.cell.value=='' || document.app.email.value=='' || 
		document.app.gpa.value=='' || document.app.major.value=='' || document.app.mentor.value=='' || document.app.agree.value==''
	)
	{
		check = check + 1;
	}	
		
	if(check != 0){
		alert("You must fill out all required fields before proceeding.");
	}			
	else{
		check_conf();						
	}
	
}


function pvamu_validation(){

	var check = 0;
	var check2 = 0;
	
	if(
		document.app.uin.value=='' || document.app.fname.value=='' || document.app.lname.value=='' || 
		document.app.bmonth.value=='' || document.app.bday.value=='' || document.app.byear.value=='' || document.app.gender.value=='' || document.app.race.value=='' || document.app.citizen.value=='' || 
		document.app.pstreet.value=='' || document.app.pcity.value=='' || document.app.pstate.value=='' || document.app.pzip.value=='' || document.app.pctry.value=='' || 
		document.app.cstreet.value=='' || document.app.ccity.value=='' || document.app.cstate.value=='' || document.app.czip.value=='' || document.app.cctry.value=='' || 
		document.app.cell.value=='' || document.app.email.value=='' || 
		document.app.gpa.value=='' || document.app.major.value=='' || document.app.mentor.value=='' || document.app.agree.value==''
	)
	{
		check = check + 1;
	}	
	
	if(isnumber(document.app.uin.value) == 0){				
		check2 = check2 + 1;
	}
	
	if(check2 != 0){
		alert("The UIN that you entered is not valid.");
	}
	else if(check != 0){
		alert("You must fill out all required fields before proceeding.");
	}			
	else{
		check_conf();	
	}
	
}

// Checks if applicant has agreed to the terms and conditions
 function check_conf(){
	var conf = confirm("Proceed with submission?");
	 if(conf == true){				
	//	if(document.app.agree.checked==true){ 
			document.app.submit();
	//	}
	//	else{
	//		alert("You must agree to the terms and conditions before submitting your application.");
		}							
	//}						
} 