var baseHref = "http://www.escortnews.eu/";

function ChangeImgBg(sDomain, sNr, sParent, sId){
	$("#MainGirlIMG").css("background", "url('"+sDomain+"/escort/"+sParent+"/"+sNr+"_332_497_"+sId+".jpg') no-repeat center");
}

function enterTextCounter(oField, object){
	document.getElementById(oField).innerHTML = object.value.length;
}

function addBookmark(url, title) {
  if (window.sidebar) {
    window.sidebar.addPanel(title, url,"");
  } else if( document.all ) {
    window.external.AddFavorite(url, title);
  } else {
    return true;
  }
}

function ScrollAndLoad(object){
	window.scrollTo(0,0);
	$("#loaderBIG").show();
	$("#"+object).hide();
}

function changeRegType(type){
	$("#regForm_type").hide();
	$("div[id^='regForm_']").hide();
	$("#regForm_"+type).show();
}

function ChangeCityByCountry(sCountry, sField){
	$("#"+sField).html("<option value=''>Selecting...</option>");
	$.post(baseHref+'ajax.php', {"action":"getCityByCountryOptions", "query":sCountry}, function(data){
		data = data.replace(/&quot;/g, '"');
		$("#"+sField).html(data);
	});
}

function addToFavourite(id){
	$.post(baseHref+'ajax.php', {action:"addToFavourite", id:id}, function(data){
		alert(data);
	});
}

function removeFromFavourite(id){
	$.post(baseHref+'ajax.php', {action:"removeFromFavourite", id:id}, function(data){
		alert(data);
		window.location.reload();
	});
}

function addToFake(id, sText){
	$.post(baseHref+'ajax.php', {action:"reportFake", id:id, text:sText}, function(data){
		if (data == '0') {
			$("#regForm").html("Thanks, Your message has been sent!");
		} else {
			$("#regErrors").html(data);
		}
	});
}

function activate(sId){
	$.post(baseHref+'ajax.php', {action:"activate", id:sId}, function(data){
		$("#ViewHideID").html(data);
	});
}

function hide(sDomain, sId){
	$.post(baseHref+'ajax.php', {action:"activate", id:sId}, function(data){
		if (data == 'off'){
			$("#ViewHideID_"+sId).attr({
				src : baseHref + "/static/img/items/hide_off.gif",
				alt : "Press to activate",
				title : "Press to activate"
			});
		} else {
			$("#ViewHideID_"+sId).attr({
				src : baseHref + "/static/img/items/hide_on.gif",
				alt : "Press to deactivate",
				title : "Press to deactivate"
			});
		}
	});
}


function removeTour(Id){
	if (confirm('Delete this tour?')){
		$.post(baseHref+'ajax.php', {action:"removeTour", id:Id}, function(data){
			alert(data);
			window.location.reload();
		});
	}
}

function removePhoto(Nr, Id){
	if (confirm('Delete this photo?')){
		$.post(baseHref+'ajax.php', {action:"removePhoto", id:Id, n:Nr}, function(data){
			alert(data);
			window.location.reload();
		});
	}
}

function removePhotoHelper(event){
	removePhoto(event.data.n, event.data.id);
}

function removeEscortPhoto(Nr, Id, eID){
	if (confirm('Delete this photo?')){
		$.post(baseHref+'ajax.php', {action:"removePhoto", id:Id, n:Nr, e:eID}, function(data){
			alert(data);
			window.location.reload();
		});
	}
}

function Smiley(oField, code){
	sel = document.getElementById(oField);
	sel.value = sel.value + code;
	sel.focus();
}

function submitEscortReview(oForm){
	$('#submitButton').attr("disabled", true);
	$.post(baseHref+'ajax.php', {action:"addEscortReview", data:$("#"+oForm).serialize()}, function(data){
		alert(data);
		if (data == 'Thanks, Your review is waiting to be cofirmed by admin.') $('#newreview').html(data);
		$('#submitButton').removeAttr("disabled");
	});
}

function submitAgencyReview(oForm){
	$('#submitButton').attr("disabled", true);
	$.post(baseHref+'ajax.php', {action:"addAgencyReview", data:$("#"+oForm).serialize()}, function(data){
		alert(data);
		if (data == 'Thanks, Your review is waiting to be cofirmed by admin.') $('#newreview').html(data);
		$('#submitButton').removeAttr("disabled");
	});
}

function submitEscortMessage(oForm){
	$('#messageButton').attr("disabled", true);
	$.post(baseHref+'ajax.php', {action:"addEscortMessage", data:$("#"+oForm).serialize()}, function(data){
		alert(data);
		$('#messageButton').removeAttr("disabled");
	});
}

function submitGuestEscortMessage(oForm){
	$('#GuestMessageButton').attr("disabled", true);
	$.post(baseHref+'ajax.php', {action:"addGuestEscortMessage", data:$("#"+oForm).serialize()}, function(data){
		alert(data);
		if (data == 'Thanks, Your message sent.') {
			window.location.reload();
		}
		$('#GuestMessageButton').removeAttr("disabled");
	});
}

function viewEscortReviews(eID, iPage){
	$.post(baseHref+'ajax.php', {action:"viewEscortReviews", eID:eID, page:iPage}, function(data){
		$('#viewreview').html(data);
	});
}

function viewAgencyReviews(aID, iPage){
	$.post(baseHref+'ajax.php', {action:"viewAgencyReviews", aID:aID, page:iPage}, function(data){
		$('#viewreview').html(data);
	});
}

function changeReviewStatus(sType, iID){
	$.post(baseHref+'ajax.php', {action:"changeReviewStatus", sType:sType, iID:iID}, function(data){
		if (data != '')	$('#viewReview_'+iID).html(data);
	});
}

function ChangeReviewByCountry(sLang, sCountry){
	if (sLang != "") window.location.href="http://www.escortnews.eu/"+sLang+"/reviews/"+sCountry;
	else window.location.href="http://www.escortnews.eu/reviews/"+sCountry;
}

function ajaxPhotoUpload(imgHost, nr){
	$("#fileUpload"+nr).hide();
	$("#fileUploadStatus"+nr).show();
	$.ajaxFileUpload({
		url: baseHref+'ajax.php?action=imageUpload&imageField='+nr, 
		secureuri:false,
		fileElementId:'fileUpload'+nr,
		dataType: 'json',
		success: function (data, status){
			if(typeof(data.error) != 'undefined'){
				if(data.error != ''){
					$("#fileUpload"+nr).show();
					$("#fileUploadStatus"+nr).hide();
					alert(data.error);
				} else {
					$("#fileUploadStatus"+nr).show();
					$("#fileUploadStatus"+nr).html('Uploaded!');
					imgPath = imgHost + '/escort/'+data.id+'/'+nr+'_125_125_'+data.text;
					$("#fileUploaded"+nr).attr({ src: imgPath, title:"Image "+nr, alt:"Image "+nr});
					$("#fileUploaded"+nr).css("cursor","pointer");
					$("#fileUploaded"+nr).bind("click", {n: nr, id:data.image}, removePhotoHelper);
					$("#fileUploaded"+nr).show();
				}
			}
		},
		error: function (data, status, e){
			$("#fileUpload"+nr).show();
			$("#fileUploadStatus"+nr).hide();
			alert(e);
		}
	})
	return false;
}

function ajaxVerifyUpload(imgHost, nr){
	$("#fileUpload"+nr).hide();
	$("#fileUploadStatus"+nr).show();
	$.ajaxFileUpload({
		url: baseHref+'ajax.php?action=imageVerify&imageField='+nr, 
		secureuri:false,
		fileElementId:'fileUpload'+nr,
		dataType: 'json',
		success: function (data, status){
			if(typeof(data.error) != 'undefined'){
				if(data.error != ''){
					$("#fileUpload"+nr).show();
					$("#fileUploadStatus"+nr).hide();
					alert(data.error);
				} else {
					$("#fileUploadStatus"+nr).show();
					$("#fileUploadStatus"+nr).html('Uploaded!');
				}
			}
		},
		error: function (data, status, e){
			$("#fileUpload"+nr).show();
			$("#fileUploadStatus"+nr).hide();
			alert(e);
		}
	})
	return false;
}

function ajaxVerifyUploadToEscort(imgHost, nr, e){
	$("#fileUpload"+nr).hide();
	$("#fileUploadStatus"+nr).show();
	$.ajaxFileUpload({
		url: baseHref+'ajax.php?action=imageVerify&imageField='+nr+'&escortID='+e, 
		secureuri:false,
		fileElementId:'fileUpload'+nr,
		dataType: 'json',
		success: function (data, status){
			if(typeof(data.error) != 'undefined'){
				if(data.error != ''){
					$("#fileUpload"+nr).show();
					$("#fileUploadStatus"+nr).hide();
					alert(data.error);
				} else {
					$("#fileUploadStatus"+nr).show();
					$("#fileUploadStatus"+nr).html('Uploaded!');
				}
			}
		},
		error: function (data, status, e){
			$("#fileUpload"+nr).show();
			$("#fileUploadStatus"+nr).hide();
			alert(e);
		}
	})
	return false;
}

function ajaxPhotoUploadToEscort(imgHost, nr, e){
	$("#fileUpload"+nr).hide();
	$("#fileUploadStatus"+nr).show();
	$.ajaxFileUpload({
		url: baseHref+'ajax.php?action=imageUpload&imageField='+nr+'&escortID='+e, 
		secureuri:false,
		fileElementId:'fileUpload'+nr,
		dataType: 'json',
		success: function (data, status){
			if(typeof(data.error) != 'undefined'){
				if(data.error != ''){
					$("#fileUpload"+nr).show();
					$("#fileUploadStatus"+nr).hide();
					alert(data.error);
				} else {
					$("#fileUploadStatus"+nr).show();
					$("#fileUploadStatus"+nr).html('Uploaded!');
					imgPath = imgHost + '/escort/'+data.id+'/'+nr+'_125_125_'+data.text;
					$("#fileUploaded"+nr).attr({ src: imgPath, title:"Image "+nr, alt:"Image "+nr});
					$("#fileUploaded"+nr).css("cursor","pointer");
					$("#fileUploaded"+nr).bind("click", {n: nr, id:data.image}, removePhotoHelper);
					$("#fileUploaded"+nr).show();
				}
			}
		},
		error: function (data, status, e){
			$("#fileUpload"+nr).show();
			$("#fileUploadStatus"+nr).hide();
			alert(e);
		}
	})
	return false;
}

function answerReview(sType, iID){
	sText = $("#answer_"+iID).val();
	$.post(baseHref+'ajax.php', {action:"answerReview", sType:sType, iID:iID, sText:sText}, function(data){
		if (data != '')	$('#viewReview_'+iID).html(data);
	});
}
