var uniq_login=false;

function trim(str) {
    var newstr = str.replace(/^s*(.+?)s*$/, "$1");
    if (newstr == " ") {
        return "";
    }
    return newstr;
}


function drop_spaces(str) {
    var newstr = trim(str); //функцию trim() см. выше
    return newstr.replace(/(s)+/g, ""); 
}


function check_email(email) {
    var template = /^[A-Za-z0-9](([_.-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([.-]?[a-zA-Z0-9]+)*).([A-Za-z])+$/;
    email = drop_spaces(email); //функцию drop_spaces() см. выше
    if (template.test(email)) {
        return true;
    }
    return false; 
}




function get_text(str) {
	var text='';
	
    JsHttpRequest.query(
      'action/ajax_get_text.php', // путь к backend-скрипту
      {
        
        'str': str

       
      },
      
      function(result, errors) {
        text=result["res"];
      }
    );
    return text;
  }


function get_date_select(name,too) {
    JsHttpRequest.query(
      'action/ajax_date.php', // путь к backend-скрипту
      {
        // передаем текстовые данные 
        'str': name
        // передаем файл для закачки
       
      },
      // Функция-обработчик, вызывается при ответе сервера. 
      function(result, errors) {
        // document.getElementById("debug").innerHTML = errors; 
        document.getElementById(too).innerHTML = result["res"];
      }
    );
  }


  function get_country_select(name,too,region) {
    JsHttpRequest.query(
      'action/ajax_country.php', // путь к backend-скрипту
      {
        // передаем текстовые данные 
        'str': name,
	'region':region
        // передаем файл для закачки
       
      },
      // Функция-обработчик, вызывается при ответе сервера. 
      function(result, errors) {
        // document.getElementById("debug").innerHTML = errors; 
        document.getElementById(too).innerHTML = result["res"];
      }
    );
  }

  function get_region_select(name,country,too) {
    JsHttpRequest.query(
      'action/ajax_region.php', // путь к backend-скрипту
      {
        // передаем текстовые данные 
        'str': name,
        'country': country
        // передаем файл для закачки
       
      },
      // Функция-обработчик, вызывается при ответе сервера. 
      function(result, errors) {
        // document.getElementById("debug").innerHTML = errors; 
        document.getElementById(too).innerHTML = result["res"];
      }
    );
  }
  
  function used_free(i) {
  	if (i==true) return get_text('login_free');  else return get_text('login_used');
  }
  
  function check_uniq_login(login,too) {
    JsHttpRequest.query(
      'action/ajax_uniq_login.php', // путь к backend-скрипту
      {
        // передаем текстовые данные 
        'str': login
        // передаем файл для закачки
 
      },
      // Функция-обработчик, вызывается при ответе сервера. 
      function(result, errors) {
        // document.getElementById("debug").innerHTML = errors; 
        document.getElementById(too).innerHTML =  result["res"]; //used_free( result["res"] );
        window.uniq_login=result["res2"];
      }
    );
  }
  
  
  
function get_personal2(p,too) {
 // 	document.getElementById(too).value = p;
  	
    JsHttpRequest.query(
      'action/ajax_personal.php',  
      {
        'str': p
      },
      function(result, errors) {
        document.getElementById(too).value =  result["res"]; 
      }
    );
  }

  
  
  
  function get_banner(banner,too) {
    JsHttpRequest.query(
      'action/ajax_banner.php', // путь к backend-скрипту
      {
        // передаем текстовые данные 
        'str': banner
        // передаем файл для закачки
       
      },
      // Функция-обработчик, вызывается при ответе сервера. 
      function(result, errors) {
        // document.getElementById("debug").innerHTML = errors; 
        document.getElementById(too).innerHTML =  result["res"];//used_free( result["res"] );
      }
    );
  }


  function a_login(login,password,too) {
  	
    
    JsHttpRequest.query(
      'action/ajax_login.php', // путь к backend-скрипту
      {
        // передаем текстовые данные 
        'login': login,
        'password': password
        // передаем файл для закачки
       
      },
      // Функция-обработчик, вызывается при ответе сервера. 
      function(result, errors) {
        document.getElementById(too).innerHTML =  result["res"]; 
      }
     ); 
  }



  

function get_personal(p,too) {
 // 	document.getElementById(too).value = p;
  	
    JsHttpRequest.query(
      'action/ajax_personal.php',  
      {
        'str': p
      },
      function(result, errors) {
        document.getElementById(too).value =  result["res"]; 
      }
    );
  }  



function get_url_param(name)
{ 
name = name.replace(/[[]/,"[").replace(/[]]/,"]"); 
var regexS = "[?&]"+name+"=([^&#]*)"; 
var regex = new RegExp( regexS ); 
var results = regex.exec( window.location.href ); 
if( results == null )    return ""; 
else return results[1];
}

function plus_minus(p) {
	if (p==true || p==1 || p=='1') return '<font color="green">+</font>'; 
	else if (p==false || p==0 || p=='0') return '<font color="red">-</font>';
	else return '<font color="yellow">?</font>';
}

function clear_pass(pass) {
	var c=pass.length;
	var i=0;
	for (i=0;i<=c;i++) pass=pass.replace(/[^A-Za-z0-9]/,'');
	return pass;
}

function check_password(p1,p2) {
	if (p1==p2 && clear_pass(p1)==p1 && p1.length>=8) return true 
	else return false;
}


function checkPasswordStrength(strPassword) {
	// Reset combination count
	var nScore = 0;
	
	// Password length
	// -- Less than 4 characters
	if (strPassword.length < 5)
	{
		nScore += 5;
	}
	// -- 5 to 7 characters
	else if (strPassword.length > 4 && strPassword.length < 8)
	{
		nScore += 10;
	}
	// -- 8 or more
	else if (strPassword.length > 7)
	{
		nScore += 25;
	}

	// Letters
	var nUpperCount = countContain(strPassword, m_strUpperCase);
	var nLowerCount = countContain(strPassword, m_strLowerCase);
	var nLowerUpperCount = nUpperCount + nLowerCount;
	// -- Letters are all lower case
	if (nUpperCount == 0 && nLowerCount != 0) 
	{ 
		nScore += 10; 
	}
	// -- Letters are upper case and lower case
	else if (nUpperCount != 0 && nLowerCount != 0) 
	{ 
		nScore += 20; 
	}
	
	// Numbers
	var nNumberCount = countContain(strPassword, m_strNumber);
	// -- 1 number
	if (nNumberCount == 1)
	{
		nScore += 10;
	}
	// -- 3 or more numbers
	if (nNumberCount >= 3)
	{
		nScore += 20;
	}
	
	// Characters
	var nCharacterCount = countContain(strPassword, m_strCharacters);
	// -- 1 character
	if (nCharacterCount == 1)
	{
		nScore += 10;
	}	
	// -- More than 1 character
	if (nCharacterCount > 1)
	{
		nScore += 25;
	}
	
	// Bonus
	// -- Letters and numbers
	if (nNumberCount != 0 && nLowerUpperCount != 0)
	{
		nScore += 2;
	}
	// -- Letters, numbers, and characters
	if (nNumberCount != 0 && nLowerUpperCount != 0 && nCharacterCount != 0)
	{
		nScore += 3;
	}
	// -- Mixed case letters, numbers, and characters
	if (nNumberCount != 0 && nUpperCount != 0 && nLowerCount != 0 && nCharacterCount != 0)
	{
		nScore += 5;
	}
	
	
	return nScore;
}

 