String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

var xmlHttp;
var mTimer;
var mTimer2;

function showHint(str)
{
clearInterval(mTimer);
if (str.length==0)
  { 
  document.getElementById("txtHint").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="any_unread.php";
url=url+"?q="+str;
//xmlHttp.onreadystatechange=stateChanged;
	str2 = str;
xmlHttp.onreadystatechange=function() {
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
		mTimer = setTimeout( "showHint(str2)", 2003 );
	}
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function showHint2(str)
{
clearInterval(mTimer2);
if (str.length==0)
  { 
  document.getElementById("txtHint2").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="any_unread2.php";
url=url+"?q="+str;
//xmlHttp.onreadystatechange=stateChanged;
	str2 = str;
xmlHttp.onreadystatechange=function() {
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("txtHint2").innerHTML=xmlHttp.responseText;
		mTimer2 = setTimeout( "showHint2(str2)", 3003 );
	}
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged(str) 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
mTimer = setTimeout( "showHint(str)", 2003 );
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


function twist( sid )
{
  imgobj = document.getElementById( "img_"+sid );
  divobj = document.getElementById( sid );
  if ( imgobj.src.match( "up.gif" ) )
  {
	imgobj.src = "down.gif";
	divobj.style.position = "relative";
	divobj.style.visibility = "visible";
  }
  else
  {
	imgobj.src = "up.gif";
	divobj.style.visibility = "hidden";
	divobj.style.position = "absolute";
  }
}
function deleteApp( ID, Name )
{				
  if (confirm("Сигурни ли сте, че желаете да изтриете " + Name + "?" )) 
  {
	window.location = "postpage.php?delete=1&appid=" + ID;
  }
}

function deleteDoc( ID, Name )
{				
  if (confirm("Сигурни ли сте, че желаете да изтриете " + Name + "?" )) 
  {
	window.location = "ppage.php?delete=doc&docid=" + ID;
  }
}

function deleteNote( ID, Name )
{				
  if (confirm("Сигурни ли сте, че желаете да изтриете  " + Name + "?" )) 
  {
	window.location = "postpage.php?delete=2&noteid=" + ID;
  }
}

function loadSendMailData( mail ){
	document.frmMessage.to.value = mail;
}

function switchform( nr, name, address, phone, mail, birthday ) 
{
	document.frm.nr.value = nr;
	document.frm.newname.value = name;
	document.frm.newaddress.value = address;
	document.frm.newphone.value = phone;
	document.frm.newemail.value = mail;
	document.frm.newbirthday.value = birthday;
	//document.frm.newcat.value = 'Cool';
	document.frm.newname.focus(); 
}

function deleteContact( ID, Name )
{				
  if (confirm("Сигурни ли сте, че желаете да изтриете " + Name + "?" )) 
  {
	window.location = "postpage.php?delete=3&contactid=" + ID;
  }
}

function add() 
{
	document.frm.action = "postpage.php?act=addcontact";
	document.frm.submit(); 
}
    
function edit() 
{
	document.frm.action = "postpage.php?act=editcontact";
	if(document.frm.nr.value == "-1") 
	{
		alert('Няма нищо за променяне!\n Искате ли да добавите нов контакт?'); 
	} 
	else 
	{
		document.frm.submit(); 
	} 
}

function clear()
{
	document.frm.nr.value = -1;
	document.frm.reset();
}

function clearContactForm(){
	document.frm.nr.value = -1;
	document.frm.reset();
}

function clearMessageForm(){
	document.frmMessage.reset();
}

function validateEmail( strValue ) {
	emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
	return emailpat.test(strValue);
}

function sendMessage(){
	var theme = document.getElementById( "theme" ).value.trim();
	var message = document.getElementById( "message" ).value.trim();
	var to = document.getElementById( "to" ).value.trim();

	var error = "";
	if( to.length == 0 ){
		error += "празно поле за email-a\n";
	}
	else if( !validateEmail( to ) ){
		error += " невалиден email\n";
	}

	if( theme.length == 0 ){
		error += "празно поле за темата\n";
	}

	if( message.length == 0 ){
		error += "празно поле за съобщението\n";
	}

	if( error.length > 0 )
		alert( error );
	else{
		document.frmMessage.action = "postmessage.php";
		document.frmMessage.submit();
	}
}

function fillform2( nr2, name, link, cat, id ) 
{
	document.frm2.nr2.value = nr2;
	document.frm2.linkname.value = name;
	document.frm2.linklink.value = link;
	document.frm2.catcatname.value = cat;
	document.frm2.selcat.options.selectedIndex = id;
	document.frm2.linkname.focus(); 
}

function deleteLink2( ID, Name )
{				
  if (confirm("Сигурни ли сте, че желаете да изтриете " + Name + "?" )) 
  {
	window.location = "postpage.php?delete=4&linkid=" + ID;
  }
}

function add2() 
{
	document.frm2.action = "postpage.php?act=addlink2";
	document.frm2.submit(); 
}

function clear2()
{	
	document.frm2.nr2.value = -1;
	document.frm2.reset();
}

function clear3()
{	
	document.frm4.reset();
}

function changesel()
{
	document.frm2.catcatname.value = document.frm2.selcat.value;
}

function getselvalue()
{
	document.frm2.catcatname.value = document.frm2.selcat.value;
}

function fillform3( name, birthday, sex, interest ) 
{
	document.frm4.prname.value = name;
	document.frm4.prbirthday.value = birthday;
	document.frm4.prsex[sex].checked = true;
	document.frm4.printerest.value = interest;
	document.frm4.prname.focus(); 
}

function changepic()
{
	document.frm5.prpic.disabled = false;
}

function changeprdata()
{
	document.frm4.action = "portal/profilepost.php?act=updatepr";
	document.frm4.submit(); 
}

function changeprpic()
{
	document.frm5.action = "portal/profilepost.php?act=updatepic";
	document.frm5.submit(); 
}
function show2(id) {
	var d = document.getElementById(id);
	if (d.style.display=='block') 
	{
		document.getElementById(id).style.display='none';
	}
	else
	{
		document.getElementById(id).style.display='block';
	}
}

function show_hide(id, id_to_hide) {
	var h = document.getElementById(id_to_hide);
	if (h.style.display=='block') 
	{
		document.getElementById(id_to_hide).style.display='none';
	}

	var d = document.getElementById(id);
	if (d.style.display=='block') 
	{
		document.getElementById(id).style.display='none';
	}
	else
	{
		document.getElementById(id).style.display='block';
	}
}

function show_hide2(id, id_to_hide) {
	var h = document.getElementById(id_to_hide);
	if (h.style.display=='block') 
	{
		document.getElementById(id_to_hide).style.display='none';
	}

	var d = document.getElementById(id);
	if (d.style.display=='block') 
	{
	
	}
	else
	{
		document.getElementById(id).style.display='block';
	}
}


function setSubCat()
{

  if ( document.main )
    if ( (document.main.cat)&&(document.main.sub) )
      {
        marka='';
        if ( document.main.cat.selectedIndex>=0 )
          marka=document.main.cat.options[document.main.cat.selectedIndex].value;
        document.main.sub.length=0;

        if (marka == '0') {
         document.main.sub.options[0] = new Option("Моля изберете категория", "0");
         return true;
        }

        arrSubCat=document.categories.allinone.value.split('**');
        i=0;
        //document.main.sub.options[0]=new Option('',-1);
        while ( i<arrSubCat.length )
          {
            arrSubCat[i]=arrSubCat[i].split('~');
            if ( arrSubCat[i][0]==marka )
              {
                k=1;
                while ( k<arrSubCat[i].length )
                  {
                  opt = arrSubCat[i][k].split('&');
                    document.main.sub.options[k-1]=new Option(opt[1],opt[0]);
                    k++;
                  }
                break;
              }
            i++;
          }
        return true;
      }
}

function fillformnotes( nr, text ) 
{
	document.frmnotes.nrnote.value = nr;
	document.frmnotes.notebody.value = text;
	document.frmnotes.notebody.focus(); 
}

function clearnotes()
{	
	document.frmnotes.nrnote.value = -1;
	document.frmnotes.reset();
}

function addnote() 
{
	document.frmnotes.action = "postpage.php?act=addnote";
	document.frmnotes.submit(); 
}

function changestatus() 
{
	document.frmpp.action = "postp.php?act=lstatus";
	document.frmpp.submit(); 
}

function notestatus() 
{
	document.frmpp.action = "postp.php?act=nstatus";
	document.frmpp.submit(); 
}

function casestatus() 
{
	document.frmpp.action = "postp.php?act=cstatus";
	document.frmpp.submit(); 
}

function profilest() 
{
	document.frmpppr.action = "postp.php?act=stpr";
	document.frmpppr.submit(); 
}

function galst() 
{
	document.frmppgal.action = "postp.php?act=stgal";
	document.frmppgal.submit(); 
}

function vidst() 
{
	document.frmppvid.action = "postp.php?act=stvid";
	document.frmppvid.submit(); 
}

function addfriend() 
{
	document.frmadd.action = "postpage.php?act=addfriend";
	document.frmadd.submit(); 
}

function removefriend() 
{
	document.frmadd.action = "postpage.php?act=removefriend";
	document.frmadd.submit(); 
}

function blockuser() 
{
	document.frmadd.action = "postpage.php?act=block";
	document.frmadd.submit(); 
}

function reblockuser() 
{
	document.frmadd.action = "postpage.php?act=reblock";
	document.frmadd.submit(); 
}

function addfriend2( id ) 
{
	document.frmadd.action = "postpage.php?act=addfriend&userid=" + id;
	document.frmadd.submit(); 
}

function removefriend2( id ) 
{
	document.frmadd.action = "postpage.php?act=removefriend&userid=" + id;
	document.frmadd.submit(); 
}

function blockuser2( id ) 
{
	document.frmadd.action = "postpage.php?act=block&userid=" + id;
	document.frmadd.submit(); 
}

function reblockuser2( id ) 
{
	document.frmadd.action = "postpage.php?act=reblock&userid=" + id;
	document.frmadd.submit(); 
}

function uploadv() 
{
	document.videoform.action = "postp.php?act=upldv";
	document.videoform.submit(); 
}

function openChatWindow( id )
{
	 window.open ("http://www.makeyour.net/chat.php?userid=" + id, "win", "location=0,status=0,scrollbars=1, width=650,height=400");
}

function deleteMessage( ID, Name )
{				
  if (confirm("Сигурни ли сте, че желаете да изтриете " + Name + "?" )) 
  {
	window.location = "postp.php?delete=message&messid=" + ID;
  }
}
function checkUncheckAll(theElement) 
{
     var theForm = theElement.form, z = 0;
     for(z=0; z<theForm.length;z++)
     {
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall')
      {
	  theForm[z].checked = theElement.checked;
      }
     }
}

function deleteAllChoosed() 
{
	 theMessage = "";
	 var multiCheckbox = false;
	 var arrayInputs = document.getElementsByTagName("input");	
	 for (i = 0; i < arrayInputs.length ; i++) 
	 {
		var input = arrayInputs[i] ;
	 	if ( input.type == "checkbox" && input.name.indexOf("list") == 0 && input.checked )
		{
			multiCheckbox = true; 
		}
	 }
	
	 if (!multiCheckbox) 
	 {
		theMessage = "Не сте избрали съобщения за триене.";
        }
	 if (theMessage == "") 
	 {
		if (confirm("Сигурни ли сте, че желаете да изтриете избраните съобшения?" )) 
		{
 			document.frm_messages.submit();
		}
	 } 
	 else 
	 {
		alert(theMessage);
	 } 
}

function addFavouriteVideo( ID, Name, GROUPID )
{				
  if (confirm("Сигурни ли сте, че желаете да добавите " + Name + " в любими?" )) 
  {
	document.frmuri.action = "postp.php?fav=add&videoid=" + ID + "&groupid=" + GROUPID;
	document.frmuri.submit(); 
  }
}

function deleteFavouriteVideo( ID, Name, USERID )
{				
  if (confirm("Сигурни ли сте, че желаете да премахнете " + Name + " от любими?" )) 
  {
	document.frmrem.action = "postp.php?fav=rem&videoid=" + ID + "userid=" + USERID;
	document.frmrem.submit();
  }
}

function deleteVideo( ID, Name )
{				
  if (confirm("Сигурни ли сте, че желаете да изтриете " + Name + "?" )) 
  {
	window.location = "postp.php?delete=video&videoid=" + ID;
  }
}

function AdvertOut()
{				
  if (confirm("Сигурни ли сте, че желаете да излезете?" )) 
  {
	window.location = "advertadmin/loginpost.php?do=out";
  }
}

function clearVideoEditForm()
{
	document.getElementById('edit_form').style.display = "none";
	document.vid_edit.edit_vid_info.disabled = true;
	document.vid_edit.vid_id.value = -1;
	document.vid_edit.vid.value = -1;
	document.vid_edit.vid_title.value = '';
	document.vid_edit.vid_key.value = '';
	document.vid_edit.vid_desc.value = '';
}

function loadVideoInfo( ID, TITLE, DESC, KEY )
{
	document.getElementById('edit_form').style.display = "block";
	document.vid_edit.edit_vid_info.disabled = false;
	document.vid_edit.vid_id.value = ID;
	document.vid_edit.vid.value = ID;
	document.vid_edit.vid_title.value = TITLE;
	document.vid_edit.vid_key.value = KEY;
	document.vid_edit.vid_desc.value = DESC;
	document.videoform.style.visibility='hidden';
	document.videoform.style.display='none';
}

function changeAdvertType( type, value )
{
	document.getElementById('blockme').style.display=type;
	document.getElementById('typeAdvert').value=value;
}

function changeSearchToWeb()
{
	document.getElementById('web').style.display='block';
	document.getElementById('users').style.display='none';
	document.getElementById('video').style.display='none';
	document.getElementById('photos').style.display='none';
	document.getElementById('catalog').style.display='none';
	document.getElementById('SearchToWeb').style.background='#999999';
	document.getElementById('SearchToCatalog').style.background='none';
	document.getElementById('SearchToVideo').style.background='none';
	document.getElementById('SearchToPhotos').style.background='none';
	document.getElementById('SearchToUsers').style.background='none';

}

function changeSearchToUsers()
{
	document.getElementById('web').style.display='none';
 	document.getElementById('users').style.display='block';
	document.getElementById('video').style.display='none';
	document.getElementById('photos').style.display='none';
	document.getElementById('catalog').style.display='none';
	document.getElementById('SearchToWeb').style.background='none';
	document.getElementById('SearchToCatalog').style.background='none';
	document.getElementById('SearchToVideo').style.background='none';
	document.getElementById('SearchToPhotos').style.background='none';
	document.getElementById('SearchToUsers').style.background='#999999';

}

function changeSearchToVideo()
{
	document.getElementById('web').style.display='none';
	document.getElementById('users').style.display='none';
	document.getElementById('video').style.display='block';
	document.getElementById('photos').style.display='none';
	document.getElementById('catalog').style.display='none';
	document.getElementById('SearchToWeb').style.background='none';
	document.getElementById('SearchToCatalog').style.background='none';
	document.getElementById('SearchToVideo').style.background='#999999';
	document.getElementById('SearchToPhotos').style.background='none';
	document.getElementById('SearchToUsers').style.background='none';
}

function changeSearchToPhotos()
{
	document.getElementById('web').style.display='none';
	document.getElementById('users').style.display='none';
	document.getElementById('video').style.display='none';
	document.getElementById('photos').style.display='block';
	document.getElementById('catalog').style.display='none';
	document.getElementById('SearchToWeb').style.background='none';
	document.getElementById('SearchToCatalog').style.background='none';
	document.getElementById('SearchToVideo').style.background='none';
	document.getElementById('SearchToPhotos').style.background='#999999';
	document.getElementById('SearchToUsers').style.background='none';

}

function changeSearchToCatalog()
{
	document.getElementById('web').style.display='none';
	document.getElementById('users').style.display='none';
	document.getElementById('video').style.display='none';
	document.getElementById('photos').style.display='none';
	document.getElementById('catalog').style.display='block';
	document.getElementById('SearchToWeb').style.background='none';
	document.getElementById('SearchToCatalog').style.background='#999999';
	document.getElementById('SearchToVideo').style.background='none';
	document.getElementById('SearchToPhotos').style.background='none';
	document.getElementById('SearchToUsers').style.background='none';

}

function UploadNewVideo()
{
	document.videoform.style.visibility='visible';
	document.videoform.style.display='block';
	document.getElementById('showVideoUpload').style.display='none';
	document.getElementById('showVideoUpload').style.visibility='hidden';
	document.getElementById('hideVideoUpload').style.display='block';
	document.getElementById('hideVideoUpload').style.visibility='visible';
	clearVideoEditForm();
}

function HideUploadNewVideo()
{
	document.videoform.style.visibility='hidden';
	document.videoform.style.display='none';
	document.getElementById('hideVideoUpload').style.display='none';
	document.getElementById('hideVideoUpload').style.visibility='hidden';
	document.getElementById('showVideoUpload').style.display='block';
	document.getElementById('showVideoUpload').style.visibility='visible';
}

function ClearUploadNewVideo()
{
	document.videoform.reset();
}

function ShowUploadMP3()
{
	document.getElementById('mp3form').style.display='block';
	document.getElementById('mp3form').style.visibility='visible';
	document.getElementById('showform').style.display='none';
	document.getElementById('showform').style.visibility='hidden';
	document.getElementById('hideform').style.display='block';
	document.getElementById('hideform').style.visibility='visible';
}

function HideUploadMP3()
{
	document.getElementById('mp3form').style.display='none';
	document.getElementById('mp3form').style.visibility='hidden';
	document.getElementById('showform').style.display='block';
	document.getElementById('showform').style.visibility='visible';
	document.getElementById('hideform').style.display='none';
	document.getElementById('hideform').style.visibility='hidden';
}

function deleteSong( ID, Name )
{				
  if (confirm("Сигурни ли сте, че желаете да изтриете " + Name + "?" )) 
  {
	window.location = "postmp3.php?delete=" + ID;
  }
}