var width = 0;
/*$(window).bind('load',function(){
});*/
$(document).ready(function(){
	$('#menu').css({right:'15px'});
	if($.browser.msie){
		$('#menu').css({marginTop:'1px'});
		if($.browser.version<7){
			var width = 0;
			$('#menu>ul>li').each(function(){
				width += $(this).width()+16;
			});
			$('#menu>ul').width(width-9);
		}
	}
	$('#menu>ul>li').each(function(){
		$(this).mouseover(function(){
			$(this).children('ul').css({left:-15});
		});
		$(this).mouseout(function(){
			$(this).children('ul').css({left:-10000});
		});
	});
	$('#menu>ul>li.active').prev(':not(#first)').css({backgroundImage:"url('/images/menu/before_active_right.gif')"});
	if($('#menu>ul>li.active').prev().attr('id')=='first'){
		$('#menu>ul>li.active').prev().addClass('active');
	}
	$('#print').click(function(){
		print_page();
		return false;
	});
	$('#email').cBox({overlayBgColor: '#000',
						overlayOpacity:0.75,
						borderWidth: 8,
						borderColor: '#ee3224',
						width:       500,
						height:      400});
	$('.apply').click(function(){
		$(this).parent().parent().submit();
		return false;
	});
	$('#result_popup').cBox({overlayBgColor: '#000',
						overlayOpacity:0.75,
						borderWidth: 8,
						borderColor: '#ee3224',
						width:       383,
						height:      163});
	$('#store').change(function(){
		$.ajax({
			type:"POST",
			url:'/validate/get_jobs/'+new Date().getTime(),
			data:'store_id='+$(this).val(),
			success:function(html){
				$('#job').html(html);
			}
		});
	});
	$('#keywords').click(function(){
		if($(this).val() == 'enter keywords'){
			$(this).val('');
		}
	});
	$('#keywords').blur(function(){
		if($(this).val() == ''){
			$(this).val('enter keywords');
		}
	});
	$('#search a.sh').click(function(){
		self.location.href=$(this).attr('href') + '/' + $('#keywords').val();
		return false;
	});
	$('#login').click(function(){
		$.ajax({
			type:"POST",
			url:$(this).attr('href'),
			data:'from_cBox=true',
			success:function(html){
				$('#pageContainer').prepend(html);
			}
		});
		return false;
	});
	$('#logout').click(function(){
		$.ajax({
			type:"POST",
			url:$(this).attr('href'),
			data:'from_cBox=true',
			dataType:'json',
			success:function(json){
				if(json.status==0){
					self.location.href = self.location.href;
				}
			}
		});
		return false;
	});
	$('#submit').parent().ajaxForm({
		beforeSubmit:function(){
			$('#submit').attr('disabled','disabled');
			$('#status').html('<img src="/images/admin/loading.gif" /><span class="success">Processing your request, please wait...</span>');
		},
		dataType:'json',
		success:function(response){
			$('#submit').removeAttr('disabled');
			if(response.status==1){
				$('#status').html('');
				for (i=0; i< response.message.length; i++)
				{
					$('#status').append( response.message[i].error ); // print error message
				}
			}else{
				$('#status').html('<span class="success">'+response.message+'</span>');
				setTimeout("$('#result_popup').click()", 2000);
				setTimeout("self.location.href = self.location.href", 6000);
			}
			
		}
	});
	$('#reset').click(function(){
		$(':input', $(this).parent()).val('');
		$('#status').html('');
		return false;
	});
});
function print_page(){
	self.open(self.location.href + '/print_page');
}