function framestuff() {
	if (window.top != window.self){
		window.top.location="http://www.babybonze.com";
	}
}

function PopupPic(sPicURL,WIDTH,HEIGHT,SCROLL) {
	window.open( "/popup.php?picUrl="+sPicURL, "", "resizable=1,scrollbars="+SCROLL+",height="+HEIGHT+",width="+WIDTH);
}

function navJump(jumpTo) {
	if(jumpTo != 0) {
		window.location = jumpTo;
	}
}

function displayToggle(id) {
	var ref = getRefToDiv(id);
	var el = ref.style;
	if(el.display == "none") {
		el.display = "block";
	}
	else if(el.display == "block") {
		el.display = "none";
	}
}

function hideThis(id) {
	var ref = getRefToDiv(id);
	var el = ref.style;
	if(el.display == "block") {
		el.display = "none";
	}
}

function confirmDelete(msg){
	disallowmenu = true;
	if (confirm(msg))
	{
		return true;
	}
	else
	{
		disallowmenu = false;
		return false;
	}
}

function openerForm(url) 
{ 
 opener.location.href = url;
 fermeture();
 return false; 
}

function fermeture()
{
 window.close();
 return false;
}
	
var n4 = (document.layers) ? 1 : 0;
var ie = (document.all) ? 1 : 0;
var n6 = (document.getElementById && ! document.all) ? 1 : 0;
var plusN6 = 10;
function popup(page,width,height,nom)
{
 if ( width == 0 )
 {
  var windowWidth = screen.width/2;
 }
 else
 {
  var windowWidth = width;
 }
 if ( height == 0 )
 {
  var windowHeight = screen.height/2;
 }
 else
 {
  var windowHeight = height;
 }
 if ( n6 )
 {
  windowHeight = windowHeight + plusN6;	
 } 
 var windowLeft = (screen.width-windowWidth)/2;
 var windowTop  = (screen.height-windowHeight)/2;
 w = window.open(page,nom,'menubar=yes,status=yes,resizable=yes,scrollbars=yes,fullscreen=no,width='+windowWidth+',height='+windowHeight+',top='+windowTop+',left='+windowLeft+' ');
}

var ie5=document.all && !window.opera
var ns6=document.getElementById

if (ie5||ns6)
document.write('<div id="popitmenu" onMouseover="clearhidemenu();" onMouseout="dynamichide(event)"></div>')

function iecompattest()
{
	return (document.compatMode && document.compatMode.indexOf("CSS")!=-1)? document.documentElement : document.body
}

function showmenu(e, which, optWidth)
{
	if (!document.all&&!document.getElementById || window.disallowmenu)
	return
	clearhidemenu()
	menuobj=ie5? document.all.popitmenu : document.getElementById("popitmenu")
	menuobj.innerHTML=which
	menuobj.style.width=(typeof optWidth!="undefined")? optWidth : "155px";
	menuobj.contentwidth=menuobj.offsetWidth
	menuobj.contentheight=menuobj.offsetHeight
	eventX=ie5? event.clientX : e.clientX
	eventY=ie5? event.clientY : e.clientY
	var rightedge=ie5? iecompattest().clientWidth-eventX : window.innerWidth-eventX
	var bottomedge=ie5? iecompattest().clientHeight-eventY : window.innerHeight-eventY
	if (rightedge<menuobj.contentwidth)
	menuobj.style.left=ie5? iecompattest().scrollLeft+eventX-menuobj.contentwidth+"px" : window.pageXOffset+eventX-menuobj.contentwidth+"px"
	else
	menuobj.style.left=ie5? iecompattest().scrollLeft+eventX+"px" : window.pageXOffset+eventX+"px"
	if (bottomedge<menuobj.contentheight)
	menuobj.style.top=ie5? iecompattest().scrollTop+eventY-menuobj.contentheight+"px" : window.pageYOffset+eventY-menuobj.contentheight+"px"
	else
	menuobj.style.top=ie5? iecompattest().scrollTop+event.clientY+"px" : window.pageYOffset+eventY+"px"
	menuobj.style.visibility="visible"
	return false;
}

function contains_ns6(a, b) {
	while (b.parentNode)
	if ((b = b.parentNode) == a)
	return true
	return false
}

function hidemenu(){
	if (window.menuobj)
	menuobj.style.visibility="hidden"
}

function dynamichide(e){
	if (ie5&&!menuobj.contains(e.toElement))
	hidemenu()
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
	hidemenu()
}

function delayhidemenu(){
	delayhide=setTimeout("hidemenu()",500)
}

function clearhidemenu(){
	if (window.delayhide)
	clearTimeout(delayhide)
}

if (ie5||ns6)
document.onclick=hidemenu
if (window.menuobj)
menuobj.onclick=hidemenu

//onmouseover="changeCouleur(this,\'Liste2\')" onmouseout="changeCouleur(this,\'Liste0\')"

function $(id) 
{
    return document.getElementById(id);
}

function assignEditor(objectId) 
{
    document.getElementById(objectId).onclick = function() { runEditor(this) }
}

function saveData(objectId) 
{

    advAJAX.post({
        url : "3b.php",
        parameters : {
            id : objectId,
            value : $(objectId + "_editor_ta").value
        },
        onInitialization : function() {
        
            $(objectId + "_editor_ta").disabled = "disabled";
            $(objectId + "_editor_save").disabled = "disabled";
            $(objectId + "_editor_cancel").disabled = "disabled";
        },
        onError : function() {
        
            alert("There was an error while establishing connection, please try again.");
            $(objectId + "_editor_ta").removeAttribute("disabled");
            $(objectId + "_editor_save").removeAttribute("disabled");
            $(objectId + "_editor_cancel").removeAttribute("disabled");
        },
        onSuccess : function(obj) {
        
            if (obj.responseText == "1")
              $(objectId).innerHTML = $(objectId + "_editor_ta").value.replace(/\n/g, '<br>');
            removeElement(objectId + "_editor");
        }
    });
}

function runEditor(obj) 
{
	//alert('hu ' + obj.id);
    l = t = 0;
    //obj2 = obj;
    //while (obj2.parentNode) {
        //l += obj2.offsetLeft;
        l += findPosX(obj);
        //t += obj2.offsetTop;
        t += findPosY(obj);
        //obj2 = obj2.parentNode;
    //}
    
    editor = document.createElement("div");
    h = obj.offsetHeight >= 60 ? obj.offsetHeight : 60;
    with (editor.style) {
        position = "absolute";
        zIndex = "100";
        top = t + "px";
        left = l + "px";
        width = obj.offsetWidth + "px";
        height = h + "px";
        backgroundColor = "#ffffff";
    }
    editor.id = obj.id + "_editor";
    editor.innerHTML = "<textarea id='" + obj.id + "_editor_ta'></textarea><br /><button id='" + obj.id + "_editor_save' onclick=\"saveData('" + obj.id + "')\">Save</button>&nbsp;<button id='" + obj.id + "_editor_cancel' onclick=\"removeElement('" + obj.id + "_editor');removeElement('" + obj.id + "_link')\">Cancel</button>";
    document.body.appendChild(editor);
    
    ta = $(obj.id + "_editor_ta");
    with (ta.style) {
        width = "100%";
        height = (h - 19) + "px";
    }
    ta.value = stripBR(obj.innerHTML);

}

function removeElement(id) 
{
    try {
      obj = $(id);
      obj.parentNode.removeChild(obj);
    } catch(e) {}
}

function changeCouleur(ligne,classe){
	ligne.className = classe;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj) 
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function stripHTML(oldString) 
{
   var newString = "";
   var inTag = false;
   for(var i = 0; i < oldString.length; i++) {
        if(oldString.charAt(i) == '<') inTag = true;
        if(oldString.charAt(i) == '>') {
              inTag = false;
              i++;
        }
        if(!inTag) newString += oldString.charAt(i);

   }
   return newString;
}

function stripBR(oldString) 
{
	  var newString = oldString.replace(/\n/g, '');
	  newString = newString.replace(/<\s*br\s*>/gi, '\n');
	  return newString;
}

function none() 
{
}

function changeHText()
{
	if(document.getElementById("idh").childNodes[0].nodeType == "3")
	{
		document.getElementById("idh").childNodes[0].nodeValue = "Turn off highlighting";
	}
	this.disabled = true;
}

function turnHighlightOnOff(divID_as_a_string) {
	var myReference = getRefToDiv(divID_as_a_string);
	if( !myReference ) { window.alert('Nothing works in this browser'); return; }
	if( myReference.innerHTML ) { 
		if( rewr ) { 
			myReference.innerHTML = '<a href="javascript:;" class="nohighlight" id="aidh" onclick="change(\'aidh\', \'pedit\');turnHighlightOnOff(\'idh\');">Turn on highlighting</a>'; 
			for (i = 0; i < editids.length; i++)
			{
				//alert("change(\'"+editids[i]+"\', \'nohighlight\')");
				change(editids[i], 'nohighlight');
			}
			sendRequest("saveh.php?param=0", none);
			rewr = false;
		} else {
			myReference.innerHTML = '<a href="javascript:;" class="pedit" id="aidh" onclick="change(\'aidh\', \'nohighlight\');turnHighlightOnOff(\'idh\');">Turn off highlighting</a>';
			for (i = 0; i < editids.length; i++)
			{
				change(editids[i], 'pedit');
			}
			sendRequest("saveh.php?param=1", none);
			rewr = true;
		}
		
	}
}

var clodiv = true;

function clDiv(divID_as_a_string) {
	var dC = clodiv ? '#ffffff' : '#D7FAE3'; clodiv = clodiv ? false : true;
	var myReference = getRefToDiv(divID_as_a_string);
	if( !myReference ) { window.alert('Nothing works in this browser'); return; }
	if( myReference.style ) { myReference = myReference.style; }
	if( typeof( myReference.background ) != 'undefined' ) { myReference.background = dC; } else {
		if( myReference.backgroundColor ) { myReference.backgroundColor = dC; } else {
			if( typeof( myReference.bgColor ) != 'undefined' ) { myReference.bgColor = dC; } else {
				window.alert('Nothing works in this browser'); return; } } }
}

function getRefToDiv(divID,oDoc) {
	if( document.getElementById ) { return document.getElementById(divID); }
	if( document.all ) { return document.all[divID]; }
	if( !oDoc ) { oDoc = document; }
	if( document.layers ) {
		if( oDoc.layers[divID] ) {
			return oDoc.layers[divID];
		} else {
			for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
				y = getRefToDiv(divID,oDoc.layers[x].document);
			}
			return y;
		}
	}
	return false;
}

function change(divID_as_a_string, newClass) {
	var myReference = getRefToDiv(divID_as_a_string);
	myReference.className=newClass;
}


function makeRequest(url)
{
	sendRequest(url, onResponse);
}

function sendRequest(url, callbackMethod)
{
	request = createRequestObject();
	request.onreadystatechange = callbackMethod;
	request.open("POST", url, true);
	request.send(url);
}

function createRequestObject()
{
	if(window.XMLHttpRequest)
	{
		obj = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		obj = new ActiveXObject("MSXML2.XMLHTTP");
	}
	return obj;
}

function checkReadyState(obj)
{
	if(obj.readyState == 0) { //document.getElementById('loading').innerHTML = "Sending Request..."; 
	}
	if(obj.readyState == 1) { //document.getElementById('loading').innerHTML = "Loading..."; 
	}
	if(obj.readyState == 2) { //document.getElementById('loading').innerHTML = "Loading..."; 
	}
	if(obj.readyState == 3) { //document.getElementById('loading').innerHTML = "Loading..."; 
	}
	if(obj.readyState == 4)
	{
		if(obj.status == 200)
		{
			//document.getElementById('loading').innerHTML = "";
			return true;
		}
		else
		{
			//document.getElementById('loading').innerHTML = "HTTP " + obj.status;
		}
	}
}

