$(document).ready(function(){	$(".cheeperLink").click(function(){
	    var wWidth = $(window).width();
		var wHeight = $(window).height();

		var scrollT = $(document).scrollTop();

		var divHeight = $(".mainBuyPPDVCH").height();

		var nPosLeft = (wWidth - 377)/2;
		var nPosTop = (wHeight - divHeight)/2+scrollT;

		$(".mainBuyPPDVCH").css("left",nPosLeft+"px");
		$(".mainBuyPPDVCH").css("top",nPosTop+"px");
		$(".mainBuyPPDVCH").fadeIn("slow");
		return false;
	});

	/*CLOSE ERROR DIALOG*/
	$(".closeBuyPPCH").click(function(){
       $(".mainBuyPPDVCH").fadeOut("slow");
       $(".chSuccessDV").hide();
       $(".buyPPcontTextDVCH").show();
       $("#fotofanProd").val("");
       $("#siteName").val("http://");
       $("#emailName").val("");

       $("#fotofanProd").css("border","solid 1px #1189D6");
       $("#siteName").css("border","solid 1px #1189D6");
       $("#emailName").css("border","solid 1px #1189D6");

       $(".buyPPaddCartProdCH").show();
	});
	/*END*/

	/*SEND CHEEPER BUTTON*/
	$(".buyPPaddCartProdCH").click(function(){		var fotofanProd = $("#fotofanProd").val();		var siteName = $("#siteName").val();
		var emailName = $("#emailName").val();
		var countErrors = 0;

		if(fotofanProd == "")
		{
			countErrors ++;
			$("#fotofanProd").css("border","solid 1px #EB0000");
		}
		else
		{
            $("#fotofanProd").css("border","solid 1px #1189D6");
		}

		if(siteName == "" || siteName == "http://")
		{			countErrors ++;
			$("#siteName").css("border","solid 1px #EB0000");
		}
		else
		{            $("#siteName").css("border","solid 1px #1189D6");
		}

		if(emailName == "")
		{
			countErrors ++;
			$("#emailName").css("border","solid 1px #EB0000");
		}
		else if ( emailName. indexOf ( "@" , 2) == -1 )
		{			countErrors ++;
			$("#emailName").css("border","solid 1px #EB0000");
			emailName.focus();
		}
		else
		{
            $("#emailName").css("border","solid 1px #1189D6");
		}

		if(countErrors > 0)
		{
		}
		else
		{           $(".buyPPcontTextDVCH").hide();
           $(".chSuccessDV2").show();
           $(".buyPPaddCartProdCH").hide();

            JsHttpRequest.query(
			"/skin/php/sendCheeper.php",
			{
				"fotofanProd": fotofanProd,
				"siteName": siteName,
				"emailName": emailName
			},
			function (result,errors)
			{
				if (result)
				{
					var ok = result.ok;

					if(ok == 'ok')
					{
			            $(".chSuccessDV2").hide();
			            $(".chSuccessDV").show();
					}
					else
					{

					}
				}
				else
				{

				}
			},
			true
			)
		}
	});
	/*END*/
});