//_____________________________________________________________________________
function checkname(){
    pattern = /^[A-Za-z_0-9.]*$/;
    var first=document.myform.fld.value.substring(0,1);
    numbers='0123456789';
    var test=(pattern.test(document.myform.fld.value)) && (numbers.indexOf(first)<0);
    if(test==false){
        alert("Please, use only ( _ ), (A-Z), (a-z), (0-9) .\nFirst letter can't be a number");
		n=document.myform.fld.value.length;
		document.myform.fld.value="";
        document.myform.fld.focus();
    }
}
//______________________________________________________________________________
function jSubmit(){
	document.myform.submit();
}
//_____________________________________________________________________________
function clearForm() {
	var elements = document.getElementById('myform').elements;
	for(i=0; i<elements.length; i++) {
		field_type = elements[i].type.toLowerCase();
		switch(field_type) {
			case "text":
			case "password":
			case "textarea":
			case "hidden":
				elements[i].value = "";
				break;
			case "radio":
			case "checkbox":
				elements[i].checked = false;
				break;
			case "select-one":
			case "select-multi":
				elements[i].selectedIndex = -1;
				break;
			default:
				break;
		}
	} 	
}
//_____________________________________________________________________________
function showMe(){
	obj=document.getElementById('mask');
	obj.style.display="none";	
	obj=document.getElementById('main');
	obj.style.display="";
}
//_____________________________________________________________________________
function doLinkF(s,p,nbpp,o){
	w=document.getElementById('w').value;
	fld=document.getElementById('fld').value;
	window.location="?"+s+"&p="+p+"&nbpp="+nbpp+"&w="+w+"&fld="+fld+"&o="+o;
}
//_____________________________________________________________________________
function Toogle_ul(obj){
	uls=obj.getElementsByTagName('ul');
	ul=uls[0];
	ul.style.display=ul.style.display=='none'?'':'none';
}
//_____________________________________________________________________________
function Toggle(id){
	o=document.getElementById(id);
	o.style.display=o.style.display=='none'?'':'none';
}
//_____________________________________________________________________________
function BigOne(obj){
	//obj.className="BigOne";
	src=obj.src.replace('_small','');
	window.open(src);
}
//_____________________________________________________________________________
function gotoTab(obj){
	var sel=parseInt(obj.id.replace("div_",""));
	i=0;
	while(document.getElementById("div_"+i)){
		document.getElementById("div_"+i).className="tab";
		document.getElementById("content_"+i).style.display="none";
		i++;
	}
	document.getElementById(obj.id).className="tabdown";
	document.getElementById("content_"+sel).style.display="";
	jSetTab(sel);
}
//_____________________________________________________________________________
function jSetTab(tab){
    document.getElementById('tab').value=tab;
}
//_____________________________________________________________________________
function show_hide(div0,Check){
    if(Check.checked==true) show(eval(div0)); else hide(eval(div0));
}
//_____________________________________________________________________________
function hide(div0){
    div0.style.display="none";
    div0.visibility="hide";
}
//_____________________________________________________________________________
function show(div0){
    div0.style.display="";
    div0.visibility="show";
}
//_____________________________________________________________________________
function editIt(field){
    arg=field+"";
    var sel=ow("wysiwyg.php","WYSIWYG",630,430); 
    if (window.navigator.appVersion.indexOf("MSIE")!=-1){
        if(sel != null) field.value=sel;
    }
}
//_____________________________________________________________________________
function getTitle(val1,val2){
	val2.value=val1.options[val1.selectedIndex].innerHTML;
}
//_____________________________________________________________________________
function changeClass(id,val){
	cl=val.options[val.value-1].innerText;
	if(cl=='none') cl='tdr';
	document.getElementById(id).className=cl;
}
//_____________________________________________________________________________
function jUpdate(_id){
    jSetMode("");
    jSetId(_id);
    jSubmit();
}
//_____________________________________________________________________________
function jCopy(_id){
    jSetMode("c");
    jSetId(_id);
    jSubmit();
}
//_____________________________________________________________________________
function jAdd(){
	clearForm();
	jSetTab(1);	
    jSetMode("");
    jSetId("");
    jSubmit();
}
//_____________________________________________________________________________
function jDelete(_id){
    if (!confirm("Are you sure you want to delete this record?")) return false;
    jSetMode("x");
    jSetId(_id);
    jSubmit();
}
//_____________________________________________________________________________
function jSetId(_id){	
    document.getElementById("_id").value=_id;
}
//_____________________________________________________________________________
function jSetMode(_mode){
    document.getElementById("mode").value=_mode;
}
//_____________________________________________________________________________
function jSetLink(_link){
    document.getElementById("tmp_link").value=_link;
}
//_____________________________________________________________________________
function fm_RemoveFromLinks(list){
	var link=list.value;
	jSetMode('l');
	jSetLink(link);
	jSubmit();
}
//_____________________________________________________________________________
function treeIt(field){
    arg=field;
    var sel=showModalDialog("tree.php","Browse","dialogWidth:"+295+"px;dialogHeight:"+400+"px;resizable:no;help:no;status:Off;scroll:yes;center:yes;"); 
    if (window.navigator.appVersion.indexOf("MSIE")!=-1){
        if(sel != null) field.value+=sel+"\n";
    }
}
//_____________________________________________________________________________
function openWindow(url,width,height) {
	var myWindow;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status=no,scrollbars=yes,location=no,menubar=no,resizable=no,titlebar=no,toolbar=no,left=" + left + ",top=" + top + ",screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "Search", windowFeatures);
	myWindow.focus();
}
//_____________________________________________________________________________
function openWindowNS(url,width,height) {
	var myWindow;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status=no,scrollbars=no,location=no,menubar=no,resizable=no,titlebar=no,toolbar=no,left=" + left + ",top=" + top + ",screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "Search", windowFeatures);
	myWindow.focus();
}
//_____________________________________________________________________________
function ow(url,title,width,height){
	sel=window.open(url,title,"width="+width+"px,height="+height+"px,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
	sel.focus();
}
//_____________________________________________________________________________
function calIt(field){
	arg=field;
	ow('cal.html','Calendar',200,214);
}
//_____________________________________________________________________________
function streeIt(field){
    arg=field;
    var sel=showModalDialog("itree.php","Browse","dialogWidth:"+450+"px;dialogHeight:"+400+"px;resizable:no;help:no;status:Off;scroll:yes;center:yes;"); 
    if (window.navigator.appVersion.indexOf("MSIE")!=-1){
        if(sel != null) field.value=sel;
    }
}
//_____________________________________________________________________________
if (typeof window.showModalDialog == 'undefined'){
    window.showModalDialog = function(sURL, vArguments, sFeatures){
        if (sFeatures==null||sFeatures=='') sFeatures=dFeatures;
        aFeatures = sFeatures.split(";");
        sWinFeat = "directories=0,menubar=0,titlebar=0,toolbar=0,dependent=1,";
        for ( x in aFeatures ){
            aTmp = aFeatures[x].split(":");
            sKey = aTmp[0].toLowerCase();
            sVal = aTmp[1];
            switch (sKey) {
                case "dialogheight":
                    sWinFeat += "height="+sVal+", "; pHeight = parseInt(sVal.replace("px","")); break;
                case "dialogwidth":
                    sWinFeat += "width="+sVal+", "; pWidth = parseInt(sVal.replace("px","")); break;
                case "dialogtop":
                    sWinFeat += "screenY="+sVal+", "; break;
                case "dialogleft":
                    sWinFeat += "screenX="+sVal+", "; break;
                case "resizable":
                    sWinFeat += "resizable="+sVal+", "; break;
                case "status":
                    sWinFeat += "status="+sVal+", "; break;
                case "scroll":
                    sWinFeat += "scrollbars="+sVal+", "; break;
                case "center":
                    if ( sVal.toLowerCase() == "yes" )  {
                        sWinFeat += "screenY="+((screen.availHeight-pHeight)/2)+", ";
                        sWinFeat += "screenX="+((screen.availWidth-pWidth)/2)+", ";
                    }
                    break;
            }
        }
        modalWin=window.open(String(sURL),"win",sWinFeat);
        if (vArguments!=null&&vArguments!=''){
            modalWin.dialogArguments=vArguments;
        }
    }
}   
//_____________________________________________________________________________
function setAlbum(id,nom) {
	document.myform.album.value=id;
	document.myform.album1.value=nom;
	jSetMode('');
	jSetId('');
	jSubmit();
}
//___________________________________________________________________________________
function addCatRow(tid){
	tbl=document.getElementById(tid);
	idx=tbl.rows.length-1;
	elems=new Array();
	elems[0]="<select name='c1_description[]'></select>";
	elems[1]="<input name='c1_prix1[]' type='text'>";
	elems[2]="<input name='c1_prix2[]' type='text'>";
	elems[3]="<input name='c1_rang[]' type='text'>";
	elems[4]="<a href='javascript:Nothing()'><img onclick=\"javascript:removeRow('"+tid+"',this)\" src='../icons1/del.gif' border='0' align='absmiddle'></a>";
	newRow=addRow(tid,elems,idx);
	spans = newRow.getElementsByTagName('SELECT');
	sel=spans[0];
	sel.options.length = 0;
	for(j=0;j<cats.length;j++){
		sel.options[j] = new Option(cats[j][2], cats[j][0], false, false);		
	}
}
//___________________________________________________________________________________
function addOptRow(tid){
	tbl=document.getElementById(tid);
	idx=tbl.rows.length-1;
	elems=new Array();
	elems[0]="<select name='c2_description[]'></select>";
	elems[1]="<input name='c2_prix[]' type='text'>";
	elems[2]="<input name='c2_rang[]' type='text'>";
	elems[3]="<a href='javascript:Nothing()'><img onclick=\"javascript:removeRow('"+tid+"',this)\" src='../icons1/del.gif' border='0' align='absmiddle'></a>";
	newRow=addRow(tid,elems,idx);
	spans = newRow.getElementsByTagName('SELECT');
	sel=spans[0];
	sel.options.length = 0;
	for(j=0;j<opts.length;j++){
		sel.options[j] = new Option(opts[j][2], opts[j][0], false, false);		
	}
}
//___________________________________________________________________________________
function addWrkRow(tid){
	tbl=document.getElementById(tid);
	idx=tbl.rows.length-1;
	elems=new Array();
	elems[0]="<select name='c3_description[]'></select>";
	elems[1]="<input name='c3_prix1[]' type='text'>";
	elems[2]="<input name='c3_prix2[]' type='text'>";
	elems[3]="<input name='c3_rang[]' type='text'>";
	elems[4]="<a href='javascript:Nothing()'><img onclick=\"javascript:removeRow('"+tid+"',this)\" src='../icons1/del.gif' border='0' align='absmiddle'></a>";
	newRow=addRow(tid,elems,idx);
	spans = newRow.getElementsByTagName('SELECT');
	sel=spans[0];
	sel.options.length = 0;
	for(j=0;j<wrks.length;j++){
		sel.options[j] = new Option(wrks[j][2], wrks[j][0], false, false);		
	}
}
//___________________________________________________________________________________
function addChambreRow(tid){
	tbl=document.getElementById(tid);
	idx=tbl.rows.length-1;
	elems=new Array();
	elems[0]="<select name='c4_type[]'></select>";
	elems[1]="<input name='c4_prix[]' type='text'>";
	elems[2]="<input name='c4_rang[]' type='text'>";
	elems[3]="<a href='javascript:Nothing()'><img onclick=\"javascript:removeRow('"+tid+"',this)\" src='../icons1/del.gif' border='0' align='absmiddle'></a>";
	newRow=addRow(tid,elems,idx);
	spans = newRow.getElementsByTagName('SELECT');
	sel=spans[0];
	sel.options.length = 0;
	for(j=0;j<chambres.length;j++){
		sel.options[j] = new Option(chambres[j][1], chambres[j][0], false, false);		
	}
}
//___________________________________________________________________________________
function addRow(tid,elems,idx){
	tbl=document.getElementById(tid);
	var newRow = tbl.insertRow(idx);
	j=newRow.rowIndex;
	for(var i=0; i<elems.length; i++){
		var oCell = newRow.insertCell(i);
		oCell.innerHTML = elems[i];
	}
	return newRow;
}
//_____________________________________________________________________________
function removeRow(tid,src){
	row=src.parentNode.parentNode.parentNode;
	spans = row.getElementsByTagName('INPUT');
	id=0;
	if(spans.length){
		for(k=0;k<spans.length;k++){
			if(spans[k].name.indexOf('_id')>=0){
				id=spans[k].value;
				parts=spans[k].name.split('_');
				t=parts[0].replace('c','');
				break; 
			}
		}
	} 
    if (id>0 && confirm("Are you sure you want to delete this record?")){
		url="conf/delete.php?t="+t+"&_id="+id;
		ow(url,"Delete",200,200);
		id=0;
	}
	if(id==0) document.getElementById(tid).deleteRow(row.rowIndex); 
}
//_____________________________________________________________________________
function Nothing(){
	return;
}
//_____________________________________________________________________________
function bank_transfer(obj){
	document.getElementById("div_transfer").style.display=(obj.value==1?"":"none");
}
//_____________________________________________________________________________
function reload(id){
	im=document.getElementById(id);
	i=Math.random();
	im.src="captcha.php?i="+i;
}
//_____________________________________________________________________________
function hideParent(src){
	o=src.parentNode;
	o.style.display='none';	
}
//_____________________________________________________________________________
function restore(){
	Toggle("div_h");
	Toggle("small_logo");
	head=document.getElementById("div_h").style.display=='none'?0:1;
	window.open("config.php?head="+head);
}
//_____________________________________________________________________________
