//start js clock
function startTime()
{
	function checkTime(i)
	{
	if (i<10) 
	  {i="0" + i}
	  return i
	}
var today=new Date()
var h=today.getHours()
var m=today.getMinutes()
var s=today.getSeconds()
// add a zero in front of numbers<10
m=checkTime(m)
s=checkTime(s)
document.getElementById('txt').innerHTML=h+":"+m+":"+s
t=setTimeout('startTime()',500)
}

//returns the element ID
function getElement(id) { 

	return document.getElementById ? document.getElementById(id) : 
						document.all ? document.all(id) : null; 
} 

function show_element(id)
{
	obj = getElement(id);
	obj.style.display = 'none';
}

function hide_element(id)
{
	obj = getElement(id);
	obj.style.display = '';
}

//show / hide element by ID
function show_hide(id) {

	var obj = getElement(id)
	if (obj.style.display == 'none') {
		obj.style.display = '';
	}
	else {
		obj.style.display = 'none';
	}
}

function credits(ref)
{
	cl = document.getElementById('credits');
	cl.innerHTML = "design by: <a href='http://www.pmd-studio.com/?ref="+ref+"' title='web design & programming' rel='folow' target='_blank'><b>pmd</b>studio</a>";
	cl.style.display = "";
}

//redirect the URL
function redirect(url)
{
	if(url!="") document.location = url;
}


//clear  text field
function clear_text(form) 
				{
				 if ((form.Search.value == 'search') || (form.Search.value == 'търси в сайта') || (form.Search.value == 'търси') || (form.Search.value == 'search the site') || form.Search.value =='търсене' ) {form.Search.value = "";}
				}
//set  text field if empty
function set_text(form, text) 
				{
				 if  (form.Search.value == "") { form.Search.value = text;}
				}
				
//submit a search form	
function do_search(form) 
				{
				if (form.Search.value != "") {form_submit(form);}
				//form_submit(form);
				}

//form submit	
function form_submit(form) 
				{
				 form.submit();
				}



//open image with image Title in new window
function popImage(imageURL,imageTitle)
{
	PositionX = 100;
	PositionY = 100;
	
	defaultWidth  = 500;
	defaultHeight = 500;
	
	var AutoClose = true;
	
	if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
	
	var imageURL = imageURL;
	imageURL = imageURL.replace(' ','%20');
	
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}

	with (imgWin.document)
	{
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
		writeln('width=100-(document.body.clientWidth-document.images[0].width);');
		writeln('height=100-(document.body.clientHeight-document.images[0].height);');
		writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
		writeln('window.innerWidth=document.images["bigPicture"].width;');writeln('window.innerHeight=document.images["bigPicture"].height;}}');
		writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
		if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
		else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
		writeln('<img name="bigPicture" src='+imageURL+' style="display:block"></body></html>');
		close();		
	}
}

//preload page images
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

//form validate

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('Моля въведете всички задължителни полета!:\n'+errors);
  document.MM_returnValue = (errors == '');
}


//open public access image 
function pub_img_view(imageURL)
{
	PositionX = 100;
	PositionY = 100;
	
	defaultWidth  = 500;
	defaultHeight = 500;
	
	var AutoClose = true;
	imageTitle = "";
	if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
	
	var imageURL = imageURL;
	imageURL = imageURL.replace(' ','%20');
	
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}

	with (imgWin.document)
	{
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
		writeln('width=100-(document.body.clientWidth-document.images[0].width);');
		writeln('height=100-(document.body.clientHeight-document.images[0].height);');
		writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
		writeln('window.innerWidth=document.images["bigPicture"].width;');writeln('window.innerHeight=document.images["bigPicture"].height;}}');
		writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
		if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
		else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
		writeln('<img name="bigPicture" src=web/pub/'+imageURL+' style="display:block"></body></html>');
		close();		
	}
}

//navigation bar rolover function
function navbar_rollover()
{
  if(!document.getElementById || !document.createTextNode){return;}
  var n=document.getElementById('navbar');
  if(!n){return;}
  var lis=n.getElementsByTagName('li');
  for (var i=0;i<lis.length;i++)
  {
  
    lis[i].onmouseover=function()
    {
      this.className=this.className?'cur':'over'; 	
    }
    lis[i].onmouseout=function()
    {
       this.className=this.className=='cur'?'cur':'';
	   if(i==1)
	   		this.className=this.className?'cur1':'';
	  }
  }
}
window.onload=navbar_rollover;


function popupContent(content)
{
	PositionX = 100;
	PositionY = 100;
	
	defaultWidth  = 500;
	defaultHeight = 500;
	
	var AutoClose = true;
	
	if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
	var optNN='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	var optIE='scrollbars=yes,width=350,height=500,left='+PositionX+',top='+PositionY;
	

	if (isNN){Win=window.open('about:blank','',optNN);}
	if (isIE){Win=window.open('about:blank','',optIE);}

	with (Win.document)
	{
		write(content);
		close();		
	}
}


function popup_window(url,w,h)
{
	var width=w;
	var height=h;
	var from_top=350;
	var from_left=500;
	var toolbar='no';
	var location='no';
	var directories='no';
	var status='no';
	var menubar='no';
	var scrollbars='yes';
	var resizable='yes';
	var atts='width='+width+'show,height='+height+',top='+from_top+',screenY=';
	atts+= from_top+',left='+from_left+',screenX='+from_left+',toolbar='+toolbar;
	atts+=',location='+location+',directories='+directories+',status='+status;
	atts+=',menubar='+menubar+',scrollbars='+scrollbars+',resizable='+resizable;
	window.open(url,'win_name',atts);
}

function swap_image(object, src)
{
	obj = document.getElementById(object)
	obj.src = src;
}

function change_class(object, class_name)
{
	var	x = document.getElementById(object)
	x.className = class_name
}


//anti-bot secure check

var areal = Math.random() + "";
var real = areal.substring(2,6);

function check_values() {
	var valid_antibot = document.getElementById("valid_antibot").value;
	if(real !== valid_antibot) {
		alert("Ant-Bot check failed.....\nPlease enter the 4 digits as they appear.");
		return false;
	}
}

function isUndefined(a) {
   return typeof a == 'undefined';
}

function trim(a) {
	return a.replace(/^s*(S*(s+S+)*)s*$/, "$1");
}

function botCheckInfo() {
	alert("To prevent automatic programs (bots)\n from submitting spam through this form,\n we have added a simple validationncheck to the form. You must enter nthese 4 digits in the box provided innorder to submit the form.");
}
//end anti-bot


function duplicateRow(tableID, dplRow)
{
   if(dplRow === undefined)
   		dplRow = 0;
   else
   		dplRow = parseInt(dplRow);
   
   table = document.getElementById(tableID);
   var newRow = table.tBodies[0].rows[dplRow].cloneNode(true);
   table.tBodies[0].appendChild(newRow);
}

function deleteRow(tableID, minRows)
{
	if(parseInt(minRows) <= 0) minRows = 1;
	var table = document.getElementById(tableID);
	if (table.rows.length > minRows) table.deleteRow(table.rows.length - 1);
}


//set screen resolution cookie
function screen_resolution() 
{
 var today = new Date();
 var the_cookie = "users_resolution_width="+ screen.width;
 document.cookie=the_cookie;
}

screen_resolution() ;

//swap element style
function swap_style(style, element)
{

  var n=document.getElementById(element);
  n.className= style;
}


//increase / decrease font
var min=8;
var max=18;
function increaseFontSize(){
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 10;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}
function decreaseFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 10;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
}


//print preview
function printPreview()
{
var OLECMDID = 7;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 1 - open window
* 4 - Save As
*/
var PROMPT = 1; // 2 DONTPROMPTUSER 
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser); 
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = "";
}