
var months 		= Array('January','February','March','April','May','June','July','August','September','October','November','December');
var monthsShort = Array('Jan','Feb','Mar','Apr','May','June','Jul','Aug','Sept','Oct','Nov','Dec');

time();

function time(){
	var log = '';

	//Month
	var currentTime = new Date()
	var month 		= currentTime.getMonth();
	var day 		= currentTime.getDate();
	var year 		= currentTime.getFullYear();

	//Time
	var currentTime = new Date();
	var hours		= currentTime.getHours();
	var minutes 	= currentTime.getMinutes();
	var seconds 	= currentTime.getSeconds();
	
	if (minutes < 10){
		minutes = "0" + minutes
	}
	if (seconds < 10){
		seconds = "0" + seconds	
	}
	
	log += monthsShort[month] + ". " + day + ", ";
	log += hours + ":" + minutes + ":"+seconds+" ";

	if(hours > 11){
		log += "PM";
	} else {
		log += "AM";
	}
	
	$("#time").remove();
	$(".time").append('<span id="time">'+log+'</span>');
 	window.setTimeout("time()",100);
}

function site(toopen){
	if(toopen == 'Maintenance'){ 
		var thesite = 'http://www.exceltire.com/maintenance.html'; 
		var toolbar = 0;
	}else{ 
		var thesite = 'http://www.exceltire.com';
		var toolbar = 1;
	}
	window.open(thesite,'Excel Tire Centre :: Maintenance','width=950,height=500,toolbar='+toolbar+',resizable=1');
	return false;
}





$(document).ready(function(){
						   
	//Contact Us
	if($(".contactType").length > 0){
		
		//CONTACT TYPE SETTINGS
		$(".contactType",this).each(function(){
			$(this,this).click(function(){
				if($(this).val() == 1){
					var type = 'Information';	
				}else
				if($(this).val() == 2){
					var type = 'Employment';	
				}
				$("#contactType").remove();
				$("#contactus").append('<span id="contactType"> :: '+type+'</span>');
			});
		});

		if($("input[@name='contactType']:checked").val() == 1){
			var type = '<span id="contactType"> :: Information </span>';
			$("#contactus").append(type);	
		}else
		if($("input[@name='contactType']:checked").val() == 2){
			var type = '<span id="contactType"> :: Employment </span>';
			$("#contactus").append(type);
		}
	
	//SUBMISSION CHECK
		$("form").submit(function(){
			var error   = false;
			var name 	= $("#name");
			var email	= $("#email");
			var message	= $("#message");
			var formfields = new Array(name,email,message);
			for(i=0; i<formfields.length; i++){
				var fieldname = formfields[i].attr("name");
				var curval 	  = formfields[i].val();
				
				if(curval == '' || ( (fieldname == 'email') && (!emailCheck(curval)) ) ){
					if(!error){ error = formfields[i]; }
					if($("#"+fieldname+"img").length > 0){ $("#"+fieldname+"img").remove(); }
					formfields[i].parent().append('<img src="images/icons/warning.gif" id="'+fieldname+'img" />');
					formfields[i].css("border","1px solid red");
				}else{
					var fieldname = formfields[i].attr("name");
					if($("#"+fieldname+"img").length > 0){ $("#"+fieldname+"img").remove(); }
					formfields[i].parent().append('<img src="images/icons/check.png" id="'+fieldname+'img" />');
					formfields[i].css("border","1px solid darkgray");
				}
			}
			if(error !== false){
				error.focus();
				return false;	
			}else{
				if($("input[@name='contactType']:checked").val() == 1 || $("input[@name='contactType']:checked").val() == 2){
					return true;
				}
				$(".contactType")[0].focus();
				alert('Please choose the receiver: Information or Employment');
				return false;
			}
		});
	}
});
		
function emailCheck(str){
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   	if(reg.test(str) == false) {
    	  return false;
   	}
	return true;
}

$(document).ready(function(){
						   
	$('.promotions').find('a').click(function(e){				  
		e.preventDefault();
		var link = "images/promotions/"+$(this).attr("title")+".1.jpg";
		
		window.open (link,"Symons Excel Tire Promotional Offer","status=1,toolbar=1"); 									
	});
});