$("document").ready(function(){
	
	$("#category").change(function(){
		$("#sub_category").html("Please Wait.. ..");
		$.get(site+"/xml/get/category/"+$(this).val(),function(data){
			$("#sub_category").html(data);
		});
	});
	
	$("div.url-wrap div.url a").click(function(){
		$.get(site+"/xml/get/linkCount/"+$(this).attr("id"));
	});
	
	$("form :input[name='link_type']").bind("click", function(){
		$link_type = 0;
		$("form :input[name='link_type']").each(function (){
			if($(this).attr("checked") && $link_type == 0)
			{
				$link_type = $(this).attr("value");
				$.get(site+"/xml/dir/getPlan/"+$link_type,function (data){
					$("#url").html(data);
				});
			}
		});
	});
	$(".login form :input[name='email']").bind("focus", function(){
		$(".login form :input[name='email']").val("");
	});
	
	$(".login form :input[name='email']").bind("blur", function(){
		if($(".login form :input[name='email']").val() == ''){
			$(".login form :input[name='email']").val("Username");
		}
	});
	
	$(".login form :input[name='password']").bind("focus", function(){
		$(".login form :input[name='password']").val("");
	});

	$(".login form :input[name='password']").bind("blur", function(){
		if($(".login form :input[name='password']").val() == ''){
			$(".login form :input[name='password']").val("Password");
		}
	});	
});

function validate()
{
	$link_type = 0;
	$("form :input[name='link_type']").each(function(){
		if($(this).attr("checked") && $link_type == 0)
		{
			$link_type = $(this).attr("value");
		}
	});
	if($link_type == 0)
	{
		alert("Select your link submission type");
	}
	else if($("form :input[name='name']").val() == '')
	{
		alert("Enter Your name");
	}
	else if($("form :input[name='email']").val() == '')
	{
		alert("Enter Your Email");
	}
	else if($("form :input[name='password']").val() == '')
	{
		alert("Please Enter desired password");
	}
	else if($("form :input[name='country']").val() == 0)
	{
		alert("Please Select your Country");
	}
	else if($("form :input[name='title']").val() == '')
	{
		alert("Please Enter your Site Title");
	}
	else if($("form :input[name='title']").val().length > 50)
	{
		alert("Please Enter Site Title below 50 Chars");
	}
	else if($("form :input[name='desc']").val() == '')
	{
		alert("Please Enter your Site Description");
	}
	else if($("form :input[name='desc']").val().length > 1000 || $("form :input[name='desc']").val().length < 250)
	{
		alert("Please Enter Site Description between 250 to 1000 Chars");
	}
	else if($("#category").val()=='' || $("#sub-category").val()=='')
	{
		alert("Please Category and/or Sub Category");
	}
	
	return true;
}
function count_hits($link_id)
{
	$.post(site+"/xml/top-hits/count/"+$link_id);
}
function verify_reciprocal($link_id, $reciprocal_url)
{
	$.get(site+"/xml/admin/verify/"+$link_id,function(data){
		if(data== true)
		{			
			$(".green-"+$link_id).html("[ Found ] <a href='"+ $reciprocal_url+"'>"+$reciprocal_url+"</a>");
			$(".red-"+$link_id).html("");
		}
		else
		{		
			$(".red-"+$link_id).html("[ Not Found ] <a href='"+ $reciprocal_url+"'>"+$reciprocal_url+"</a>");
			$(".green-"+$link_id).html("");
		}
	});
}
