Event.observe(window, 'load', function() { 
	var searchBox2 = $("search_input");
	Event.observe(searchBox2, 'focus', function(){
		if($(this).value == searchBox2Default)
			$(this).value = "";
	});
	Event.observe(searchBox2, 'blur', function(){
		if($(this).value == "")
			$(this).value = searchBox2Default;
	});
	var cookie = readCookie("style");
  	var title = cookie ? cookie : getPreferredStyleSheet();
  	setActiveStyleSheet(title);
});

function add_book(lang_val){
	if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function')) {
		window.sidebar.addPanel (document.title, document.location.href,'');
	}
 	else if( window.external ) {
 		window.external.AddFavorite(document.location.href, document.title)
 	}
 	else{
 		if(lang_val==1)
 			alert('Unfortunately, this browser does not support the requested action, try pressing CTRL+D to bookmark this page manually.');
 		else
 			alert('&#1047;&#1072; &#1089;&#1098;&#1078;&#1072;&#1083;&#1077;&#1085;&#1080;&#1077;, &#1078;&#1077;&#1083;&#1072;&#1085;&#1086;&#1090;&#1086; &#1086;&#1090; &#1074;&#1072;&#1089; &#1076;&#1077;&#1081;&#1089;&#1090;&#1074;&#1080;&#1077; &#1085;&#1077; &#1084;&#1086;&#1078;&#1077; &#1076;&#1072; &#1073;&#1098;&#1076;&#1077; &#1080;&#1079;&#1087;&#1098;&#1083;&#1085;&#1077;&#1085;&#1086; &#1074; &#1090;&#1086;&#1079;&#1080; &#1073;&#1088;&#1072;&#1091;&#1079;&#1098;&#1088;. &#1047;&#1072; &#1076;&#1072; &#1076;&#1086;&#1073;&#1072;&#1074;&#1080;&#1090;&#1077; &#1089;&#1090;&#1088;&#1072;&#1085;&#1080;&#1094;&#1072;&#1090;&#1072; &#1074; &#1051;&#1102;&#1073;&#1080;&#1084;&#1080;, &#1086;&#1087;&#1080;&#1090;&#1072;&#1081;&#1090;&#1077; &#1089; &#1085;&#1072;&#1090;&#1080;&#1089;&#1082;&#1072;&#1085;&#1077; &#1085;&#1072; CTRL+D.');
 	}
}

function checkLength(elementId, maxLength) {
	var field = $(elementId);
 	var value = field.value;
 	
	 if(value.length>maxLength) {
 		field.value=value.substring(0,maxLength);
 	}
}

// Style Sheet Stuff
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

function IsValidPhone(sText){
	var ValidChars = "0123456789()-+";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++){
 		Char = sText.charAt(i);
 		if (ValidChars.indexOf(Char) == -1){
 			return IsNumber = false;
 		}
 	}
 	return IsNumber;
}

function IsValidNum(sText)
{
   var ValidChars = "0123456789.,";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
            return IsNumber = false;
         }
      }
   return IsNumber;
   
}
