/////////
// POPUP
/////////
function openPopupPDF(pdf, width, height) {
	//alert("width="+width+",height="+height+",scrollbars=NO");
	window.open(pdf,"ventana1","width="+width+",height="+height+",scrollbars=NO") 
}

function openPopupURL(winname, r, width, height) {
	objXml = new getHTTPObject();
	objXml.open("GET",r,false);
	objXml.send(null);
	openPopup(winname, objXml.responseText, width, height);
}

function openPopupURL(winname, r, width, height) {
	objXml = new getHTTPObject();
	objXml.open("GET",r,false);
	objXml.send(null);
	openPopup(winname, objXml.responseText, width, height);
}

function openPopup(winname, r, width, height)
{
	var w=open("",winname,'width='+width+',height='+height+',toolbar=no,scrollbars=no,resizable=yes');
	w.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" /><meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\" /><title>Popup</title><link href=\"/main.css\" rel=\"stylesheet\" type=\"text/css\"></head>\n<body>");
	w.document.write(r);
	w.document.write("\n<CENTER><FORM><INPUT TYPE=\"BUTTON\" VALUE=\"OK\" ONCLICK=\"window.close()\"></FORM></CENTER></body></html>");	
	w.document.close();
}

///////
// AJAX
///////
/**
  * Envoie des données à l'aide d'XmlHttpRequest?
  * @param string methode d'envoi ['GET'|'POST']
  * @param string url
  * @param string données à envoyer sous la forme var1=value1&var2=value2...
  */



function sendData(method, url, data, async)
 {
	var xmlhttp = getHTTPObject();

    if (!xmlhttp)
    {
        return "Erreur";
    }

    if(method == "GET")
     {
     if(data == 'null')
     {
            xmlhttp.open("GET", url, async);
     }
     else
     {
            xmlhttp.open("GET", url+"?"+data, async);
     }
        xmlhttp.send(false);
     }
	 
     else if(method == "POST")
     {
        xmlhttp.open("POST", url, async);
        xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xmlhttp.send(data);
     }

	if (async == true) {
		// implementer pour ouverture asynchrone si besoin
	}
	else { 
		r = xmlhttp.responseText;
		// openPopup(r);
    	return r;
	}
 } 

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
        xmlhttp = false;
        }
      }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
      } catch (e) {
      xmlhttp = false;
      }
    }
  return xmlhttp;
}

////////////////////
// MENUS DEROULANTS
//	http://www.dustindiaz.com/dhtml-expand-and-collapse-div-menu/
////////////////////
/*function switchMenu(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		// if (arguments.length == 1) // (DH) marche pas qd un seul élément...
		//	return element;
		elements.push(element);
	}
return elements;
}

function collapseAll(objs) {
	var i;
	for (i=0;i<objs.length;i++ ) {
		objs[i].style.display = 'none';
	}
}

function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();

addEvent(window,'unload',EventCache.flush);
*/

///////
// MSN
///////
function verifStep2()
 {
	 document.getElementById("statusMSN").innerHTML = '<img src="/images/bigrotation2.gif" alt="Arrows" />';
	 
	 var requete = 
       'xmlhttp=1&'+
       'id_msn='+document.getElementById('id_msn_membre').value+
       '&'+
       'pass_msn='+document.getElementById('pass_msn_membre').value;
	   
	   //alert(requete);
	 
    //envoi des données
    r = sendData(
       'GET',
	   '/main/membres/forms/inscr_step2-validation.php',
       requete,
	   false
	   );

	if (r.indexOf('+OK') != -1) {
		document.getElementById("statusMSN").innerHTML = "Connexion <b><font color=\"green\">réussie</font></b>";
		return false;
	} else { 
		document.getElementById("statusMSN").innerHTML = r;
		return false; 
	}
}

//////////////
// MENU GAUCHE
//////////////

function blockEnter(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode :
        ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13 || charCode == 3) {
        return false;
    } else {
        return true;
    }
}

function getLocationsAndMap() { 
 if (receiveReq.readyState == 4 || 
     receiveReq.readyState == 0) 
 {     
   receiveReq.open("GET", '/main/ajax/centrer-cp.php?menucp='+document.getElementById('menucp').value+'&menupays='+document.getElementById('menupays').value, true);
   receiveReq.onreadystatechange = getLocationsAndMapCallback;      
   receiveReq.send(null);       
 } // end  if   
} // end  function

function getLocationsAndMapCallback() {
 // state == 4 is when the response is complete
 if (receiveReq.readyState == 4) {
 	var response = receiveReq.responseText.substring(0,3);
	// alert(response);
    if (response == "+OK") {
		var response = receiveReq.responseText.substring(4,receiveReq.responseText.length);
		var coord = response.split(',');

		// On charge la page avec la map et les coordonnées voulues
		// window.location = '/main/privatepage/index.php?lat='+coord[0]+'&lng='+coord[1];
		window.location = '/main/ajax/centrer-cp-callback.php?lat='+coord[0]+'&lng='+coord[1];
	} else {
		//openPopup('allera', 'test', 200, 100);
		alert(receiveReq.responseText);
	} // end if receiveReq.responseText == "+OK"
 } // end   if (state == 4)
} // end   function


/////////////////////////
// TEXTAREA: Maxlength 
////////////////////////

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}



////////////////////
// EDITION PROFIL
///////////////////

function modify_profil(element)
{
 if (document.getElementById("modify_profil_ajax_input") != null) {
 	alert("Vous ne pouvez modifier qu'un seul champ à la fois.\nValidez l'élément en cours d'édition.");
	return;
 }

 if (receiveReq.readyState == 4 || 
     receiveReq.readyState == 0) 
 {
	if (element == 'msn') { // Cas particulier
		self.location = '/main/privatepage/msn/synchroniser_contacts.php';
	} else { // Cas général
	   receiveReq.open("GET", '/main/ajax/modify_profil.php?element='+element+'&modif_hidden='+document.getElementById("modif_hidden").innerHTML, true);
	   receiveReq.onreadystatechange = modify_profilCallback;      
	   receiveReq.send(null);       
	 } // end  if
 } // end if
}

function modify_profilCallback() {
 // state == 4 is when the response is complete
 if (receiveReq.readyState == 4) {
 	// On évalue le tableau renvoyé: [OK/NOK, champ, message]
	var response = eval(receiveReq.responseText);
	if (response[0] == "OK") {
		document.getElementById(response[1]).innerHTML = response[2];
	} else {
		alert(response[2]);
	} // end if receiveReq.responseText == "+OK"
 } // end   if (state == 4)
} // end   function

function validate_profil_modification(element) {
 if (receiveReq.readyState == 4 || 
     receiveReq.readyState == 0) 
 {  
 	// Récupère tous les element_value
	var form = document.getElementById("modify_profil_ajax_form");
	var element_value="";
	for(var i = 0; i < form.length; i++) {
		//alert(form[i].type);
		switch (form[i].type) {
			case "text":
			case "textarea":
			case "hidden":
				// On fait quelques modifs sur la valeur pour que l'élément passe bien
				form[i].value = form[i].value.replace(/£/g, "");
				form[i].value = form[i].value.replace(/\n/g, "\\n");
				// On ajoute l'élément
				element_value = element_value+form[i].value+"£";
			break;
			case "select-one":
				element_value = element_value+form[i].options[form[i].selectedIndex].value+"£";
			break;
		}
	}
	// alert(element_value);
	
	receiveReq.open("GET", '/main/ajax/validate_profil_modification.php?element='+element+'&modif_hidden='+document.getElementById("modif_hidden").innerHTML+'&element_value='+element_value, true);  
   receiveReq.onreadystatechange = validate_profil_modificationCallback;      
   receiveReq.send(null);       

 } // end if
}

function validate_profil_modificationCallback() {
 if (receiveReq.readyState == 4) {
 	// On évalue le tableau renvoyé: [OK/NOK, champ, message]
 	var response = eval(receiveReq.responseText);
	if (response[0] == "OK") {
		// On met à jour le champ sur la page
		document.getElementById(response[1]).innerHTML = "<a href=\"javascript:modify_profil(\'"+response[1]+ "\')\">"+response[2]+'</a>';
		 // Si la mise à jour d'un autre champ est requise, on la lance
		 if (response[3] != "") {
			modify_profil(response[3]);
		}		
	} else {
		alert(response[2]);
	} // end if receiveReq.responseText == "+OK"
 } // end   if (state == 4)
}

////////////////////
// SCROLLING INFOS
////////////////////

function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}

//////////////////////////////
// COCHER TOUTES LES CHECKBOX
//////////////////////////////
function Check_all(container_id,state)
 {
  var checkboxes = document.getElementById(container_id).getElementsByTagName('input');
  for (var i=0;i<checkboxes.length-1;i++)
   {
	if((checkboxes[i].type == 'checkbox') && (checkboxes[i].name != "tous"))
	 {
	  checkboxes[i].checked = (checkboxes[i].checked)?false:true;
	 }
   }
  return true;
 }
 
///////////////////////////////////////////////////
// ACTIONS SUR FICHES EN AJAX SYNCHRONE (car pb d'ouverture du Popup dans un callback async sous FF)
//////////////////////////////////////////////////

function flash_membre(pseudo)  {
 if (receiveReq.readyState == 4 || 
     receiveReq.readyState == 0) 
 {
 	receiveReq.open("GET", '/main/ajax/flash.php?pseudo='+pseudo, false);
	receiveReq.send(null);

 	var response = eval(receiveReq.responseText);
	openPopup('popup', response[1], 200, 100);
  }
}

function invit_chat_membre(pseudo)  {
 if (receiveReq.readyState == 4 || 
     receiveReq.readyState == 0) 
 {
 	receiveReq.open("GET", '/main/ajax/invit_chat.php?pseudo='+pseudo, false);
	receiveReq.send(null);

 	var response = eval(receiveReq.responseText);
	
	// We try to open a window to check whether a window with the same name exists
	newwindow = window.open("", "popup_chat",'height=400,width=400');
	if (!newwindow.closed && newwindow.document.URL=="about:blank")
		newwindow=window.open('/main/chat2/chat.php?nick='+pseudo,'popup_chat','height=400,width=400');
	if (window.focus && newwindow && newwindow.top) {newwindow.focus()}
	// openPopupURLFullHTML('popup_chat', '/main/chat2/chat.html', 400, 400);
  }
}

function contenu_innap(pseudo, type_contenu)  {
 if (receiveReq.readyState == 4 || 
     receiveReq.readyState == 0) 
 {
 	receiveReq.open("GET", '/main/ajax/contenu_innap.php?pseudo='+pseudo+'&type_contenu='+type_contenu, false);
	receiveReq.send(null);

 	var response = eval(receiveReq.responseText);
	openPopup('popup', response[1], 300, 200);
  }
}

/////////////////////////////////
// MESSAGES ONLINE
/////////////////////////////////

function loopThroughMessagesOnline() {
	getMessagesOnline();
	var t = setTimeout("loopThroughMessagesOnline();", 60000);
}

function getMessagesOnline() {
	var xmlHttp=getHTTPObject();
	if (xmlHttp==null) {
		alert ("Votre navigateur est inadapté pour ce site ! Vous devez autoriser l'exécution de scripts Javascript.");
	return;
	}

	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState==4) {
			if (xmlHttp.status == 200) {
				var newmsg = xmlHttp.responseText;
			} else {
				var newmsg = "Erreur Ajax: " + xmlHttp.status+"<br />";
			}

			document.getElementById("msgs_online").innerHTML = newmsg;
		}
	};
	xmlHttp.open("GET", "/main/ajax/get-messages-online.php", true);
	xmlHttp.send(null);
}

//////////////////////////////
// ANNONCES
/////////////////////////////
function modify_section_annonce(section)
{
 if (receiveReq.readyState == 4 || 
     receiveReq.readyState == 0) 
 {
	   receiveReq.open("GET", '/main/ajax/modify_section_annonce.php?section='+section, true);
	   receiveReq.onreadystatechange = modify_section_annonceCallback;      
	   receiveReq.send(null);       
 } // end if
}

function modify_section_annonceCallback() {
 // state == 4 is when the response is complete
 if (receiveReq.readyState == 4) {
	document.getElementById('type_annonce').innerHTML = receiveReq.responseText;
 } // end   if (state == 4)
} // end   function

///////////////////////
// CLOCK
///////////////////////
function js_clock() {
	var clock_time = new Date();
	var clock_date = clock_time.getDate();
	var clock_month = clock_time.getMonth()+1;
	var clock_fullyear = clock_time.getFullYear();
	var clock_hours = clock_time.getHours();
	var clock_minutes = clock_time.getMinutes();
	var clock_seconds = clock_time.getSeconds();

	clock_date = js_clock_check0(clock_date);
	clock_month = js_clock_check0(clock_month);
	clock_hours = js_clock_check0(clock_hours);
	clock_minutes = js_clock_check0(clock_minutes);
	clock_seconds = js_clock_check0(clock_seconds);

	var clock_div = document.getElementById('js_clock');
	clock_div.innerHTML = "<b>Nous sommes le:</b> "+clock_date+"/"+clock_month+"/"+clock_fullyear+" "+clock_hours + ":" + clock_minutes + ":" + clock_seconds /*+ " " + clock_suffix*/;
	setTimeout("js_clock()", 1000);
}

function js_clock_check0(field) {
	if (field < 10) {
		field = "0" + field;
	}
	return field;
}

//////////////
// TOP MEMBRES
//////////////
function topMembresChanges() {
 if (receiveReq.readyState == 4 || 
     receiveReq.readyState == 0) 
 {
	receiveReq.open("GET", '/main/ajax/top_membres.php?sexe='+document.getElementById('tm_sexe').options[document.getElementById('tm_sexe').selectedIndex].value+'&type='+document.getElementById('tm_type').options[document.getElementById('tm_type').selectedIndex].value+'&nb='+document.getElementById('tm_nombre').options[document.getElementById('tm_nombre').selectedIndex].value, true);
   receiveReq.onreadystatechange = topMembresCallback;
   receiveReq.send(null);       
 }
}

function topMembresCallback() {
 // state == 4 is when the response is complete
 if (receiveReq.readyState == 4) {
 	// On évalue le tableau renvoyé: [OK/NOK, champ, message]
	document.getElementById('tm_response').innerHTML = receiveReq.responseText;
 } // end   if (state == 4)
} // end   function

//////////////////
// STATS MEMBRES
//////////////////
function statsMembresChanges() {
	window.open('/main/privatepage/profil/stats.php?type='+document.getElementById('stats_type').options[document.getElementById('stats_type').selectedIndex].value, "_self");
}

//////////////////
// AFFICHER MSN
/////////////////
function showMSNChanges() {
	window.open('/main/privatepage/msn/afficher_contacts.php?type='+document.getElementById('msn_type').options[document.getElementById('msn_type').selectedIndex].value, "_self");
}
////////////////
// FLAGS MEMBRES
////////////////
function member_flag_toggle(flag, checked) {
 if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
	receiveReq.open("GET", '/main/ajax/membres_flag_toggle.php?flag='+flag+'&checked='+checked, true);
    receiveReq.send(null);       
 }
}

////////////////////////////
// SELECTION DU ZOOM MEMBRE
////////////////////////////
function member_zoom_select(Objet){
 var zoom = Objet.value;
 if (receiveReq.readyState == 4 || receiveReq.readyState == 0)  {
	receiveReq.open("GET", '/main/ajax/membres_zoom_select.php?zoom='+zoom, true);
    receiveReq.send(null);
 }
}

////////////////////
// CAPTCHA
///////////////////
function regenerate_captcha() {
	document.getElementById('captcha').src = '/main/functions/captcha/securimage_show.php?' + Math.random();	
}

//////////////////////
// LOAD AND RESIZE CADRES MAIN
//////////////////////
function getElementsByStyleClass (className) {
  var all = document.all ? document.all :
    document.getElementsByTagName('*');
  var elements = new Array();
  for (var e = 0; e < all.length; e++)
    if (all[e].className == className)
      elements[elements.length] = all[e];
  return elements;
}

function check_resize() {
	var width = (document.body.clientWidth > 0 ? document.body.clientWidth : document.body.offsetWidth) - 303;

	// Set size in session
	 if (receiveReq.readyState == 4 || 
		 receiveReq.readyState == 0) 
	 {
		receiveReq.open("GET", '/main/ajax/set_width.php?width='+width, true);
		receiveReq.send(null);
	 }

	// If map, resize it
	if (window.map_resize) {
		map_resize((width) + 'px');
	}

	// Resize all cadres main
	//resize_class('cadre_main_haut_menu_big', width);
	//resize_class('cadre_main_haut_home_big', width);
}

/*function resize_class(class, width) {
	var elements = getElementsByStyleClass (class);
	for (var e = 0; e<elements.length; e++)		
		elements[e].style.width = width + 'px';	
}*/

function check_load() {
	check_resize();
	// If map, load it
	if (window.map_load)
		map_load();
}

function isset(varname)  {
  if(typeof( window[ varname ] ) != "undefined") return true;
  else return false;
}

/****************
* ROUNDED CORNERS
* http://www.html.it/articoli/nifty/index.html
*****************/
function NiftyCheck()
{
if(!document.getElementById || !document.createElement)
    return(false);
var b=navigator.userAgent.toLowerCase();
if(b.indexOf("msie 5")>0 && b.indexOf("opera")==-1)
    return(false);
return(true);
}

function Rounded(selector,bk,color,size){
var i;
var v=getElementsBySelector(selector);
var l=v.length;
for(i=0;i<l;i++){
    AddTop(v[i],bk,color,size);
    AddBottom(v[i],bk,color,size);
    }
}

function RoundedTop(selector,bk,color,size){
var i;
var v=getElementsBySelector(selector);
for(i=0;i<v.length;i++)
    AddTop(v[i],bk,color,size);
}

function RoundedBottom(selector,bk,color,size){
var i;
var v=getElementsBySelector(selector);
for(i=0;i<v.length;i++)
    AddBottom(v[i],bk,color,size);
}

function AddTop(el,bk,color,size){
var i;
var d=document.createElement("b");
var cn="r";
var lim=4;
if(size && size=="small"){ cn="rs"; lim=2}
d.className="rtop";
d.style.backgroundColor=bk;
for(i=1;i<=lim;i++){
    var x=document.createElement("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    d.appendChild(x);
    }
el.insertBefore(d,el.firstChild);
}

function AddBottom(el,bk,color,size){
var i;
var d=document.createElement("b");
var cn="r";
var lim=4;
if(size && size=="small"){ cn="rs"; lim=2}
d.className="rbottom";
d.style.backgroundColor=bk;
for(i=lim;i>0;i--){
    var x=document.createElement("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    d.appendChild(x);
    }
el.appendChild(d,el.firstChild);
}

function getElementsBySelector(selector){
var i;
var s=[];
var selid="";
var selclass="";
var tag=selector;
var objlist=[];
if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag"
    s=selector.split(" ");
    var fs=s[0].split("#");
    if(fs.length==1) return(objlist);
    return(document.getElementById(fs[1]).getElementsByTagName(s[1]));
    }
if(selector.indexOf("#")>0){ //id selector like "tag#id"
    s=selector.split("#");
    tag=s[0];
    selid=s[1];
    }
if(selid!=""){
    objlist.push(document.getElementById(selid));
    return(objlist);
    }
if(selector.indexOf(".")>0){  //class selector like "tag.class"
    s=selector.split(".");
    tag=s[0];
    selclass=s[1];
    }
var v=document.getElementsByTagName(tag);  // tag selector like "tag"
if(selclass=="")
    return(v);
for(i=0;i<v.length;i++){
    if(v[i].className==selclass){
        objlist.push(v[i]);
        }
    }
return(objlist);
}

/*********************
* Multiple Onloads
*********************/
function addLoadEvent(func) { 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function') { 
		window.onload = func; 
		} else { 
		window.onload = function() { 
		  if (oldonload) { 
			oldonload(); 
		} 
		  func(); 
		} 
	} 
} 