function startLoading(contentArea, loadingArea, displayLoading) {
  if (displayLoading == true || displayLoading == false) {
	 if (contentArea == null)
		$("#mainAreaContent").hide();
	  else
		$("#" + contentArea).hide();
  
	  if (loadingArea == null) {
		$("#mainAreaLoading").show();
		}
	  else
		$("#" + loadingArea).show();
  }  
}
function finishLoading(contentArea, loadingArea, displayLoading) {
  if (displayLoading == true || displayLoading == false) {
	  if (contentArea == null)
		$("#mainAreaContent").show();
	  else
		$("#" + contentArea).show();

	  if (loadingArea == null)
		$("#mainAreaLoading").hide();
	  else
		$("#" + loadingArea).hide();
  }
}

function loadContent(pageURL, contentArea, loadingArea) {
	loadContent2(pageURL, contentArea, loadingArea, true);
}

function addToCart(pageURL, contentArea, loadingArea) {
	//$("html, body").animate({scrollTop:0},"fast");
	loadContent2(pageURL, contentArea, loadingArea, true);
}

function loadContent2(pageURL, contentArea, loadingArea, displayLoading) {
  startLoading(contentArea, loadingArea, displayLoading);
  if (contentArea == null)
	$("#mainAreaContent").load(pageURL,'',function() {finishLoading(contentArea, loadingArea, displayLoading);});
  else {
	$("#" + contentArea).load(pageURL,'',function() {finishLoading(contentArea, loadingArea, displayLoading);});
  }
}

function loadContentPost(pageURL, params, contentArea, loadingArea) {
  startLoading(contentArea, loadingArea, true);
  if (contentArea == null)
      jQuery.ajax({ 
	      type: 'POST',
	      url: pageURL,
	      data: params,
	      error:function(){ $('#mainAreaContent').html("Bir hata oluştu, lütfen daha sonra tekrar deneyiniz."); }, 
	      success: function(returnData) { $('#mainAreaContent').html(returnData); finishLoading(contentArea, loadingArea, true);}
      });
  else
      jQuery.ajax({ 
	      type: 'POST',
	      url: pageURL,
	      data: params,
	      error:function(){ $("#" + contentArea).html("Bir hata oluştu, lütfen daha sonra tekrar deneyiniz."); }, 
	      success: function(returnData) { $("#" + contentArea).html(returnData); finishLoading(contentArea, loadingArea, true);}
      });
}

function loadTabContent(pageURL, targetTab, activeTab1, activeTab2, activeTab3, activeTab4) {
	loadContent(pageURL);
	if(targetTab!="null") {
		var targetTabObj =  document.getElementById(targetTab)
		if(targetTabObj != null)
			targetTabObj.style.display = "";
	}

	if(targetTab != 'Tab_1') {
		var targetTabObj =  document.getElementById('Tab_1');
		if(targetTabObj != null)
			targetTabObj.style.display = "none"
	}

	if(targetTab != 'Tab_2') {
		var targetTabObj =  document.getElementById('Tab_2');
		if(targetTabObj != null)
			targetTabObj.style.display = "none"
	}

	if(targetTab != 'Tab_3') {
		var targetTabObj =  document.getElementById('Tab_3');
		if(targetTabObj != null)
			targetTabObj.style.display = "none"
	}

	if(targetTab != 'Tab_4') {
		var targetTabObj =  document.getElementById('Tab_4');
		if(targetTabObj != null)
			targetTabObj.style.display = "none"
	}

	if(targetTab != 'Tab_5') {
		var targetTabObj =  document.getElementById('Tab_5');
		if(targetTabObj != null)
			targetTabObj.style.display = "none"
	}
}
function writeReview() {
	var targetTabObj =  document.getElementById('reviewWriteArea');
	if(targetTabObj != null)
		targetTabObj.style.display = ""

	targetTabObj =  document.getElementById('reviewButtonArea');
	if(targetTabObj != null)
		targetTabObj.style.display = "none"

}
function closeReviewWrite() {
	var targetTabObj =  document.getElementById('reviewWriteArea');
	if(targetTabObj != null)
		targetTabObj.style.display = "none"

	targetTabObj =  document.getElementById('reviewButtonArea');
	if(targetTabObj != null)
		targetTabObj.style.display = ""

}
function submitForm(targetURL, formId) {
	loadContentPost(targetURL, $("#" + formId).serialize());
	$("html, body").animate({scrollTop:0},"slow");
	return false;
}
function submitFormWithoutScroll(targetURL, formId) {
	loadContentPost(targetURL, $("#" + formId).serialize());
	return false;
}
function loadAddressData(pageURL, selectData, addressType) {
	if (addressType=="billing") {
		loadContent(pageURL + "&addressId=" + selectData.value,'billingAddressAreaContent', 'billingAddressAreaLoading');
	}
	else
	{
		loadContent(pageURL + "&addressId=" + selectData.value,'deliveryAddressAreaContent', 'deliveryAddressAreaLoading');
	}
}
function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}
