// JavaScript Document
$(document).ready(function() {
	$("#AddressDetails").hide();
	$("#Activity").hide();
	$("#PasswordResetDiv").hide();
	$("#RetailerSpecials").hide();
	$("#ClosedDates").hide();
});

function UpdateRShipping()
{
	jQuery(document).ready(function(){
		var Shipping = parseFloat(jQuery("#EstimatedShippingFee").val());
		var SubTotal = parseFloat(jQuery("#SubTotal").val());

		jQuery.ajax({type: "POST", url: "/tools/retailerdistributor/updateshipping", data: "Shipping="+Shipping, success: function(msg){}});
		var Total = Shipping+SubTotal;
		jQuery.ajax({type: "POST", url: "/tools/retailerdistributor/roundnumber", data: "Amount="+Total, success: function(msg){ jQuery("#OrderTotal").html(msg); }});
	});
}

function ShowPricingScreen(Price, ShowDiv)
{
	$("#"+ShowDiv).slideToggle();
	$.ajax({type: "POST", 
			url: "/tools/creator/PricingRecommendation/", 
			data: "Price="+Price+"&ShowDiv="+ShowDiv,
			dataType: "html",
			success: function(msg){ 
				$("#"+ShowDiv).html(msg); 
			}
	});
}

function RecPriceReset(PrintCost, ShowDiv)
{
	var Price;
	$.ajax({type: "POST", 
		   	data: "PrintCost="+PrintCost,
			url: "/tools/creator/GetPrintCost/",
			success: function(msg){ 
				$("#CoverPrice").val(msg);
				Price = msg;
				CoverUpdate(Price, PrintCost, ShowDiv);
			}
	});
}

function SubmitFilter(Filter)
{
	$("#"+Filter, top.document).submit();
}

function CoverUpdate(Price, PrintCost, ShowDiv)
{
	$.ajax({type: "GET", 
			url: "/tools/creator/PricingRecommendation/"+Price+"/"+PrintCost+"/"+ShowDiv+"/1",
			success: function(msg){ 
				var Data = msg.split("^");
				$("#WholeSalePrice").val(Data[0]); 
				$("#CreatorProfit").val(Data[1]); 
				$("#CreatorProfitHidden").val(Data[1]);
			}
	});
}

function CreatorProfitUpdate(newProfit)
{
	if(1)
	{
		var Difference = $("#CreatorProfitHidden").val() - newProfit;
		$("#CreatorProfitHidden").val(newProfit);
		NewWholeSalePrice = $("#WholeSalePrice").val() - Difference;
		$.ajax({type: "POST", 
			   data: 'Number='+NewWholeSalePrice,
			url: "/tools/creator/GetRound/",
			success: function(msg){ 
				$("#WholeSalePrice").val(msg);
			}
		});
	}
}

function PriceRecProfit(Delta)
{
	var CoverPrice = parseFloat($("#CoverPrice").val());
	var CreatorProfit = parseFloat($("#CreatorProfit").val());
	var WholeSalePrice = parseFloat($("#WholeSalePrice").val());
	var PrintCost = parseFloat($("#PrintCost").val());
	$.ajax({type: "POST", 
				url: "/tools/creator/PricingRecommendationChange/", 
				data: "CoverPrice="+CoverPrice+
						"&CreatorProfit="+CreatorProfit+
						"&WholeSalePrice="+WholeSalePrice+
						"&PrintCost="+PrintCost+
						"&Change="+Delta,
				dataType: "html",
				success: function(msg){ 
					var Data = msg.split("^");
					$("#WholeSalePrice").val(Data[0]);
					$("#CreatorProfit").val(Data[1]);
					$("#CreatorProfitHidden").val(Data[1]);
				}
		});
}

function HideCoverRetailer(CartIndex)
{
	$("#CoverRetailerDiv"+CartIndex).hide('fast');
	$("#CoverOnlyDiv"+CartIndex).hide('fast');
}

function ShowHideDiv(ShowDiv, HideDiv)
{
	$("#"+ShowDiv).show('fast');
	$("#"+HideDiv).hide('fast');
}

function ViewDiv(divName){
	$("#"+divName).slideToggle();
}

function SubmitForm(Action, FormName){
		$("#"+FormName, top.document).attr("action",Action); 
		$("#"+FormName, top.document).submit();
}

function SetAdImage(ImageName){
	$("#AdImage").html('<img src="/tools/images/ads/'+ImageName+'" />');
	$("#AdImageInput").val(ImageName);
	$("#AdImageInputPlacerHolder").html(ImageName);
	parent.tb_remove()
}

function CheckPageSelect()
{
	var Selection = $("#adPlacement").val();
	if(Selection == 4)
	{
		$("#AdPageSelectionDiv").show();
	}
	else
	{
		$("#AdPageSelectionDiv").hide();
	}
}

function closeTBEditor() {
	parent.tb_remove();
	parent.location.reload();
}

function GetSingleRetailerPrice()
{
	$("#Suggested").slideDown();
	var RetailerPrice = $("#CoverPrice").val();
	var Price1 = Math.round((RetailerPrice-(RetailerPrice*.4))*100)/100;
	var Price2 = Math.round((RetailerPrice-(RetailerPrice*.35))*100)/100;

	$("#Suggested-1").html(Price1);
	$("#Suggested-2").html(Price2);
}

function GetRetailerPrice(Line){
	$("#Suggested"+Line).slideDown();
	var RetailerPrice = $("#CoverPrice"+Line).val();
	var Price1 = Math.round((RetailerPrice-(RetailerPrice*.4))*100)/100;
	var Price2 = Math.round((RetailerPrice-(RetailerPrice*.35))*100)/100;

	$("#Suggested"+Line+"-1").html(Price1);
	$("#Suggested"+Line+"-2").html(Price2);
}

/*function SubmitForm(){
	$("#CalculatorForm").submit();
}

$(document).ready(function() {
	$("#CustomSize").hide();
	$("#Section1").hide();
	$("#Section2").hide();
						   });

function ShowSection(divSection){
	if(divSection == '1'){
		$("#Section1").show();
		$("#Section2").hide();
	}else{
		$("#Section1").hide();
		$("#Section2").show();
	}
}

function CalculateOrder(){
	var Size = $("select#Size").val();
	var Width = $("input#Width").val();
	var Height = $("input#Height").val();

	var Color = $("select#Color").val();
	var InteriorColor = $("select#InteriorColor").val();

	var Paper = $("select#Paper").val();
	var InteriorPaper = $("select#InteriorPaper").val();
	var InteriorPageQty = $("input#InteriorPageQty").val();

	//var Options = $('input#Options').is(':checked');  //  $("input#Options").val();
	var Options = '0';
	if(document.getElementById('Options').checked){
		Options = '1';
	}
	
	var TotalQty = $("input#Qty").val();

	var dataString = 'Size=' + Size
						+ '&Color=' + Color 
						+ '&InteriorColor=' + InteriorColor 
						+ '&Paper=' + Paper 
						+ '&InteriorPaper=' + InteriorPaper 
						+ '&InteriorPageQty=' + InteriorPageQty 
						+ '&Options=' + Options 
						+ '&TotalQty=' + TotalQty
						+ '&Width=' + Width
						+ '&Height=' + Height;

	$.ajax({type: "POST", url: "Configurator.php",data: dataString, success: function(msg){ //$("#StatusData").html(msg);
																							$("#PriceValue").html(msg);} });
}

function CheckSizeSelection(SizeSelection){
	if(SizeSelection == '1-5'){
		//  Add Width * Height Box
		//  var id = 'testID';
		//  "<p id='row'><label for='txt'>Field <input type='text' size='20' name='txt[]' id='txt'></p>"
		$("#CustomSize").show();
	}else{
		$("#CustomSize").hide();
	}
	if(SizeSelection[0] == '2' || SizeSelection[0] == '3'){
		//  Add Cover Label & Interior Lable + Interior Section
		//  document.write('Modify For book');
	}
}*/
