var x=screen.width/2-220;
var y=screen.height/2-250;
winsettings = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,left=' +x +',top='+y+',';
var t;
function colorwin(){ 		cyber=window.open('win.php?Info=Colors', 'info', winsettings + 'width=250,height=280') }
function bgroundwin(){ 		cyber=window.open('win.php?Info=Background', 'info2',  winsettings + 'width=250,height=290') }
function emoticonwin(){		cyber=window.open('win.php?Info=Emoticons', 'info4', winsettings + 'width=350,height=300') }
function exturl(){ 		cyber=window.open('win.php?Info=Custom', 'info5', winsettings + 'width=450,height=270') }
function notify(){ 		cyber=window.open('win.php?Info=Notify', 'info6', winsettings + 'width=300,height=140') }
function fontface(){ 		cyber=window.open('win.php?Info=Fonts', 'info7', winsettings + 'width=550,height=270') }
function stampwin(){ 		cyber=window.open('win.php?Info=Stamp', 'info8', winsettings + 'width=250,height=290') }
function wishes(cat_id) { cyber=window.open('showwishes.php?cat_id='+cat_id, 'info9', winsettings + 'width=450,height=400') }
function contacts() { cyber=window.open('showcontact.php', 'info10', winsettings + 'width=450,height=400') }

function playmusic(formObj)
{
	musicName = formObj.sound_file.value;
    inx = formObj.sound_file.selectedIndex;

	if(musicName != "")
	{
	 if (d){
	    d.close();
	    d=window.open('musicpreview.php?music_url='+ musicName+'&title='+formObj.sound_file.options[inx].text,'',winsettings +'width=400,height=250');
	  	  }
	 else
      {
        d=window.open('musicpreview.php?music_url='+ musicName+'&title='+formObj.sound_file.options[inx].text,'',winsettings +'width=400,height=250');
      }

	}
	else
	   alert(MsgWinMusicNote);
}
function addrecp(formObj){
  NumberRecp = formObj.addrecip.options[formObj.addrecip.selectedIndex].value;
  if(NumberRecp != ""){
    window.location="create.php?" + query_string + "&addrecip=" + NumberRecp;
  }
}
var show_contacts = false;
var set_check_all = false;
var addtional_reciv = 0;
function changeLink()
{
  var div_contact = document.getElementById('div_contact');
  var div = document.getElementById('link');
  if (show_contacts == false)
    {
      div.innerHTML = 'Спрятать мои контакты';
      show_contacts = true;
      div_contact.style.display='';
    }
  else
    {
      div.innerHTML = 'Показать мои контакты';
      show_contacts = false;
      div_contact.style.display='none';
    }
}
function set_group(group_id)
{
   document.vCardLiteform.send_group_id.value = group_id;
   create_list(group_id);
}
function create_list(group_id)
{

  var contact_list = document.getElementById('contact_list');
  var check_all = document.getElementById('check_all');
  var data = new Array();
  var checked = '';
  contact_list.innerHTML = '';
  if (group_id > 0)
    {
      checked = 'checked';
      check_all.innerHTML = 'снять отметку со всех';
      set_check_all = true;
    }
  else
    {
      check_all.innerHTML = 'отметить все';
      set_check_all = false;
    }
  for (i = 0; i < contacts_ar.length; i++)
    {
      if (group_id > 0)
        {
          if (group_id == contacts_ar[i][1])
            {
              contact_list.innerHTML += '<input type="checkbox" name="send_to_contacts" id="send_to_contacts" value="' + contacts_ar[i][0] + '" '+checked+' onClick="change_ar();"> ' + contacts_ar[i][2] + ' ('+contacts_ar[i][3]+')<br>';
              if (group_id > 0) data.push(contacts_ar[i][0]);
            }
        }
      else
        {
          contact_list.innerHTML += '<input type="checkbox" name="send_to_contacts" id="send_to_contacts" value="' + contacts_ar[i][0] + '" '+checked+' onClick="change_ar();"> ' + contacts_ar[i][2] + ' ('+contacts_ar[i][3]+')<br>';
          if (group_id > 0) data.push(contacts_ar[i][0]);
        }
    }
  selected_contacts = data;
}
function change_ar()
{
  var data = new Array();
  if (document.vCardLiteform.send_to_contacts.length > 1)
    {
      for (i = 0; i < document.vCardLiteform.send_to_contacts.length; i++)
        {
          if (document.vCardLiteform.send_to_contacts[i].checked)
            {
              data.push(document.vCardLiteform.send_to_contacts[i].value)
            }
        }
    }
  else
    {
      if (document.vCardLiteform.send_to_contacts.checked)
        {
          data.push(document.vCardLiteform.send_to_contacts.value)
        }
    }
  selected_contacts = data;
}
function check_all()
{
  var check_all = document.getElementById('check_all');
  if (set_check_all == false)
    {
      check_all.innerHTML = 'снять отметку со всех';
      set_check_all = true;
    }
  else
    {
      check_all.innerHTML = 'отметить все';
      set_check_all = false;
    }
  /*
  var frm = document;
  for(var i=0;i<frm.elements.length;i++) {
    alert(frm.elements[i].type);
    if(frm.elements[i].type) {
      if(frm.elements[i].type.toLowerCase() == 'checkbox') {
           alert(frm.elements[i].name);
           //frm.elements[i].disabled = cbx.checked;
         }
      }
  */

  //alert(document.forms[0].elements['send_to_contacts'].length);
  if (document.vCardLiteform.send_to_contacts.length > 1)
    {
      for (i = 0; i < document.vCardLiteform.send_to_contacts.length; i++)
        {
          document.vCardLiteform.send_to_contacts[i].checked = set_check_all;
        }
    }
  else
    {
      document.vCardLiteform.send_to_contacts.checked = set_check_all;
    }
  change_ar();

}

function add_reciver()
  {
    addtional_reciv++;
    var add_name = document.getElementById('add_name');
    var add_email = document.getElementById('add_email');
    var caption_num = addtional_reciv+1;

    var new_div_name = document.createElement('div');
    var div_name = 'div_name_'+ addtional_reciv;
    new_div_name.setAttribute('id',div_name);
    new_div_name.innerHTML = '<b>Имя получателя № ' +caption_num+ ':</b><br><input type="text" class="cardform" name="ecard_rname' + addtional_reciv + '" value="" SIZE="25" MAXLENGTH="50">';
    add_name.appendChild(new_div_name);

    var new_div_email = document.createElement('div');
    var div_name = 'div_email_'+ addtional_reciv;
    new_div_email.setAttribute('id',div_name);
    new_div_email.innerHTML = '<b>Эл.почта получателя: № ' +caption_num+ ':</b><br><input type="text" class="cardform" name="ecard_remail' + addtional_reciv + '" value="" SIZE="25" MAXLENGTH="50">';
    add_email.appendChild(new_div_email);
  }
function show_blog_code()
  {
    var blog_code = document.getElementById('blog_code');
    var blog_link = document.getElementById('blog_link');

    if (blog_code.style.display == '')
       {
         blog_code.style.display='none';
         blog_link.innerHTML = 'Поставить открытку в блог';
       }
    else
       {
         blog_code.style.display='';
         blog_link.innerHTML = 'Спрятать код для блога';
       }
  }
function copyFunc(el)
  {
    var txt = document.getElementById(el).value;
    window.event.returnValue = false;
    window.clipboardData.setData("Text", txt);
    alert('Код для  блога скопирован в буфер обмнена');
  }
function selectFunc(el)
  {
    var range = document.getElementById(el).createTextRange(); // создаём объект TextRange
    range.select();
  }
var submitted = false;
function check_order_form()
{
  var error = 0;
  var error_message = "";
  if(submitted){
    alert( "Your form already submited");
    return false;
  }
  var name = document.order.name.value;
  var country = document.order.country.value;
  var city = document.order.city.value;
  var address = document.order.address.value;
  var email = document.order.email.value;
  var comments = document.order.comments.value;

    if (name == '' || name.length < 2)
	{
      error_message = error_message + "* Пожалуйста введите Ваше имя.\n";
      error = 1;
    }
    if (country == '' || country.length < 2)
	{
      error_message = error_message + "* Пожалуйста введите страну.\n";
      error = 1;
    }
    if (city == '' || city.length < 2)
	{
      error_message = error_message + "* Пожалуйста введите город.\n";
      error = 1;
    }

    if (email == '' || email.length < 6)
	{
      error_message = error_message + "* Пожалуйста введите Ваш email.\n";
      error = 1;
    }
    if (comments == '')
	{
      error_message = error_message + "Пожалуйста введите описание проекта/задачи\n";
      error = 1;
    }

 if (error == 1)
  {
    alert(error_message);
    return false;
  } else
 {
   submitted = true;
    return true;
 }
}
