$(document).ready(function(){	
	$("#s input").hover(
		function () { if($(this).val() == 'Търсене') { $(this).val(''); this.focus(); }  }, 
		function () { if($(this).val() == '') $(this).val('Търсене'); }
	);

	$("#ps input").hover(
		function () { if($(this).val() == 'Търсене') { $(this).val(''); this.focus(); } }, 
		function () { if($(this).val() == '') $(this).val('Търсене'); }
	);

});

function BgChange(obj, color, type){
	var x = 0;
	for ( i = 0; i <= obj.childNodes.length; i++ ){
	
		if(obj.childNodes[i]){
		
			if(obj.childNodes[i].nodeName == 'TD')
				x++;
			if(type == 1)
				obj.childNodes[i].bgColor=color;
			else{
				obj.childNodes[i].bgColor='#ffffff';
				if(x <= 9)
					obj.childNodes[i].bgColor=color;
			}
		}
	}
}

function Switch(id,type){

	obj = document.getElementById('pg'+id);
	if(!obj) return;
	if((type == undefined && obj.style.display == 'block') || type==2){
		obj.style.display = 'none';
		setClass('arw'+id, '');
		eraseCookie('cat[' + id + ']');
	}
	else if(type == undefined || type == 1){
		createCookie('cat[' + id + ']',true,0);
		setClass('arw'+id, 'op');
		obj.style.display = 'block';
	}
}

function Expand(){

	for(i=0; i < window.pages.length; i++)
		Switch(pages[i],1)

}

function Collapse(){

	for(i=0; i < window.pages.length; i++)
		Switch(pages[i],2)

}

function setClass (elementName, className) {
	var theElement = document.getElementById(elementName);
	if(theElement)
		theElement.className = className;
}


var win= null;
function PopUpWindow(mypage,myname,w,h,scroll,resizeable){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable='+resizeable+',';
  win=window.open(mypage,myname,settings);
  if (win.opener == null) {  // for Nav 2.0x
      win.opener = self  // this creates and sets a new property
   }
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

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 var 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;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}