﻿function ShowCalendar(returnObjectId, inValue, path)
{
	var myValue = window.showModalDialog(path + '/Cal.aspx?start='+inValue, myValue, 'center:yes;resizable:no;dialogHeight:230px;dialogWidth:210px;status:No;help:no;');
	
	if(myValue != null && myValue != 'undefined')
		document.getElementById(returnObjectId).value = myValue;
}

function ShowVideoPlayer(url)
{
	window.open (url, "TVRvideoWindow","location=0,status=1,scrollbars=0, width=700,height=460");
	return false;
}

function Show(elm)
{
	document.getElementById(elm).style.display = '';
	document.getElementById(elm).style.visibility = 'visible';
}
function Hide(elm)
{
	document.getElementById(elm).style.display = 'none';
	document.getElementById(elm).style.visibility = 'hidden';
}

function SetClass(elm, className)
{
	document.getElementById(elm).className = className;
}

function ChangeImage(photoId, photoSource)
{
	document.getElementById(photoId).src = photoSource;
}

/*RECHERCHE*/
function ClickTextBox(tbObj, originalText)
{
	if(tbObj.value == originalText)
		tbObj.value = '';
}
function BlurTextBox(tbObj, originalText)
{
	if(tbObj.value == '')
		tbObj.value = originalText;
}
/*--------------------------------*/

/*GESTION DES FAVORIS*/
function AddPro(firstObj, lastObj)
{
	var firstName = document.getElementById(firstObj).value;
	var lastName = document.getElementById(lastObj).value;
	
	if(firstName != '' || lastName != '')
		document.location = 'Professionals.aspx?firstName=' + firstName + '&lastName=' + lastName;

	return false;
}

function AddGroup(tbObj)
{
	var group = document.getElementById(tbObj).value;
	
	if(group != '')
		document.location = 'Account.aspx?addGroup=' + group;

	return false;
}

function AddChannel(chObj, grObj)
{
	var chann = document.getElementById(chObj).options[document.getElementById(chObj).selectedIndex].value;
	var group = document.getElementById(grObj).options[document.getElementById(grObj).selectedIndex].value;
	
	document.location = 'Account.aspx?addChannel=' + chann + '&toGroup=' + group;
}
/*-------------------*/

function RefreshMosaic(elm, chid)
{
	document.getElementById(elm).src = '/Mosaic/' + chid + '.aspx?' + Math.random();
	setTimeout('RefreshMosaic(\''+elm+'\', '+chid+')', 2000);
}
var xmlR = false;
var elmId = false;
function RefreshMosaicV2(elm)
{
	//document.getElementById(elm).src = '/Mosaic/' + chid + '.aspx?' + Math.random();
	//setTimeout('RefreshMosaicV2(\''+elm+'\', '+chid+')', 2000);
	elmId = elm;
	
	xmlR = MakeXmlObject();
	xmlR.onreadystatechange = CheckMosaic;
	xmlR.open('GET', 'Extras/MosaicXml.aspx', true);
	xmlR.send(null);
	
	setTimeout('RefreshMosaicV2(\''+elm+'\')', 2000);
}

function CheckMosaic()
{
	// only if req shows "loaded"
	if (xmlR.readyState == 4) {
		// only if "OK"
		if (xmlR.status == 200) {
			//alert(xmlR.responseXML.xml);
			
			for(var n=0; n<xmlR.responseXML.childNodes[1].childNodes.length; n++)
			{
				var index = n*2+1;
				var theId = index.toString();
				if(theId.length == 1)
					theId = '0' + theId;
				
				document.getElementById(elmId + '_ctl'+theId+'_imgMos').src = 'http://www.tvregions.com/Mosaic/'+xmlR.responseXML.childNodes[1].childNodes[n].getAttribute("id")+'.aspx?' + Math.random();
				document.getElementById(elmId + '_ctl'+theId+'_lblTitle').innerText = xmlR.responseXML.childNodes[1].childNodes[n].text;
				
				var duration = xmlR.responseXML.childNodes[1].childNodes[n].getAttribute("length");
				var pointer = xmlR.responseXML.childNodes[1].childNodes[n].getAttribute("pointer");
				//alert(duration + ' - ' + pointer);
				
				var longu = Math.round(pointer * 128 / duration);
				document.getElementById(elmId + '_ctl'+theId+'_imgPoint').style.width = longu + 'px';
			}
		} else {
			alert("There was a problem retrieving the XML data:\n" + xmlR.statusText);
		}
	}
}

/* AJAX */
function MakeXmlObject() {
	var http_request = false;
	
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	
	if (!http_request) {
		return false;
	}
	
	return http_request;
}

// RegEx replace
function reReplace(str, reg, rep) {
	var s = unescape(str);
	var re = new RegExp(eval(unescape(reg)));
	return s.replace(re, unescape(rep));
}

function ShowFlash(name, src, width, height)
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="'+name+'" name="'+name+'" align="middle">');
	document.write('<param name="allowScriptAccess" value="always" />');
	document.write('<param name="movie" value="'+src+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#ffffff" />');
	document.write('<param name="menu" value="false" />');
	document.write('<embed src="'+src+'" quality="high" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+name+'e" id="'+name+'e" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}