$(document).ready(function() {

	jQuery.preloadImages = function()
	{
	  for(var i = 0; i<arguments.length; i++)
	  {
	    jQuery("<img>").attr("src", arguments[i]);
	  }
	}
	
	$.preloadImages("../images/btn_enter_h.gif", "../images/cornertext_h.gif", "../images/arrow2.gif", "../images/top.gif", "../images/cornerinput_h.gif", "../images/cornersubmit_h.gif");
	
	$('img#gotQuestions').hover(function () {
		this.src = 'images/btn_enter_h.gif';
	}, function () {
		this.src = 'images/btn_enter.gif';
	}); 
	
	$('img#topTen').hover(function () {
		this.src = 'images/top.gif';
	}, function () {
		this.src = 'images/top_h.gif';
	});

	$('.cornered').parent().css('padding', '3px').corner("round");

	
	$("#submitSite").click( function() {
		$("#resultTxt").hide();
		$('#loading').show();
		$.ajax({
				type: "POST",
				url: "include/process.php",
				data: $("#formPlaceHolder form").serialize(),
				success: function(msg){
					$("#loading").fadeOut('fast');
					$("#resultTxt").fadeIn('slow');
					$("#resultTxt").html(msg);
					document.getElementById('capImg').src = 'include/securimage_show.php?sid=' + Math.random();
				}
			});
	} );	 
	
	
	$("#contactUs").click( function() {
		$("#resultTxt").hide();
		$('#loading').show();
		$.ajax({
				type: "POST",
				url: "include/process.php",
				data: $("#formPlaceHolder form").serialize(),
				success: function(msg){
					$("#loading").fadeOut('fast');
					$("#resultTxt").fadeIn('slow');
					$("#resultTxt").html(msg);
					document.getElementById('capImg').src = 'include/securimage_show.php?sid=' + Math.random();
				}
			});
	} );
	
	$('body').click(function(){
		$('#letterResult').hide();
	});
	
	
	$("#newsLetterBtn").click(function(){
		$("#lettertxt").hide('');
		$("#letterResult").slideDown('fast');
		$('#headLoading').show();
		$.ajax({
				type: "POST",
				url: "include/process.php",
				data: $("#headerTxt form").serialize(),
				success: function(msg){
					$("#headLoading").hide();
					$("#lettertxt").fadeIn('slow');
					$("#lettertxt").html(msg);
					setTimeout(function(){$('#letterResult').slideUp();}, 5000); 
				}
			});
	});
	
	
	$("#reviewPostBtn").click(function(){
		$("#rtxt").html('');
		$("#rtxt").hide('');
		$("#rResult").slideDown('fast');
		$('#rLoading').show();
		$.ajax({
				type: "POST",
				url: "include/process.php",
				data: $("#reviewForm form").serialize(),
				success: function(msg){
					$("#rtxt").html('');
					$("#rLoading").hide();
					$("#rtxt").fadeIn('slow');
					if(msg=='yes'){
						var temp=$('#providerID').val();
						window.location='?page=provider&msg=success&p='+temp;
					}else{
						$("#rtxt").html(msg);
						document.getElementById('capImg').src = 'include/securimage_show.php?sid=' + Math.random();
						//document.getElementById('capthca').value=''; 
						setTimeout(function(){$('#rResult').slideUp('fast');}, 5000); 
					}
				}
			});
	});
	

	$('#rate2').rating('www.url.php', {maxvalue:5, curvalue:3});
	
	$('#sortInput').change(function(){
		var temp=$('#sortInput').val();
		if (temp!=''){
			window.location='?page=providers&sort='+temp;
		}
	});
	
	$('#sortReview').change(function(){
		var temp=$('#sortReview').val();
		var temp2=$('#providerID').val();
		if (temp!=''){
			window.location='?page=provider&p='+temp2+'&sort='+temp;
		}
	});
	
	$('#frontPSelect').change(function(){
		var temp=$('#frontPSelect').val();
		if (temp!=''){
			window.location='?page=provider&p='+temp;
		}
	});
	  
 });
 
