var Core = (function () { 

	var _SetHelpBoxTimeOut = 150000;
	var _FadeSpeed = 350;
	var _SlideSpeed = 350;	
	var _Count = 0;
	var _DynamicHeaderTextId = '#Header .InnerHeader .Text';

	var _o = {
		
		'Init': function () {
			$('[rel="PDFGuideButton"]').click(function(){ _o.PDFGuide(); return false; });
			//setInterval(function(){ _o.HeaderTextAnimation() }, 7500);
			$('input').focus(function(){ $.cookie('ShowHelp', '1', { expires: 7, path: '/' }); });	
			if ($.cookie('ShowHelp') != '1') { setTimeout(function(){ _o.UseHelpBox(); }, _SetHelpBoxTimeOut); } 
		},
		
		'UseHelpBox' : function () {
			
			if ($.cookie('ShowHelp') != '1') {
				_o.ShowHelp();
			} else {
				return false;	
			}
			
		},
		
		'ShowHelp' : function () { 
		
			$.ajax({
				'url': '/Includes/MoreHelp.php',
				'type': 'GET',
				'cache':false,
				'success': function (Data){
		
				Core.UI.SetPopupBox({'Title':'Need Help?', 'Show':true, 'ShowClose': true, 'ShowProgress': false, 'Text': Data, 'Width': '700px'});
				$.cookie('ShowHelp', '1', { expires: 7, path: '/'});
				
				if (typeof CallBack !== 'undefined'){
							// CallBack();
						}
				}, 
				'error': function(a,b,c) {
					alert (a + b + c);
				}
			});		
			
		},
		
		'HeaderTextAnimation' : function  () {
	
			if (_Count <= 2) {
				$(_DynamicHeaderTextId).animate({opacity: 0.05}, _FadeSpeed, function(){
					$(this).animate({opacity:1}, _FadeSpeed); 
				});
			}
			
			if (_Count >= 2) {
				$(_DynamicHeaderTextId).animate({opacity: 0.0}, _FadeSpeed, function(){
					$(this).html('We have been helping people claim for injury since 1998').animate({opacity:1}, _FadeSpeed);
				});
			}
			
			if (_Count >= 3) { 
				$(_DynamicHeaderTextId).animate({opacity: 0.0}, _FadeSpeed, function(){
					$(this).html('Call Us Now On: 0845 9000 408').animate({opacity:1}, _FadeSpeed);
				});		
			}
			
			_Count++;
		},	
		
		'SlideDownPDF': function (Id) {
			$('.SubmitPDFForm').attr( 'value', 'Download PDF & Submit Form');
			$('.SubmitPDFForm').attr( 'name', 'SubmitPDFAndDetails');
			$('.MoreInfo').css({'display':'none'});
			$(Id).slideDown(500);
		},
		
		'PDFSubmit': function (Id) {
			
			var x = _o.ValidatePDF(Id);
			
			if (x.length == 0){
						
				$.ajax({
					'url': '/Includes/SendMail.php',
					'type': 'GET',
					'cache': false,
					'data': "PDFName=" + $('#PDFName').val() + "&PDFEmail=" + $('#PDFEmail').val() + "&PDFNumber=" + $('#PDFNumber').val() + "&PDFInjury=" + $('.PDFInjury').val(),
					'dataType': 'json',
					'success': function (Data){
							
							if (Data.Success == '1' && Data.Error != '1') {
									window.location.href = Data.URL;
							} else { 
									
							}
							
					if (typeof CallBack !== 'undefined'){
								// CallBack();
							}
					}, 
					'error': function(a,b,c) {
						alert (a + b + c);
					}
				});
				
			} else { 
				var ErrMsg = '<h2>Problem With Your Form:</h2><ul>';
				for (var i = 0; i < x.length; i++) {
					ErrMsg += '<li>' + x[i] + '</li>';
				}
				ErrMsg += '</ul>';
				$('.Errors').html(ErrMsg).slideDown(_SlideSpeed);
			}	
			
		},		
			
		'ValidatePDF' : function(Id) {
			
			var Errors = [];
		
			if (Id == 'SubmitPDFOnly') {
				if (!(/^[a-zA-Z \-'.]+$/.test($('#PDFName').val()))){ Errors.push('Your Name');	}
				if (!(/^[A-z0-9_\.\-]+\@([A-z0-9_-]+\.)+[A-z]{2,4}$/.test($('#PDFEmail').val()))){ Errors.push('Invalid Email Address'); }
			} else {
				if (!(/^[a-zA-Z \-'.]+$/.test($('#PDFName').val()))){ Errors.push('Your Name');	}
				if (!(/^[A-z0-9_\.\-]+\@([A-z0-9_-]+\.)+[A-z]{2,4}$/.test($('#PDFEmail').val()))){ Errors.push('Invalid Email Address'); }
				if (!(/^0[1278]\d{9}$/.test($('#PDFNumber').val()))){ Errors.push('Your Number'); }
			}
			
			return Errors;
			 
		},		

		'PDFGuide': function () {		
		
			$.ajax({
				'url': '/Includes/DownloadPDF.php',
				'type': 'GET',
				'cache':false,
				'success': function (Data){
						Core.UI.SetPopupBox({'Title':'Download PDF Guide', 'Show':true, 'ShowClose': true, 'ShowProgress': false, 'Text': Data, 'Width': '550px'});
						if (typeof CallBack !== 'undefined'){
							// CallBack();
						}
				}, 
				'error': function(a,b,c) {
					alert (a + b + c);
				}
			});
		
			
		}
		
	}
	
return _o;	

})();
