/* проверка заполнения полей формы комментариев */
function checkFields()
{
	var flag = true;
	var flag_email = true;
	var txt = "";
	var t = document.getElementById("warn");
   var tt = t.firstChild;
	var te = document.getElementById("warn_email");
   var tte = te.firstChild;
	var nickname = document.form.nickname.value;
	var text = document.form.text.value;
	var email = document.form.email_form.value;
	if (nickname == ""){
	   flag = false;
		txt += "nickname ";
	}
	if (text == ""){
	   flag = false;
		txt += " text ";
	}
	if (email != '' && !checkEmail(email))
	   flag_email = false;
	if (flag == false){
		tt.nodeValue = "You haven't entered required fields: " + txt;
		t.style.visibility = "visible";
		t.style.display = "block";
	} else {
	   tt.nodeValue = "";
	}
	if (flag_email == false){
	   tte.nodeValue = "You have entered wrong e-mail format";
		te.style.visibility = "visible";
		te.style.display = "block";
	}
	if (flag == true){
		t.style.visibility = "hidden";
		t.style.display = "none";
	}
	if (flag_email == true){
		te.style.visibility = "hidden";
		te.style.display = "none";
	}
	if (flag && flag_email)
	{
		return true;
	}
	return false;
}
/* проверка заполнения полей формы на странице подписки на рассылку */
function checkFieldsExtra()
{
	var flag = true;
	var ch_email = true;
	var txt = "";
	var t = document.getElementById("warn");
   var tt = t.firstChild;
	var te = document.getElementById("wrong_email");
   var tte = te.firstChild;
	var fname = document.subscription.first_name.value;
	var lname = document.subscription.last_name.value;
   var email = document.subscription.email.value;
	var platform_w = document.subscription.platform_w.checked;
	var platform_m = document.subscription.platform_m.checked;
	if (fname == ""){
	   flag = false;
		txt += "first name ";
	}
	if (lname == ""){
	   flag = false;
		txt += " last name ";
	}
	if (email == ""){
	   flag = false;
		txt += " email ";
	} else {
	   var emailFormat = /(\w+\.)*\w+@(\w+\.)+[A-Za-z]{2,4}/;
		if (!emailFormat.test(email))
		   ch_email = false;
	}
	if (!platform_w && !platform_m){
	   flag = false;
		txt += " platform ";
	}
	if (flag == false){
		tt.nodeValue = "You haven't entered required fields: " + txt;
		t.style.visibility = "visible";
		t.style.display = "block";
	} else {
	   tt.nodeValue = "";
	}
	if (ch_email == false){
	   tte.nodeValue = "Wrong e-mail format";
		te.style.visibility = "visible";
		te.style.display = "block";
	} else {
	   tte.nodeValue = "";
	}
	if (flag && ch_email)
	{
		return true;
	}
	return false;
}
/* проверка заполнения полей формы support */
function checkFieldsSupport()
{
	var flag = true;
	var ch_email = true;
	var txt = "";
	var t = document.getElementById("warn");
   var tt = t.firstChild;
	var te = document.getElementById("wrong_email");
   var tte = te.firstChild;
	var name = document.form.name.value;
   var email = document.form.email.value;
	var platform = document.form.platform.value;
	var product = document.form.product.value;
	var subject = document.form.subject.value;
	var comment = document.form.comment.value;
	if (name == ""){
	   flag = false;
		txt += " name ";
	}
	if (email == ""){
	   flag = false;
		txt += " email ";
	} else {
	   var emailFormat = /(\w+\.)*\w+@(\w+\.)+[A-Za-z]{2,4}/;
		if (!emailFormat.test(email))
		   ch_email = false;
	}
	if (comment == ""){
	   flag = false;
		txt += " comment ";
	}
	if (platform == "-- choose platform --" || platform == ""){
	   flag = false;
		txt += " platform ";
	}
	if (product == "" || product == "---"){
	   flag = false;
		txt += " product ";
	}
	if (subject == "-- choose --" || subject == ""){
	   flag = false;
		txt += " subject ";
	}
	if (flag == false){
		tt.nodeValue = "You haven't entered required fields:" + txt;
		t.style.visibility = "visible";
      t.style.display = "block";
	} else {
	   tt.nodeValue = "";
	}
	if (ch_email == false){
	   tte.nodeValue = "Wrong e-mail format";
		te.style.visibility = "visible";
      te.style.display = "block";
	} else {
	   tte.nodeValue = "";
	}
	if (flag && ch_email)
	{
		return true;
	}
	return false;
}
/* запомнить адресс страницы в браузере */
function addBookmark(url, title) 
{ 
   if (!url)
	   url = location.href; 
   if (!title)
	   title = document.title; 
   //Gecko 
   if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function"))
	   window.sidebar.addPanel(title, url, ""); 
   //IE4+ 
   else if (typeof window.external == "object")
     window.external.AddFavorite("http://www.gameyard.com/", "GameYard.com - Download free games and play online."); 
   //Opera7+ 
   else if (window.opera && document.createElement) 
   { 
      var a = document.createElement('A'); 
      if (!a) return false; //IF Opera 6 
      a.setAttribute('rel','sidebar'); 
      a.setAttribute('href',url); 
      a.setAttribute('title',title); 
      a.click(); 
   } 
   else return false; 
   return true; 
}
/* построение списка для support */
function build_menu(obj)
{
   platformData = obj.value;
   document.form.product.options.length = 0;
   document.form.product.options[0] = new Option('-- choose product --','---');
   for (i = 0; i < a.length; i++)
   {
      if (platformData.indexOf(a[i][0]) != -1)
		{
         for (j = 1; j < a[i].length; j++)
			{
            document.form.product.options[j] = new Option(a[i][j],a[i][j]);
         }
      }
   }
   return true;
}
/* инициализаци для списка с products на support */
function init()
{
   document.form.platform.size = 1;
	document.form.platform.options[0].selected = "selected";
	document.form.product.size = 1;
   document.form.subject.size = 1;
	document.form.subject.options[0].selected = "selected";
}
/* проверка корректности email */
function checkEmail(email)
{
   var emailFormat = /(\w+\.)*\w+@(\w+\.)+[A-Za-z]{2,4}/;
	if (!emailFormat.test(email))
		   return false;
   else
         return true;
}
/* функция открывает окно для отправки письма с линком на игру */
function tellFriend(server,category,name,abbr)
{
   newWindow = window.open("","","toolbar=no,menubar=no,width=550px,height=430px,resizable=no,status=no,scrollbar=no");
   newWindow.location.href = "http://" + server + "/" + "tell_friend.php?category=" + category + "&name=" + name + "&abbr=" + abbr;
}
function change(obj,status,dir)
{
   if (dir == 1){
      tr = obj.nextSibling;
      if (status == 1){
         obj.style.background = "#fcb620";
         obj.style.color = "#ffffff";
         tr.style.background = "#fcb620";
         obj.style.cursor = "pointer";
      }
      if (status == 0){
         obj.style.background = "#ffffff";
         obj.style.color = "#000000";
         tr.style.background = "#ffffff";
      }
   } else {
      tr = obj.previousSibling;
      if (status == 1){
         obj.style.background = "#fcb620";
         obj.style.color = "#ffffff";
         tr.style.background = "#fcb620";
         tr.style.color = "#ffffff";
      }
      if (status == 0){
         obj.style.background = "#ffffff";
         obj.style.color = "#000000";
         tr.style.background = "#ffffff";
         tr.style.color = "#000000";
      }
   }
}