var user_agent = navigator.userAgent;
var isOpera = user_agent.indexOf("Opera") >= 0;
var isFirefox = user_agent.indexOf("Firefox") >= 0;
var isWin32up = user_agent.indexOf("Win32") >= 0 
	|| user_agent.indexOf("Win64") >= 0
	|| user_agent.indexOf("Windows NT") >= 0;

// disallow Opera faking IE
var isIE = !isOpera && user_agent.indexOf("MSIE") >= 0;
var isIE55up = isIE && isWin32up && user_agent.match(/MSIE ((5\.5)|[6789])/);
var isIE55dn = isIE && !isIE55up;
var browser = "other";

if (isFirefox)
	browser = "firefox";
else if (isOpera) 
	browser = "opera";
else if (isIE55up) 
	browser = "ie55p";
else if (isIE55dn) 
	browser = "ie55d";

function IEObject() {
	if (!isIE) return;
	
	// For IE "click to activate and use this control" problem.
	var theObjects = document.getElementsByTagName("OBJECT");
	for (var i = 0; i < theObjects.length; i++) {
		theObjects[i].outerHTML = theObjects[i].outerHTML;
	}
}

function FillSeries(lst,start,end){
	for (var i=start;i<=end;i++) {
		var op=document.createElement("OPTION");
		var i2=(i<10)?'0'+i:''+i;
		op.text=op.value=i2;
		lst.options.add(op);
	}
}

function FillDays(lst){
	FillSeries(lst,1,31);
}

function FillMonths(lst){
	FillSeries(lst,1,12);
}

function FillYears(lst,year1,year2) {
	for (var i=year1;i<=year2;i++) {
		var op=document.createElement("OPTION");
		op.value=op.text=i;
		lst.options.add(op);
	}
}

function setHomePage2(ths, url) {
	ths.style.behavior='url(#default#homepage)';
	ths.setHomePage(url);
}

function popup2(url, window_name, width, height) {
	var left = parseInt((screen.width - width) / 2);
	var top = parseInt((screen.height - height) / 2);
	
	var wnd = window.open(url, 
		window_name, 
		'status=1, toolbar=0, menubar=0, scrollbars=no, resizable=0, ' +
		'left=' + left + ', top=' + top + ', ' +
		'width=' + width + ', height=' + height);

	wnd.focus();
	return wnd;
}

function popup_sizeable(url, window_name, width, height) {
	var left = parseInt((screen.width - width) / 2);
	var top = parseInt((screen.height - height) / 2);
	
	var wnd = window.open(url, 
		window_name, 
		'status=1, toolbar=0, menubar=0, scrollbars=yes, resizable=1, ' +
		'left=' + left + ', top=' + top + ', ' +
		'width=' + width + ', height=' + height);

	wnd.focus();
	return wnd;
}

function popupComment(program_alias) {
	popup2('/yorum,' + program_alias + '.html', 'tv_yorum_' + program_alias, 485, 450);
}

function popupBasvuru(program_alias) {
	popup2('/yorum_basvur.php?program=' + program_alias, 'tv_yorum_basvur_' + program_alias, 485, 410);
}

function popupAkilliIsaretler() {
	popup2('/akilli_isaretler.html', 'akilli_isaretler', 220, 360);
}

function popupLive() {
	popup2('/live.html', 'tv_live', 480, 420);
}

function popupWallURL(program_alias, index) {
	return "/wall_popup," + program_alias + ".html?index=" + index;
}

function popupWall(program_alias, index) {
	var url = popupWallURL(program_alias, index);
	popup_sizeable(url, 'tv_wall_' + program_alias, 600, 480, 1);
}

function checkFormYorum() {
	var txt_ad_soyad = document.getElementById("ad_soyad"); 
	var txt_eposta = document.getElementById("eposta"); 
	var txt_gorusler = document.getElementById("gorusler"); 
	var errors = "";
	
	txt_ad_soyad.value = trim(txt_ad_soyad.value);
	txt_eposta.value = trim(txt_eposta.value);
	txt_gorusler.value = trim(txt_gorusler.value);
	
	if (txt_ad_soyad.value.length == 0)
		errors += "* Lütfen ad ve soyadınızı giriniz!\n";

	if (txt_eposta.value.length == 0)
		errors += "* Lütfen epostanızı giriniz!\n";
	else if (!CheckEmail(txt_eposta.value))
		errors += "* Lütfen geçerli bir eposta giriniz!\n";

	if (txt_gorusler.value.length == 0)
		errors += "* Lütfen görüşlerinizi giriniz!\n";

	if (errors != "") {
		alert("Kanal 1 - GÖRÜŞLERİNİZ\n" + errors);
		return false;
	} else {
		return true;
	}
}

function checkFormBasvur() {
	var txt_ad_soyad = document.getElementById("ad_soyad");
	var txt_eposta = document.getElementById("eposta");
	var txt_yas = document.getElementById("yas");
	var txt_telefon = document.getElementById("telefon");
	var txt_sehir = document.getElementById("sehir");
	var errors = "";
	
	txt_ad_soyad.value = trim(txt_ad_soyad.value);
	txt_eposta.value = trim(txt_eposta.value);
	txt_yas.value = trim(txt_yas.value);
	
	if (txt_ad_soyad.value.length == 0)
		errors += "* Lütfen ad ve soyadınızı giriniz!\n";

	if (txt_eposta.value.length == 0)
		errors += "* Lütfen epostanızı giriniz!\n";
	else if (!CheckEmail(txt_eposta.value))
		errors += "* Lütfen geçerli bir eposta giriniz!\n";

	if (txt_yas.value.length == 0)
		errors += "* Lütfen yaşınızı giriniz!\n";

	if (txt_telefon.value.length == 0)
		errors += "* Lütfen telefonunuzu giriniz!\n";

	if (txt_sehir.value.length == 0)
		errors += "* Lütfen şehrinizi giriniz!\n";

	if (errors != "") {
		alert("Kanal 1 - BAŞVUR\n" + errors);
		return false;
	} else {
		return true;
	}
}

// IE icin "anasayfam yap"
function linkHomePage(url) {
	if (isIE) {
		document.write("<a href=\"javascript:;\" onClick=\"setHomePage2(this, '" + url + "');\" class=\"atvgirissayfam\"><img src=\"/i/white_arrow.gif\" width=\"7\" height=\"9\" border=\"0\" alt=\"\">&nbsp;Giriş sayfam yap</a>");
	}
}

// bir resmin dört köşesi üstüne nokta koy
function imgBorderPoints(wid, hgt, colorNW, colorNE, colorSW, colorSE) {
	// eksik renkleri ilk renk ile değiştir
	if (colorNE == null) colorNE = colorNW;
	if (colorSW == null) colorSW = colorNW;
	if (colorSE == null) colorSE = colorNW;
	
	var img = "<img width=\"1\" height=\"1\" border=\"0\" alt=\"\" src=\"/i/1cpx.gif\">";
	
	document.write(
		'<div style="position: absolute; left: 0px; top: 0px; width: 1px; height: 1px; z-index: 100; background-color: ' + colorNW + '">' + img + '</div>' +
		'<div style="position: absolute; left: 0px; top: ' + (hgt - 1) + 'px; width: 1px; height: 1px; z-index: 100; background-color: ' + colorSW + '">' + img + '</div>' +
		'<div style="position: absolute; left: ' + (wid - 1) + 'px; top: 0px; width: 1px; height: 1px; z-index: 100; background-color: ' + colorNE + '">' + img + '</div>' +
		'<div style="position: absolute; left: ' + (wid - 1) + 'px; top: ' + (hgt - 1) + 'px; width: 1px; height: 1px; z-index: 100; background-color: ' + colorSE + '">' + img + '</div>'
	);
}

function navigateOpener(url) {
	if (window.opener)
		window.opener.document.location.href = url;
	else
		self.location.href = url;
}

function WriteSWF(width, height, movie, wmode) {
	if (wmode == null) wmode = "transparent";
	document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" WIDTH="' + width + '" HEIGHT="' + height + '"  style="position: absolute; left: 0px; top: 0px;">');
	document.write('<PARAM NAME=movie VALUE="' + movie + '">');
	document.write('<PARAM NAME=wmode VALUE="' + wmode + '">');
	document.write('<PARAM NAME="Quality" VALUE="High">');
	document.write('<EMBED src="' + movie + '" quality=high ');
	document.write(' WMODE="' + wmode + '" NAME="flashad" swLiveConnect="TRUE" WIDTH="' + width + '" HEIGHT="' + height + '"');
	document.write(' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" >');
	document.write('</EMBED>');
	document.write('</OBJECT>');
}

function writeLivePlayer(stream_url, width, height) {
	var playerObj = 
	"<object id=\"TVLivePlay\" width=\"" + width + "\" height=\"" + height + "\"" +
	"  classid=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\"" +
	"  codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701\"" +
	"  standby=\"Loading Microsoft Windows Media Player components...\"" +
	"  type=\"application/x-oleobject\">" +
	"          <param name=\"FileName\" value=\"" + stream_url + "\" />" +
	"          <param name=\"AutoStart\" value=\"1\" />" +
	"          <param name=\"AutoSize\" value=\"0\" />" +
	"          <param name=\"Volume\" value=\"-200\" />" +
	"          <param name=\"ShowControls\" value=\"1\" />" +
	"          <param name=\"ShowDisplay\" value=\"0\" />" +
	"          <param name=\"ShowStatusBar\" value=\"1\" />" +
	"          <param name=\"ShowGotoBar\" value=\"0\" />" +
	"          <param name=\"ShowTracker\" value=\"0\" />" +
	"          <param name=\"ShowPositionControls\" value=\"0\" />" +
	"          <param name=\"EnablePositionControls\" value=\"0\" />" +
	"          <param name=\"EnableContextMenu\" value=\"0\" />" +
	"          <embed type=\"application/x-mplayer2\" " +
	"  pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/download/default.asp\" " +
	"  src=\"" + stream_url + "\" " +
	"  filename=\"" + stream_url + "\" " +
	"  name=\"TVLivePlay\" " +
	"  AutoStart=\"1\"" +
	"  AutoSize=\"0\"" +
	"  Volume=\"-200\"" +
	"  ShowControls=\"1\"" +
	"  ShowDisplay=\"0\"" +
	"  ShowStatusBar=\"1\" " +
	"  ShowGotoBar=\"0\" " +
	"  ShowTracker=\"0\" " +
	"  ShowPositionControls=\"0\" " +
	"  EnablePositionControls=\"0\" " +
	"  EnableContextMenu=\"0\" " +
	"  width=\"" + width + "\" height=\"" + height + "\"></embed>" +
	"</object>";
	document.write(playerObj);
}

/** returns a browser specific alpha image layer.
* - imgPNG - PNG with alpha channel
* - imgGIF - failsafe transparent GIF image
* - imgSpacer - transparent spacer GIF image
*/
function alphaImgLayer(left, top, width, height, imgSpacer, imgPNG, imgGIF) {
	var divStyle = 'position: absolute; left: ' + left + 'px; top: ' + top + 'px; width: ' + width + 'px; height: ' + height + 'px;';
	var html;
	
	if (isIE55up) {
		// use directX filters
		html = '<div style="' + divStyle + ' filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + imgPNG + '\',sizingMethod=\'scale\');\">' +
			'<img src="' + imgSpacer + '" width="' + width + '" height="' + height + '" border="0" alt=""></div>';
	} else if (isOpera || isFirefox) {
		// use PNGs directly
		html = '<div style="' + divStyle + '"><img src="' + imgPNG + '" width="' + width + '" height="' + height + '" border="0" alt=""></div>';
	} else {
		// use failsafe GIF images
		html = '<div style="' + divStyle + '"><img src="' + imgGIF + '" width="' + width + '" height="' + height + '" border="0" alt=""></div>';
	}
	
	document.write(html);
}

function index_sw_round_border(nav_theme) {
	var imgSpacer = "/i/1cpx.gif";
	var imgdir = "/i/topimgs/";
	var imgdirFailsafe = imgdir + "nav_" + nav_theme + "/";

	alphaImgLayer(0, 265, 10, 10, imgSpacer,
		imgdir + 'kose_sw.png',
		imgdirFailsafe + 'kose_sw.gif');
}

function top_round_borders(nav_theme, bottomCorners) {
	var imgSpacer = "/i/1cpx.gif";
	var imgdir = "/i/topimgs/";
	var imgdirFailsafe = imgdir + "nav_" + nav_theme + "/";
	
	alphaImgLayer(0, 0, 10, 10, imgSpacer,
		imgdir + 'kose_nw.png',
		imgdirFailsafe + 'kose_nw.gif');
	alphaImgLayer(740, 0, 10, 10, imgSpacer,
		imgdir + 'kose_ne.png',
		imgdirFailsafe + 'kose_ne.gif');

	if (bottomCorners) {
		alphaImgLayer(0, 290, 10, 10, imgSpacer,
			imgdir + 'kose_sw.png',
			imgdirFailsafe + 'kose_sw.gif');
		alphaImgLayer(740, 290, 10, 10, imgSpacer,
			imgdir + 'kose_se.png',
			imgdirFailsafe + 'kose_se.gif');
	}
}
