﻿
var loadTimer;

String.prototype.replaceAll = function(search, replace){
  return this.split(search).join(replace);
}


function getId(id)
{
    var tmp = document.getElementById(id);
    return tmp;
}

function RefrashPage(){
    window.location.href = document.location.href;
}

function LoadPaGe(php,id,aR)
{
    var param = '';
	
   	for(i=1; i<20; i++){      
		if(getId('e'+i)){	
		    if(getId('e'+i).value){ 
		        param += '&e'+i+'=' + getId('e'+i).value; 
		    }
		}
	}

	$('#'+id).css("opacity","0.3");
	
    $.ajax({
           type: "POST",
           url: php,
           data: param,
           success: function(content){
		            $('#'+id).css("opacity","1");
				    $('#'+id).html(content);					
					if(aR!=undefined && aR!=''){
                  	    eval(aR);
                    }
								
           }
    });
}

function jqAuth(php,id,log)
{
    var param = '';
	     
	if(getId('email') && getId('password')){	
		if(getId('email').value){ 
		    param += '&email='+getId('email').value; 
		}
		if(getId('password').value){ 
		    param += '&password='+getId('password').value; 
		}		
	}

	$('#'+id).css("opacity","0.3");
	
    $.ajax({
           type: "POST",
           url: php,
           data: param,
           success: function(content){
		   
		        if (typeof content == 'object' && content.nodeType)
			        content = elementToString(content.documentElement, true);
		        else if (typeof content == 'object')
			        content = objToString(content);	
				
                $('#'+id).css("opacity","1");
				
		        if(content=='1'){      $('#'+log).html('<div style="margin-top:10px; margin-right:2px; text-align:center; color:#FF0000; border: 1px solid rgb(245, 224, 130); padding:2px; background:rgb(255, 255, 229);">Укажите логин/пароль</div>');  }    
				else if(content=='2'){ $('#'+log).html('<div style="margin-top:10px; margin-right:2px; text-align:center; color:#FF0000; border: 1px solid rgb(245, 224, 130); padding:2px; background:rgb(255, 255, 229);">Неверный логин/пароль</div>'); } 
				else{ 
				    $('#'+id).html(content); 
					RefrashPage(); 				
				}
		   }
    });
}

function ShowHide(id){

    var css = $('#'+id).css("display");

	switch(css){
		case "none":
		    $('#'+id).slideDown(500);
		break;
		case "block":
			$('#'+id).slideUp(500);		
		break;
	}	
}
