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 != "")
	{
     d=window.open('musicpreview.php?music_url='+ musicName+'&title='+formObj.sound_file.options[inx].text,'',winsettings +'width=400,height=250');
     /*
     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;
var show_group = new Array();
var checkbox_ar = new Array();

function in_array(exists_ar, value)
  {
    var exist = false;

    for (j = 0; j < exists_ar.length; j++)
     {
      if (value == exists_ar[j])
        {
          exist = true;
        }
     }
    return exist;
  }


function changeLink()
{
  var div_contact = document.getElementById('div_contact');
  var div = document.getElementById('link');
  if (show_contacts == false)
    {
      div.innerHTML = 'Hide my contacts';
      show_contacts = true;
      div_contact.style.display='';
    }
  else
    {
      div.innerHTML = 'Show my contacts';
      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 del_group(group_id)
{
  var contact_list = document.getElementById('contact_list');
  var div_name = 'div_group_'+ group_id;
  var group_div = document.getElementById(div_name);
  contact_list.removeChild(group_div);
  var data = new Array();
  for (i = 0; i < show_group.length; i++)
    {
      if (show_group[i] != group_id) data.push(show_group[i])
    }
  show_group = data;
  var group_adr = new Array();
  var data = new Array();
  for (i = 0; i < contacts_ar.length; i++)
    {
      if (group_id == contacts_ar[i][1])
        {
          group_adr.push(contacts_ar[i][0]);
        }
    }
  // удаляю из выбранных
  for (i = 0; i < selected_contacts.length; i++)
    {
      if (!in_array(group_adr,selected_contacts[i])) data.push(selected_contacts[i]);
    }
  selected_contacts = data;

  // удаляю из чекбоксов
  var data = new Array();
  for (i = 0; i < checkbox_ar.length; i++)
    {
      if (!in_array(group_adr,checkbox_ar[i])) data.push(selected_contacts[i]);
    }
  checkbox_ar = data;
}
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 = '';
  if (show_group.length == 0)
    {
      contact_list.innerHTML = '';
      checkbox_ar = data;
    }
  if (group_id > 0)
    {
      checked = 'checked';
      check_all.innerHTML = 'uncheck all';
      set_check_all = true;
    }
  else
    {
      check_all.innerHTML = 'check all';
      set_check_all = false;
    }
  var new_div = document.createElement('div');
  var div_name = 'div_group_'+ group_id;
  new_div.setAttribute('id',div_name);

  if (group_id > 0)
    {
      new_div.innerHTML += '<b>'+cat_ar[group_id]+'</b> <a href="#" onclick="del_group('+group_id+'); return false;" style="font-size:10px; font-weight:normal;">delete</a><br>';
    }
  for (i = 0; i < contacts_ar.length; i++)
    {
      if (group_id > 0)
        {
          if (group_id == contacts_ar[i][1])
            {
              new_div.innerHTML += '<input type="checkbox" name="send_to_contacts" id="send_to_contacts_'+contacts_ar[i][0]+'" value="' + contacts_ar[i][0] + '" '+checked+' onClick="change_ar();"> ' + contacts_ar[i][2] + ' ('+contacts_ar[i][3]+')<br>';
              if (group_id > 0 && !in_array(selected_contacts, contacts_ar[i][0])) selected_contacts.push(contacts_ar[i][0]);
              if (!in_array(checkbox_ar, contacts_ar[i][0])) checkbox_ar.push(contacts_ar[i][0]);
            }
        }
      else
        {
          new_div.innerHTML += '<input type="checkbox" name="send_to_contacts" id="send_to_contacts_'+contacts_ar[i][0]+'" value="' + contacts_ar[i][0] + '" '+checked+' onClick="change_ar();"> ' + contacts_ar[i][2] + ' ('+contacts_ar[i][3]+')<br>';
          if (group_id > 0 && !in_array(selected_contacts, contacts_ar[i][0])) selected_contacts.push(contacts_ar[i][0]);
          if (!in_array(checkbox_ar, contacts_ar[i][0])) checkbox_ar.push(contacts_ar[i][0]);
        }
    }
  if (!in_array(show_group, group_id) && group_id > 0)
    {
      contact_list.appendChild(new_div);
      show_group.push(group_id);
    }
  if (group_id == 0)
    {
      contact_list.appendChild(new_div);
    }
}
function change_ar()
{
  var data = new Array();
  for (i = 0; i < checkbox_ar.length; i++)
    {
      if (document.getElementById('send_to_contacts_'+checkbox_ar[i]).checked)
        {
          data.push(document.getElementById('send_to_contacts_'+checkbox_ar[i]).value)
        }
    }
  selected_contacts = data;
}
function check_all()
{
  var check_all = document.getElementById('check_all');
  if (set_check_all == false)
    {
      check_all.innerHTML = 'uncheck all';
      set_check_all = true;
    }
  else
    {
      check_all.innerHTML = 'check all';
      set_check_all = false;
    }
  for (i = 0; i < checkbox_ar.length; i++)
    {
      document.getElementById('send_to_contacts_'+checkbox_ar[i]).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);

    var new_text = document.createElement('input');
    new_text.setAttribute('type','text');
    new_text.setAttribute('name','ecard_rname' + addtional_reciv);
    new_text.setAttribute('id','ecard_rname' + addtional_reciv);
    new_text.setAttribute('class','cardform');
    new_text.setAttribute('size','25');
    new_text.setAttribute('maxlength','50');
    new_text.setAttribute('value','');

    new_div_name.innerHTML = '<b>Recipient\'s name # ' +caption_num+ ':</b><br>';
    new_div_name.appendChild(new_text);

    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);

    var new_text = document.createElement('input');
    new_text.setAttribute('type','text');
    new_text.setAttribute('name','ecard_remail' + addtional_reciv);
    new_text.setAttribute('id','ecard_remail' + addtional_reciv);
    new_text.setAttribute('class','cardform');
    new_text.setAttribute('size','25');
    new_text.setAttribute('maxlength','50');
    new_text.setAttribute('value','');

    new_div_email.innerHTML = '<b>Recipient\'s email # ' +caption_num+ ':</b><br>';
    new_div_email.appendChild(new_text);

    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;
 }
}