$(function() {
	$('.second-nav').hide();
	$('.occ,.emp,.web').hide();
	$('.occ-block,.emp-block').css('height','0px');
	$('#occupation-blank').css('height','0px');
	
	$('#about').click(function(){
		if($('.programs').css('display') == 'block')
			$('.programs').slideToggle('normal');
		if($('.admissions').css('display') == 'block')
			$('.admissions').slideToggle('normal');
		if($('.careers').css('display') == 'block')
			$('.careers').slideToggle('normal');	
		$('.about').slideToggle('normal');
		return false;
	});
	$('#admissions').click(function(){
		if($('.programs').css('display') == 'block')
			$('.programs').slideToggle('normal');
		if($('.about').css('display') == 'block')
			$('.about').slideToggle('normal');
		if($('.careers').css('display') == 'block')
			$('.careers').slideToggle('normal');	
			
		$('.admissions').slideToggle('normal');
	});
	$('#programs').click(function(){
		if($('.admissions').css('display') == 'block')
			$('.admissions').slideToggle('normal');
		if($('.about').css('display') == 'block')
			$('.about').slideToggle('normal');
		if($('.careers').css('display') == 'block')
			$('.careers').slideToggle('normal');
			
		$('.programs').slideToggle('normal');
	});
	$('#careers').click(function(){
		if($('.admissions').css('display') == 'block')
			$('.admissions').slideToggle('normal');
		if($('.about').css('display') == 'block')
			$('.about').slideToggle('normal');
		if($('.programs').css('display') == 'block')
			$('.programs').slideToggle('normal');
		$('.careers').slideToggle('normal');
	});
	
	/*Programs Menu-SubNav*/

	$('.programhours').click(function(){
		var listing = document.getElementById('prognav').getElementsByTagName('a');
		for(i = 0;i<listing.length;i++){
			if(listing[i].id == 'checked'){
				if(listing[i].className != 'first programhours')
				listing[i].id = "";
				else listing[i].id = 'checked';
			}else if(listing[i].className == 'first programhours'){
				listing[i].id = 'checked';
			}
		}
	});
	
	$('.programobjectives').click(function(){
									 
		var listing = document.getElementById('prognav').getElementsByTagName('a');
		for(i = 0;i<listing.length;i++){
			if(listing[i].id == 'checked'){
				if(listing[i].className != 'first first-item programobjectives')
				listing[i].id = "";
			}else if(listing[i].className == 'first first-item programobjectives'){
				listing[i].id = 'checked';
			}
		}
	});
	
	/*Programs Menu-SubNav*/
	
	$('.admissionsreq').click(function(){
		var listing = document.getElementById('admissionsnav').getElementsByTagName('a');
		for(i = 0;i<listing.length;i++){
			if(listing[i].id == 'checked'){
				if(listing[i].className != 'first first-item admissionsreq')
				listing[i].id = "";
			}else if(listing[i].className == 'first first-item admissionsreq'){
				listing[i].id = 'checked';
			}
		}								   
	});
	
	$('.admissionstuitions').click(function(){
		var listing = document.getElementById('admissionsnav').getElementsByTagName('a');
		for(i = 0;i<listing.length;i++){
			if(listing[i].id == 'checked'){
				if(listing[i].className != 'admissionstuitions')
				listing[i].id = "";
			}else if(listing[i].className == 'admissionstuitions'){
				listing[i].id = 'checked';
			}
		}								   
	});

	/**form validation on alumni page**/
	$('.errors').hide();
	$('#vonlee-submit').click(function(){

		$('.errors').hide();
		var firstname = $("input#firstname").val();
		if (firstname == "") {
			$("span#firstname-blank").show();
			$("input#firstname").focus();
			$("input#firstname").blur(function(){$("span#firstname-blank").hide();});
		return false;
		}
		if(isNumber(firstname) ||  hasSpecialChars(firstname)){
			$("span#firstname-incorrect").show();
			$("input#firstname").focus();
			$("input#firstname").blur(function(){$("span#firstname-incorrect").hide();});
		return false;
		}
		var lastname = $('input#lastname').val();
		if(lastname == ""){
			$('span#lastname-blank').show();
			$('input#lastname').focus();
			$("input#lastname").blur(function(){$("span#lastname-blank").hide();});
				return false;
		}
		if(isNumber(lastname) ||  hasSpecialChars(lastname)){
			$("span#lastname-incorrect").show();
			$("input#lastname").focus();
			$("input#lastname").blur(function(){$("span#lastname-incorrect").hide();});
			return false;
		}
		var email = $('input#email').val();
		if(email == ""){
			$('span#email-blank').show();
			$('input#email').focus();
			$('input#email').blur(function(){$("span#email-blank").hide();});
				return false
		}
		if(!echeck(email)){
			$('span#email-incorrect').show();
			$('span#email-blank').hide();
			$('input#email').focus();
			$('input#email').blur(function(){$("span#email-incorrect").hide();});
				return false
		}
		var phone = $('input#phone').val();
		var cellphone = $('input#cellphone').val();
		var address2 = $('input#address2').val();
		var employer = $('input#currentEmployer').val();	
		var website = $('input#website').val();
		/*if(phone != ""){
		if(!isNumber(phone) || hasSpecialChars(phone)){
			$('span#phone-incorrect').show();
			$('input#phone').focus();
			$("input#phone").blur(function(){$("span#phone-incorrect").hide();});
				return false
		}}
		var cellphone = $('input#cellphone').val();
		if(cellphone != ""){
		if(!isNumber(cellphone) || hasSpecialChars(cellphone)){
			$('span#cell-incorrect').show();
			$('input#cellphone').focus();
			$("input#cellphone").blur(function(){$("span#cell-incorrect").hide();});
				return false
		} }*/
		var address = $('input#address1').val();
		if(address == ""){
			$('span#address1-blank').show();
			$('input#address1').focus();
			$("input#address1").blur(function(){$("span#address1-blank").hide();});
				return false
		}
		
		var city = $('input#city').val();
		if(city == ""){
			$('span#city-blank').show();
			$('input#city').focus();
			$("input#city").blur(function(){$("span#city-blank").hide();});
				return false;
		}
		if(isNumber(city) ||  hasSpecialChars(city)){
			$("span#city-incorrect").show();
			$("input#city").focus();
			$("input#city").blur(function(){$("span#city-incorrect").hide();});
			return false;
		}
		
		var state = $('input#state').val();
		if(state == ""){
			$('span#state-blank').show();
			$('input#state').focus();
			$("input#state").blur(function(){$("span#state-blank").hide();});
				return false;
		}
		if(isNumber(state) ||  hasSpecialChars(state)){
			$("span#state-incorrect").show();
			$("input#state").focus();
			$("input#state").blur(function(){$("span#state-incorrect").hide();});
			return false;
		}
		
		var zipcode = $('input#zipcode').val();
		
		/*if(zipcode != ""){
		if(!isNumber(zipcode) || hasSpecialChars(zipcode)){
			$('span#zipcode-incorrect').show();
			$('input#zipcode').focus();
			$("input#zipcode").blur(function(){$("span#zipcode-incorrect").hide();});
				return false;
		}}else{*/
		if(zipcode == ""){
			$('span#zipcode-blank').show();
			$('input#zipcode').focus();
			$("input#zipcode").blur(function(){$("span#zipcode-blank").hide();});
			return false;
		}
			

		var employed = $('#employed option:selected').val();
		if(employed == ""){
			$('span#employed-blank').show();
			$('select#employed').focus();
			$("select#employed").blur(function(){$("span#employed-blank").hide();});
				return false;
		}
		if(employed == 'Yes'){
			var occupation = $('#occupation').val();
				if(occupation == ""){
				$('.alumni-bucket .tr ').css('height','880px');			
				$('span#occupation-blank').show();
				$('input#occupation').focus();
				$("input#occupation").blur(function(){$("span#occupation-blank").hide();});
				return false
				}
		}
		var message = $('textarea#message').val();
			if(message == ""){
				$('.alumni-bucket .tr ').css('height','885px');
				$('span#message-blank').show();
				$('textarea#message').focus();
				$("textarea#message").blur(function(){
					$("span#message-blank").hide();
					if((message == "") && employed == 'Yes'){
						$('.alumni-bucket .tr ').css('height','880px');			
					}else
					$('.alumni-bucket .tr ').css('height','840px');
				});
				return false;
			}
			
		
		var dataString = 'firstname='+ firstname + '&lastname=' + lastname + '&email=' +email + '&phone=' + phone + '&cellphone=' + cellphone + '&address=' + address + '&address2=' + address2 + '&city=' + city + '&state=' + state + '&zip=' + zipcode + '&employed=' +employed + '&occupation=' + occupation + '&employer=' + employer + '&website=' + website + '&message='+ message;
		$.ajax({
      type: "POST",
      url: "bin/alumni.php",
      data: dataString,
      success: function() {
        $('.form').html("<div id='message-part' style='padding-left: 100px;padding-top:20px'></div>");
        $('#message-part').html("<p>Your message has been sent! We will contact you soon.<br />Thank you.</p>")
		.append("<div align='center' style='padding-right:80px;padding-top: 30px;'><a href='index.html'><img src='images/ok-btn.jpg' wdith='61' height='20' alt='' border='0' class='ok-btn'/></a></div>")
       .hide()
		.show()
		$('.alumni-bucket .tr').css('height','150px')
		$('.alumni-bucket').css('padding-top','100px')
		$('.fb').css('display','none');
		
      }
     }); //ajax call
	
	
	
    return false;
	});
	

	
	
});
function changeThis(item){
	if(item == "Yes"){
		$('.occ,.emp,.web').show();
		$('.occ-block,.emp-block').css('height','10px');
    	$('#occupation-blank').css('height','20px');
		$('.alumni-bucket .tr ').css('height','880px');
	}
	else {
		$('.occ,.emp,.web').hide();
		$('.occ-block,.emp-block').css('height','0px');
	    $('#occupation-blank').css('height','0px');
	}
}
function isNumber(sText) {
		
			if (sText=="") return false;
			var ValidChars = "0123456789()-";
			var IsNumber=true;
			var Char;
			var dotCnt = 0;
		
				for (i = 0; i < sText.length ; i++){
					Char = sText.charAt(i);
					if (ValidChars.indexOf(Char) == -1){
						IsNumber = false;
					}
					else if (ValidChars.indexOf(Char)){
						IsNumber = true;
						break;
					}
					
				}
				return IsNumber;
}
function hasSpecialChars(sText) {
		
			if (sText=="") return false;
			var ValidChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?`";
			var IsNumber=true;
			var Char;
			var dotCnt = 0;
		
				for (i = 0; i < sText.length ; i++){
					Char = sText.charAt(i);
					if (ValidChars.indexOf(Char) == -1){
						IsNumber = false;
					}
					else if (ValidChars.indexOf(Char)){
						IsNumber = true;
						break;
					}
					
				}
				return IsNumber;
	}
function echeck(str)
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   //alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   //alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		//alert("Invalid E-mail ID")
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		//alert("Invalid E-mail ID")
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		//alert("Invalid E-mail ID")
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		//alert("Invalid E-mail ID")
		return false
	 }

	 if (str.indexOf(" ")!=-1){
		//alert("Invalid E-mail ID")
		return false
	 }
	 if(ldot == (str.length-1)){
		return false
	}

	 return true
}
function toCount(entrance,exit,text,characters) {
  var length=characters - document.getElementById("message").value.length;
  if(length>=0)
  document.getElementById("start").innerHTML = text.replace("{CHAR}",length);
  else
  document.getElementById("start").innerHTML = text.replace("{CHAR}","0");
}
