/*
' ****************************************************************************
' Name:	   /js/AllPages.js
' 
' Purpose: Functions used on every page of the site
' 
' Author:  Derrick Sterzel
' 
'          
' History:  06/26/2004 DS  created
'			10/27/2004 jhk removed JS code to fix "blinking"
'
' **************************************************************************** 
*/
////////////////MAIL/////////////////
//m(name,subject,body,server)
function m(name)
{
var mi="to";
var host="";
var fi="mail";
var ri=":";
var sbj="";
var bdi="";
if (arguments[1]) sbj="?subject="+arguments[1];
if (arguments[2]) {if (sbj) bdi="&";bdi=bdi+"body="+arguments[2];}
if (arguments[3]) 
{
host=arguments[3];
} else
{
host=location.href;
host=host.substr(host.indexOf("//")+2,host.length);
host=host.substr(0,host.indexOf("/"));
if (host.indexOf("www.")!=-1) host=host.substr(host.indexOf("www.")+4,host.length);
}
location.href=fi+mi+ri+name+unescape("%40")+host+sbj+bdi;
}
//pm(name,server)
function pm(name)
{
var host="";
if (arguments[1]) 
{
host=arguments[1];
} else
{
host=location.href;
host=host.substr(host.indexOf("//")+2,host.length);
host=host.substr(0,host.indexOf("/"));
if (host.indexOf("www.")!=-1) host=host.substr(host.indexOf("www.")+4,host.length);
}
document.write(name+unescape("%40")+host);
}
///////////////END MAIL/////////////////
var searchText = 'поиск по сайту:';

// Clears the search text field when it is given the focus (if user has not entered anything)
function clearSearchText(formfield) {
	if (formfield.value == searchText) formfield.value = '';
}

// Refills the search text field on blur if it is empty
function fillSearchText(formfield) {
	if (formfield.value == '') formfield.value = searchText;
}

function top_frame_checkSearchString( theForm ) { 
 var newstring = new String(theForm.search.value);
 newstring = ignoreQuotes(newstring);
 if( newstring.length < 3 ) {
  alert("The search string needs to be three or more characters.");
  return false;
 } else return true; 
}







////////////////////////////////////////////

var emailform = 'Ваш E-mail';


function clearemailform(formfield) {
	if (formfield.value == emailform) formfield.value = '';
}

function fillemailform(formfield) {
	if (formfield.value == '') formfield.value = emailform;
}








//////////////////////////
function ignoreQuotes(string) {
 var temp = "";
 string = '' + string;
 splitstring = string.split("\"");
 for(i = 0; i < splitstring.length; i++)
  temp += splitstring[i];
 return temp;
}

function openWin(url, title, features){
window.open(url, title, features);
}

var emailcheckresults
function checkemail(str){
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
emailcheckresults=true
else{
alert("Email address seems incorrect.  \n\nPlease re-enter your email address.")
emailcheckresults=false
}
return (emailcheckresults)
}


function checkEmailFormat(emailStr) {

var checkTLD=1;

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|COM|NET|ORG|EDU|INT|MIL|GOV|ARPA|BIZ|AERO|NAME|COOP|INFO|PRO|MUSEUM)$/;

var emailPat=/^(.+)@(.+)$/;

var specialChars="\\(\\)><@,;:'\\\\\\\"\\.\\[\\]";

var validChars="\[^\\s" + specialChars + "\]";

var quotedUser="(\"[^\"]*\")";

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

var atom=validChars + '+';

var word="(" + atom + "|" + quotedUser + ")";

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

var matchArray=emailStr.match(emailPat);

var sInvalidChars = "!#$%^&*()=+{}[]|\;:'/?>,< "

if (matchArray==null) {

alert("Email address seems incorrect (check @ and .'s) \n\nPlease re-enter your email address.");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters. \n\nPlease re-enter your email address.");
return false;
   }
}


var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (!filter.test(emailStr)){
alert("Email address seems incorrect.  \n\nPlease re-enter your email address.")
return false;
}



for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters. \n\nPlease re-enter your email address.");
return false;
   }
}

if (user.match(userPat)==null) {

alert("The username doesn't seem to be valid. \n\nPlease re-enter your email address.");
return false;
}



var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!\n\nPlease re-enter your email address.");
return false;
   }
}
return true;
}

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.\n\nPlease re-enter your email address.");
return false;
   }
}

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.\n\nPlease re-enter your email address.");
return false;
}

if (len<2) {
alert("This address is missing a hostname! \n\nPlease re-enter your email address.");
return false;
}

if (document.layers||document.getElementById||document.all)
return checkemail(emailStr)

return true;
}


// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this  header

function printWindow(){
   bV = parseInt(navigator.appVersion)
   if (bV >= 4) window.print()
}

function popup(url,w,h,params)
{
open(url, "win","width="+w+",height="+h+",status=no,toolbar=no,menubar=0"+params);
}

function Validate(){
if (document.register.metro.value == "nometro"){		
alert('Вы не выбрали Ваше метро!')
return false
}}

