// JavaScript Document
// <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
var lang = (lang==undefined) ? 'bg' : lang;

function PopupPic(sPicURL) { 
     window.open( "/bg/popup.html?"+sPicURL, "",  
     "resizable=1,HEIGHT=200,WIDTH=200, left=3, top=5"); 
   }

isNS = (navigator.appName == 'Netscape');
isIE = (navigator.appName.indexOf('Microsoft') != -1);
isOP = (navigator.appName == 'Opera');
ns4 = (document.layers);
ie4 = (document.all && !document.getElementById);
ie5 = (document.all && document.getElementById);
ns6 = (!document.all && document.getElementById);
useSWF = true;

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 swap_img(img_src, img_txt) {
  var obj = document.getElementById('snimka');
  var obj2 = document.getElementById('img_tеxt');
	obj.src = img_src;
	obj2.innerHTML = img_txt; 
}

function crawler() {
	if (window.name!='sredna' && !((self.innerHeight == 0) && (self.innerWidth == 0))) top.location.replace('/');
}

function calcHeight_admin(koi) {
	var the_height=document.body.scrollHeight;
	var obj = parent.document.getElementById(koi);
	obj.style.height = (!isNS && !isOP) ? the_height : the_height+'px';
}

function calcHeight(koi) {
	crawler();
	var the_height=document.body.scrollHeight;
	var obj = parent.document.getElementById(koi);
	obj.style.height = (!isNS && !isOP) ? the_height : the_height+'px';
}

function sh_div(what) {
	 var i=0;
	 var coll = [];
	 while (document.getElementById('d'+ i)) {
	  coll[i] = document.getElementById('d'+ i);
		i++;
	 }
 obj = document.getElementById(what);
 var i=0;
 if (obj.className == 'off') {
	 while (coll[i]) {
		coll[i].className = 'off';
		i++;
		} 
	obj.className = 'on';
 } else {
	obj.className = 'off';
 }
}

// swf container
var menu = '<object style="position: absolute; left: -5px; top: 0px; z-index: 16000" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="310" height="280" align="left">'
				+ '<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="swf/menu_v1.swf?language='+lang+'"><param name="menu" value="false"><param name="quality" value="high"><param name="bgcolor" value="#D8D8CD"><param name="FlashVars" value="language='+lang+'"><param name="wmode" value="transparent">'
				+ '<embed style="position: absolute; left: -5px; top: 0px; z-index: 16001" src="swf/menu_v1.swf?language='+lang+'" width="310" height="280" align="left" menu="false" wmode="transparent" quality="high" bgcolor="#D8D8CD" swLiveConnect=true id="vmenu" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="language='+lang+'"></object>';

var menu0 =  	'<div style="position: relative; width:100%">'
				+ '<div style="position: absolute; z-index: 1; width: 350px" id="swfm">'

				+ '<object style="position: absolute; left: 0px; top: 0px;" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="350" height="280" align="left">'
				+ '<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="/swf/menu_v1.swf?language='+lang+'"><param name="menu" value="false"><param name="quality" value="high"><param name="FlashVars" value="language='+lang+'"><param name="wmode" value="transparent">'
				+ '<embed style="position: absolute; left: 0px; top: 0px; width: 350px" src="/swf/menu_v1.swf?language='+lang+'" width="350" height="280" align="left" menu="false" wmode="transparent" quality="high" id="vmenu" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="language='+lang+'"></object>'

				+ '	</div></div>';

function content(ID, what) { // layer id and content
  if ((ie5 || ns6) && !isOP) document.getElementById(ID).innerHTML = what;  
} 

function content2(what) { // layer id and content
  document.write(what); 
} 

function initMenu() {} // remove if xml based

function initMainBody() {
	// TODO: proverka za flash
	// initMenu();
	// (top.location.pathname == '/index.php') ? initMenu() : content('vmenu', menu);
	
		var vvMenu = document.getElementById("vmenu");
		vvMenu.style.display = 'none';
		content('swfmenu', menu0);
}

// --- Window functions -------------------------
function openWindow(url, name) {
  popupWin = window.open(url, name, 'scrollbars=yes,resizable=yes,status=no,personal=no,menu=no,location=no,toolbar=no,left=20,top=20,width=770,height=500')
}

//example: openSizedWindow('http://www.mysite.com','myName','400','500');
function openSizedWindow(url, name, myHeight, myWidth) {
 popupWin = window.open(url, name, 'scrollbars=yes,resizable=yes,status=yes,personal=no,menu=no,location=no,toolbar=no,left=20,top=20,width=' +myWidth+',height='+myHeight+'');
}

function openSizedWindowPlain(url, name, myHeight, myWidth) {
 popupWin = window.open(url, name, 'scrollbars=no,resizable=no,status=no,personal=no,menu=no,location=no,toolbar=no,left=20,top=20,width=' +myWidth+',height='+myHeight+'');
}

function openSizedWindowUI(url, name, myHeight, myWidth) {
 popupWin = window.open(url, name, 'scrollbars=yes,resizable=yes,status=yes,personal=no,menubar=yes,location=yes,toolbar=yes,left=20,top=20,width=' +myWidth+',height='+myHeight+'');
}
// ----------------------------------------------

// --- Flash functions -------------------------

function nextVal_swf(max) {
	var date = new Date();
	var currMin = date.getMinutes();
	var nVal = currMin % max;
	if (isNaN(nVal)) { nVal = 0; }
	if (nVal < 0) { nVal = 0; }
	else if (nVal >= max) { nVal = (max - 1); }
	return nVal;
}

var swf_list;
var url_list;
var img_list;

function activateBanner(plugin) {
    if ( plugin ) {
		var swf_index;
		var random_swf;
		var random_swf_param = '';
		var random_swf_embed = '';
		var random_swf_url = '';
		swf_index = nextVal_swf(swf_list.length);
		random_swf = swf_list[swf_index];
		random_swf_url = url_list[swf_index];
		random_swf_param += '<param name="flashvars" value="learnURL=' + random_swf_url + '" />';
		random_swf_embed = '<embed src="' + random_swf + '" quality="high" width="800" height="166" name="merc_bd" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" menu="false" flashvars="learnURL=' + random_swf_url + '"/>';
		document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="800" height="166" id="merc_bd" align="middle">');
		document.write('<param name="allowScriptAccess" value="sameDomain" />');
		document.write('<param name="movie" value="' + random_swf + '" /><param name="quality" value="high" /><param name="menu" value="false" />');
		document.write(random_swf_param);
		document.write(random_swf_embed);
		document.write('</object>');
    } else {
		var img_index = nextVal_swf(img_list.length);
	    var random_img = img_list[img_index];
	    document.write(random_img);
    }
}


function activateFlash(swf_url, width, height, flashVars) {
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="video_player" align="middle">');
	document.write('<param name="movie" value="' + swf_url + '" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="flashVars" value="' + flashVars + '"/>');
	document.write('<embed src="' + swf_url + '" wmode="transparent" quality="high" width="'+width+'" height="'+height+'" name="video_player" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="' + flashVars + '"/>');
	document.write('</object>');
}

function activateVideoPlayer(swf_url, xml_url) {
	document.write('<div style="position:relative;height:250px;">');
	document.write('<div style="overflow: hidden; position: absolute; z-index: 1; width: 195px; height: 258px; left: 0px; top: 0px;" id="flashVideoPlayer">');
	document.write('<object style="position: absolute; left: -375px; top: -100px;" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="575" height="450" id="video_player" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="wmode" value="transparent"/>');
	document.write('<param name="movie" value="' + swf_url + '" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="flashVars" value="presentationData=' + xml_url + '"/>');
	document.write('<embed style="position: absolute; left: 0px; top: 0px;" src="' + swf_url + '" wmode="transparent" quality="high" width="575" height="450" name="video_player" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="presentationData=' + xml_url + '"/>');
	document.write('</object>');
	document.write('</div>');
	document.write('</div>');
}

   // ## -Start compensation for FF click through bug- ##
   //note the checks for IE. sinze the positioning is done differently in FF
   var fullVideo = false;
   var isIE = navigator.userAgent.toLowerCase().indexOf("msie") > 0;
   /**
    * sizeFlashDivForVideo waits a second and then calls size
    * parameters - none
    */
   function sizeFlashDivForVideo()
   {
      setTimeout("doSizeFlashDivForVideo()", 450);
   }
   
   function doSizeFlashDivForVideo()
   {
      document.getElementById("flashVideoPlayer").style.width = 575 + 'px';
      document.getElementById("flashVideoPlayer").style.height = 450 + 'px';
      document.getElementById("flashVideoPlayer").style.top = -100 + 'px';
      document.getElementById("flashVideoPlayer").style.left = -380 + 'px';
      document.getElementById("video_player").style.top = 0 + 'px';
      document.getElementById("video_player").style.left = 0 + 'px';
   }
   /**
    * sizeFlashDivForPreview waits a second and then calls size
    * parameters - none
    */
   function sizeFlashDivForPreview()
   {
      setTimeout( "doSizeFlashDivForPreview()", 1050);
   }
   /**
    * doSizeFlashDivForPreview collapses the video div's size and position to it's original state
    * parameters - none
    */
   function doSizeFlashDivForPreview()
   {
      document.getElementById("flashVideoPlayer").style.width = 195 + 'px';
      document.getElementById("flashVideoPlayer").style.height = 258 + 'px';
      document.getElementById("flashVideoPlayer").style.top = 0 + 'px';
      document.getElementById("flashVideoPlayer").style.left = 0 + 'px';
      document.getElementById("video_player").style.left = -375 + 'px';
      document.getElementById("video_player").style.top = -100 + 'px';
   }
   /**
    * toggleFlashVideo will toggle between open and closed - currently not used
    * parameters - none
    */
   function toggleFlashVideo()
   {
      if( !fullVideo )
      {
         sizeFlashDivForVideo();
         fullVideo = true;
      }
      else
      {
         sizeFlashDivForPreview();
         fullVideo = false;
      }
   }
   // ## -End compensation for FF click through bug- ## -bsh 4.20.2006


function send_mail_() {
var name = document.send_mail.name.value;
var email = document.send_mail.email.value;
var comment = document.send_mail.comment.value;
var ran = document.send_mail.ran.value;

var emailRegxp = /^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/;


	if( (name=="") || (comment=="") || (ran=="")) {
		alert("Не сте попълнили всички полета!");	
	} else	 if ((emailRegxp.test(email) != true) || (email == "")) {
		 alert("Въвели сте невалиден e-mail адрес!");			
	} else {
		document.send_mail.submit();
	}
}
