var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror')) {
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('firefox')) browser = "Firefox"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible')) {
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS) {
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function checkIt(string){
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

// flash detector
var OsIsFlashSupported;
if ( OS == 'Windows' ) {
	OsIsFlashSupported = true;
} else {
	OsIsFlashSupported = false;
}

var requiredMajorVersion = 6;
var requiredMinorVersion = 0;
var requiredRevision = 0;
var jsVersion = 1.0;

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
jsVersion = 1.1;

function JSGetSwfVer(i){
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else {
		flashVer = -1;
	}
	return flashVer;
} 

function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) {
 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
	for (i=25;i>0;i--) {	
		if (isIE && isWin && !isOpera) {
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);		
		}
		if (versionStr == -1 ) { 
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray         = versionStr.split(" ");
				tempString        = tempArray[1];
				versionArray      = tempString .split(",");				
			} else {
				versionArray      = versionStr.split(".");
			}
			versionMajor      = versionArray[0];
			versionMinor      = versionArray[1];
			versionRevision   = versionArray[2];
			
			versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum        = parseFloat(versionString);
			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );	
			}
		}
	}	
	return (reqVer ? false : 0.0);
}

/////////////////////////////////////

function flashnominations(part1id,part2id,part1num,part2num) {
	var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	if ((hasRightVersion) && (OsIsFlashSupported)) {
		var oeTags = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="165" height="380" id="nominations_2part" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="http://vipimages.bigbrother.bg/flash/nominations_2part.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" /><param name="flashVars" value="part1='+part1id+'&part2='+part2id+'&num1='+part1num+'&num2='+part2num+'" /><embed src="http://vipimages.bigbrother.bg/flash/nominations_2part.swf" quality="high" wmode="transparent" bgcolor="#ffffff" width="165" height="380" name="nominations_2part" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashVars="part1='+part1id+'&part2='+part2id+'&num1='+part1num+'&num2='+part2num+'" /></object>';
		document.write(oeTags);
	} else {  
//		var alternateContent = '<img src="http://vipimages.bigbrother.bg/img/noFlashLogo.jpg"><div id="dayCounter">'+dayCounter+'</div>';
//		document.write(alternateContent); 
		document.getElementById('pollCont').className = 'noNom';
	}
}



function flashWriteLogo(dayCounter,isIndex) {
	var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	if ((hasRightVersion) && (OsIsFlashSupported)) {
		var oeTags = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="293" height="401" id="logoFlash"><param name="allowScriptAccess" value="always" /><param name="movie" value="http://vipimages.bigbrother.bg/flash/logotop.swf" /><param name="wmode" value="transparent" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="flashVars" value="day='+dayCounter+'&isIndex='+isIndex+'" /><embed src="http://vipimages.bigbrother.bg/flash/logotop.swf" quality="high" bgcolor="#ffffff" width="293" height="401" name="logotop" align="middle" menu="false" wmode="transparent" allowScriptAccess="always" type="application/x-shockwave-flash" flashVars="day='+dayCounter+'&isIndex='+isIndex+'" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
		document.write(oeTags);
	} else {  
		var alternateContent = '<img src="http://vipimages.bigbrother.bg/img/noFlashLogo.jpg"><div id="dayCounter">'+dayCounter+'</div>';
		document.write(alternateContent); 
	}
}

function flashWriteParticipants(isIndex) {
	var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	if ((hasRightVersion) && (OsIsFlashSupported)) {
		var oeTags = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="495" height="171" id="participantsFlash"><param name="allowScriptAccess" value="always" /><param name="menu" value="false" /><param name="movie" value="http://vipimages.bigbrother.bg/flash/participants.swf" /><param name="loop" value="false" /><param name="menu" value="true" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" /><param name="flashVars" value="isIndex='+isIndex+'" /><embed src="http://vipimages.bigbrother.bg/flash/participants.swf" loop="false" menu="true" quality="high" wmode="transparent" bgcolor="#ffffff" width="495" height="171" name="participants" align="middle" menu="false" allowScriptAccess="always" flashVars="isIndex='+isIndex+'"  type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
		document.write(oeTags);
	} else {  
		var alternateContent = '<img src="http://vipimages.bigbrother.bg/img/noFlashParticipants.jpg" border="0" usemap="#MapPartic" /><map name="MapPartic" id="MapPartic"><area shape="poly" coords="31,167,16,135,17,128,40,107,47,106,44,94,49,89,58,81,69,87,71,100,60,111,63,114,68,127,76,142,76,168" href="player_profile.pcgi?player_id=1" title="Весела" /><area shape="poly" coords="78,167,77,139,64,114,73,105,73,96,84,81,93,82,96,93,93,102,97,113,94,138,96,147,102,154,101,167" href="player_profile.pcgi?player_id=2" title="Виолета" /><area shape="poly" coords="99,114,96,137,96,144,103,151,104,168,130,167,132,160,139,153,139,148,133,141,137,118,129,110,127,87,121,81,108,85,107,105" href="player_profile.pcgi?player_id=3" title="Галя \'КариZма\'" /><area shape="poly" coords="139,118,134,139,137,145,142,149,138,156,134,164,172,167,175,150,168,142,165,137,166,115,167,111,170,107,171,93,161,80,151,79,143,94,144,103" href="player_profile.pcgi?player_id=4" title="Галя Литова" /><area shape="poly" coords="189,75,200,82,197,98,210,107,201,113,196,124,196,144,203,159,203,168,175,167,177,149,168,137,168,112,173,106,181,100,180,86,183,79" href="player_profile.pcgi?player_id=5" title="Денди" /><area shape="poly" coords="213,106,207,111,200,120,198,130,196,143,202,153,206,158,206,167,235,168,235,159,224,140,229,112,231,107,228,102,233,90,229,79,218,77,211,85,210,93" href="player_profile.pcgi?player_id=6" title="Дим Дуков" /><area shape="poly" coords="237,167,237,156,226,140,231,112,237,102,243,96,245,93,242,86,242,76,249,71,254,71,261,76,263,83,263,93,275,99,268,109,263,125,263,132,266,138,276,135,279,139,276,152,272,168" href="player_profile.pcgi?player_id=7" title="Дичо" /><area shape="poly" coords="276,100,271,111,265,126,266,134,275,134,280,136,280,148,275,166,315,168,314,149,313,140,320,133,310,133,307,126,304,113,310,108,317,98,313,94,301,89,302,81,298,71,287,68,281,81,284,91" href="player_profile.pcgi?player_id=8" title="Киро" /><area shape="poly" coords="317,167,317,154,319,138,322,131,311,130,307,114,319,100,323,97,318,90,317,77,319,71,327,69,336,76,337,90,344,98,348,102,336,122,332,136,336,148,341,156,346,162,348,168" href="player_profile.pcgi?player_id=9" title="Константин" /><area shape="poly" coords="350,168,348,156,334,137,340,122,352,104,349,85,355,75,363,73,372,83,373,99,380,100,373,140,370,166" href="player_profile.pcgi?player_id=10" title="ЛиЛана" /><area shape="poly" coords="399,75,396,85,400,92,383,101,375,138,372,163,379,167,430,168,427,138,430,116,437,102,432,94,416,91,417,78,412,70,404,67" href="player_profile.pcgi?player_id=11" title="Митьо Пищова" /><area shape="poly" coords="432,168" href="#" /><area shape="poly" coords="431,168,432,117,439,104,435,90,435,83,447,75,458,77,462,88,467,107,471,130,466,151,460,162,459,167" href="player_profile.pcgi?player_id=12" title="Райна" /></map>';
		document.write(alternateContent); 
	}
}

function flashWriteMenu(section) {
	var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	if ((hasRightVersion) && (OsIsFlashSupported)) {
		var oeTags = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="671" height="107" id="menuFlash"><param name="allowScriptAccess" value="always" /><param name="movie" value="http://vipimages.bigbrother.bg/flash/menu.swf" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" /><param name="flashVars" value="curSection='+section+'" /><embed src="http://vipimages.bigbrother.bg/flash/menu.swf" loop="false" menu="false" quality="high" wmode="transparent" bgcolor="#ffffff" width="671" height="107" name="menu" align="middle" allowScriptAccess="always" flashVars="curSection='+section+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
		document.write(oeTags);
	} else {  
		var alternateContent = '<div id="menuNoFlashCont">'
		if (OsIsFlashSupported) {
			alternateContent += '<div class="menuNote">За пълните възможности на сайта е нужен Flash версия 6 или по-нов от <a href="http://www.macromedia.com/go/getflashplayer" target="_blank">тук</a>.</div>';
		} else {
			alternateContent += '<div class="menuNote">&nbsp;</div>';
		}
		alternateContent += '<div><img src="http://vipimages.bigbrother.bg/img/menu'+section+'.gif" border="0" usemap="#MapMenu" /><map name="MapMenu" id="MapMenu"><area shape="rect" coords="0,0,86,39" href="index.pcgi" /><area shape="rect" coords="86,0,167,39" href="news_archiv.pcgi" /><area shape="rect" coords="167,0,257,39" href="gallery.pcgi" /><area shape="rect" coords="257,0,367,39" href="participants.pcgi" /><area shape="rect" coords="367,0,459,39" href="live.pcgi" /><area shape="rect" coords="459,0,565,39" href="chatforum.pcgi" /><area shape="rect" coords="565,0,654,39" href="gsm.pcgi" /></map></div></div>';
		document.write(alternateContent); 
	}
}

function flashWritePromos(isIndex) {
	var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	if ((hasRightVersion) && (OsIsFlashSupported)) {
		var oeTags = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="671" height="103" id="promosFlash" ><param name="allowScriptAccess" value="always" /><param name="movie" value="http://vipimages.bigbrother.bg/flash/promos.swf" /><param name="menu" value="false" /><param name="loop" value="false" /><param name="quality" value="high" /><param name="flashVars" value="isIndex='+isIndex+'" /><param name="bgcolor" value="#ffffff" /><embed src="http://vipimages.bigbrother.bg/flash/promos.swf" flashVars="isIndex='+isIndex+'" loop="false" quality="high" bgcolor="#ffffff" width="671" height="103" name="promos" menu="false" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
		document.write(oeTags);
	} else {  
		var alternateContent = '<div><img src="http://vipimages.bigbrother.bg/img/noFlashPromos.jpg" border="0" usemap="#MapPromos" /><map name="MapPromos" id="MapPromos"><area shape="rect" coords="0,0,229,103" href="live.pcgi" /><area shape="rect" coords="229,0,371,103" href="gsm.pcgi" /><area shape="rect" coords="371,0,521,103" href="chatforum.pcgi" /><area shape="rect" coords="521,0,670,103" href="vodeshti.pcgi" /></map></div>';
		document.write(alternateContent); 
	}
}


function imageOver(param) {
	document.getElementById("image"+param).className="imgOver";
}

function imageOut(param) {
	document.getElementById("image"+param).className="imgOut";
}

function openBrWindow(theURL) {
	
	window.open(theURL,'poplive','status=no,width=564,height=560');
}

function openVidDemo(type) {
	window.open('pop-demo.pcgi?type='+type,'vidPlayer','scrollbars=no,resizable=yes,width=580,height=490');
}

var old_class;
var old_id; 
function make_it_active(ID) {

	old_class = document.getElementById(ID).className ;
	document.getElementById(ID).className=old_class+' activeVidPack';
	if ( old_id > 0 ) {
		
		document.getElementById(old_id).className=old_class;
	}
	old_id = ID ;
}

function checkRegisterEntries() {
	
	if (document.forms["registerForm"].rusername.value == "" || document.forms["registerForm"].rpassword.value == "" || document.forms["registerForm"].rpassword2.value == "" || document.forms["registerForm"].remail.value == "") return false;
	if (!document.getElementById("genderM").checked && ! document.getElementById("genderF").checked) return false;
	if (document.forms["registerForm"].rage.value == "0" || document.forms["registerForm"].rcity.value == "0") return false;
	if (!document.getElementById("inetModem").checked && !document.getElementById("inetModem").checked && !document.getElementById("inetModem").checked && !document.getElementById("inetModem").checked && !document.getElementById("inetAdsl").checked && !document.getElementById("inetIsdn").checked && !document.getElementById("inetLan").checked && !document.getElementById("inetOther").checked) return false;
	if (!document.getElementById("statusPupil").checked && !document.getElementById("statusStudent").checked && !document.getElementById("statusEmployed").checked && !document.getElementById("statusUnemployed").checked && !document.getElementById("statusRetired").checked) return false;
	return true;
}

function registerValidate() {
	if (checkRegisterEntries()) {
		
		document.getElementById('jsValidatorDiv').style.display = "none";
		return true;
	} else {
		
		document.getElementById('jsValidatorDiv').style.display = "block";
		document.getElementById('jsValidatorDiv').innerHTML="<h1>Моля въведете всички задължителни полета!</h1>";
		return false;
	}
}

function validateLivePacksForm() {
	if (document.getElementById("vidPack56k7").checked || document.getElementById("vidPack56k30").checked || document.getElementById("vidPack128k7").checked || document.getElementById("vidPack128k30").checked || document.getElementById("vidPack256k7").checked || document.getElementById("vidPack256k30").checked) return true;
	return false;
}


function validateLiveLoginForm() {
	if (document.getElementById("loginNameL").value == "" || document.getElementById("loginPassL").value == "") return false;
	if (!liveWatchNow) return validateLivePacksForm();
	return true;
}
