$(document).ready(function()
{
	$("#username").blur(function()
	{
		$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
		$.post("user_availability.php",{ username:$(this).val() } ,function(data)
        {
		  if(data=='no') //if username not avaiable
		  {
		  	$("#msgbox").fadeTo(200,0.1,function() 
			{ 
			 $(this).html('Username already exists.').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
		  else
		  {
		  	$("#msgbox").fadeTo(200,0.1,function() 
			{ 
			  $(this).html('Username available.').addClass('messageboxok').fadeTo(900,1);	
			});
		  }
				
        });
 
	});
});

function formValidator_city(){
	var city_name = document.getElementById('city_name');
	var security_code = document.getElementById('security_code');

if(isEmpty(city_name, "Please enter city name!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}
return false;
}

function formValidator_course(){
	var security_code = document.getElementById('security_code');

if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}
return false;
}

function formValidator_testi(){
	var name = document.getElementById('name');
	var more = document.getElementById('more');
	var testi = document.getElementById('testi');
	var security_code = document.getElementById('security_code');

if(isEmpty(name, "Please enter your name!!")){
if(isEmpty(more, "Please enter something about you!!")){
if(isEmpty(testi, "Please enter what do you want to say!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}}}
return false;
}

function formValidator_rm(){
	var category = document.getElementById('category');
	var desc = document.getElementById('desc');
	var security_code = document.getElementById('security_code');

if(isEmpty(category, "Please select category!!")){
if(isEmpty(desc, "Please enter your requirement!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}}
return false;
}

function formValidator_toppers_list(){
	var tl_name = document.getElementById('tl_name');
	var tl_exam = document.getElementById('tl_exam');
	var tl_marks = document.getElementById('tl_marks');
	var security_code = document.getElementById('security_code');

if(isEmpty(tl_name, "Please enter student's name!!")){
if(isEmpty(tl_exam, "Please enter exam name!!")){
if(isEmpty(tl_marks, "Please enter marks!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}}}
return false;
}


function enableTextbox() {
var sc = document.getElementById('sc');
var standard = document.getElementById('standard');

if (document.getElementById("occupation").value == "Student") {
sc.disabled = false;
standard.disabled = false;
}
else {
sc.disabled = true;
standard.disabled = true;
sc.value="";
standard.value="";
}



}


function formValidator_contactus(){
	var name = document.getElementById('name');
	var mobile = document.getElementById('mobile');
	var email = document.getElementById('email');
	var query = document.getElementById('query');
	var security_code = document.getElementById('security_code');

if(isEmpty(name, "Please enter your name!!")){
if(emailValidator(email, "Please enter a valid email address!!")){
if(isEmpty(mobile, "Please enter mobile number!!")){          
if(isNumeric(mobile,"Mobile number can only be numeric!!")){
if(lengthRestriction(mobile, 10, 10)){
if(isEmpty(query, "Please enter message or query!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}}}}}}
return false;
}


function formValidator_add_faculty(){
	var faculty_name = document.getElementById('faculty_name');
	var faculty_post = document.getElementById('faculty_post');
	var security_code = document.getElementById('security_code');

if(isEmpty(faculty_name, "Please enter faculty name!!")){
if(isEmpty(faculty_post, "Please enter faculty post!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}}
return false;
}


function formValidator_custompages(){
	var custom_pages_title = document.getElementById('custom_pages_title');
	var security_code = document.getElementById('security_code');

if(isEmpty(custom_pages_title, "Please enter page title!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}
return false;
}


function formValidator_ne(){
	var type = document.getElementById('type');
	var heading = document.getElementById('heading');
	var security_code = document.getElementById('security_code');

if(madeSelection(type, "Please select type!!")){
if(isEmpty(heading, "Please enter news/events heading!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}}
return false;
}

function formValidator_college_category(){
	var cat_name = document.getElementById('cat_name');
	var cat_desc = document.getElementById('cat_desc');
	var security_code = document.getElementById('security_code');

if(isEmpty(cat_name, "Please enter category name!!")){
if(isEmpty(cat_desc, "Please enter category description!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}}
return false;
}

function formValidator_programme(){
	var prg_level = document.getElementById('prg_level');
	var prg_name = document.getElementById('prg_name');
	var security_code = document.getElementById('security_code');


if(madeSelection(prg_level, "Please select level!!")){
if(isEmpty(prg_name, "Please enter programme name!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}}
return false;
}

function formValidator_login(){
	var uname = document.getElementById('uname');
	var pwd = document.getElementById('pwd');
if(islogin(uname, "Please enter your username!!", "username")){
if(islogin(pwd, "Please enter your password!!", "password")){
return true;
}}
return false;
}


function formValidator_newsletter(){
	var mobileno = document.getElementById('mobileno');
if(islogin(mobileno, "Please enter your mobile number!!", "Mobile Number")){
if(isNumeric(mobileno,"Mobile number can only be numeric!!")){
if(lengthRestriction(mobileno, 10, 10)){
return true;
}}}
return false;
}

function islogin(elem, helperMsg, defaultvalue){
	if(elem.value == defaultvalue || elem.value==""){
		alert(helperMsg);
		elem.focus();
		return false;
	}
	return true;
}

function agreebox(elem, helperMsg) {
  if (elem.checked == false) {
    alert(helperMsg);
	elem.focus();
    return false;
  } else
    return true;
}


function formValidator_register(){
	var name = document.getElementById('name');
	var username = document.getElementById('username');
	var password = document.getElementById('password');
	var email = document.getElementById('email');
	var mobile = document.getElementById('mobile');
	var city = document.getElementById('city');
	var address = document.getElementById('address');
	var occupation = document.getElementById('occupation');
	var security_code = document.getElementById('security_code');
	var agree = document.getElementById('agree');


if(isEmpty(name, "Please enter your name!!")){
if(isEmpty(username, "Please enter your username!!")){
if(isEmpty(password, "Please enter your password!!")){
if(emailValidator(email, "Please enter a valid email address!!")){
if(isEmpty(mobile, "Please enter mobile number!!")){          
if(isNumeric(mobile,"Mobile number can only be numeric!!")){
if(lengthRestriction(mobile, 10, 10)){
if(madeSelection(city, "Please select city!!")){
if(madeSelection(occupation, "Please select occupation!!")){
if(isEmpty(address, "Please enter your address!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
if(agreebox(agree,"You have to agree our privacy & policy")){
return true;
}}}}}}}}}}}}
return false;
}

function formValidator_updatepassword(){
	var oldpassword = document.getElementById('oldpassword');
	var newpassword = document.getElementById('newpassword');

if(isEmpty(oldpassword, "Please enter your old password!!")){
if(isEmpty(newpassword, "Please enter the new password!!")){
return true;
}}
return false;
}

function formValidator_updatemobile(){
	var newmobile = document.getElementById('newmobile');
	var security_code = document.getElementById('security_code');

if(isEmpty(newmobile, "Please enter new mobile number!!")){          
if(isNumeric(newmobile,"Mobile number can only be numeric!!")){
if(lengthRestriction(newmobile, 10, 10)){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}}}
return false;
}

function formValidator_updateemail(){
	var newemail = document.getElementById('newemail');
	var security_code = document.getElementById('security_code');

if(emailValidator(newemail, "Please enter a valid email address!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}
return false;
}

function formValidator_activate(){
	var username = document.getElementById('username');
	var code = document.getElementById('code');
	var security_code = document.getElementById('security_code');


if(isEmpty(username, "Please enter your username!!")){
if(isEmpty(code, "Please enter activation code!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}}
return false;
}

function formValidator_resend(){
	var username = document.getElementById('username');
	var email = document.getElementById('email');
	var security_code = document.getElementById('security_code');


if(isEmpty(username, "Please enter your username!!")){
if(isEmpty(email, "Please enter your email address!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}}
return false;
}

function formValidator_forgot_password(){
	var username = document.getElementById('username');
	var email = document.getElementById('email');
	var security_code = document.getElementById('security_code');


if(isEmpty(username, "Please enter your username!!")){
if(isEmpty(email, "Please enter your email address!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}}
return false;
}

function formValidator_forgot_username(){
	var email = document.getElementById('email');
	var security_code = document.getElementById('security_code');


if(isEmpty(email, "Please enter your email address!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}
return false;
}



function formValidator_college_add(){
	var category = document.getElementById('category');
	var funding = document.getElementById('funding');
	var name = document.getElementById('name');
	var year = document.getElementById('year');
	var university = document.getElementById('university');
	var city = document.getElementById('city');
	var address = document.getElementById('address');
	var security_code = document.getElementById('security_code');


if(madeSelection(category, "Please select the category!!")){
if(madeSelection(funding, "Please select funding option!!")){
if(isEmpty(name, "Please enter college name!!")){
if(madeSelection(year, "Please select year of establishment!!")){
if(isEmpty(university, "Please enter university name!!")){
if(madeSelection(city, "Please select city!!")){
if(isEmpty(address, "Please enter college address!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}}}}}}}
return false;
}

function formValidator_school_add(){
	var board = document.getElementById('board');
	var funding = document.getElementById('funding');
	var name = document.getElementById('name');
	var year = document.getElementById('year');
	var medium = document.getElementById('medium');
	var city = document.getElementById('city');
	var address = document.getElementById('address');
	var security_code = document.getElementById('security_code');


if(isEmpty(name, "Please enter school name!!")){
if(madeSelection(funding, "Please select funding option!!")){
if(madeSelection(board, "Please select the board!!")){
if(madeSelection(medium, "Please select the medium!!")){
if(madeSelection(year, "Please select year of establishment!!")){
if(madeSelection(city, "Please select city!!")){
if(isEmpty(address, "Please enter school address!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}}}}}}}
return false;
}

function formValidator_cc_add(){
	
	var name = document.getElementById('name');
	var year = document.getElementById('year');
	var city = document.getElementById('city');
	var address = document.getElementById('address');
	var security_code = document.getElementById('security_code');


if(isEmpty(name, "Please enter institute name!!")){
if(madeSelection(year, "Please select year of establishment!!")){
if(madeSelection(city, "Please select city!!")){
if(isEmpty(address, "Please enter institute address!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}}}}
return false;
}


function formValidator_review(){
	var name = document.getElementById('name');
	var review_desc = document.getElementById('review_desc');
	var security_code = document.getElementById('security_code');


if(isEmpty(name, "Please enter your name!!")){
if(isEmpty(review_desc, "Please enter review/message!!")){
if(isEmpty(security_code, "Please enter the number shown in image!!")){
return true;
}}}
return false;
}



function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


function madeSelection(elem, helperMsg){
	if(elem.value == ""){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Mobile number must be of 10 digit without any preceding 0 or +91!!");
		elem.focus();
		return false;
	}
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function blank(a) { if(a.value == a.defaultValue) a.value = ""; }
function unblank(a) { if(a.value == "") a.value = a.defaultValue; }

function select_all(a)
{
a.select();
}

		var swfu;

	var txtLastName = document.getElementById("lastname");
		window.onload = function () {
			swfu = new SWFUpload({
				// Backend settings
				upload_url: "upload.php",
				file_post_name: "resume_file",
				

				// Flash file settings
				file_size_limit : "10 MB",
				file_types : "*.*",			// or you could use something like: "*.doc;*.wpd;*.pdf",
				file_types_description : "All Files",
				file_upload_limit : "0",
				file_queue_limit : "1",

				// Event handler settings
				swfupload_loaded_handler : swfUploadLoaded,
				
				file_dialog_start_handler: fileDialogStart,
				file_queued_handler : fileQueued,
				file_queue_error_handler : fileQueueError,
				file_dialog_complete_handler : fileDialogComplete,
				
				//upload_start_handler : uploadStart,	// I could do some client/JavaScript validation here, but I don't need to.
				upload_progress_handler : uploadProgress,
				upload_error_handler : uploadError,
				upload_success_handler : uploadSuccess,
				upload_complete_handler : uploadComplete,

				// Button Settings
				button_image_url : "XPButtonUploadText_61x22.png",
				button_placeholder_id : "spanButtonPlaceholder",
				button_width: 61,
				button_height: 22,
				
				// Flash Settings
				flash_url : "swfupload/swfupload.swf",

				custom_settings : {
					progress_target : "fsUploadProgress",
					upload_successful : false
				},
				
				// Debug settings
				debug: false
			});

		};
