// JavaScript Document
 // GLOBAL VARIABLE FOR DISPLAYING AJAX MESSAGES
 var throbber = "http://portal.campus-connect.com/images/campus_throbber.gif";
 var campusComment='mainContents';
	// ---------------------------------------------------------------------------------------
	//To check the availability of a username
			function checkUsername()
			{
				if(document.registration.username.value=="")
				{
				document.getElementById('availability').innerHTML = "Check Availability";
				}
				else
				{
			createRequest();
			var username=document.registration.username.value;
			var url="registrationServer.php?action=checkUsername";
			request.open("POST", url, true);
			request.onreadystatechange = checkUsername_showStatus;
			request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			request.send("username=" + encodeURIComponent(username));
				}
			}
			
			function checkUsername_showStatus()
			{
			if(request.readyState == 1 || request.readyState == 2 || request.readyState == 3)
				{
				document.getElementById('availability').innerHTML = "Checking Availability..";
				}
			if(request.readyState == 4)
				{
				if(request.responseText==0)
					{
						document.getElementById('availability').innerHTML = "Not Available";
						document.registration.username.value="";
						document.registration.username.focus();
						return false;
					}
				else
					{
					document.getElementById('availability').innerHTML = "Available";
					return true;
					}			
				}
			}
//------------------------------------------------------------------------------------------
// CHECK THE EXISTANCY OF THE MAIL ENTERED			
		function checkMail()
			{
			createRequest();
			var email = document.registration.email.value;
			var url = "registrationServer.php?action=checkEmail";
			request.open("POST", url, true);
			request.onreadystatechange = checkMail_showStatus;
			request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			request.send("email=" + encodeURIComponent(email));			
			}
		function checkMail_showStatus()
			{
				if(request.readyState == 4)
					{
						if(request.responseText==0)
							{
								document.getElementById('addcomment_email').innerHTML="The mail id that you have entered is already existing in our database or blank field.";
								
							}
					}
			}			
//-----------------------------------------------------------------------------------------
function checkCG()
{    
		if (document.registration.checkCGPA.checked == true) 
		{
			  if (document.registration.checkper.checked == true) 
		      {
					document.registration.checkper.checked = false;
					document.registration.textCGPA.disabled = false;
					document.registration.textPer.value = "";
					document.registration.textPer.disabled = true;
			  }
		}	  
		else if(document.registration.checkCGPA.checked == false) 
			 {
					document.registration.checkper.checked = true;
			    	document.registration.textCGPA.value = "";
					document.registration.textCGPA.disabled = true;
				    document.registration.textPer.disabled = false;
     		}
	
}
function checkPER()
{
		if(document.registration.checkper.checked == true) 
		{
				if(document.registration.checkCGPA.checked == true) 
				{
					document.registration.checkCGPA.checked = false;
					document.registration.textCGPA.value = "";
					document.registration.textCGPA.disabled = true;
					document.registration.textPer.disabled = false;
		         }
	    }			 
		else if(document.registration.checkper.checked == false) 
	      		{
						if (document.registration.checkCGPA.checked == false) 
					            {
								    document.registration.checkCGPA.checked = true;
								    document.registration.textPer.value ="";
								    document.registration.textPer.disabled = true;
								    document.registration.textCGPA.disabled = false;
					            }
				}
		
}

function select_gender_male()
{
	if (document.registration.male.checked == true)
		{
			document.registration.male.checked = true;
			document.registration.female.checked = false;
			document.registration.gender.value = "M";
		}
	else
		{
			document.registration.female.checked = true;
			document.registration.male.checked = false;
			document.registration.gender.value = "F";
		}
}
function select_gender_female()
{
	if (document.registration.female.checked == true)
		{
			
			document.registration.male.checked = false;
			document.registration.female.checked = true;
			document.registration.gender.value = "F";
		}
	else
		{		
			document.registration.female.checked = false;
			document.registration.male.checked = true;
			document.registration.gender.value = "M";
		}
}



//-------------------------------------------------------------------------------------------
// Email validation
function echeck(str) {
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{
//alert("Please input a valid email address!")
testresults=false
}
return (testresults)
}
//----------------------------------------------------------------------------------------
// Special charecter validation 
	function isSpecialChars(str)
{
    var text=str;
	var alphaExp = /^[a-zA-Z0-9_.]+$/;
	if(!text.match(alphaExp))
		{
	    return true;
		}
	
	else return false ;
		
}


				
//-----------------------------------------------------------------------------------------
// String Validation
function valText(a)
{
  //		var a = text;
  		for(i=0;i<a.length;i++)
			{		
					if((a.charCodeAt(i)<65 && a.charCodeAt(i)!=32 && a.charCodeAt(i)!=46)|| (a.charCodeAt(i)>90 && a.charCodeAt(i)<97)|| 	a.charCodeAt(i)>122)
					{
					
						return false;
					}
			}
  			return true;
 }
 //------------------------------------------------------------------------------------
// Number validation
function valNum(x){
//var x=document.checknum.pnum.value
var anum=/(^\d+$)|(^\d+\.\d+$)/
if (anum.test(x))
testresult=true
else{
testresult=false
}
return (testresult)
}
//// Empty validation 
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
// FLOAT VALIDATION 
var reFloat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/
function isFloat (s)

{   
if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    return reFloat.test(s)
}
// Function to get the Uploaded file id from the session and validate.....
function getUploadedFileId()
	{
		document.registration.failures.value=0;
		createRequest();
		var url = "registrationServer.php?action=getUploadedFileId";
		request.open("POST", url, true);
		request.onreadystatechange = register;
		request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		request.send("email=test");
	}
	
////////  Checking for white space
var reWhitespace = /^\s+$/;

function isWhitespace (s)

{   // Is s empty?
    return (isEmpty(s) || reWhitespace.test(s));
}

//-------------------------------------------------------------------------------------------
// VALIDATE THE FORM AND SUBMIT ......
function register()
	{
		var firstErrorField = "none";
	if(request.readyState == 4)
	{
	if(request.responseText==0)
	{
	alert("Upload file")
	}
	else
	{
		document.registration.resumeid.value=request.responseText;
		// VALIDATE THE FORM ..		
	//******************************************************************
		if(document.registration.username.value=="" || document.registration.username.value.length < 4 || isSpecialChars(document.registration.username.value) == true || document.registration.username.value.indexOf(' ')>1)
			{
				document.getElementById('comment_username').style.color="#FF0000";
				document.getElementById('addcomment_username').innerHTML="User name should be of only characters and atleast 4 characters";
				document.registration.failures.value++;
				if(firstErrorField == "none")
					firstErrorField = document.registration.username;
			}
		else
			{
				document.getElementById('comment_username').style.color="#000000";
				document.getElementById('addcomment_username').innerHTML="";
			}
	//******************************************************************
		if(document.registration.password.value=="")
			{
				document.getElementById('comment_password').style.color="#FF0000";
				document.registration.failures.value++;
				if(firstErrorField == "none")
					firstErrorField = document.registration.password;
			}
		else
				document.getElementById('comment_password').style.color="#000000";
	//*******************************************************************
		if(document.registration.password.value.length < 6)
			{
				document.getElementById('comment_password').style.color="#FF0000";
				document.getElementById('addcomment_password').innerHTML="Password should be of atleast 6 characters";
				document.registration.failures.value++;
				if(firstErrorField == "none")
					firstErrorField = document.registration.password;				
			}
		else
			{
				document.getElementById('addcomment_password').innerHTML="";	
				document.getElementById('comment_password').style.color="#000000";
			}
	//********************************************************************
		if(document.registration.repassword.value=="")
			{
				document.getElementById('comment_repassword').style.color="#FF0000";
				document.registration.failures.value++;
				if(firstErrorField == "none")
					firstErrorField = document.registration.repassword;					
			}	
		else
				document.getElementById('comment_repassword').style.color="#000000";
	//**********************************************************************
		if(document.registration.password.value != document.registration.repassword.value)
			{
				document.getElementById('addcomment_repassword').innerHTML="Passwords are not matching";
				document.getElementById('comment_repassword').style.color="#FF0000";
				document.registration.failures.value++;
				if(firstErrorField == "none")
					firstErrorField = document.registration.password;						
			}
		else
			{
				document.getElementById('addcomment_repassword').innerHTML="";
				document.getElementById('comment_repassword').style.color="#000000";
			}
	//************************************************************************
		if(document.registration.fname.value=="" || valText(document.registration.fname.value) == false)
			{
				document.getElementById('comment_fname').style.color="#FF0000";
				document.registration.failures.value++;
				if(firstErrorField == "none")
					firstErrorField = document.registration.fname;				
			}
		else
				document.getElementById('comment_fname').style.color="#000000";
	//****************************************************************************			
		if(document.registration.lname.value=="" || valText(document.registration.lname.value) == false)
			{
				document.getElementById('comment_lname').style.color="#FF0000";
				document.registration.failures.value++;
				if(firstErrorField == "none")
					firstErrorField = document.registration.lname;						
			}
		else
				document.getElementById('comment_lname').style.color="#000000";		
	//****************************************************************************	
		if(valText(document.registration.mname.value) == false)
			{
				document.getElementById('comment_mname').style.color="#FF0000";
				document.registration.failures.value++;
				if(firstErrorField == "none")
					firstErrorField = document.registration.mname;					
			}
		else
				document.getElementById('comment_mname').style.color="#000000";		
	//****************************************************************************		
	
		if(document.registration.email.value=="")
			{
				document.getElementById('comment_email').style.color="#FF0000";
				document.registration.failures.value++;
				if(firstErrorField == "none")
					firstErrorField = document.registration.email;					
			}
		else
				document.getElementById('comment_email').style.color="#000000";		
	//****************************************************************************			
		if(echeck(document.registration.email.value) == false)
			{
				document.getElementById('comment_email').style.color="#FF0000";
				document.getElementById('addcomment_email').innerHTML="Wrong Email format";
				document.registration.failures.value++;
				if(firstErrorField == "none")
					firstErrorField = document.registration.email;						
			}
		else
			{
				document.getElementById('comment_email').style.color="#000000";		
				document.getElementById('addcomment_email').innerHTML="";
			}
	//*******************************************************************************
		if(document.registration.college.value==0)
			{
				document.getElementById('comment_college').style.color="#FF0000";
				document.registration.failures.value++;	
				if(firstErrorField == "none")
					firstErrorField = document.registration.college;						
			}
			
		else if(document.registration.college.value == 2 && document.registration.otherCollege.value == "")
			{
				document.getElementById('comment_otherCollege').style.color="#FF0000";
				document.getElementById('addcomment_otherCollege').innerHTML="Enter your college name";
				document.registration.failures.value++;	
				if(firstErrorField == "none")
					firstErrorField = document.registration.college;				
			}	
			
		else
			{
				document.getElementById('comment_college').style.color="#000000";
				document.getElementById('addcomment_otherCollege').innerHTML="";
			}
//*******************************************************************************
		if(document.registration.degree.value==0)
			{
				document.getElementById('comment_degree').style.color="#FF0000";
				document.registration.failures.value++;
				if(firstErrorField == "none")
					firstErrorField = document.registration.degree;				
			}			
		else
			{
				document.getElementById('comment_degree').style.color="#000000";
			}
//*******************************************************************************
		if(document.registration.branch.value==0)
			{
				document.getElementById('comment_branch').style.color="#FF0000";
				document.registration.failures.value++;	
				if(firstErrorField == "none")
					firstErrorField = document.registration.branch;
			}
			
		else if(document.registration.branch.value == 2 && document.registration.otherBranch.value == "")
			{
				document.getElementById('comment_branch').style.color="#FF0000";
				document.getElementById('addcomment_otherBranch').innerHTML="Enter your Branch";
				document.registration.failures.value++;	
				if(firstErrorField == "none")
					firstErrorField = document.registration.branch;
			}	
			
		else
			{
				document.getElementById('comment_branch').style.color="#000000";
				document.getElementById('addcomment_otherBranch').innerHTML="";
			}
//*******************************************************************************

		if(document.registration.yop.value==0)
			{
				document.getElementById('comment_yop').style.color="#FF0000";
				document.registration.failures.value++;
				if(firstErrorField == "none")
					firstErrorField = document.registration.yop;				
			}
		else
			{
				document.getElementById('comment_yop').style.color="#000000";
			}			
	//*******************************************************************************			
		if(document.registration.textCGPA.value == "" && document.registration.textPer.value == "")
			{
				document.getElementById('comment_cgpa').style.color="#FF0000";
				document.registration.failures.value++;
				if(firstErrorField == "none")
					firstErrorField = document.registration.textCGPA;				
			}
		else if(document.registration.textCGPA.value != "" && isFloat(document.registration.textCGPA.value) == false)
			{
				document.getElementById('comment_cgpa').style.color="#FF0000";
				document.getElementById('addcomment_cgpa').innerHTML="Wrong CGPA format";
				document.registration.failures.value++;	
				if(firstErrorField == "none")
					firstErrorField = document.registration.textCGPA;					
			}
		else if(document.registration.textCGPA.value != "" && document.registration.textCGPA.value>10)
			{
				document.getElementById('comment_cgpa').style.color="#FF0000";
				document.getElementById('addcomment_cgpa').innerHTML="Wrong CGPA format";
				document.registration.failures.value++;	
				if(firstErrorField == "none")
					firstErrorField = document.registration.textCGPA;					
			}			
		else if(document.registration.textPer.value != "" && isFloat(document.registration.textPer.value) == false)
			{
				document.getElementById('comment_per').style.color="#FF0000";
				document.getElementById('addcomment_per').innerHTML="Wrong percentage format";
				document.registration.failures.value++;	
				if(firstErrorField == "none")
					firstErrorField = document.registration.textPer;				
			}	
		else if(document.registration.textPer.value != "" && document.registration.textPer.value >100)
			{
				document.getElementById('comment_per').style.color="#FF0000";
				document.getElementById('addcomment_per').innerHTML="Wrong percentage format";
				document.registration.failures.value++;	
				if(firstErrorField == "none")
					firstErrorField = document.registration.textPer;				
			}			
		else
			{
				document.getElementById('comment_cgpa').style.color="#000000";
				document.getElementById('comment_per').style.color="#000000";
				document.getElementById('addcomment_cgpa').innerHTML="";
				document.getElementById('addcomment_per').innerHTML="";
			}
	//*******************************************************************************	
		if(document.registration.tenth_yop.value==0)
			{
				document.getElementById('comment_tenth_yop').style.color="#FF0000";
				document.registration.failures.value++;	
				if(firstErrorField == "none")
					firstErrorField = document.registration.tenth_yop;				
			}
		else
			{
				document.getElementById('comment_tenth_yop').style.color="#000000";		
			}
	//***********************************************************************************
		if(document.registration.tenth_percent.value==0 || document.registration.tenth_percent.value=="")
			{
				document.getElementById('comment_tenth_percent').style.color="#FF0000";
				document.registration.failures.value++;	
				if(firstErrorField == "none")
					firstErrorField = document.registration.tenth_percent;					
			}
		else if(document.registration.tenth_percent.value >100 || isFloat(document.registration.tenth_percent.value) == false)
			{
				document.getElementById('comment_tenth_percent').style.color="#FF0000";
				document.getElementById('addcomment_tenth_percent').innerHTML='Wrong percentage format';
				document.registration.failures.value++;	
				if(firstErrorField == "none")
					firstErrorField = document.registration.tenth_percent;					
			}
		else
			{
				document.getElementById('comment_tenth_percent').style.color="#000000";	
				document.getElementById('addcomment_tenth_percent').innerHTML='';
			}
	//***********************************************************************************
		if(document.registration.twelveth_yop.value==0)
			{
				document.getElementById('comment_twelveth_yop').style.color="#FF0000";
				document.registration.failures.value++;	
				if(firstErrorField == "none")
					firstErrorField = document.registration.twelveth_yop;					
			}
		else
			{
				document.getElementById('comment_twelveth_yop').style.color="#000000";		
			}
	//***********************************************************************************		
		if(document.registration.twelveth_percent.value==0 || document.registration.twelveth_percent.value=="")
			{
				document.getElementById('comment_twelveth_percent').style.color="#FF0000";
				document.registration.failures.value++;	
				if(firstErrorField == "none")
					firstErrorField = document.registration.twelveth_percent;					
			}
		else if(document.registration.twelveth_percent.value >100 || isFloat(document.registration.twelveth_percent.value) == false)
			{
				document.getElementById('comment_twelveth_percent').style.color="#FF0000";
				document.getElementById('addcomment_twelveth_percent').innerHTML='Wrong percentage format';
				document.registration.failures.value++;	
				if(firstErrorField == "none")
					firstErrorField = document.registration.twelveth_percent;				
			}
		else
			{
				document.getElementById('comment_twelveth_percent').style.color="#000000";
				document.getElementById('addcomment_twelveth_percent').innerHTML='';
			}
	//*******************************************************************************
		if(valNum(document.registration.phone.value) == false || document.registration.phone.value.length <10 || document.registration.phone.value.length >20)
			{
				document.getElementById('comment_phone').style.color="#FF0000";
				document.registration.failures.value++;	
				if(firstErrorField == "none")
					firstErrorField = document.registration.phone;					
			}
		else
			{
				document.getElementById('comment_phone').style.color="#000000";
			}	
	//*******************************************************************************			
		if(valNum(document.registration.mobile.value) == false || document.registration.mobile.value.length <10 || document.registration.mobile.value.length >20)
			{
				document.getElementById('comment_mobile').style.color="#FF0000";
				document.registration.failures.value++;	
				if(firstErrorField == "none")
					firstErrorField = document.registration.mobile;					
			}
		else
			{
				document.getElementById('comment_mobile').style.color="#000000";
			}		
	//*******************************************************************************			
		if(document.registration.address_current.value=="")
			{
				document.getElementById('comment_address_current').style.color="#FF0000";
				document.registration.failures.value++;		
				if(firstErrorField == "none")
					firstErrorField = document.registration.address_current;					
			}
		else
			{
				document.getElementById('comment_address_current').style.color="#000000";
			}
	//*******************************************************************************			
		if(document.registration.address_permanent.value=="")
			{
				document.getElementById('comment_address_permanent').style.color="#FF0000";
				document.registration.failures.value++;	
				if(firstErrorField == "none")
					firstErrorField = document.registration.address_permanent;					
			}
		else
			{
				document.getElementById('comment_address_permanent').style.color="#000000";
			}
		
	//*******************************************************************************			
		if(document.registration.agree.checked == false)
			{
				document.getElementById('comment_agree').style.color="#FF0000";
				document.registration.failures.value++;	
				if(firstErrorField == "none")
					firstErrorField = document.registration.agree;				
			}
		else
			{
				document.getElementById('comment_agree').style.color="#000000";
			}
	
	///////////////// ALL VALIDATIONS ARE DONE BY THIS ///////////NOW SUBMIT FORM
		if(document.registration.failures.value==0)
			{
				document.registration.submit();	
			}
		else
			{
				firstErrorField.focus();
			}
	}
	}
	}
////////////////////////////////////////////  Managing Drop downs in registration page ///////////////
			function checkOtherCollege()
			{
				if(document.registration.college.value==2)
					{
						document.registration.otherCollege.disabled=false;
						document.registration.otherCollege.focus();
					}	
				else
					{
						document.registration.otherCollege.disabled=true;
						document.registration.otherCollege.value = "";
					}

			}
						
			function checkOtherBranch()
			{
				if(document.registration.branch.value==2)
					{
						document.registration.otherBranch.disabled=false;
						document.registration.otherBranch.focus();						
					}	
				else
					{
						document.registration.otherBranch.disabled=true;	
						document.registration.otherBranch.value = "";
					}
			}			


			function getCollege(state, loc, divid)
			{
			    var url= 'registrationServer.php';
				POSTDATA="action=getCollege&state="+encodeURIComponent(state)+"&loc="+encodeURIComponent(loc);
				var myRequest = new ajaxObject(url, getCollegeAction);
                myRequest.update(divid, POSTDATA, 'post', null, null, 0);				
			}
			function getCollegeAction(responseText, responseStatus, responseXML, divid)
			{
			if (responseStatus == 200) 
			{
			document.getElementById(divid).innerHTML=responseText;
			} 
			else 
			{
			alert(responseStatus);
			}
			}
			




/*----------------------------------------------------------------------------------------------------------------------*/

function getLocations(state, divid)
			{
				var url= 'registrationServer.php';
				POSTDATA="action=getLocations&state="+encodeURIComponent(state);
				var myRequest = new ajaxObject(url, getLocationsAction);
                myRequest.update(divid, POSTDATA, 'post', null, null, 0);				
			}
			function getLocationsAction(responseText, responseStatus, responseXML, divid)
			{
			if (responseStatus == 200) 
			{
			document.getElementById(divid).innerHTML=responseText;
			} 
			else 
			{
			alert(responseStatus);
			}
			}	
			
/*-----------------------------------------------------------------------------------------------------------------------*/



//-------------------------------------------------------------------
// To Show Ajax based Windows ....
function showEditWindow(title,page)
{
new Widgets.Dialog(title, page, { click_outside: false, width: 400, height: 400 });
}
function showEditWindowSmall(title,page)
{
new Widgets.Dialog(title, page, { click_outside: false, width: 300, height: 200 });
}
function showEditWindowVSmall(title,page)
{
new Widgets.Dialog(title, page, { click_outside: false, width: 200, height: 200 });
}
//-------------------------------------------------------------------------