$(document).ready(function(){
	
	//initDate();
	initRandom();
	initAutocomplete();
	ieHover('#nav > li');
	initPopup();
	limitChar();
	fullScreen();
	addSubject();
	validateForm();
	validateForm2();
	writeInputText();
	rateSlide();
	/*Added On 03/08/09 for New HTML*/
	checkInput();
	/*Added On 02/09/09 for New HTML*/
	selectItems();
});
/*--- select items ---*/
function selectItems() {
	var _select = $('#wide');
	var _selectBar = $('#wide-bar');
	var _wideText = $('strong', _selectBar);
	var _reChange = $('a', _selectBar);
	_select.change(function(){
		var _val = this.value;
		_select.hide();
		_selectBar.show();
		_wideText.text(_val);
	});
	_reChange.click(function(){
		_select.show();
		_selectBar.hide();
		return false;
	});
	
	// subjects
	var _subjects = $('#subjects');
	var _subjectsList = $('#subjects-list');
	var _subjectsUl = $('ul.check-list', _subjectsList);
	var _asTextarea = $('.as-textarea');
	var _btnDelete = $('#btnDelete');
	var _ch = [];
	_subjectsUl.html('');
	var _n = 0;
	
	_subjects.change(function(){
		if (this.value != 'default') {
			var _is = true;
			for (var i=0; i<_ch.length; i++) {
				if (_ch[i] == this.value) _is = false;
			}
			if (_is && _ch.length < 30) {
				if (_subjectsList.is(':hidden')) {
					_asTextarea.hide();
					_subjectsList.show();
				}
				_n++;
				_ch.push(this.value);
				_subjectsUl.prepend('<li><input type="checkbox" value="'+this.value+'" id="check'+_n+'" /><label for="check'+_n+'">'+this.value+'</label></li>');
			}
		}
	});
	_btnDelete.click(function(){
		var _chBox = _subjectsUl.find('input[type="checkbox"]');
		if (_chBox.length) {
			_chBox.each(function(){
				if ($(this).is(':checked')) {
					$(this).parents('li').remove();
					for (var i=0; i<_ch.length; i++) {
						if (_ch[i] == this.value) {
							_ch = _ch.splice(i,1);
						}
					}
					if (!_subjectsUl.find('input[type="checkbox"]').length) {
						_asTextarea.show();
						_subjectsList.hide();
					}
				}
			});
		}
		return false;
	});
}
/*--- rate slide ---*/
var ratingBlockState;
function rateSlide(){
	var _btRate = $('a.btn-rate');
	var _rateBlock = $('div.rating-block');
	var _cancel = $('input.cancel',_rateBlock);
	
	if(document.getElementById("fromFeedbackHidden") != null && document.getElementById("fromFeedbackHidden").value == "fromFeedback"){
	}else{
		_rateBlock.hide();
	}
	
	_btRate.click(function(){

		if (_rateBlock.is(':hidden')) {
			_rateBlock.slideDown(300);
			_btRate.hide();
		}
		return false;
	});
	_cancel.click(function(){

		if (_rateBlock.is(':visible')) {
			_rateBlock.slideUp(300);
			_btRate.show();
		}
		return false;
	});
	
	var _rate = $('div.rate');
	var _active  = $('li.active',_rate);
	if (!_active.length){
		_rate.each(function(i, rate){
			var _star = $('ul.star-rating a', rate);
			var _caption = $('span.caption', rate);
			_star.active = 'Not rated';
			
			_star.each(function(){
				var _t = $(this).attr('title');
				$(this).removeAttr('title');
				$(this).hover(function(){
					_caption.text(_t);
				}, function(){
					_caption.text(_star.active);
				});
				$(this).click(function(){

					_star.active = _t;
					_caption.text(_star.active);
				});
			});
		});
	}
}
/*--- write text ---*/
function writeInputText(){
	var _input = $('input[name="search"]');
	var _form = _input.parents('form');
	/*Added On 03/08/09 for New HTML*/
	var _tmpval;
	_input.focus(function(){
		//Added by sayantani on 30/7/2009
		if(_input.val() == 'Enter a topic for your search' || _input.val() == 'Enter a topic'){
			_input.attr('value','')
		}
		_input.parent().removeClass('error');
		$(this).addClass('type');
		/*Added On 03/08/09 for New HTML*/
		/*Changed On 02/09/09 for New HTML*/
		//_input.attr('value','');
		if (_input.val() == 'Enter a topic' || _input.val() =='' || _input.val() == 'Enter a topic for your search') _input.attr('value','');
	});
	_input.blur(function(){
		$(this).removeClass('type');
		/*Added On 03/08/09 for New HTML*/
		if (_input.val() == 'Enter a topic' || _input.val() =='' || _input.val() == 'Enter a topic for your search') _input.attr('value','Enter a topic');
	});
	_input.keyup(function(){
		if(_input.val()!='Enter a topic for your search') _input.parent().removeClass('error');
	});
	_form.submit(function(){

		if (_input.val() == 'Enter a topic' || _input.val() =='' || _input.val() == 'Enter a topic for your search') {
			_input.parent().addClass('error');
			_input.attr('value','Enter a topic for your search')
			return false;
		}
	});
	
}
/*--- random function ---*/
function initRandom(){
	var _list = $('#intro-image > li').hide();
	var _r = Math.floor(Math.random() * _list.length);
	_list.eq(_r).show();
}
/*--- ie hover ---*/

function ieHover(_list) {
	if ($.browser.msie && $.browser.version < 7) {
		$(_list).hover(function() {
			$(this).addClass('hover');
			if(!$(this).find('div').length) $(this).find('ul').wrap('<div class="drop" style="position:absolute;left:-2px;top:22px"></div>')
			var _wid = $(this).find('ul').width();
			var _hgh = $(this).find('ul').height();
			if(!$(this).find('iframe').length) $(this).find('.drop').append('<iframe src="about:blank"></iframe>')
			$(this).find('iframe').css({
				'width':_wid,
				'height':_hgh,
				'margin-top':-_hgh,
				'border':'none'
			}).show();
			$(this).find('ul').css({
				'position':'relative',
				'left':0,
				'top':0
			});
			// hideSelectBoxes(this.getElementsByTagName('ul')[0]);
		}, function() {
			$(this).removeClass('hover');
			$(this).find('iframe').hide();
			// showSelectBoxes(this.getElementsByTagName('ul')[0]);
		});
	}
}

/*--- function popup  ---*/
function initPopup(){
	$('.popup-holder').each(function(){
		var _btn = $(this).find('a.open');
		var _popup = $(this).find('.popup');
		var btn_close = $(this).find('a.close');
		_btn.click(function(){
			if(_popup.is(':visible')) _popup.hide();
			else _popup.fadeIn(200);
			return false;
		});
		btn_close.click(function(){
			_popup.hide();
			return false;
		});
		$(this).find('a.close').click(function(){

			$(this).parents('.grade-guru-popup').hide();
			return false;
		});
	});
}

/*--- show popup ---*/
function showFirstPopup(){
	$(document).load(function(){
		var _bgPopup = document.createElement('img');
		_bgPopup.src = 'images/bg-popup-2.png';
	
		var _popup = $('.popup2');
		if (getCookie('showFirst') !== 'true') {
			_popup.fadeIn(200);
			setCookie('showFirst', 'true');
		}
	});
}
/*--- full screen ---*/
function fullScreen(){
	var btnFullscr = $('a.btn-fullscr');
	var _body = $('body');
	btnFullscr.click(function(){
		if (_body.is('#full-page')) {
			_body.attr('id','');
			$(this).text('Full screen');
			//Following line added by sayantani to implement BACK TO NORMAL VIEW CR
			$('span.fullscrennspan').attr('style','padding-right:0;');
			//Following line added for adjusting full screen width
			document.getElementById("fullContentId").style.width='734px';
			$(this).attr('style','font-weight:normal');
			document.getElementById('averageRatingHolderList').style.display = 'block';
			//Added by sayantani to fix full screen and normal view navigation bug
			//document.getElementById('ratingBlock').style.display = 'block';
			if(ratingBlockState == 'block'){
				document.getElementById('ratingBlock').style.display = 'block';
			}
			this.title = 'Full screen';
			document.getElementById('backTO').style.marginRight = '5px';
			
		} else {
			_body.attr('id','full-page');
			//Following two lines added by sayantani to implement BACK TO NORMAL VIEW CR
			$('span.fullscrennspan').attr('style','padding-right:80px;');
			//Following line added for adjusting full screen width
			document.getElementById("fullContentId").style.width='100%';
		
			$(this).text('BACK TO NORMAL VIEW');
			$(this).attr('style','font-weight:bold;');
			document.getElementById('averageRatingHolderList').style.display = 'none';
			ratingBlockState = document.getElementById('ratingBlock').style.display;
			document.getElementById('ratingBlock').style.display = 'none';
			this.title = 'Normal view';
			document.getElementById('backTO').style.marginRight = '20px';
			
		}
	});
	
	var btnSave = $('a.btn-save');
	btnSave.click(function(){
		btnSave.css('opacity',0.5);
		btnSave.html('Saved to folder');
	});
}
/*--- add subject ---*/
function addSubject() {
	var _holder = $('div.sub-areas div.from');
	var _uls = $('ul ul', _holder);
	var _link = $('ul li > a', _holder);
	var _chb = $('input[type="checkbox"]', _holder);
	var _toUl = $('div.sub-areas div.to ul');
	var _removeLink = $('a', _toUl);
	_toUl.empty();
	
	_uls.hide();
	_link.click(function(){

		$(this).parent().toggleClass('active');
		$(this).parent().find('ul').toggle();
		return false;
	});
	_chb.each(function(){
		var _id = this.id;
		var _label = $('label[for="'+_id+'"]').text();
		if (this.checked) {
			var _item = '<li id="label-'+_id+'">'+_label+' <a href="#'+_id+'" class="del"></a></li>';
			_toUl.get(0).innerHTML += _item;
		}		
	})
	_chb.click(function(){
		var _id = this.id;
		var _label = $('label[for="'+_id+'"]').text();
		if (_toUl.find('li').length < 30) {
			if (this.checked) {
				var _item = '<li id="label-'+_id+'">'+_label+' <a href="#'+_id+'" class="del"></a></li>';
				_toUl.get(0).innerHTML += _item;
			} else {
				$('#label-'+_id).remove();
			}
		} else {
			if (this.checked) {
				return false;
			}else {
				$('#label-'+_id).remove();
			}
		}
	});
	_removeLink.live('click', function(){
		var _id = this.href.substr(this.href.indexOf('#'))
		$(this).parent().remove();
		$(_id).removeAttr('checked')
		return false;
	});
}

/*--- function validate ---*/
function validateForm(){
	var _regForm = $('div.reg-form');
	var _form = $('#reg-form');
	
	_form.submit(function(){
		var _valid = true;
		_regForm.find('div.row, div.terms').removeClass('error').removeClass('error2');
		_form.find('.error-note').remove();
		
		// validate select country
		var _selectCountry = $('select[name="country"]', _regForm);
		if (_selectCountry.val() == 'none') {
			_selectCountry.parent().addClass('error');
			_selectCountry.parent().prepend('<div class="error-note"><img src="images/error-icon.gif" />Select a country</div>');
			_valid = false;
		} else {
			_selectCountry.parent().removeClass('error');
		}
		// validate select membership
		var _selectCountry = $('select[name="membership"]', _regForm);
		if (_selectCountry.val() == 'none') {
			_selectCountry.parent().addClass('error');
			_selectCountry.parent().prepend('<div class="error-note"><img src="images/error-icon.gif" />Choose a membership</div>');
			_valid = false; 
		} else {
			_selectCountry.parent().removeClass('error');
		}
		// validate username
		var _username = $('input[name="username"]', _regForm);
		$.ajax({
			url: 'inc/valid.html',
			data: 'username='+_username.val(),
			success: function(msg){
				if (msg == 'false') {
					_username.parents('div.row').addClass('error');
					_username.parents('div.row').prepend('<div class="error-note"><img src="images/error-icon.gif"/>This username is already in use. Please choose a different one.</div>');
					_valid = false; 
				} else {
					_username.parents('div.row').removeClass('error');
				}
			}
		});
		
		// validate password
		var _password = $('input[name="password"]', _regForm);
		var _passwordConfirm = $('input[name="password-confirm"]', _regForm);
		if (_password.val().length < 6) {
			_password.parents('div.row').addClass('error');
			_password.parents('div.row').prepend('<div class="error-note"><img src="images/error-icon.gif" />Password must be 6-10 characters</div>')
			_valid = false;
		} else {
			_password.parents('div.row').removeClass('error');
		}
		if (_password.val() != _passwordConfirm.val() && !_passwordConfirm.parents('div.row').is('.error')){
			_passwordConfirm.parents('div.row').addClass('error');
			_passwordConfirm.parents('div.row').prepend('<div class="error-note"><img src="images/error-icon.gif" />Passwords do not match</div>')
			_valid = false; 
		} else {
			_passwordConfirm.parents('div.row').removeClass('error');
		}
		
		// validate college
		var _college = $('input[name="college"]', _regForm);
		$.ajax({
			url: 'inc/valid.html',
			data: 'college='+_college.val(),
			success: function(msg){
				if (msg == 'false') {
					_college.parents('div.row').addClass('error');
					_college.parents('div.row').prepend('<div class="error-note"><img src="images/error-icon.gif" />Invalid college</div>')
					_valid = false; 
				} else {
					_college.parents('div.row').removeClass('error');
				}
			}
		});
		
		// validate email
		var _email = $('input[name="email"]', _regForm);
		var _emailConfirm = $('input[name="email-confirm"]', _regForm);
		var _emailReg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (_emailReg.test(_email.val())) {
			$.ajax({
				url: 'inc/valid.html',
				data: 'email='+_email.val(),
				success: function(msg){
					if (msg == 'false') {
						_email.parents('div.row').addClass('error');
						_email.parents('div.row').prepend('<div class="error-note"><img src="images/error-icon.gif" />This email address is already in use</div>')
						_valid = false; 
					} else {
						_email.parents('div.row').removeClass('error');
					}
				}
			});
			if (_email.val() != _emailConfirm.val()){
				_emailConfirm.parents('div.row').addClass('error');
				_emailConfirm.parents('div.row').prepend('<div class="error-note"><img src="images/error-icon.gif" />Email addresses do not match</div>');
				_valid = false; 
			} else {
				_emailConfirm.parents('div.row').removeClass('error');
			}
		} else if (!_email.parents('div.row').is('.error2')) {
			_email.parents('div.row').addClass('error2');
			_email.parents('div.row').prepend('<div class="error-note error2"><img src="images/error-icon.gif" alt=" " />This email incorrect</div>');
			_valid = false; 
		}

		// validate addresses
		// 2 step
		var _addresses = $('input[name="addresses"]', _regForm);
		if (_addresses.val() != '' && _addresses.val().indexOf(',') != -1) {
			
			var _adr = _addresses.val();
			_adr = _adr.split(',');
			
			for (var i=0; i<_adr.length; i++) {
				var _eml = _adr[i].replace(' ','');
				_eml = _adr[i].replace(' ','');
				
				if (!_emailReg.test(_eml)) {
					_addresses.parent().addClass('error2');
					_addresses.parent().prepend('<div class="error-note error2"><img src="images/error-icon.gif" />Email addresses incorrect</div>');
					_valid = false;
				}
			}
		} else {
			if (_addresses.val() != '' && _addresses.val().indexOf(' ') != -1) {
				_addresses.parent().addClass('error');
				_addresses.parent().prepend('<div class="error-note"><img src="images/error-icon.gif" />Seperate the addresses with commas</div>');
				_valid = false;
			} else {
				if (!_emailReg.test(_addresses.val())) {
					_addresses.parent().addClass('error2');
					_addresses.parent().prepend('<div class="error-note error2"><img src="images/error-icon.gif" />Email addresses incorrect</div>');
					_valid = false; 
				} else {
					_addresses.parent().removeClass('error2');
				}
			}
		}

		
		// validate terms and conditions
		var _term = $('input[name="term"]', _regForm);
		if (!_term.get(0).checked) {
			_term.parent().addClass('error');
			_term.parent().prepend('<div class="error-note"><img src="images/error-icon.gif" />Check the box below to accept terms and conditions</div>');
			_valid = false; 
		} else {
			_term.parent().removeClass('error');
		}
		
		if (!_valid) return false;
		return false;
	});
	
	var _selects = $('select');
	_selects.each(function(i, s){
		var _opt = $(s).find('option');
		if (_opt.eq(0).is(':selected')) $(s).addClass('grey');
		else $(s).removeClass('grey');
		
		$(s).change(function(){
			if (_opt.eq(0).is(':selected')) $(s).addClass('grey');
			else $(s).removeClass('grey');
		});
	});
}
/*--- function validate ---*/
function validateForm2(){
	var _regForm = $('div.reg-form');
	var _form = $('#reg-form-2');
	
	_form.submit(function(){
		var _valid = true;
		_regForm.find('div.row, div.terms').removeClass('error').removeClass('error2');
		_form.find('.error-note').remove();
		
		// validate select country
		var _selectCountry = $('select[name="country"]', _regForm);
		if (_selectCountry.val() == 'none') {
			_selectCountry.parent().addClass('error');
			_selectCountry.parent().prepend('<div class="error-note"><img src="images/error-icon.gif" />Select a country</div>');
			_valid = false;
		} else {
			_selectCountry.parent().removeClass('error');
		}
		// validate select membership
		var _selectCountry = $('select[name="membership"]', _regForm);
		if (_selectCountry.val() == 'none') {
			_selectCountry.parent().addClass('error');
			_selectCountry.parent().prepend('<div class="error-note"><img src="images/error-icon.gif" />Choose a membership</div>');
			_valid = false; 
		} else {
			_selectCountry.parent().removeClass('error');
		}
		// validate username
		var _username = $('input[name="username"]', _regForm);
		$.ajax({
			url: 'inc/valid.html',
			data: 'username='+_username.val(),
			success: function(msg){
				if (msg == 'false') {
					_username.parents('div.row').addClass('error');
					_username.parents('div.row').prepend('<div class="error-note"><img src="images/error-icon.gif"/>This username is already in use. Please choose a different one.</div>');
					_valid = false; 
				} else {
					_username.parents('div.row').removeClass('error');
				}
			}
		});
		
		// validate password
		var _password = $('input[name="password"]', _regForm);
		var _passwordConfirm = $('input[name="password-confirm"]', _regForm);
		if (_password.val().length < 6) {
			_password.parents('div.row').addClass('error');
			_password.parents('div.row').prepend('<div class="error-note"><img src="images/error-icon.gif" />Password must be 6-10 characters</div>')
			_valid = false;
		} else {
			_password.parents('div.row').removeClass('error');
		}
		if (_password.val() != _passwordConfirm.val() && !_passwordConfirm.parents('div.row').is('.error')){
			_passwordConfirm.parents('div.row').addClass('error');
			_passwordConfirm.parents('div.row').prepend('<div class="error-note"><img src="images/error-icon.gif" />Passwords do not match</div>')
			_valid = false; 
		} else {
			_passwordConfirm.parents('div.row').removeClass('error');
		}
		
		// validate college
		var _college = $('input[name="college"]', _regForm);
		$.ajax({
			url: 'inc/valid.html',
			data: 'college='+_college.val(),
			success: function(msg){
				if (msg == 'false') {
					_college.parents('div.row').addClass('error');
					_college.parents('div.row').prepend('<div class="error-note"><img src="images/error-icon.gif" />Invalid college</div>')
					_valid = false; 
				} else {
					_college.parents('div.row').removeClass('error');
				}
			}
		});
		
		// validate email
		var _email = $('input[name="email"]', _regForm);
		var _emailConfirm = $('input[name="email-confirm"]', _regForm);
		var _emailReg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (_emailReg.test(_email.val())) {
			$.ajax({
				url: 'inc/valid.html',
				data: 'email='+_email.val(),
				success: function(msg){
					if (msg == 'false') {
						_email.parents('div.row').addClass('error');
						_email.parents('div.row').prepend('<div class="error-note"><img src="images/error-icon.gif" />This email address is already in use</div>')
						_valid = false; 
					} else {
						_email.parents('div.row').removeClass('error');
					}
				}
			});
			if (_email.val() != _emailConfirm.val()){
				_emailConfirm.parents('div.row').addClass('error');
				_emailConfirm.parents('div.row').prepend('<div class="error-note"><img src="images/error-icon.gif" />Email addresses do not match</div>');
				_valid = false; 
			} else {
				_emailConfirm.parents('div.row').removeClass('error');
			}
		} else if (!_email.parents('div.row').is('.error2')) {
			_email.parents('div.row').addClass('error2');
			_email.parents('div.row').prepend('<div class="error-note error2"><img src="images/error-icon.gif" alt=" " />This email incorrect</div>');
			_valid = false; 
		}
		if(_email.val() == 'Enter email address') {
			_email.parents('div.row').find('.error-note').html('<img src="images/error-icon.gif" alt=" " />Please enter your email address</div>');
		}
		// validate addresses
		var _addresses = $('input[name="addresses"]', _regForm);
		if (_addresses.val() != '' && _addresses.val().indexOf(',') != -1) {
			
			var _adr = _addresses.val();
			_adr = _adr.split(',');
			
			for (var i=0; i<_adr.length; i++) {
				var _eml = _adr[i].replace(' ','');
				_eml = _adr[i].replace(' ','');
				
				if (!_emailReg.test(_eml)) {
					_addresses.parent().addClass('error2');
					_addresses.parent().prepend('<div class="error-note error2"><img src="images/error-icon.gif" />Email addresses incorrect</div>');
					_valid = false;
				}
			}
		} else {
			if (_addresses.val() != '' && _addresses.val().indexOf(' ') != -1) {
				_addresses.parent().addClass('error');
				_addresses.parent().prepend('<div class="error-note"><img src="images/error-icon.gif" />Seperate the addresses with commas</div>');
				_valid = false;
			} else {
				if (!_emailReg.test(_addresses.val())) {
					_addresses.parent().addClass('error2');
					_addresses.parent().prepend('<div class="error-note error2"><img src="images/error-icon.gif" />Email addresses incorrect</div>');
					_valid = false; 
				} else {
					_addresses.parent().removeClass('error2');
				}
			}
		}
		
		var _addresses2 = $('input[name="addresses2"]', _regForm);
		if (_addresses2.val() != '' && _addresses2.val().indexOf(',') != -1) {
			
			var _adr = _addresses2.val();
			_adr = _adr.split(',');
			
			for (var i=0; i<_adr.length; i++) {
				var _eml = _adr[i].replace(' ','');
				_eml = _adr[i].replace(' ','');
				
				if (!_emailReg.test(_eml)) {
					_addresses2.parent().addClass('error2');
					_addresses2.parent().prepend('<div class="error-note error2"><img src="images/error-icon.gif" />Email addresses incorrect</div>');
					_valid = false;
				}
			}
		} else {
			if (_addresses2.val() != '' && _addresses2.val().indexOf(' ') != -1) {
				_addresses2.parent().addClass('error');
				_addresses2.parent().prepend('<div class="error-note"><img src="images/error-icon.gif" />Seperate the addresses with commas</div>');
				_valid = false;
			} else {
				if (!_emailReg.test(_addresses2.val())) {
					_addresses2.parent().addClass('error2');
					_addresses2.parent().prepend('<div class="error-note error2"><img src="images/error-icon.gif" />Email addresses incorrect</div>');
					_valid = false; 
				} else {
					_addresses2.parent().removeClass('error2');
				}
			}
		}
		
		// validate terms and conditions
		var _term = $('input[name="term"]', _regForm);
		if (!_term.get(0).checked) {
			_term.parent().addClass('error');
			_term.parent().prepend('<div class="error-note"><img src="images/error-icon.gif" />Check the box below to accept terms and conditions</div>');
			_valid = false; 
		} else {
			_term.parent().removeClass('error');
		}
		
		if (!_valid) return false;
		return false;
	});
	
	var _selects = $('select');
	_selects.each(function(i, s){
		var _opt = $(s).find('option');
		if (_opt.eq(0).is(':selected')) $(s).addClass('grey');
		else $(s).removeClass('grey');
		
		$(s).change(function(){
			if (_opt.eq(0).is(':selected')) $(s).addClass('grey');
			else $(s).removeClass('grey');
		});
	});
}

/*--- function date ---*/
function initDate(){
	var date_box = $('#date');
	if(date_box.length > 0){
		var _date = new Date();
		var _d = _date.getDate();
		var _m = _date.getMonth(); 
		var _y = _date.getFullYear();
		/*--- day ---*/
		if((_d == 1) || (_d == 21) || (_d == 31)) _d = _d + 'st';
		else if((_d == 2) || (_d == 22) || (_d == 32)) _d = _d + 'nd';
		else if(_d == 3) _d = _d + 'rd';
		else _d = _d + 'th';
		/*--- month ---*/
		if(_m == 0) _m = 'January';
		else if(_m == 1) _m = 'February';
		else if(_m == 2) _m = 'March';
		else if(_m == 3) _m = 'April';
		else if(_m == 4) _m = 'May';
		else if(_m == 5) _m = 'June';
		else if(_m == 6) _m = 'July';
		else if(_m == 7) _m = 'August';
		else if(_m == 8) _m = 'September';
		else if(_m == 9) _m = 'October';
		else if(_m == 10) _m = 'November';
		else if(_m == 11) _m = 'December';
		date_box.html(_m + ' ' + _d + ', ' + _y);
	}
}
/*--- function Autocomplete ---*/
function initAutocomplete(){
	if (typeof $().autocomplete == 'function') {
		var _field = $('#search-field, input.autocomplete');
		var _val = _field.attr('value');
		_field.focus(function(){
			if(this.value == _val) this.value = '';
		}).blur(function(){
			if(this.value == '') this.value = _val;
		}).autocomplete("inc/result.html", {
			autoFill: true
		});
	}
}

/*--- function char ---*/
function limitChar(){
	var _links = $('div.press-box ul.news-list a');
	_links.each(function(){
		var _char = $(this).html();
		if (_char.length > 33) {
			this.txt = '';
			for (var i=0; i<33; i++) {
				this.txt += _char.charAt(i);
			}
			this.txt += '...';
		}
		$(this).html(this.txt);
	});
	
	var _text = $('div.captcha div.top-text em');
	_text.each(function(){
		var _char = $(this).html();
		if (_char.length > 240) {
			this.txt = '';
			for (var i=0; i<240; i++) {
				this.txt += _char.charAt(i);
			}
			this.txt += '..."';
		}
		$(this).html(this.txt);
	});
}
/*This function is changed on 02/09/09 for New Html*/
function checkInput(){
	var _submit = $("input.btn_blue");
	var _message = new Array();
	_message[0] = ('Your message: please enter your message so we can contact you');
	_message[1] = ('Your name: please enter your name so we can contact you');
	_message[2] = ('Your email: please enter your email so we can contact you');
	_message[3] = ('Email address: please input the email address you have registered with GradeGuru');
	_message[4] = ('Your name: please enter your name so we can register your suggestion.');
	_message[5] = ('Your email: enter your email so we can register your suggestion</span>');
	_message[6] = ('Your message: please enter your message so we can register your suggestion');
	_message[7] = ('Your name: please input your name so we can let your friend know you sent them these notes');
	_message[8] = ('Your email: please input your email address so we can let your friend know who sent them these notes');
	_message[9] = ("Your friend's name: please input your friend's name");
	_message[10] = ("Your friend's email: please input your friend's email address");
	_message[11] = ("Your name: please input your name so we can remedy the issue reported");
	_message[12] = ("Your email: input your email so we can remedy the issue reported");
	_message[13] = ("Offensive content: please complete the offensive content field so we can remedy the issue reported");
	_message[14] = ("Your comments/suggestion: Please enter your comments/suggestions so we can remedy the issue reported");
	_message[15] = ("Please either update one or more input values or click the Home button to continue using GradeGuru without making any updates.");
	var _valid;
	_submit.click(function(){
		_valid = true;
		$('.blockalert').html('&nbsp;');
		var _input = $('input.text-input');
		var _textarea = $('.text-area');
		var _select = $('select');
		_input.each(function(_el){
			if ($(this).val().length == 0) {
				_valid = false;
				for (var i=0; i<_message.length; i++) {
					if($(this).attr('name') ==('name'+i)) {
						if ($(this).parents('.forms-holder').find('.blockalert').html().indexOf(_message[i]) ==-1) {
							$(this).parents('.forms-holder').find('.blockalert').append("<span>"+_message[i]+"</span>");
						}
					};
				}
			}
		})
		_textarea.each(function(_el){
			if ($(this).val().length == 0) {
				_valid = false;
				for (var i=0; i<_message.length; i++) {
					if($(this).attr('name') ==('name'+i)) {
						if ($(this).parents('.forms-holder').find('.blockalert').html().indexOf(_message[i]) ==-1) {
							$(this).parents('.forms-holder').find('.blockalert').append("<span>"+_message[i]+"</span>");
						}
					};
				}
			}
		});
		_select.each(function(_el){
			if ($(this).val() == -1) {
				_valid = false;
				for (var i=0; i<_message.length; i++) {
					if($(this).attr('name') ==('name'+i)) {
						if ($(this).parents('.forms-holder').find('.blockalert').html().indexOf(_message[i]) ==-1) {
							$(this).parents('.forms-holder').find('.blockalert').append("<span>"+_message[i]+"</span>");
						}
					};
				}
			}
		})




		if(!_valid) return false;
	});
}
if (window.addEventListener)
	window.addEventListener("load", showFirstPopup, false);
else if (window.attachEvent)
	window.attachEvent("onload", showFirstPopup);