
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
ns6 = (document.getElementById) ? true:false

function layerWrite(id,nestref,text) {
	if (ns4) {
		var lyr = (nestref)? eval('document.'+nestref+'.document.'+id+'.document') : document.layers[id].document;
		lyr.open()
		lyr.write(text)
		lyr.close()
	}else if (ie4) document.all[id].innerHTML = text
	//else if (ns6) document.getElementById(id).innerHTML = text2
}



function popup(url,xtr) {
	window.open(url,'',xtr);
}

function erase(obj,msg) {
    if(confirm(msg)) {
        obj.submit();
    }
}

function selection(obj) {
	for(var i=0; i < obj.options.length; i++) {
		obj.options[i].selected = 1;
	}
}

function deltomenu(obj)
{
	if(obj.selectedIndex==-1) return false;
	if (obj.options.length < 1) return 0;

	var itemNo = obj.selectedIndex;
	obj.options[itemNo]=null;
}


function remove(objsource) {
	deltomenu(objsource)
}

function empty(obj) {
	obj.options[0].selected = 1
	if(obj.options[0].value=="") {
		deltomenu(obj);
	}
}

function reset(obj) {
	for(var i=0;;i++) {
    if(obj.options.length==0) break;
    obj.options[0].selected = 1
    var itemNo = obj.selectedIndex;
    obj.options[itemNo]=null;
  }
}

function moveUp(objsource) {
	if(objsource.selectedIndex==-1) return false;
	var pos = objsource.selectedIndex;
	var value = objsource[objsource.selectedIndex].value;
	var text  = objsource[objsource.selectedIndex].text;
	if(pos!=0) {
		var value2 = objsource[objsource.selectedIndex-1].value;
		var text2  = objsource[objsource.selectedIndex-1].text;
		objsource[objsource.selectedIndex-1].value = value;
		objsource[objsource.selectedIndex-1].text = text;
		objsource[objsource.selectedIndex].value = value2;
		objsource[objsource.selectedIndex].text = text2;
		objsource.selectedIndex = pos-1;
	}else
		objsource.selectedIndex = pos;
}

function moveDown(objsource) {
	if(objsource.selectedIndex==-1) return false;
	var pos = objsource.selectedIndex;
	var value = objsource[objsource.selectedIndex].value;
	var text  = objsource[objsource.selectedIndex].text;
	if(objsource.length!=pos+1) {
		var value2 = objsource[objsource.selectedIndex+1].value;
		var text2  = objsource[objsource.selectedIndex+1].text;
		objsource[objsource.selectedIndex+1].value = value;
		objsource[objsource.selectedIndex+1].text = text;
		objsource[objsource.selectedIndex].value = value2;
		objsource[objsource.selectedIndex].text = text2;
		objsource.selectedIndex =pos+1;
	}else
		objsource.selectedIndex =pos;
}

function addtomenuFromText(objsource,objdest) {
    if(objsource.value=='') return false;

	var value = objsource.value;
	var name  = objsource.value;

	//you have to make the item into an array to add to select box
	var opt = new Option(name, value);
	objdest.options[objdest.options.length]=opt;

}

function addtomenu(objsource,objdest)
{
	if(objsource.selectedIndex==-1) return false;

	var value = objsource[objsource.selectedIndex].value;
	var name  = objsource[objsource.selectedIndex].text;

	//you have to make the item into an array to add to select box
	var opt = new Option(name, value);
	objdest.options[objdest.options.length]=opt;
}


function addXmlOption(tagname,objsource1,attr1,objsource2,attr2,objdest)
{


  if(objsource1.type=='text') {
    var value1 = objsource1.value;
    var name1  = objsource1.value;
  } else {
    if(objsource1.selectedIndex==-1) return false;

    var value1 = objsource1[objsource1.selectedIndex].value;
    var name1  = objsource1[objsource1.selectedIndex].text;
  }

  if(objsource2.type=='text' || objsource2.type=='hidden') {
    var value2 = objsource2.value
    var name2= objsource2.value
  } else {
    if(objsource2.selectedIndex==-1) return false;
    var value2 = objsource2[objsource2.selectedIndex].value;
    var name2  = objsource2[objsource2.selectedIndex].text;
  }
	var xmlstr='<'+ tagname + ' ' + attr1 + '="' + value1 + '" ' + attr2 + '="' + value2 + '"/>';

  var name = name1 + ' (' + name2 + ')';

	//you have to make the item into an array to add to select box
	var opt = new Option(name, xmlstr);
	objdest.options[objdest.options.length]=opt;

}

function popupCenter(URL,width,height,xtr) {
  var top=(screen.height-height)/2;
  var left=(screen.width-width)/2;
  window.open(URL,"","top="+top+",left="+left+",width="+width+",height="+height+","+xtr);
}

function  formatDate(str) {
    val = str.split("/");
    if (val.length!=3) {
        return false;
    }
    str2= val[2]+ '-' + val[1] + '-' + val[0];
    return str2
}

/**
 * for the list
 */
function levelUp(obj) {
    var value = obj.options[obj.selectedIndex].value;
    window.location=link ="list.php?"+value;
}

/**
 * for the list
 */
function PopuplevelUp(obj) {
    var value = obj.options[obj.selectedIndex].value;
    window.location=link ="choose.php?"+value;
}

function addObject(obj) {
    var link="";
    var value = obj.options[obj.selectedIndex].value;
    if(value!="-1") {
        window.location=link ="view.php?action=add&grcltype="+value;
    }
}


var strColumns_Current = "215,*";
var TreeVisible=0;


function displayTree() {
	TreeVisible = (TreeVisible==1) ? 0 : 1;

	if(TreeVisible) {
      strColumns_Current = top.mainframeset.cols
      top.mainframeset.cols = "1,*";
      //top.contentbar.document.all("showtoc").style.display = "block";
	} else {
      top.mainframeset.cols = strColumns_Current;
      //top.contentbar.document.all("left").style.display = "none";
  }
}

function openMainarea(link,link2) {
    top.frames['mainarea'].location.href = link;
    if(link2!="") top.frames['left'].location.href = link2;
    if(TreeVisible) displayTree()
}

function getParam(name) {
  var dc = window.location.search;
	var prefix = name + "=";
	var begin = dc.indexOf("& " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin == -1) return null;
	}else
		begin += 2;
	 var end = dc.indexOf("&", begin);
	 if (end == -1) end = dc.length;
	 return unescape(dc.substring(begin + prefix.length, end));
}

function get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function set_Cookie (name, value, expires, path,domain) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "")
	};


function delete_Cookie(name,path,domain) {
    if (getCookie(name)) document.cookie = name + "=" +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "") +
        ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function ajouterFavoris() {
   if ( navigator.appName != 'Microsoft Internet Explorer' ) {
       window.sidebar.addPanel("RobertPapin.com","http://www.robertpapin.com/","");
   } else {
       window.external.AddFavorite("http://www.robertpapin.com/","RobertPapin.com");
   }
}
