/**
* Styleswitch stylesheet switcher built on jQuery
* Under an Attribution, Share Alike License
* By Kelvin Luck ( http://www.kelvinluck.com/ )
**/
function autoFill(id, v){
	$(id).css({ color: "#b2adad" }).attr({ value: v }).focus(function(){
		if($(this).val()==v){
			$(this).val("").css({ color: "#333" });
		}
	}).blur(function(){
		if($(this).val()==""){
			$(this).css({ color: "#b2adad" }).val(v);
		}
	});

}

$(document).ready(function() {
	$('.styleswitch').click(function()
	{
		switchStylestyle(this.getAttribute("rel"));
		return false;
	});
	var c = readCookie('style');
	if (c) switchStylestyle(c);
});

function switchStylestyle(styleName)
{
	$('link[@rel*=style][@title]').each(function(i) 
	{
		this.disabled = true;
		if (this.getAttribute('title') == styleName) this.disabled = false;
	});
	createCookie('style', styleName, 365);
}

// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
// /cookie functions


$(document).ready(function() {
    // to show it in an alert window
  //  alert(window.location);

    // to store it in a variable
  // var loc = window.location.toString();
    //var home= "http://vailgayskiweek.com/";
    //if (loc.indexOf( "tickets")){
    	$.metadata.setType("attr", "validate");
			$("#registration_form").validate({
				 submitHandler: function(form) {
				  //alert("ljlj"+$("#registration_form").serialize());
					$('#submit_regform').hide();
					jQuery.post("http://vailgayskiweek.com/wp-content/themes/vintage/js/sendemail.php",				
							$("#registration_form").serialize(),
							function(data){
						$("#registration_form").slideUp("normal", function() {				   
							//$("#firstName").html(firstName);
							$("#registration_form").before($("#reg_form_message").html());
							//pageTracker._trackPageview("/quoteform_request/thankyou");
							_gaq.push(['_trackPageview', '/reg_form/thankyou']);
						});
						}
							
						 );
					
				 }
			});
    	
   
    		
    
});


 
/*

$(document).ready(function() {
	//	openbox(1);
	$('#submit_regform').click(function() {
			$("#registration_form").validate({
				 submitHandler: function(form) {
				  //alert("ljlj"+$("#registration_form").serialize());
					jQuery.post("http://vgsw.rmvrmedia.com/wp-content/themes/vintage/js/sendemail.php",				
							$("#registration_form").serialize()
					
							
						 );
					
				 }
			});
		});
	

}); 
*/


$(document).ready(function(){
	$("#submit").click(function(){
		//alert("submit clicked");
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		/*var emailToVal = $("#emailTo").val();
		if(emailToVal == '') {
			$("#emailTo").after('<span class="error">You forgot to enter the email address to send to.</span>');
			hasError = true;
		} else if(!emailReg.test(emailToVal)) {	
			$("#emailTo").after('<span class="error">Enter a valid email address to send to.</span>');
			hasError = true;
		}*/
		
		var ContactEmail = $("#Email").val();
		if(ContactEmail == '') {
			$("#Email").after('<span class="error"><br/>You forgot to enter the email address to send from.</span>');
			hasError = true;
		} else if(!emailReg.test(ContactEmail)) {	
			$("#Email").after('<span class="error"><br/>Enter a valid email address to send from.</span>');
			hasError = true;
		}
		
		var firstname = $("#FirstName").val();
		var lastname = $("#LastName").val();
		if(firstname == '' || lastname=='') {
			$("#FirstName").after('<span class="error">You forgot to enter the subject.</span>');
			hasError = true;
		}

		var FirstName=$("#FirstName").val();
		var LastName=$("#LastName").val();
		
		if(hasError == false) {
			$(this).hide();
			$(".subscribe").append('<img src="http://vailgayskiweek.com/wp-content/themes/vintage/images/loading.gif" alt="Loading" id="loading" />');
			
			//$.post("/wp-content/uploads/2008/01/sendemail.php",
			//{ emailTo: emailToVal, emailFrom: emailFromVal, subject: subjectVal, message: messageVal },
			$.post("http://vailgayskiweek.com/wp-content/themes/vintage/js/sendemail.php",				
					{ FirstName: FirstName, LastName: LastName,ContactEmail: ContactEmail},
   					function(data){
						$("#newsletter").slideUp("normal", function() {				   
							//"Thank you for signing up for our Weekly Newsletter. You'll receive our Newsletter from our staff every tuesday morning!"
							$("#newsletter").after('<p><h1>Get ready for Vail Gay Ski Week!</h1><br><br><br>Thank you! You\'ll be the first to receive updates!</p>');
						});
   					}
				 );
		}
		
		return false;
	});		
	autoFill($("#FirstName"), "First");
	autoFill($("#LastName"), "Last");
	autoFill($("#Email"), "Email");
	$(".subscribe").hover(
			function(){
				$(this).addClass("hover");
			}, 
			function(){
				$(this).removeClass("hover");
			}
		);
});	






