$(document).ready(function(){
	
	var pageWidth = 0;		
	var pages = {
		'hem' : {
			'page' : 'ajax/hem',
			'name' : 'hem',
			'id' : 'cpac-dynamic-hem',
			'required' : true,
			'parameter' : false,
			'loaded' : false,
			'userFriendlyUrl' : 'pages/hem',
			'startupLoad' : true,
			'userFriendlyParm' : ''
		},
		'newslist' : {
			'page' : 'ajax/news/list',
			'name' : 'newslist',
			'id' : 'cpac-dynamic-news-list',
			'required' : true,
			'parameter' : true,
			'loaded' : false,
			'userFriendlyUrl' : 'pages/news',
			'parentPage' : 'hem',
			'startupLoad' : true,
			'userFriendlyParm' : ''
		},
		'newsdetails' : {
			'page' : 'ajax/news/details',
			'name' : 'newsdetails',
			'id' : 'cpac-dynamic-news-details',
			'required' : true,
			'parameter' : true,
			'loaded' : false,
			'userFriendlyUrl' : 'pages/news/details',			
			'parentPage' : 'hem',
			'startupLoad' : false,
			'userFriendlyParm' : ''
		},
		'ideology' : {
			'page' : 'ajax/ideology/video',
			'name' : 'ideology',
			'id' : 'cpac-dynamic-ideology',
			'required' : true,
			'parameter' : true,
			'loaded' : false,
			'userFriendlyUrl' : 'pages/ideology',
			'startupLoad' : true,			
			'userFriendlyParm' : ''
		},		
		'ideology-text' : {
			'page' : 'ajax/ideology/details',
			'name' : 'ideology-text',
			'id' : 'cpac-dynamic-ideology-text',
			'required' : true,
			'parameter' : true,
			'loaded' : false,
			'userFriendlyUrl' : 'pages/ideology/details',			
			'parentPage' : 'ideology',
			'startupLoad' : true,
			'userFriendlyParm' : ''
		},
		'offer' : {
			'page' : 'ajax/offer',
			'name' : 'offer',
			'id' : 'cpac-dynamic-offer',
			'required' : true,
			'parameter' : true,
			'loaded' : false,
			'userFriendlyUrl' : 'pages/offer',			
			'startupLoad' : false,
			'userFriendlyParm' : ''
		},
		'about' : {
			'page' : 'ajax/about',
			'name' : 'about',
			'id' : 'cpac-dynamic-about',
			'required' : true,
			'parameter' : true,
			'loaded' : false,
			'userFriendlyUrl' : 'pages/about',		
			'startupLoad' : false,			
			'userFriendlyParm' : ''
		},
		'contact' : {
			'page' : 'ajax/contact',
			'name' : 'contact',
			'id' : 'cpac-dynamic-contact',
			'required' : true,
			'parameter' : true,
			'loaded' : false,
			'userFriendlyUrl' : 'pages/contact',			
			'startupLoad' : false,
			'userFriendlyParm' : ''
		},
		'career' : {
			'page' : 'ajax/career',
			'name' : 'career',
			'id' : 'cpac-dynamic-career',
			'required' : true,
			'parameter' : true,
			'loaded' : false,
			'userFriendlyUrl' : 'pages/career',			
			'startupLoad' : true,
			'userFriendlyParm' : ''
		},
		'application' : {
			'page' : 'ajax/career/application',
			'name' : 'application',
			'id' : 'cpac-dynamic-career-aaplication',
			'required' : true,
			'parameter' : true,
			'loaded' : false,
			'userFriendlyUrl' : 'pages/career/application',			
			'parentPage' : 'career',
			'startupLoad' : false,
			'userFriendlyParm' : ''			
		},		
		'search' : {
			'page' : 'ajax/search',
			'name' : 'search',
			'id' : 'cpac-dynamic-search',
			'required' : true,
			'parameter' : true,
			'loaded' : false,
			'userFriendlyUrl' : 'pages/search',
			'startupLoad' : false,
			'userFriendlyParm' : ''
		}
		
	};
	
	var commonImg = {
		'arrow' : 'images/system/arrow.png',
		'arrow_hover' : 'images/system/arrow-mouseover.png',
		'fb' : 'images/system/facebook-share.png',
		'fb_hover' : 'images/system/facebook-share-mouseover.png',
		'twitter' : 'images/system/twitter-share.png',
		'twitter_hover' : 'images/system/twitter-share-mouseover.png',
		'mail' : 'images/system/dela-share.png',
		'mail_hover' : 'images/system/dela-share-mouseover.png'		
	};
	
	(function(){
		jQuery.each(commonImg , function(index , value){
			var img = new Image();
			img.src = value;
		});
	})()
	//window.location	
	
	/*function placeArrow(){
		var screenWidth = $(window).width();
		var contentWidth = 960;		
		var remainingSpace = screenWidth - contentWidth;
		if(remainingSpace > 0)
		{
			var righDistace = (remainingSpace) / 2;					
			$('.arrow').css({'position' : 'fixed' , 'top' : 102 , 'right' : righDistace});
		}
	}
	
	placeArrow();
	
	$(window).bind('resize' , function(){
		placeArrow();
	});*/
	/*$('.current-page .resume').live('click' , function(){
		//alert('Hey 123');
		
	});*/
	
	$('.current-page .file').live('change' , function(){
		/*var extnArr = { 'pdf' : 'pdf' , 'doc' : 'doc'}
		//alert($(this).val());
		var filePath = $(this).val();
		var fileArr = filePath.split('\\');
		//console.log(fileArr);
		var fileName = fileArr[fileArr.length - 1];
		var extArr = fileName.split('.');
		var extension = extArr[extArr.length - 1];
		var className = $(this).attr('data-type');
		$('.current-page .'+className+' p').html(fileName);
		if(extension in extnArr)
			$('.current-page .'+className).addClass(extnArr.extension);
		$('.current-page .'+className).css({'display' : 'block'});*/
	});
	
	if ($.browser.msie && $.browser.version < 9) {
		$('.current-page .file').bind('propertychange' , function(event){
			/*$(this).trigger('blur' , function(){
				//alert(12312);
			});*/
		});
	}
	
	$('.current-page .file-name a').live('click' , function(){
		var clasName = $(this).attr('data-type');
		$('.current-page .'+clasName).css({'display' : 'none'});

	});
	
	$(window).scroll(function(){		
		$('.arrow').stop().animate({'top' : $(window).scrollTop() + 85 } , 1000)
	});
	
	
	var currentPage = '';	
	if(jQuery.trim(window.location.hash) == '')
	{		
		currentPage = 'hem';
	}
	else
	{
		hash = window.location.hash.replace('#' , '');
		for(var page in pages){						
			if(hash.search('^'+pages[page].userFriendlyUrl) != -1)
			{
				tmp = pages[page].name;
			}
		}
		currentPage = tmp;
	}
	
	/*var timeAnimator = function(){
		var time = $('.current-page')
	};*/
	
	/*setTimeout(function(){
		$('.arrow').fadeOut(750 , function(){				
			$('.arrow').fadeIn(750 , function(){			
				$('.arrow').fadeOut(750 , function(){				
					$('.arrow').fadeIn(750 , function(){			
						
					});		
				});
			});		
		});
	} , 2000);*/
	
	/*$('.arrow').addClass('arrow-hover-effect');
	setTimeout(function(){
		$('.arrow').removeClass('arrow-hover-effect');
	} , 4000);*/
	
	//$('.page-content').addClass('current-page');
	//console.log(pages);
	$('.content').pageslider({
		'pages' : pages,
		'urlPage' : currentPage

	});
	
	$(window).resize(function(){
		var contentHeight = $('.current-page').height() + 106;
		var windowHeight = $(window).height();
		var diff = windowHeight - contentHeight;
		if(diff >= 0){
			$('body').css({'overflow-y' : 'scroll'});
		}
		else
		{
			$('body').css({'overflow-y' : 'visible'});
		}
	});
	
	//console.log(window.location);
	//window.location.search = '';
	var search_field = $('#search-field').val();
	$('#search-field , #search-field-fullpage').live('click , focus', function(){
		var val = $(this).val();
		if(search_field == val){
			$(this).val('');
		}
	});
	
	$('#search-field , #search-field-fullpage').live('blur' , function(){
		if($('#search-field').val() ==''){
			$('#search-field').val('search');
		}
	});
	
	$('.vcard').live('click'  , function(event){			
		event.preventDefault();
		if($(this).siblings('.vcard-popup').css('display') == 'none')
		{
			$('.vcard-popup').css({'display' : 'none'});			
			$(this).siblings('.vcard-popup').css({'display' : 'block'});
			
		}
		else{
			$(this).siblings('.vcard-popup').css({'display' : 'none'});		
		}
	});	
	
	$('.vcard-popup #email').live('click' , function(){
		var val = $(this).val();
		if(val == 'EMAIL'){
			$(this).val('');
		}
		if(val == '')
		{
			$(this).val('EMAIL')
		}		
	});
	
	$('.vcard-popup #email').live('blur' , function(){
		var val = $(this).val();
		if(val == ''){
			$(this).val('EMAIL');
		}
	});
	
	
	$('#email-vcard #email-vcard-submit').live('click' , function(event){
		//var email = $('#email-vcard #email').val();	
		var email = $(this).siblings('#email').val();		
		var id = $(this).attr('class').substring(8);
		$('#email-vcard #email').css({'border' : 'none'});
		
		
		event.preventDefault();
		event.stopPropagation();
		if(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(email))
		{
			$.ajax({
				url : '/ajax/contact?ucms_ajax_page_module_id=62&email='+email+'&id='+id,
				type : 'GET',
				data : 'email='+email+'&id='+id,
				success : function(data){
					//alert(data);
					$('.vcard-popup').css('display' , 'none');
				},
				error : function(msg){
					alert(msg);
				}
			});
		}
		else
		{
			$('#email-vcard #email').css({'border' : '1px solid red'});
		}
	});
	
});

var defaultMessages = {
	'call-you-form' :{
		'username' : 'NAME',
		'telephone' : 'TELEPHONE NUMBER',
		'mail' : 'MAIL',
		'subject' : 'SUBJECT'
	},
	'application' : {
		'name' : 'first name*',
		'last_name' : 'last name*',
		'ph_no' : 'phone number*',
		'email' : 'email address*',
		'country' : 'country',
		'city' : 'city',
		'street_address' : 'street address',
		'zip' : 'zip',
		'super_name' : 'super hero',
		'power' : 'super power',
		'weakness' : 'weakness',
		'archenemy' : 'archenemy',
		'how_help' : 'how would you help CPAC? (use ten words or less)',
		'resume' : 'resume',
		'cover_file' : 'cover file'
	}
};

function resetFields(form){
	var field_list = defaultMessages[form];
	for(key in field_list){
		$('.current-page .'+key).val('');
		var default_msg = field_list[key];
		$('.current-page .'+key).val(default_msg);
		/*var default_msg = field_list[key];
		console.log($('.current-page .'+key).val(default_msg))*/
	}
}

var checkAnimationFlag = true , interval = 0;

var timeAnimator = function(time ,dst){
	//alert("Time is "+time);
	
	//var time = $('.current-page #map_id').val();
	//console.log("Before time "+new Date(time));	
	//time = time+(1*1000);
	var localdate = new Date();	
	var localTime = localdate.getTime();
	var localOffset = localdate.getTimezoneOffset() * 60000;			
	var universalTime = localTime + localOffset;
	var swedishOffset = '';	
	if(dst == 0){		
		swedishOffset = 60 * 60000;
	}else{
		swedishOffset = 120 * 60000;
	}
	var swedishTime = swedishOffset +  universalTime;
	var date = new Date(swedishTime);
	
	var weekday=new Array(7);
	weekday[0]="Sunday";
	weekday[1]="Monday";
	weekday[2]="Tuesday";
	weekday[3]="Wednesday";
	weekday[4]="Thursday";
	weekday[5]="Friday";
	weekday[6]="Saturday";
	
	var month=new Array(12);
	month[0]="January";
	month[1]="February";
	month[2]="March";
	month[3]="April";
	month[4]="May";
	month[5]="June";
	month[6]="July";
	month[7]="August";
	month[8]="September";
	month[9]="October";
	month[10]="November";
	month[11]="December";
	
	var day = (date.getDate().toString().length == 1) ? '0'+date.getDate() : date.getDate();
	var hour = (date.getHours().toString().length == 1) ? '0'+date.getHours() : date.getHours();
	var min = (date.getMinutes().toString().length == 1) ? '0'+date.getMinutes() : date.getMinutes();
	var sec = (date.getSeconds().toString().length == 1) ? '0'+date.getSeconds() : date.getSeconds();
	
	
	// Full date: (also change backend to get this to work nicely)
	//var str =  'CPAC TIME: '+weekday[date.getDay()]+', '+month[date.getMonth()]+' '+day+' '+hour+':'+min+':'+sec;
	var str =  'CPAC TIME: '+month[date.getMonth()]+' '+day+' '+hour+':'+min;
	if(!checkAnimationFlag){		
		clearTimeout(interval);
	}
	else{
		var tmpInterval = setTimeout(function(){
			timeAnimator((time+1000) , dst);
		} , 1000);
		setTimeInterval(tmpInterval);
	}
	//console.log(str);
	$('.visit-us time').html('');
	$('.visit-us time').html(str);
	//var str = date.
};

var setTimeInterval = function(i){
	interval = i;
};
var stoptimeanimator = function(){
	checkAnimationFlag = false;
}

var starttimeanimator = function(){
	checkAnimationFlag = true;
}

function applicationConfirmation(jsondata){		
	if(jsondata.status == 'success')
	{
		$('.current-page .confirmation').fadeIn(1000 , function(){
			setTimeout(function(){
				$('.current-page .confirmation').fadeOut(1000 , function(){
					
				});
			} , 5000);							
		});
	}
	else
	{
		if(jsondata.type == 'file')
		{
			for(key in jsondata.err){				
				if(key == 'resume')
					$('.current-page .resume-span').css({'border' : '1px solid red'});
				if(key == 'cover_file')
					$('.current-page .cover-span').css({'border' : '1px solid red'});
			}
			alert('We don\'t support your uploaded file format. Please upload another file and try again.');
		}
		else
		{
			alert('Failed to send email');
		}
	}
	
	/*$('.current-page .confirmation').fadeIn(1000 , function(){
		setTimeout(function(){
			$('.current-page .confirmation').fadeOut(1000 , function(){
				
			});
		} , 5000);							
	});*/
}


$('.current-page .input').live('click focus' , function(){
	var id = $(this).attr('id');
	//alert(id);
	var classname = $(this).parent().attr('class');	
	if(classname == 'call-you-form')
	{
		var messages = defaultMessages['call-you-form'];
		
	}
	else
		var messages = defaultMessages['application'];
	var val = $(this).val();	
	if(jQuery.trim(val) == jQuery.trim(messages[id]))
	{
		
		$(this).val('');
	}
});

$('.current-page .input').live('blur' , function(){
	var id = $(this).attr('id');
	
	var classname = $(this).parent().attr('class');
	if(classname == 'call-you-form')
		var messages = defaultMessages['call-you-form'];
	else
		var messages = defaultMessages['application'];
	var val = $(this).val();	
	if(jQuery.trim(val) == '')
	{
		//alert('Both are same');
		$(this).val(messages[id]);
	}
});

$('.vcard-popup a.close').live('click' , function(){
	var parent = $(this).parents('.vcard-popup');
	parent.css({'display' : 'none'});
});

$('.current-page .case-detail').live('click' , function(){	
	var self = this;
	var link = $(this).parent();
	var id = $(this).attr('id').substring(5);		
	var container_id = Math.ceil(id/2);	
	var html = $(this).parent().next('.case-data').html();		
	var case_position = '';
	if($(this).parent('figure').hasClass('left'))
	{
		case_position= 'left';
	}
	
	if($(this).parent('figure').hasClass('right'))
	{
		case_position= 'right';
	}
	/*if($('.case-detail-container').hasClass('active'))
	{
		$('.case-detail-container').animate({ 'height' : 0} , 1000 , 'easeOutQuint' , function(){		
			$(this).html('');
			
		});
		
	}*/

	//$('.cases figure').not(link).find(".details").animate({ 'height' : 0} , 1000 , 'easeOutQuint');

	//$("html, body").stop().animate({ scrollTop: link.offset().top }, 300);
	var height = $('.current-page #case-container-'+container_id).children('.details').outerHeight() + 17;	/* margin-bottom of parent */
	$('.arrow').stop().css({'top' : parseFloat($('.arrow').css('top')) - $('.current-page .case-detail-container.active').height() - height });
	
	if(!$(this).hasClass('active')){
		
		var callback = function () {

			$('.current-page #case-container-'+container_id).html('<div class="details"><div class="case-detail-arrow"></div>'+html+"</div>");
			var height = $('.current-page #case-container-'+container_id).children('.details').outerHeight() + 17;	/* margin-bottom of parent */
			$('.current-page #case-container-'+container_id).children('.details').addClass(case_position);

			setTimeout(function () {
				$("html, body").stop().animate({ scrollTop: link.offset().top - 15 }, 500);
			}, 500);
			$('.current-page #case-container-'+container_id).animate({ 'height' : height} , 500 , 'easeInQuint' , function(){
				//alert(html);
				$(this).addClass('active');
			});
			$(self).addClass('active');
		};

		$(self).parent().siblings().find(".case-detail").removeClass("active");
		$('.current-page .case-detail-container').not('#case-container-'+container_id).each(function () {
			if ($(this).hasClass('active')) {
				$(this).css({ overflow: "hidden" }).animate({'height' : '0px'}, 500, function () {
					$(this).html('').css({ overflow: "visible" });
				});
			}
		});
		if ($('.current-page #case-container-'+container_id).hasClass('active')) {
			$('.current-page #case-container-'+container_id).animate({'height' : '0px'}, 500, callback);
		} else {
			$('.current-page #case-container-'+container_id).css({'height' : '0px'});
			callback();
		}
	}
	else
	{

		$('.current-page #case-container-'+container_id).html('<div class="details"><div class="case-detail-arrow"></div>'+html+"</div>");
		var height = $('.current-page #case-container-'+container_id).children('.details').outerHeight() + 17;	/* margin-bottom of parent */
		$('.current-page #case-container-'+container_id).children('.details').addClass(case_position);

		setTimeout(function () {
			$("html, body").stop().animate({ scrollTop: link.offset().top - 15 }, 500);
		}, 500);
		$('.current-page #case-container-'+container_id).animate({ 'height' : 0} , 500 , 'easeOutQuint' , function(){		
			$(this).html('');
			$(this).removeClass('active');
		});
		$('.current-page .case-detail').removeClass('active');
	}
});

$('.current-page .close').live('click' , function(){
	var id = $(this).parents('.current-page .case-detail-container').attr('id');

	$('.arrow').stop().css({'top' : parseFloat($('.arrow').css('top')) - $('.current-page #'+id).height() }, 300);
	
	$('.current-page #'+id).animate({ 'height' : 0} , 1000 , 'easeOutQuint' , function(){
		$(this).html('');
		$(this).removeClass('active');
	});
});

$('.current-page .call-you .submit-call-you').live('click', function(event){
	event.preventDefault();
	validateCallYou();
});

function validateField(id , key , messages , type)
{	
	var val = jQuery.trim($(id).val());
	var obj = $(id);
	if(type == 'email')
	{
		if(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(val))
		{
			//obj.removeClass('error');			
			obj.css({ 'border' : '1px solid transparent'});
			return true;
			
		}
		else
		{
			//obj.addClass('error');
			obj.css({ 'border' : '1px solid red'});
			return false;
		}
	}
	else
	{
		
		if(val == '' || jQuery.trim(val) == jQuery.trim(messages[key]))
		{	
			//obj.addClass('error')		
			obj.css({ 'border' : '1px solid red'});
			return false;
		}
		else
		{
			//obj.removeClass('error');
			obj.css({ 'border' : '1px solid transparent'});
			return true;
		}
	}
}


$('.current-page .application-form-submit').live('click' , function(event){
	event.preventDefault();	
	var form_url = $('.current-page #application-form-url').val();
	$('.current-page .application-form').attr('action' , form_url);
	validateApplication();
});

function validateApplication()
{
	var pageClass = '.current-page';
	var isValid = true;
	if(!validateField(pageClass+' .name' , 'name' , defaultMessages['application'] , 'input'))
	{
		isValid = false;
	}
	if(!validateField(pageClass+' .last_name' , 'last_name' , defaultMessages['application'] , 'input'))
	{
		isValid = false;
	}
	if(!validateField(pageClass+' .ph_no' , 'ph_no' , defaultMessages['application'] , 'input'))
	{
		isValid = false;
	}
	if(!validateField(pageClass+' .email' , 'email' , defaultMessages['application'] , 'email'))
	{
		isValid = false;
	}
	/*if(!validateField(pageClass+' .country' , 'country' , defaultMessages['application'] , 'input'))
	{
		isValid = false;
	}
	if(!validateField(pageClass+' .city' , 'city' ,  defaultMessages['application'] , 'input'))
	{
		isValid = false;
	}
	if(!validateField(pageClass+' .street_address' , 'street_address' , defaultMessages['application'] , 'input'))
	{
		isValid = false;
	}
	if(!validateField(pageClass+' .zip' , 'zip' , defaultMessages['application'] , 'input'))
	{
		isValid = false;
	}
	if(!validateField(pageClass+' .super_name' , 'super_name', defaultMessages['application'] , 'input'))
	{
		isValid = false;
	}
	if(!validateField(pageClass+' .power' , 'power' , defaultMessages['application'] , 'input'))
	{
		isValid = false;
	}
	if(!validateField(pageClass+' .weakness' , 'weakness' , defaultMessages['application'] , 'input'))
	{
		isValid = false;
	}
	if(!validateField(pageClass+' .archenemy' , 'archenemy' , defaultMessages['application'] , 'input'))
	{
		isValid = false;
	}
	if(!validateField(pageClass+' .how_help' , 'how_help' , defaultMessages['application'] , 'input'))
	{
		isValid = false;
	}
	else
	{
		var help_length = jQuery.trim($(pageClass+' .how_help').val());
		var split_data = help_length.split(' ');
		
		if(split_data.length > 11){
			$(pageClass+' .how_help').css({'border' : '1px solid red'})
		}
		else{
			$(pageClass+' .how_help').css({'border' : 'none'});
		}
	}*/
	
	if(!validateField(pageClass+' .resume'  , 'resume', defaultMessages['application'] , 'input'))
	{
		isValid = false;
		$(pageClass+' .resume-span').css({'border' : '1px solid red'});
	}	
	else
	{
		$(pageClass+' .resume-span').css({'border' : '1px solid transparent'});
	}
	
	$(pageClass+' .cover-span').css({'border' : '1px solid transparent'});
	/*if(!validateField(pageClass+' .cover_file' , 'cover_file' , defaultMessages['application'] , 'input'))
	{
		isValid = false;
	}*/	
	if(isValid){
	  
		$(pageClass+' .application-form').submit();
		//resetFields('application');
	}
}

function validateCallYou()
{
	var pageClass = '.current-page';
	var messages = defaultMessages['call-you-form'];
	var name = jQuery.trim($(pageClass+' .username').val());
	var nameObj = $(pageClass+' .username');
	var telephone = jQuery.trim($(pageClass+' .telephone').val());
	var telObj = $(pageClass+' .telephone');
	var mail = jQuery.trim($(pageClass+' .mail').val());
	var mailObj = $(pageClass+' .mail');
	var subject = jQuery.trim($(pageClass+' .subject').val());
	var subObj = $(pageClass+' .subject');
	var isValid = true;
	//alert(name);
	if(name == '' || name == messages['name'] )
	{
		nameObj.addClass('error');
		isValid = false;
	}
	else{
		nameObj.removeClass('error');
		isValid = true;
	}
	
	if(telephone == '' || telephone == messages['telephone'])
	{
		telObj.addClass('error');
		isValid = false;
	}
	else{
		telObj.removeClass('error');
		isValid = true;
	}
	
	if(subject == '' || subject == messages['subject'])
	{
		subObj.addClass('error');
		isValid = false;
	}
	else{
		subObj.removeClass('error');
		isValid = true;
	}
	
	if(mail == '' || mail == messages['mail'])
	{
		mailObj.addClass('error');
		isValid = false;
	}
	else{
		//nameObj.removeClass('error');
		if(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(mail))
		{
			mailObj.removeClass('error');
			isValid = true;
		}
		else
		{
			isValid = false;
			mailObj.addClass('error');
		}
	}
	
	if(isValid)
	{
		$.ajax({
			url : '/ajax/contact?ucms_ajax_page_module_id=53',
			type : 'POST',
			data : 'username='+name+'&telephone='+telephone+'&mail='+mail+'&subject='+subject,
			success : function(data){
				//alert('Request Successful');
				$('.current-page .confirmation-call-you').fadeIn(1000 , function(){
					setTimeout(function(){
						$('.current-page .confirmation-call-you').fadeOut(1000 , function(){
							resetFields('call-you-form');
						});
					} , 5000);					
				});
			},
			error : function(msg){
				//alert(msg);
			}
		});
	}
}


function applicationSubmitConfirmation(){
	$('.current-page .confirmation').fadeIn(1000 , function(){
		setTimeout(function(){
			$('.current-page .confirmation').fadeOut(1000 , function(){
			
			});
		} , 5000);					
	});
}

// http://jdbartlett.github.com/innershiv | WTFPL License
window.innerShiv = (function () {
	var div;
	var doc = document;
	var needsShiv;

	// Array of elements that are new in HTML5
	var html5 = 'abbr article aside audio canvas datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video'.split(' ');

	// Used to idiot-proof self-closing tags
	function fcloseTag(all, front, tag) {
		return (/^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i).test(tag) ? all : front + '></' + tag + '>';
	}

	return function (
		html, /* string */
		returnFrag /* optional false bool */
	) {
		if (!div) {
			div = doc.createElement('div');

			// needsShiv if can't use HTML5 elements with innerHTML outside the DOM
			div.innerHTML = '<nav></nav>';
			needsShiv = div.childNodes.length !== 1;

			if (needsShiv) {
				// MSIE allows you to create elements in the context of a document
				// fragment. Jon Neal first discovered this trick and used it in his
				// own shimprove: http://www.iecss.com/shimprove/
				var shimmedFrag = doc.createDocumentFragment();
				var i = html5.length;
				while (i--) {
					shimmedFrag.createElement(html5[i]);
				}

				shimmedFrag.appendChild(div);
			}
		}

		html = html
			// Trim whitespace to avoid unexpected text nodes in return data:
			.replace(/^\s\s*/, '').replace(/\s\s*$/, '')
			// Strip any scripts:
			.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '')
			// Fix misuses of self-closing tags:
			.replace(/(<([\w:]+)[^>]*?)\/>/g, fcloseTag)
			;

		// Fix for using innerHTML in a table
		var tabled;
		if (tabled = html.match(/^<(tbody|tr|td|th|col|colgroup|thead|tfoot)[\s\/>]/i)) {
			div.innerHTML = '<table>' + html + '</table>';
		} else {
			div.innerHTML = html;
		}

		// Avoid returning the tbody or tr when fixing for table use
		var scope;
		if (tabled) {
			scope = div.getElementsByTagName(tabled[1])[0].parentNode;
		} else {
			scope = div;
		}

		// If not in jQuery return mode, return child nodes array
		if (returnFrag === false) {
			return scope.childNodes;
		}

		// ...otherwise, build a fragment to return
		var returnedFrag = doc.createDocumentFragment();
		var j = scope.childNodes.length;
		
		while (j--) {
			returnedFrag.appendChild(scope.firstChild);
		}

		return returnedFrag;
	};
}());
