﻿// фиксит баги в каталоге для IE
function fixCatalogTooltip() {
    if ($("ul.catalog").size() > 0) {
        $("ul.catalog li").hover(function(){
            $(this).css("z-index", "2");
        },function(){
            $(this).css("z-index", "1");
        });
        $("ul.catalog div.pic").hover(function(){
            $(this).addClass("jshover");
        },function(){
            $(this).removeClass("jshover");
        });
    }
}

function initSccrollH (current) {
    var total = 0;
    $(current).find("li").each(function(i){total += 159;});
    $(current).find("ul").width(total);
    $(current).jScrollHorizontalPane({showArrows:true, scrollbarHeight: 11, arrowSize: 11});
}

function reloadPage() {
    $("body").css("display","inline").css("display","block");
}

function initAll() {
     	
    if ($.browser.msie) {fixCatalogTooltip();};
    $(".scroll").each(function() {$(".scroll").jScrollPane({showArrows:true, scrollbarWidth: 11});});

    $(".scrollh").each(function() {if ($(".scrollh").parent('.section').css("display")=="block") {initSccrollH(this);}});

    $("p.section-title").each(function() {
        $(this).unbind("click");
        $(this).click(function(){
            $(this).toggleClass("expanded");
            if ($.browser.msie) {$(this).next(".section").toggle();}
            else {$(this).next(".section").slideToggle(250,function(){reloadPage();});}
            if ($(this).next(".section").not(".hidden")) {initSccrollH($(this).next(".section").find(".scrollh"));}
            reloadPage();
        });
    });

	if( typeof _____jquery_ui_datepicker_____ == 'function' )
	{
		$("input.selectdate").each(function() { 
			var inputobj = $(this);
			if( inputobj.attr( "name" ).indexOf("birth") == -1 )
			{
				inputobj.datepicker( { dateFormat: 'dd.mm.yy' } );
			}
			else
			{
				inputobj.datepicker( { dateFormat: 'dd.mm.yy', yearRange: '1930:1991' } );
			}
			inputobj.attr("readonly", "true" );
			var inputname = inputobj.attr("name")
			var imgobj = $("#img_" + inputname );
			if( imgobj.length )
			{
				imgobj.click(function() {
					$(inputobj).datepicker( "show" ); 
					return false;
				})				
			}
		});
	}
    addReadOnlyClass();
    reloadPage();
}

function loadNews()
{
	$(".news").each( function(i)
	{
		if( i>1 )
		{
			alert("Поддерживается только один блок новостей!");
			return;
		}
		category = this.id.replace("news_", "" );
		u = '/serv/news.php'
		if( category != '' )
		{
			u = u + "?category="+category;
		}
		news_block=this;
		$(news_block).html( '<img src="images/ajax-loader2.gif"/>' );
	    jQuery.getFeed({
    	    url: u,
        	success: function(feed) {
            	var html = "";
            	if( feed.items.length > 0 )
            	{
		            html += '<ul class="news">';
    		        for(var i = 0; i < feed.items.length && i < 3; i++) {   
        		        var x = new Date(feed.items[i].updated);
            		    html += '<li><var>';
                		html += x.getDate() + '.' + x.getMonth() + '.' + x.getFullYear();
	                	html += '</var><p><a href="';
	    	            html += feed.items[i].link;
    	    	        html += '" target="_blank">';
        	    	    html += feed.items[i].title;
            	    	html += '</a></p></li>';
	            	}
	    	        html += '</ul>';
				}
				else
				{
					html = "Новости отсутствуют";
				}
        	    $(news_block).html( html );
	        }    
    	});
	});
}

$(document).ready(function(){

    if(typeof registrationBoxInit == 'function') { registrationBoxInit(); };

    if(typeof customerPerformerProfileInit == 'function') { customerPerformerProfileInit(); }
    if(typeof customerJoinInit == 'function') { customerJoinInit(); }
    if(typeof customerProfileInit == 'function') { customerProfileInit(); }
    if(typeof customerChatInit == 'function') { customerChatInit(); }
    if(typeof customerPayInit == 'function') { customerPayInit(); }
    if(typeof performerGalleryInit == 'function') { performerGalleryInit(); };
    if(typeof performerJoinInit == 'function') { performerJoinInit(); }
    if(typeof performerProfileInit == 'function') { performerProfileInit(); }

    if(typeof managerProfileInit == 'function') { managerProfileInit(); }


    if(typeof managerJoinInit == 'function') { managerJoinInit(); }

    loadNews();

    initAll();
    
    initCheck();

})


  function S4()
  {
    return (((1+Math.random())*0x10000)|0).toString(10).substring(1);
  }
  
  function GUID()
  {  
    return (S4()+S4()).toUpperCase();
  }

function addReadOnlyClass(){
     $("input").each(function (i) {
	  if ($(this).attr("readonly")){
		$(this).removeClass("text").addClass("readonly").addClass("textR");
	    }			   
	}
    );
}
function onSuccessSubmit(param,status){
	document.location.href='/exec/performer/gallery/public';
		
}

function onSuccessSubmitPer(param,status){
	document.location.href='/exec/performer/profile/3';
		
}

function submitBlockForm(flag){	
	var options_submit={
		success:onSuccessSubmit
	}

	var options_submit_per={
		success:onSuccessSubmitPer
	}
	
	var select = document.getElementsByName('performer_custom_payment_type')[0];
	if (select && !flag)
	{
		var inputN = 'performer_custom_'+select.value;
		var input = document.getElementsByName(inputN)[0]; 
		if (input.value == '')
		{
			if( !confirm('ВНИМАНИЕ! Не указан номер кошелька. Рекомендуем в ближайшее время указать его, иначе мы не сможем осуществлять выплаты.  Продолжить?'))
			{
				return false;
			}
		}
	
		var scan = document.getElementsByName('performer_custom_2257_1')[0]; 
		var passport= document.getElementsByName('performer_custom_2257_2')[0]; 
		if ( (scan && scan.value=='') || (passport && passport.value==''))
		{
			if( !confirm('ВНИМАНИЕ! Не указан скан и/или фото с паспортом. Для утверждения анкеты нам необходимо убедиться в совершеннолетии модели. Отправить скан и фото позже можно по электронной почте vprivate.ru@gmail.com. До этого момента доступ в эккаунт будет заблокирован. Продолжить?') )
			{
				return false;
			}
		}
		$("#frm_performer_pforile").ajaxSubmit(options_submit_per);
	}
	else
	{
		$("#frm_performer_pforile").ajaxSubmit(options_submit);
	}
}


String.prototype.trim = function() { var temp= this.replace(/^\s+|\s+$/, '');return temp.replace(/^\n+|\n+$/, '');};


function initCheck(){
    var option_login_customer = {callback: checkLoginCustomer,captureLength: 0,wait : 750};
    var option_login_perfomer = {callback: checkLoginPerfomer,captureLength: 0,wait : 750};
    var option_login_manager = {callback: checkLoginManager,captureLength: 0,wait : 750};

    var option_screen_customer = {callback: checkScreenCustomer,captureLength: 0,wait : 750};
    var option_screen_perfomer = {callback: checkScreenPerfomer,captureLength: 0,wait : 750};

    $("input").each(function (i) {
	if ($(this).attr('name') == 'customer_name'){
		$(this).typeWatch(option_login_customer);
		$(this).blur(function(){		
			if (this.value.length == 0){
			   $("#errorLabelL").show();
			   $("#errorLabelL").html("This field is required.");
			}
		});
	}

	if ($(this).attr('name') == 'performer_name'){
		$(this).typeWatch(option_login_perfomer);
		$(this).blur(function(){		
			if (this.value.length == 0){
			   $("#errorLabel").show();
			   $("#errorLabel").html("This field is required.");
			}
		});
	}

	if ($(this).attr('name') == 'manager_name'){
		$(this).typeWatch(option_login_manager);
		$(this).blur(function(){		
			if (this.value.length == 0){
			   $("#errorLabel").show();
			   $("#errorLabel").html("This field is required.");
			}
		});

	}

	if ($(this).attr('name') == 'customer_screen_name'){
		$(this).typeWatch(option_screen_customer);
		$(this).blur(function(){		
			if (this.value.length == 0){
			   $("#errorLabelSL").show();
			   $("#errorLabelSL").html("This field is required.");
			}
		});

	}

	if ($(this).attr('name') == 'performer_screen_name'){
		$(this).typeWatch(option_screen_perfomer);
		$(this).blur(function(){		
			if (this.value.length == 0){
			   $("#errorLabel").show();
			   $("#errorLabel").html("This field is required.");
			}
		});
	}



    });	

}


function checkLoginCustomer(_login){		
	$("#errorPicL").html( '<img src="images/ajax-loader2.gif" id="imgError"/>' );		
	$.post('/exec/includes/checkLogin.jsp',{login:_login,type:'customers',isExclusive:true},function(data){
		$("#errorPicL").html( '' );		
		var result = data.trim();
		if (result!=''){					
			$("#errorLabelL").show();
			$("#errorLabelL").html(result);
		}else{
			$("#errorLabelL").html('');
			$("#errorLabelL").attr("style","display:none");

		}
		
	});

}

function checkLoginPerfomer(_login){		
	$("#errorPic").html( '<img src="images/ajax-loader2.gif" id="imgError"/>' );		
	$.post('/exec/includes/checkLogin.jsp',{login:_login,type:'performers',isExclusive:true},function(data){
		$("#errorPic").html( '' );		
		var result = data.trim();
		if (result!=''){					
			$("#errorLabel").show();
			$("#errorLabel").html(result);
		}else{
			$("#errorLabel").html('');
			$("#errorLabel").attr("style","display:none");

		}
		
	});

}

function checkLoginManager(_login){		
	$("#errorPic").html( '<img src="images/ajax-loader2.gif" id="imgError"/>' );		
	$.post('/exec/includes/checkLogin.jsp',{login:_login,type:'managers',isExclusive:true},function(data){
		$("#errorPic").html( '' );		
		var result = data.trim();
		if (result!=''){					
			$("#errorLabel").show();
			$("#errorLabel").html(result);
		}else{
			$("#errorLabel").html('');
			$("#errorLabel").attr("style","display:none");

		}
		
	});

}

function checkScreenCustomer(_screen){		
	$("#errorPicSL").html( '<img src="images/ajax-loader2.gif" id="imgError"/>' );		
	$.post('/exec/includes/checkLogin.jsp',{screen:_screen,type:'customers',isExclusive:true},function(data){
		$("#errorPicSL").html( '' );		
		var result = data.trim();
		if (result!=''){					
			$("#errorLabelSL").show();
			$("#errorLabelSL").html(result);
		}else{
			$("#errorLabelSL").html('');
			$("#errorLabelSL").attr("style","display:none");

		}
		
	});

}

function checkScreenPerfomer(_screen){		
	$("#errorPicS").html( '<img src="images/ajax-loader2.gif" id="imgError"/>' );		
	$.post('/exec/includes/checkLogin.jsp',{screen:_screen,type:'performers',isExclusive:true},function(data){
		$("#errorPicS").html( '' );		
		var result = data.trim();
		if (result!=''){					
			$("#errorLabelS").show();
			$("#errorLabelS").html(result);
		}else{
			$("#errorLabelS").html('');
			$("#errorLabelS").attr("style","display:none");

		}
		
	});

}

function checkIfEmpty(){
		
}

