var escort = {
    setListView: function (view) {
        $.post(baseHref + 'ajax.php', {action: "setListView", view: view}, function (data) {
			if (view == 'list') {
				window.location.reload();
			}
        }, 'json');
    },
    pressVoteEscort : function(iID) {
        $.post(baseHref+'ajax.php', {action:"pressVoteEscort", ei:iID}, function(data){
            if (data.status == 'success') {
                console.log(data.html)
                /*$('#vote-button-'+iID).empty().html(data.html);*/
                console.log(data)

                $('#vote-button-'+iID).empty().html(vTxt.replace("{{Count}}") + data.count);
            } else {
                alert(data.html);
            }
        }, 'json');
    },
    pressLike : function(iID,what) {

        $.post(baseHref+'ajax.php', {action:"pressLike", ei:iID, w:what}, function(data){

            if (data.status == 'success') {
                $('#like-button-'+iID).find("span").empty().html(data.like+ "/"+ data.dislike);
                proc = (parseInt(data.like) * 100) / (parseInt(data.like) + parseInt(data.dislike));
                $('#like-button-'+iID).find(".linein").css('width',proc+'%');
                if (what == 0) {
                    $(".divlike1").addClass("divgren");
                    $(".divlike3").removeClass("divred");
                    $(".divlike3 img").css("cursor", "pointer");
                    $(".divlike1 img").css("cursor", "auto");
                } else {
                    $(".divlike3").addClass("divred");
                    $(".divlike1").removeClass("divgren");
                    $(".divlike1 img").css("cursor", "pointer");
                    $(".divlike3 img").css("cursor", "auto");
                }
                //alert(data.html);
            } else {
                alert(data.html);
            }
        }, 'json');
    },
	pressFavoritesAgency : function(aID, sType) {
        if (sType == 'remove') {
            $.post(baseHref+'ajax.php', {action:"removeFromFavouritesAgency", aID:aID}, function(data){
                $("#fav_1_"+aID).hide();
                $("#fav_2_"+aID).show();
            });
        } else {
            $.post(baseHref+'ajax.php', {action:"addToFavouritesAgency", aID:aID}, function(data){
                $("#fav_2_"+aID).hide();
                $("#fav_1_"+aID).show();
            });
        }
    },
    pressFavorites : function(eID, sType) {
        if (sType == 'remove') {
            $.post(baseHref+'ajax.php', {action:"removeFromFavourites", eID:eID}, function(data){
                $("#fav_1_"+eID).hide();
                $("#fav_2_"+eID).show();
            });
        } else {
            $.post(baseHref+'ajax.php', {action:"addToFavourites", eID:eID}, function(data){
                $("#fav_2_"+eID).hide();
                $("#fav_1_"+eID).show();
            });
        }
    },
    pressFollow : function(eID) {
        $.fancybox.showLoading();
        $.post(baseHref+'ajax.php', {action:"viewSiteForm",popup:"followForm",eID:eID}, function(data){
            $('#site-popup').empty().html(data.html);
            $.fancybox({
                wrapCSS : "fancybox-popup",
                closeBtn : false,
                scrolling : false,
                content : $('#site-popup'),
                beforeShow : function() {
                    $("#site-popup .chzn-select-small").chosen({disable_search:true,inherit_select_classes:true});
                    $('#site-popup div.multibox > ul').jScrollPane({mouseWheelSpeed:30});
                    $('.jspContainer').css("height","165px");

                }
            });
            $('#site-popup div.multibox > ul').data('jsp').reinitialise();
        }, 'json');
    },

    pressFollowPost : function(oForm) {
        $.post(baseHref+'ajax.php', {action:"changeFollows", data:$("#"+oForm).serialize()}, function(data){
            if (data.status == 'success') {
                $.fancybox.close();
            } else {
                alert(data.html);
            }
        }, 'json');
    },

    addFollowCity : function(oForm){
        var country = $("#"+oForm).find('select[name="form[Country]"]').val();
        var city = $("#"+oForm).find('select[name="form[City]"]').text();
        var city = $("#"+oForm).find('select[name="form[City]"] option:selected').text();
        var countrycity = $("#"+oForm).find('select[name="form[City]"]').val();

        if ((countrycity != '') && (countrycity != '+')) {
            var array = $('#'+oForm).find('input[name="tour[]"][value="'+countrycity+'"]');
            if (array.length == 0) {
                api = $('#site-popup div.multibox > ul').data('jsp');
                api.getContentPane().append('<li onclick="escort.removeFollowCity($(this));">'+city+'<span class="remove"><img width="22" height="22" alt="" src="http://static.escortnews.com/spacer.gif"></span><input type="hidden" name="tour[]" value="'+countrycity+'"></li>');
                api.reinitialise();
                api.scrollToBottom(true);
            }
        }
    },

    removeFollowCity : function(oLocation){
        var loc = oLocation.find('input').val();
        oLocation.remove();
        $('#site-popup div.multibox > ul').data('jsp').reinitialise();
    },
    pressFake : function(eID) {
        $.fancybox.showLoading();
        $.post(baseHref+'ajax.php', {action:"viewSiteForm",popup:"fakeForm",eID:eID}, function(data){
            $('#site-popup').empty().html(data.html);
            $.fancybox({
                wrapCSS : "fancybox-popup",
                closeBtn : false,
                scrolling : false,
                content : $('#site-popup'),
                beforeShow : function() {
                   // $("#site-popup div.label > div > div").each(function(){$(this).height($(this).width());});
                }
            });
        }, 'json');
    },

    pressFakePost : function(oForm) {
        $.post(baseHref+'ajax.php', {action:"saveFakeForm",data:$("#"+oForm).serialize()}, function(data){
            if (data.status == 'success') {
                $.fancybox.close();
            } else {
                $(".errors").css('color','red');
                $(".errors").html(data.html);
                inner.showerror(".errors");
               // alert(data.html);
            }
        }, 'json');
    },
    showVideo : function(o) {
        $f("videoControls").unload();
        $f("videoControls").play({url:o.parent().attr('data-v')});
    },
    pressReplyComment : function(eID) {
        alert('Comming Soon.');
    },

    pressNewComment : function(eID) {
        $.fancybox.showLoading();
        $.post(baseHref+'ajax.php', {action:"viewSiteForm",popup:"commentForm",eID:eID}, function(data){
            $('#site-popup').empty().html(data.html);
            $.fancybox({
                wrapCSS : "fancybox-popup",
                closeBtn : false,
                scrolling : false,
                content : $('#site-popup'),
                beforeShow : function() {
                    //$("#site-popup div.label > div > div").each(function(){$(this).height($(this).width());});
                    //$("#site-popup .chzn-select-small").chosen({disable_search:true,inherit_select_classes:true});
                }
            });
        }, 'json');
    },

    pressNewCommentPost : function(oForm) {
        $.post(baseHref+'ajax.php', {action:"saveCommentForm",data:$("#"+oForm).serialize(),type:'e'}, function(data){
            if (data.status == 'success') {
                alert(data.html);
                $.fancybox.close();
            } else {
                $(".errors").css('color','red');
                $(".errors").html(data.html);
                inner.showerror(".errors");
            }
        }, 'json');
    },



    viewEscortReviews : function(eID, iPage){
        $('#escort-review-div').html("<div class='loadingBig'></div>");

        var t = $('#escort-review-ScrollTo').offset().top;
        window.scrollTo(0,t-10);
        $.post(baseHref+'ajax.php', {action:"viewEscortReviews", eID:eID, page:iPage}, function(data){
            $('#escort-review-div').html(data.data);
        }, 'json');

    },
    pressNewReview : function(eID) {
        $.fancybox.showLoading();
        $.post(baseHref+'ajax.php', {action:"viewSiteForm",popup:"reviewForm",eID:eID}, function(data){
            $('#site-popup').empty().html(data.html);
            $.fancybox({
                wrapCSS : "fancybox-popup",
                closeBtn : false,
                scrolling : false,
                content : $('#site-popup'),
                beforeShow : function() {
                    //$("#site-popup div.label > div > div").each(function(){$(this).height($(this).width());});
                    $("#site-popup .chzn-select-small").chosen({disable_search:true,inherit_select_classes:true});
					$("#site-popup .chzn-select-small-search").chosen({disable_search:false,inherit_select_classes:true});
                }
            });
        }, 'json');
    },
    pressNewReviewPost : function(oForm) {
        $.post(baseHref+'ajax.php', {action:"saveReviewForm",data:$("#"+oForm).serialize(),type:'e'}, function(data){
            if (data.status == 'success') {
                alert(data.html);
                $.fancybox.close();
            } else {
				/*
                swal({
                    title: 'Error!',
                    text: data.html,
                    type: 'error',
                    confirmButtonText: 'Cool'
                });
				*/
                alert(data.html);
            }
        }, 'json');
    },

    pressReplyReview : function(rID) {
        alert('Coming Soon');
    },
    changeMeetingLength : function() {
        $('#MeetingLength').val($('#MeetingLengthCount').val()+' '+$('#MeetingLengthType').val());
    },

    changeAd: function(aID, Step) {
        $.fancybox.showLoading();
        if (Step > 4) {
            $.fancybox.close();
            window.location.reload();
        } else {
            $.post(baseHref+'ajax.php', {action:"viewForm",popup:"changeAdForm",aID:aID,step:Step}, function(data){

                $('#site-popup').empty().html(data.html);

                $.fancybox({
                    wrapCSS : "fancybox-popup",
                    closeBtn : false,
                    scrolling : false,
                    content : $('#site-popup'),
                    afterShow : function() {

                        $(".chzn-select-small").chosen({disable_search:true,inherit_select_classes:true});
                      //  account.tinyMceInit('tinymceEditor');
                    },
                    beforeClose: function () {
                      //  account.tinyMceRemove('tinymceEditor');
                    }
                });
            }, 'json');
        }
    },

    changeAdPost: function(oForm){
        $.post(baseHref+'ajax.php', {action:"changeAdPost", data:$("#"+oForm).serialize()}, function(data){
            if (data.status == 'success') {
                $.post(baseHref+'ajax.php', {action:"viewForm",popup:"changeAdForm",aID:data.aID,step:2}, function(data){
                    $('#site-popup').empty().html(data.html);
                    $.fancybox({
                        wrapCSS : "fancybox-popup",
                        closeBtn : false,
                        scrolling : false,
                        content : $('#site-popup'),
                        afterShow : function() {

                            //$(".chzn-select-small").chosen({disable_search:true,inherit_select_classes:true});
                        },
                        beforeClose: function () {

                        }
                    });
                }, 'json');

                //window.location.reload();
            } else {
                alert(data.html);
            }
        }, 'json');
    },
    pressPrivateMessage : function(eID) {
        $.fancybox.showLoading();
        $.post(baseHref+'ajax.php', {action:"viewSiteForm",popup:"messageForm",eID:eID,type:'e'}, function(data){
            $('#site-popup').empty().html(data.html);
            $.fancybox({
                wrapCSS : "fancybox-popup",
                closeBtn : false,
                scrolling : false,
                content : $('#site-popup'),
                beforeShow : function() {

                }
            });
        }, 'json');
    },

    pressPrivateMessagePost : function(oForm) {
        $.post(baseHref+'ajax.php', {action:"savePrivateMessageForm",data:$("#"+oForm).serialize(),type:'e'}, function(data){
            if (data.status == 'success') {
                $.fancybox.close();
            } else {
                $(".errors").css('color','red');
                $(".errors").html(data.html);
                inner.showerror(".errors");
            }
        }, 'json');
    },
    pressContactMe : function(eID) {
        $.fancybox.showLoading();
        $.post(baseHref+'ajax.php', {action:"viewSiteForm",popup:"contactForm",eID:eID,type:'e'}, function(data){
            $('#site-popup').empty().html(data.html);
            $.fancybox({
                wrapCSS : "fancybox-popup",
                closeBtn : false,
                scrolling : false,
                content : $('#site-popup'),
                beforeShow : function() {

                }
            });
        }, 'json');
    },

    pressContactMePost : function(oForm) {
        $.post(baseHref+'ajax.php', {action:"saveContactMeForm",data:$("#"+oForm).serialize(),type:'e'}, function(data){
            if (data.status == 'success') {
                $.fancybox.close();
            } else {
                $(".errors").css('color','red');
                $(".errors").html(data.html);
                inner.showerror(".errors");
            }
        }, 'json');
    },
    pressContactMeGuest : function(eID) {
        $.fancybox.showLoading();
        $.post(baseHref+'ajax.php', {action:"viewSiteForm",popup:"contactFormGuest",eID:eID,type:'e'}, function(data){
            $('#site-popup').empty().html(data.html);
            $.fancybox({
                wrapCSS : "fancybox-popup",
                closeBtn : false,
                scrolling : false,
                content : $('#site-popup'),
                beforeShow : function() {

                }
            });
        }, 'json');
    },

    pressContactMeGuestPost : function(oForm) {
        $.post(baseHref+'ajax.php', {action:"saveContactMeGuestForm",data:$("#"+oForm).serialize(),type:'e'}, function(data){
            if (data.status == 'success') {
                $.fancybox.close();
            } else {
                $(".errors").css('color','red');
                $(".errors").html(data.html);
                inner.showerror(".errors");
            }
        }, 'json');
    },

	openSkypePaymentWindow: function(e, t){
		$.post(baseHref+'ajax.php', {action:"viewSkypeForm",eID:e,Type:t}, function(data){
			if (data.status == 'success') {
				console.log(data);
				$('#skype-popup').empty().html('<div id="skype-body" style="margin:25px 0;min-width:375px;">'+data.html+'</div>');
				$.fancybox.close();
				$.fancybox({
					wrapCSS : "fancybox-popup",
					closeBtn : true,
					scrolling : false,
					content : $('#skype-popup'),
					padding: 0,
					helpers : { 
						overlay : {closeClick: false}
					},
					afterShow : function() {
						var o = $('#skype-body div.loadingBig').attr('data-order');
						var checkOrder = setInterval(function(){
							if ($("#skype-body").find('div.loadingBig').length == 1) {
								$.post(baseHref+'ajax.php', {action:"checkSkypePayment", oID:o}, function(data){
									if (data.Status != 1) {
										clearInterval(checkOrder);
										$('#skype-popup').html('<div id="skype-body" style="margin:25px;"><br /><br />'+data.Message+'<br /><br /></div>');
									}
								}, 'json');	
							} else {
								clearInterval(checkOrder);
							}
						}, 5000);
					}
				});
			} else {
				alert(data.html);
			}
		}, 'json');
	},

	openSkypeInfoWindow: function(e, t, p){
		var html = $('#skypeFormDIV').html();
		html = html.replace(new RegExp('%price%', 'g'), p);
		html = html.replace(new RegExp('%min%', 'g'), t);
		
		$('#skype-popup').empty().html('<div id="skype-body">'+html+'</div>');
		$.fancybox({
			wrapCSS : "fancybox-popup",
			closeBtn : false,
			scrolling : false,
			content : $('#skype-popup'),
			padding: 0,
			helpers : { 
				overlay : {closeClick: false}
			},
			afterShow : function() {
				
			}
		});
	},

}

var account = {

    checkImagePos: function(m, top, left, w, h, wMax, hMax){

        pos = new Object();
        if (m == "x") {
            top = 0;
            if (left > 0) left = 0;
            if (left < wMax-w) left = wMax-w;
        } else {
            left = 0;
            if (top > 0) top = 0;
            if (top < hMax-h) top = hMax-h;
        }
        pos.top = top;
        pos.left = left;
        return pos;
    },

    saveImagePos: function(aID, iID, w1, h1, w2, h2, left, top) {
        $.post(baseHref+'ajax.php', {action:"saveAdImagePos",aID:aID,iID:iID,w1:w1,h1:h1,w2:w2,h2:h2,l:left,t:top}, function(data){
            if (data.status == 'success') {

            } else {

            }
        }, 'json');
    },

    photosDelete: function(aID, iID){
        $.post(baseHref+'ajax.php', {action:"delAsImage",aID:aID,iID:iID}, function(data){
            if (data.status == 'success') {
                //$('#galleryImage_'+iID).hide();
                $('#galleryImage_'+iID).addClass('emptyImage').removeClass('galleryImage').html('');

            } else {
                alert(data.html);
            }
        }, 'json');
    },
	
    changePackage: function(){
        var o = $('#packList').find('input[name=pack]:checked');
        if (o.val() == 'premium') {
            $('#finishButton').hide();
            $('#checkoutButton').show();
        } else {
            $('#checkoutButton').hide();
            $('#finishButton').show();
        }
    },

	tinyMceInit: function(ID) {
		$('#'+ID).tinymce({
			script_url : staticDomain+'/libs/tinymce/tiny_mce.js',
			mode : "textareas",
			theme : "simple",
			plugins: "emotions,advhr,preview,paste",
			theme_advanced_toolbar_location	  : "top",
			theme_advanced_toolbar_align	  : "left",
			editor_selector : 'about-field',
			valid_elements : "a[href|target=_blank],strong/b,br,p[align|class],em,span,li,ul,i,div[style]",
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,undo,redo,|,emotions,preview",
			theme_advanced_buttons2 : "",
			theme_advanced_buttons3_add : "",
			remove_script_host : false,
			relative_urls : false,
			convert_urls : false,
			force_br_newlines : true,
			force_p_newlines : false,
			forced_root_block : '',
			convert_newlines_to_brs: false,
			content_css : staticDomain+"/libs/tinymce/base.css",
			width : "300",
			height : "250"
		});
	},
	
	tinyMceRemove: function(ID) {
		if (typeof $('#'+ID).exists !== "undefined") { 
			if ($('#'+ID).exists() > 0) {
				$('#'+ID).tinymce().execCommand('mceRemoveControl',true,ID);
			}
		}
	},
	
	changeAd: function(aID, Step) {
		if (Step > 4) {
			$.fancybox.close();
			window.location.reload();
		} else {
			$.post(baseHref+'ajax.php', {action:"viewForm",popup:"changeAdForm",aID:aID,step:Step}, function(data){
				$('#site-popup').empty().html(data.html);
				$.fancybox({
					wrapCSS : "fancybox-popup",
					closeBtn : false,
					scrolling : false,
					content : $('#site-popup'),
					afterShow : function() {
						$(".chzn-select-small").chosen({disable_search:true,inherit_select_classes:true});
						account.tinyMceInit('tinymceEditor');
					},
					beforeClose: function () {
						account.tinyMceRemove('tinymceEditor');
					}
				});
			}, 'json');
		}
	},
	
	changeAdPost: function(oForm){
		$.post(baseHref+'ajax.php', {action:"changeAdPost", data:$("#"+oForm).serialize()}, function(data){
			if (data.status == 'success') {
				$.post(baseHref+'ajax.php', {action:"viewForm",popup:"changeAdForm",aID:data.aID,step:2}, function(data){
					$('#site-popup').empty().html(data.html);
					$.fancybox({
						wrapCSS : "fancybox-popup",
						closeBtn : false,
						scrolling : false,
						content : $('#site-popup'),
						afterShow : function() {
							//$("#my-account-popup div.label > div > div").each(function(){$(this).height($(this).width());});
							$(".chzn-select-small").chosen({disable_search:true,inherit_select_classes:true});
						},
						beforeClose: function () {
							
						}
					});
				}, 'json');
				
				//window.location.reload();
			} else {
				alert(data.html);
			}
		}, 'json');
	},
}

var saveSkypeUser = function(o, n, s, e){
	$.post(baseHref+'ajax.php', {action:"saveSkypeUser",o:o,n:n,s:s,e:e}, function(data){
		if (data.status == 'success') {
			$('#skype-body').html('<div id="skype-body" style="margin:50px 0;><div style="font-size:18px;text-align:center;color:#000;margin:25px;padding-left:0!important;"><br /><br />'+data.html+'<br /><br /></div></div>');
			$("#skype-body div.label > div > div").each(function(){$(this).height($(this).width());});
		} else {
			alert(data.html);
		}
	}, 'json');
}

var agency = {
    pressContactMeGuest : function(eID) {
        $.post(baseHref+'ajax.php', {action:"viewSiteForm",popup:"contactFormGuest",eID:eID,type:'b'}, function(data){
            $('#site-popup').empty().html(data.html);
            $.fancybox({
                wrapCSS : "fancybox-popup",
                closeBtn : false,
                scrolling : false,
                content : $('#site-popup'),
                beforeShow : function() {
                   // $("#site-popup div.label > div > div").each(function(){$(this).height($(this).width());});
                }
            });
        }, 'json');
    },

    pressContactMeGuestPost : function(oForm) {
        $.post(baseHref+'ajax.php', {action:"saveContactMeGuestForm",data:$("#"+oForm).serialize(),type:'b'}, function(data){
            if (data.status == 'success') {
                $.fancybox.close();
            } else {
                $(".errors").css('color','red');
                $(".errors").html(data.html);
                inner.showerror(".errors");
            }
        }, 'json');
    },

    pressContactMe : function(eID) {
        $.post(baseHref+'ajax.php', {action:"viewSiteForm",popup:"contactForm",eID:eID,type:'b'}, function(data){
            $('#site-popup').empty().html(data.html);
            $.fancybox({
                wrapCSS : "fancybox-popup",
                closeBtn : false,
                scrolling : false,
                content : $('#site-popup'),
                beforeShow : function() {
                   // $("#site-popup div.label > div > div").each(function(){$(this).height($(this).width());});
                }
            });
        }, 'json');
    },

    pressContactMePost : function(oForm) {
        $.post(baseHref+'ajax.php', {action:"saveContactMeForm",data:$("#"+oForm).serialize(),type:'b'}, function(data){
            if (data.status == 'success') {
                $.fancybox.close();
            } else {
                $(".errors").css('color','red');
                $(".errors").html(data.html);
                inner.showerror(".errors");
            }
        }, 'json');
    },

    pressPrivateMessage : function(eID) {
        $.post(baseHref+'ajax.php', {action:"viewSiteForm",popup:"messageForm",eID:eID,type:'b'}, function(data){
            $('#site-popup').empty().html(data.html);
            $.fancybox({
                wrapCSS : "fancybox-popup",
                closeBtn : false,
                scrolling : false,
                content : $('#site-popup'),
                beforeShow : function() {
                  //  $("#site-popup div.label > div > div").each(function(){$(this).height($(this).width());});
                }
            });
        }, 'json');
    },

    pressPrivateMessagePost : function(oForm) {
        $.post(baseHref+'ajax.php', {action:"savePrivateMessageForm",data:$("#"+oForm).serialize(),type:'b'}, function(data){
            if (data.status == 'success') {
                $.fancybox.close();
            } else {
                $(".errors").css('color','red');
                $(".errors").html(data.html);
                inner.showerror(".errors");
            }
        }, 'json');
    },
};