function goVote(rank,uid) {
	document.formVote.rank.value = rank;
	document.formVote.uid.value = uid;
	document.formVote.submit();
}
	function $_GET(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  return false;
}

function validateAge() 
{
	var $select_year = $('form').find('select.year');
	
	var year_input = $select_year.val();
	var month_input = $('form').find('select.month').val();
	var day_input = $('form').find('select.day').val()
	
	if ( Validator.year > year_input
			|| (year_input == Validator.year && Validator.month > month_input)
			|| (year_input == Validator.year && Validator.month == month_input && Validator.day >= day_input)){							
		if(Validator.$hiddenAge.length > 0){
	
			Validator.$hiddenAge.val(month_input+"-"+day_input+"-"+year_input);
			Validator.$hiddenAge2.val(Validator.age - $select_year.val());
		}
		$($select_year).eq(0).next(".error").remove();
		return true;
	} else 	{
		$($select_year).eq(0).next(".error").remove();
		$($select_year).eq(0).after("<span class='error'>You must be over 18<span>");
		return false;	
	}
}

function valid_email(str) {
	var lat=str.indexOf(valid_email.at);
	var lstr=str.length-1;
	var ldot=str.indexOf(valid_email.dot);
	if (str.indexOf(valid_email.at)==-1){
	   return false;
	}
	if (str.indexOf(valid_email.at)==-1 || str.indexOf(valid_email.at)==0 || str.indexOf(valid_email.at)==lstr){
	   return false;
	}
	if (str.indexOf(valid_email.dot)==-1 || str.indexOf(valid_email.dot)==0 || str.indexOf(valid_email.dot)==lstr){
		return false;
	}
	if (str.indexOf(valid_email.at,(lat+1))!=-1){
		return false;
	}
	if (str.substring(lat-1,lat)==valid_email.dot || str.substring(lat+1,lat+2)==valid_email.dot){
		return false;
	}
	if (str.indexOf(valid_email.dot,(lat+2))==-1){
		return false;
	}
	if (str.indexOf(" ")!=-1){
		return false;
	}
	return true					
}

function valid_phone(s) 
{
     // Check for correct phone number
     rePhoneNumber = new RegExp(/^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/);
     if (!rePhoneNumber.test(s)) {
          return false;
     }
	return true;
}
function checkPassword(passwords){
	if(passwords.length <= 1)
		return true;
	return $(passwords).eq(0).val() == $(passwords).eq(1).val();
}

function isFormValid(){
	var ok = true;
	
	Validator.$required_notS_notCB.each(function(){
		if(this.value == "") ok = false;
	});
	
	if(!ok) return false;
	
	Validator.$required_select.each(function(){
		if(this.selectedIndex == 0) ok = false;
	});
	
	if(!ok) return false;

	Validator.$required_email.each(function(){
		if(!valid_email(this.value)) ok = false;
	});
	
	if(!ok) return false;

	Validator.$required_phone.each(function(){
		if(!valid_phone(this.value)) ok = false;
	});
	
	if(!ok) return false;
	
	if(!checkPassword(Validator.$required_password))
		ok = false;

	Validator.$required_checkbox.each(function(){ 
		if(!this.checked) ok = false;
	});
	
	if(!ok) return false;

	if(!validateAge())
		ok = false;
	return ok;
}

var Validator = $(document).ready(function(){
	
	valid_email.at="@";
	valid_email.dot=".";

	var checkStr = "Validator.$submit.attr('disabled','disabled');if(isFormValid())Validator.$submit.removeAttr('disabled');";
	var delay = 2000;

	Validator.Timer;	
	var now = new Date();
	Validator.age = now.getFullYear(); 
	Validator.year = now.getFullYear() -18; 
	Validator.month = parseInt(now.getMonth()) + 1;
	Validator.day =  now.getDate();
	
	Validator.$required_checkbox = $("form").find(".required").filter('input[@type=checkbox]');
	$(Validator.$required_checkbox).addClass('checkbox');
	Validator.$required_password = $("form").find(".required").filter('input[@type=password]');
	Validator.$required_select = $("form").find(".required").filter('select');
	Validator.$required_phone = $("form").find(".required").filter('.phone');
	Validator.$required_email = $("form").find(".required").filter('.email');
	Validator.$required_notS_notCB = $("form").find(".required").not('select').not('.checkbox');
	
	Validator.$hiddenAge = $('form .hiddenAge');
	Validator.$hiddenAge2 = $('form .hiddenAge2');
	Validator.$submit = $("form").find('input[@type=submit]');		
	
	// simple required fields
	if(($("form").find(".required").length > 0) && (!isFormValid()))
	{
		Validator.$submit.attr('disabled','disabled');
	}
	else
	{
		Validator.$submit.removeAttr('disabled');
	}
			
	Validator.$required_notS_notCB.keyup(function(){
		if(Validator.Timer)				
			clearTimeout(Validator.Timer);
		if(this.value == "")
		{
			$(this).next(".error").remove();
			if (this.title != "")
				$(this).after("<span class='error'>"+this.title+".<span>");
			else
				$(this).after("<span class='error'>This field is required.<span>");
			Validator.$submit.attr('disabled','disabled');
		}else{
			$(this).next(".error").remove();
			Validator.Timer = setTimeout(checkStr , delay);
		}
   });
	
	// required email fields
	Validator.$required_email.change(function(){
		if(!valid_email(this.value))
		{
			$(this).next(".error").remove();
			$(this).after("<span class='error'>Please enter a valid e-mail address.<span>");
		}else {
			$(this).next(".error").remove();
		}
   });

	// not required email fields
	$("form").find(".email").not(".required").change(function(){
		if(this.value != "" && !valid_email(this.value))
		{
			$(this).next(".error").remove();
			$(this).after("<span class='error'>Please enter a valid e-mail address.<span>");
		}else {
			$(this).next(".error").remove();
		}
   });
	
	//  required select
	Validator.$required_select.change(function(){
		if(Validator.Timer)				
			clearTimeout(Validator.Timer);
		if(this.selectedIndex != 0){
			$(this).next(".error").remove();
			Validator.Timer = setTimeout(checkStr , 300);
		}else{
			$(this).next(".error").remove();
			$(this).after("<span class='error'>You must choose an option.<span>");
			Validator.$submit.attr('disabled','disabled');
		}
   });

	$("form").find('select').not('.required').change(function(){
		if(Validator.Timer)				
			clearTimeout(Validator.Timer);	
		Validator.Timer = setTimeout(checkStr , 300);
	});
	
	Validator.$required_checkbox.click(function(){
		if(Validator.Timer)				
			clearTimeout(Validator.Timer);																	   
		if($(this).attr('checked')){
			Validator.Timer = setTimeout(checkStr , 300);												  	
		}else{
			Validator.$submit.attr('disabled','disabled');						
		}
	});
														
	Validator.$required_phone.change(function(){
		if(!valid_phone(this.value))
		{
			$(this).next(".error").remove();
			$(this).after("<span class='error'>Phone Number Must Be Entered As: (555) 555-1234.<span>");
		}else {
			$(this).next(".error").remove();
		}
   });

	$("form").find(".phone").not(".required").change(function(){
		if(this.value != "" && !valid_phone(this.value))
		{
			$(this).next(".error").remove();
			$(this).after("<span class='error'>Phone Number Must Be Entered As: (555) 555-1234.<span>");
		}else {
			$(this).next(".error").remove();
		}
   });
	
	Validator.$required_password.change(function(){
		$(Validator.$required_password).eq(1).next(".error").remove();
		if (!checkPassword(Validator.$required_password))
			$(Validator.$required_password).eq(1).after("<span class='error'>Passwords don't match.<span>");
			
	});

	$("form").find(".file").filter(".required").change(function(){
		eval(checkStr);
   });
	
  	
    Validator.$submit.click(function() {
			if (isFormValid()){
				//alert('This form will be submitted.');
				return true;
				
			} else{
				alert("There are still errors on this form, please check everything before registering.");
				return false;	
			}										  
        });


	$('.tx-srfeuserregister-pi1 fieldset.preview').hide();
	$('.tx-srfeuserregister-pi1 fieldset.preview :submit').attr('disabled','disabled');
	$('#agree input').click(function(){
		$('#agree').hide();
		$('.tx-srfeuserregister-pi1 fieldset.preview').show();
		$('.tx-srfeuserregister-pi1 :submit').removeAttr('disabled');
	});
	
	$("ul.nav").find("img").not(".active").hover(function(){
	 this.src = this.src.replace(".gif","_h.gif");
	},function(){
	 this.src = this.src.replace("_h.gif",".gif");
	});
	
	$("#front_right a").find("img").hover(function(){
	 this.src = this.src.replace(".gif","_h.gif");
	},function(){
	 this.src = this.src.replace("_h.gif",".gif");
	});
	
	$("#loginform a").find("img").hover(function(){
	 this.src = this.src.replace(".gif","_h.gif");
	},function(){
	 this.src = this.src.replace("_h.gif",".gif");
	});

	
	$("label a").click(function(){
		window.open(this.href,null,"height=400,width=550,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");
		return false;							
	});
	
	$("#footer a").not(":last-child").click(function(){
		window.open(this.href,null,"height=400,width=550,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");
		return false;							
	});

 $("a.legalpop").click(function(){                
		window.open(this.href,null,"height=400,width=550,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");                
		return false;        
});	
	$('ol.vote img').hide();

		
	$('ol.vote a').mouseover(function(){
		$('ol.vote img').show();
		n = $(this).attr('rel');
		for(i=5;i>n;i--)
		{
			$('ol.vote img').eq(i-1).hide();
		}
	});
	
	$('.media .thumbs img').click(function(){
		document.getElementById('viewer').src = this.src.replace("media/thumbs/","media/");
										
	});
	$('.media .thumbs li').click(function(){
			$('.media .thumbs li div').hide();
			$("div",this).show();
	});
	

	vid = $_GET('vid');
	//alert(vid);
	if($('.media .video-thumbs li').size() > 0 && vid)
	{
		//alert(vid);
		if($("#vi"+vid+"j div").size() > 0) {
			$('.media .video-thumbs li div').hide();
			$("#vi"+vid+"j div").show();
		}
	}
	
	$('#agree input').click(function(){$('#agree').hide();});		
	
	$('.ad a').eq(0).click(function(){
	window.open(this.href,null,"height=510,width=832,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");
		return false;	
	});
	
	
	
});



	
