var subout = false;
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll);
	//alert (arrayPageScroll[1]);
	return arrayPageScroll;
}


function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function inDiv (id, text) {
	var element = document.getElementById(id);
	element.innerHTML = text;
}

function inDiv1 (id1, id2) {
	var element1 = document.getElementById(id1);
	var element2 = document.getElementById(id2);
	element1.innerHTML = element2.innerHTML;
}

function targetopener() {
	window.opener.focus();
	window.opener.document.getElementById('submit_pl').click();
	window.close();
	return true;
}

function menu_td(num, total) {
	var element;
	var elname;
	var i;
	for (i=1; i <=total; i++) {
		elname = 'menu_td' + i;
		if (element = document.getElementById(elname)) element.bgColor='#FFFFFF';
	}
}

function overlay(el) {
	document.getElementById('overlay').style.display = 'block';
	document.getElementById('overlay').innerHTML = '<table border="0" cellspacing="2" cellpadding="0" width="220" style="border0px solid #FFFFFF; font-family:verdana; color:#CCCCCC; font-size:11px;"><tr><form name="loginover" action="idcheck.php" method="post"><td class="loginform" align="left">username:<br><input type="text" name="user" size="10"></td><td class="loginform">password:<br><input type="password" name="pswd" size="10" id="log_password"></td><td class="loginform"><input type="submit" name="submit_login" value="login"></td></form></tr></table>';
	document.loginover.user.focus();
}

function overlay_pass() {
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var centerX = arrayPageSize[0] / 2;
	var centerY = arrayPageSize[3] / 2;
	var width1 = arrayPageSize[0];
	var height1 = arrayPageSize[1];
	var overlayTop = centerY - height1 / 2;
	var overlayLeft = centerX - width1 / 2;
	var overlayTop1 = centerY - 100;
	var overlayLeft1 = centerX - 150;
	var imgX = width1-75;
	var imgY = height1-100;
	document.getElementById('overlay_pass').style.width = width1 + 'px'; 
	document.getElementById('overlay_pass').style.height = height1 + 'px';
	//document.getElementById('overlay').style.top = arrayPageScroll[1];
	document.getElementById('overlay_pass').style.left = 0; //((arrayPageSize[0] - 20 - width1) / 2);
	document.getElementById('overlay_pass').style.display = 'block';
		
	//formulaire modification du mot de passe
	document.getElementById('overlay_pass').innerHTML = '<img src="./overlay.png" width="100%" height="'+ height1 +'" style=" filter:progid:DXImageTransform.Microsoft.Alpha(opacity=75);z-index:1000; position:absolute; left:0; top:0;">' +
		'<table border="0" width="400" style="position:absolute;top:'+ arrayPageScroll[1] +'px; left:'+ overlayLeft1 +'px; border:1px ridge #000000; z-index:1000;background-color:#EEEEEE" class="create_pl">' +
		'<tr height="30"><td align="right"><a href="javascript:overlay_pass_close();"><img src="./css/images/cancel.png" border="0" align="middle" width="20" alt="close pop-in"></a></td></tr>' +
		'<tr height="30"><td valign="middle" align="left" style="padding-left:5px;" id="actual">modify your password</td></tr>' +
		'<tr><td style="padding-left:20px;"><label for="password">old password:<font color="red">*</font></label><br><div class="dvSkin"><input type="password" size="42" id="password" name="password" value="" class="dvTxt"></div><div id="comment">6-20 characters</div><span id="error_msg"></span></td></tr>' +
		'<tr><td style="padding-left:20px;"><label for="password1">new password:<font color="red">*</font></label><br><div class="dvSkin"><input type="password" size="42" id="password1" name="password1" value="" class="dvTxt"></div><div id="comment">6-20 characters</div><span id="error_msg"></span></td></tr>' +
		'<tr><td style="padding-left:20px;"><label for="password2">confirmation of the new password:<font color="red">*</font></label><br><div class="dvSkin"><input type="password" size="42" id="password2" name="password2" value="" class="dvTxt"></div><div id="comment">6-20 characters</div><span id="error_msg"></span></td></tr>' +
		'<tr><td align="center"><div id="msgbox" style="display:none"></div><div id="available"></div><input type="submit" value="save" id="save_pass"></td></tr>' +
		'</table>' +
		'<div style="position:absolute;top:10px; left:'+ imgX +'px;" onclick="javascript:overlay_close();"></div>';
}

function overlay_pict() {
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var centerX = arrayPageSize[0] / 2;
	var centerY = arrayPageSize[3] / 2;
	var width1 = arrayPageSize[0];
	var height1 = arrayPageSize[1];
	var overlayTop = centerY - height1 / 2;
	var overlayLeft = centerX - width1 / 2;
	var overlayTop1 = centerY - 100;
	var overlayLeft1 = centerX - 150;
	var imgX = width1-75;
	var imgY = height1-100;
	//document.getElementById('overlay').style.width = width1 + 'px'; 
	document.getElementById('overlay_pict').style.height = height1 + 'px';
	document.getElementById('overlay_pict').style.width = width1 + 'px';	
	//document.getElementById('overlay').style.top = arrayPageScroll[1];
	document.getElementById('overlay_pict').style.left = 0; //((arrayPageSize[0] - 20 - width1) / 2);
	document.getElementById('overlay_pict').style.display = 'block';
		
	//formulaire modification du mot de passe
	document.getElementById('overlay_pict').innerHTML = '<img src="./overlay.png" width="100%" height="'+ height1 +'" style=" filter:progid:DXImageTransform.Microsoft.Alpha(opacity=75);z-index:1000; position:absolute; left:0; top:0;">' +
	'<table border="0" width="350" style="position:absolute;top:'+ arrayPageScroll[1] +'px; left:'+ overlayLeft1 +'px; border:1px ridge #000000; z-index:1000;background-color:#EEEEEE; color:#333333;" class="create_pl">' +
	'<tr height="30"><td align="right"><a href="javascript:overlay_pass_close();"><img src="./css/images/cancel.png" border="0" align="middle" width="20" alt="close pop-in"></a></td></tr>' +
	'<tr><td style="padding-left:5px;"><label for="password1">upload a photo<font color="red">*</font>:</label><input type="file" name="avatar"></div><div id="comment">GIF, JPEG or PNG format</td></tr>' +
	'<tr><td align="center"><div id="available"></div><input type="submit" name="submit_avatar" value="upload"></td></tr></table>';
}

function pl_preview (color, playlist) {
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var centerX = arrayPageSize[0] / 2;
	var centerY = arrayPageSize[3] / 2;
	var width1 = arrayPageSize[0]-5;
	var height1 = arrayPageSize[1]-5;
	var overlayTop = centerY - height1 / 2;
	var overlayLeft = centerX - width1 / 2;
	var overlayTop1 = centerY - 100;
	var overlayLeft1 = centerX - 150;
	var imgX = width1-75;
	var imgY = height1-100;
	document.getElementById('pl_preview').style.width = width1 + 'px'; 
	document.getElementById('pl_preview').style.height = height1 + 'px';
	//document.getElementById('overlay').style.top = arrayPageScroll[1];
	document.getElementById('pl_preview').style.left = 0; //((arrayPageSize[0] - 20 - width1) / 2);
	document.getElementById('pl_preview').style.display = 'block';
		
	//formulaire modification du mot de passe
	document.getElementById('pl_preview').innerHTML = '<img src="http://www.playlistor.com/overlay.png" width="100%" height="'+ height1 +'" style=" filter:progid:DXImageTransform.Microsoft.Alpha(opacity=75);z-index:1000; position:absolute; left:0; top:0;">' +
	'<table border="0" width="400" style="position:absolute;top:'+ arrayPageScroll[1] +'px; left:'+ overlayLeft1 +'px; border:1px ridge #000000; z-index:1000;" class="pl_preview"><tr><td align="right"><a href="javascript:overlay_close();"><img src="http://www.playlistor.com/css/images/cancel.png" border="0" width=20" alt="close preview window"></a></td></tr><tr><td><div id="mediaplayer"></div></td></tr></table>';
	createPlayer(playlist, 1, color, true);
}

function overlay_close() {
	try {
		sendEvent ('thePlayerId','stop');
	}
	catch(err) {
	}
	document.getElementById('pl_preview').style.display = 'none';
}

function pl_load () {
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var centerX = arrayPageSize[0] / 2;
	var centerY = arrayPageSize[3] / 2;
	var width1 = arrayPageSize[0];
	var height1 = arrayPageSize[1];
	var overlayTop = centerY - height1 / 2;
	var overlayLeft = centerX - width1 / 2;
	var overlayTop1 = centerY - 100;
	var overlayLeft1 = centerX - 150;
	var imgX = width1-75;
	var imgY = height1-100;
	document.getElementById('pl_preview').style.width = width1 + 'px'; 
	document.getElementById('pl_preview').style.height = height1 + 'px';
	//document.getElementById('overlay').style.top = arrayPageScroll[1];
	document.getElementById('pl_preview').style.left = 0; //((arrayPageSize[0] - 20 - width1) / 2);
	document.getElementById('pl_preview').style.display = 'block';
		
	//formulaire modification du mot de passe
	document.getElementById('pl_preview').innerHTML = '<img src="./overlay.png" width="100%" height="'+ height1 +'" style=" filter:progid:DXImageTransform.Microsoft.Alpha(opacity=75);z-index:1000; position:absolute; left:0; top:0;">' +
	'<table border="0" width="100%" height="600" style="position:absolute;top:0px; left:0px; border:1px ridge #000000; z-index:1000;"><tr height="100%"><td width="100%" align="center" valign="middle"><img src="loading.gif"></td></tr></table>';
	//createPlayer(playlist, 1, color, true);
}

function overlay_pass_close() {
	document.getElementById('overlay_pass').style.display = 'none';
	document.getElementById('overlay_pict').style.display = 'none';
}

function keyPressHandler(e) {
   var kC  = (window.event) ? event.keyCode : e.keyCode;
   var Esc = (window.event) ? 27 : e.DOM_VK_ESCAPE // MSIE : Firefox
   if(kC==Esc) overlay_close()
}

var startNumber;
var currentState;
var playingFlag=false;

function sendEvent(typ,prm) { thisMovie("thePlayerId").sendEvent(typ,prm); };

function getUpdate(typ,pr1,pr2,pid) {
	if(pid != "null") {
		if((typ == "state")&&(pr1 != undefined)) { 
			currentState = pr1; 
			if((currentState=="0")&&( ! playingFlag)) {				
				playingFlag = true;
				sendEvent('playitem',  startNumber); 					
			}
		}
	}
};

// This is a javascript handler for the player and is always needed.
function thisMovie(movieName) {
    if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
};


function createPlayer(theFile, arg, color, autostart) {
	startNumber=arg;
	if (color == 'default') {
		color = '0xf7f7f9&0x000000&0x000000&0xFFFFFF';
	}
	var colors = color.split("&");
	var s = new SWFObject("http://www.playlistor.com/mediaplayer.swf","thePlayerId","450","320","7");
	s.addParam("allowfullscreen","true");
	s.addVariable("file",theFile);
	s.addVariable("width","450");
	s.addVariable("height","320");
	s.addVariable("displayheight","230");
	s.addParam("wmode", "transparent"); 
	s.addVariable("autostart", autostart);
	s.addVariable("repeat","true");
	s.addVariable("shuffle","false");
	if (document.rating) {
		if (document.rating.shuffle[1].checked == true) {
			s.addVariable("shuffle","true");
			document.rating.shuffle[0].disabled = false;
			document.rating.shuffle[1].disabled = true;
		}
		if (document.rating.shuffle[0].checked == true) { 
			document.rating.shuffle[0].disabled = true;
			document.rating.shuffle[1].disabled = false;
		}
	}
	s.addVariable("backcolor", colors[0]);
	s.addVariable("frontcolor", colors[1]);
	s.addVariable("lightcolor", colors[2]);
	s.addVariable("screencolor", colors[3]);
	s.addVariable("displayheight","0");
	s.addVariable("usefullscreen","false");
	s.addVariable("thumbsinplaylist","false");

	s.addVariable("enablejs","true");
	s.addVariable("javascriptid","thePlayerId"); 
	s.write("mediaplayer");
}

function draw_player() {
	var textcolor='';
	var file1='samples/mediaplayer.xml';
	if (document.create_pl.b_color && document.create_pl.l_color && document.create_pl.s_color && document.create_pl.f_color) {
		textcolor = '0x' + document.create_pl.b_color.value.substr(1) + '&0x' + document.create_pl.f_color.value.substr(1) + '&0x' + document.create_pl.l_color.value.substr(1) + '&0x' + document.create_pl.s_color.value.substr(1);
		if (document.create_pl.pl1) {
			file1 = 'http://www.playlistor.com/playlist.php?pl=' + document.create_pl.pl1.value;
		}
		createPlayer(file1, 1, textcolor, false);
	}
}
function sendEvent(swf,typ,prm) { 
  thisMovie(swf).sendEvent(typ,prm); 
};
function getUpdate(typ,pr1,pr2,swf) {};
function thisMovie(swf) {
  if(navigator.appName.indexOf("Microsoft") != -1) {
    return window[swf];
  } else {
    return document[swf];
  }
};

function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}

function addslashes(str) {
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}

function getY( oElement )
{
	var iReturnValue = 0;
	while( oElement != null ) {
	iReturnValue += oElement.offsetTop;
	oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getX( oElement )
{
	var iReturnValue = 0;
	while( oElement != null ) {
	iReturnValue += oElement.offsetLeft;
	oElement = oElement.offsetParent;
	}
	return iReturnValue;
}
function show_tracks (text_tracks, obj) {
	var elem = document.getElementById('tracks');
	var superX = getX(obj)-20;
	var superY = getY(obj)+25;	
	if (text_tracks !='') {
		elem.style.top = superY +'px';
		elem.style.left = superX +'px';		
		elem.innerHTML = text_tracks;
		elem.style.display = 'block';
	}
}

function hide_tracks () {
	var elem = document.getElementById('tracks');
	elem.innerHTML = '';
	elem.style.display = 'none';
}

function show_button (ref, user, obj) { //to display the delete button
	var elem = document.getElementById('button');
	var superX = getX(obj)+58;
	var superY = getY(obj)+2;	
	if (ref !='') {
		elem.style.top = superY +'px';
		elem.style.left = superX +'px';		
		elem.innerHTML = '<a href="javascript:void(0)" onclick="if (confirm(\'Are you sure you want to delete this picture?\')) window.location= \'delete_pic.php?ref='+ ref +'&user='+ user +'\'"><img src="img/close.jpg" border="0" width="16" height="16" alt="delete this picture" onmouseout="javascript:hide_button()" style="border:1px solid #EAEAEA; background-color:#FFFFFF;"></a>';
		elem.style.display = 'block';
	}
}

function hide_button () {
	var elem = document.getElementById('button');
	elem.innerHTML = '';
	elem.style.display = 'none';
}


function show_thumb (imgfile, obj, decalX) {
	var elem = document.getElementById('thumb');
	var superX = getX(obj) - decalX;
	var superY = getY(obj)-190;	
	if (imgfile !='') {
		elem.style.top = superY +'px';
		elem.style.left = superX +'px';		
		elem.innerHTML = '<img src="img/' + imgfile+ '" border="0">';
		elem.style.display = 'block';
	}
}

function hide_thumb () {
	var elem = document.getElementById('thumb');
	elem.innerHTML = '';
	elem.style.display = 'none';
}

function show_editor (obj, ref, type, value) {
	var elem = document.getElementById('editor');
	var superX = getX(obj);
	if (type != 'playlist') superX += 5;
	var superY = getY(obj);
	var length1 = value.length;
	if (length1 < 4) {
		length1 = '22';
	}
	if (ref !='' && value !='' && type !='') {
		elem.style.top = superY +'px';
		elem.style.left = superX +'px';		
		elem.innerHTML = '<input type="text" name="field_value" size="'+ length1 +'" value="' + value + '" onblur="edit_details(\'' + value + '\')" onkeypress="keyPressEditor()"><input type="hidden" name="ref" value="' + ref + '"><input type="hidden" name="type" value="' + type + '">';
		elem.style.display = 'block';
		document.addsong.field_value.select();
	}
}

function show_editor1 (obj, ref, value) { //for the pictures description
	var elem = document.getElementById('editor');
	var superX = 450;
	var superY = getY(obj) - 5;
	var length1 = 65;
	/*if (length1 < 10) {
		length1 = '15';
	}
	if (length1 > 60) {
		length1 = '60';
	}*/
	if (ref !='' && value !='') {
		//elem.style.top = superY +'px';
		//elem.style.left = superX +'px';		
		elem.innerHTML = '<textarea name="field_value" cols="'+ length1 +'" rows="2" onblur="edit_details1(\'' + escape(value) + '\')" onkeypress="keyPressEditor1()">' + value + '</textarea><input type="hidden" name="ref" value="' + ref + '">';
		//elem.style.display = 'block';
		document.editpic.field_value.select();
		//document.getElementById('available').innerHTML = '';
	}

}

function hide_editor () {
	var elem = document.getElementById('editor');
	elem.innerHTML = '';
	elem.style.display = 'none';
}

function keyPressEditor(e) {
   var kC  = (window.event) ? event.keyCode : e.keyCode;
   var Esc = (window.event) ? 27 : e.DOM_VK_ESCAPE // MSIE : Firefox
   var Enter = (window.event) ? 13 : e.DOM_VK_ESCAPE // MSIE : Firefox
   if(kC==Esc) hide_editor()
   if(kC==Enter) edit_details()

}
function keyPressEditor1(e) {
   var kC  = (window.event) ? event.keyCode : e.keyCode;
   var Esc = (window.event) ? 27 : e.DOM_VK_ESCAPE // MSIE : Firefox
   var Enter = (window.event) ? 13 : e.DOM_VK_ESCAPE // MSIE : Firefox
   if(kC==Esc) hide_editor()
   //if(kC==Enter) edit_details1()

}

function show_feat (ref) {
	var elem = document.getElementById('feat_player');
	var elem1 = document.getElementById('map2');

	elem.innerHTML = '<object width="315" height="335"><embed src="mediaplayer.swf" width="315" height="335" allowscriptaccess="always" allowfullscreen="true" flashvars="height=335&width=315&file=playlist.php?pl='+ ref +'&displayheight=0&usefullscreen=false&thumbsinplaylist=false&autostart=true&shuffle=false&repeat=true"/></object>';
	elem1.style.display='none';
}

function recipient(user) {
	if (document.getElementById('recipient')) {
		document.getElementById('recipient').innerHTML = user + '  <input type="hidden" name="recipient" value="'+ user +'">';
	}
	if (document.getElementById('close_frame')) {
		document.getElementById('close_frame').click();
	}

}

function show_elem(id, obj) {
	var superX = getX(obj);
	var superY = getY(obj)+18;
var idx = 'sub_menu'+ id;
	var elem = document.getElementById(idx);
	elem.style.top = superY +'px';
	elem.style.left = superX +'px';
	hide_elem(0);hide_elem(1);
	elem.style.display = 'block';		

}
function hide_elem(id) {
var idx = 'sub_menu'+ id;
	var elem = document.getElementById(idx);
	elem.style.display = 'none';
}
function sleepF(millis) {
	var date = new Date();
	var curDate = null;

	do {
		curDate = new Date();
	} 
	while(curDate-date < millis);
} 
function strip_tags(text){
	var strInputCode = text;
	strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
		return (p1 == "lt")? "<" : ">";
	});
	var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
	return strTagStrippedText;
}
