

function writefile(fname,fpath,fdata){

	act = "/PHP/savefile.php"	
//	$filepath = $_GET['fpath'];
//	$filename = $_GET['fname'];
//	$filedata = $_GET['fdata'];

	filedata = fdata

	var ht=''
	ht+='\n<body onload="document.savefile.fdata.value=opener.filedata;document.savefile.submit()">'
	ht+='\n<font face=verdana size=2>Saving file: <b>'+fname+'</b></font><hr size=1>'
	ht+='\n<form name="savefile" action="'+act+'" method="post">'
	ht+='\n<input name="fpath" type="hidden" value="'+fpath+'">'
	ht+='\n<input name="fname" type="hidden" value="'+fname+'">'		
	ht+='\n<input name="fdata" type="hidden" value="">'
	ht+='\n<input style="font-family:verdana;font-size:11px;" type="button" value="Close" onclick="window.close()">'
	ht+='\n</form></body>'
	custwindow('createalbum',ht,350,150,50,50,0,'c')
}


// Custom window - SM (Conceptis Technologies)

function custwindow(wname,loc,wx,wy,px,py,typ,opt){

	var scrol='no';var resiz=0;var cent=0;var stat=0;
	if(!px){px=10;py=10}
	if(opt){
		if(opt.indexOf('r')!=-1){resiz=1}
		if(opt.indexOf('c')!=-1){cent=1}
		if(opt.indexOf('s')!=-1){scrol=1}
		if(opt.indexOf('t')!=-1){stat=1}
	}

	if(cent){
		var ww=screen.availWidth
		var wh=screen.availHeight
		px = Math.round((ww/2)-(wx/2))
		py = Math.round((wh/2)-(wy/2))
	}

	var isfile=true
	if(loc.indexOf(' ')!=-1){isfile=false}
	if(loc.indexOf('<')!=-1 && loc.indexOf('>')!=-1){isfile=false}

	if(typ==1){windowstr = 'fullscreen=yes'}

	else if(typ==2 && IE5){		// borderless window
		windowstr = 'fullscreen=1,width='+wx+',height='+wy+',scrollbars='+scrol+',center='+cent+',resizable='+resiz
		eval(wname+'=window.open("","",windowstr)')
		eval(wname+'.moveTo(5000,0)')
		eval(wname+'.resizeTo(wx,wy)')
		if(isfile){eval(wname+'.document.location=loc')}
		else{
			eval(wname+'.document.write(styleref)')
			eval(wname+'.document.write(loc)')
			eval(wname+'.document.close()')
		}
		eval(wname+'.moveTo(px,py)')
		return
	}

	else if(typ==3 && IE5){		// Modal window
		windowstr = 'dialogHeight:'+wy+'px;dialogWidth:'+wx+'px;edge:Sunken;center:'+cent+';help:0;resizable:'+resiz+';status:0;unadorned:0;dialogTop:'+py+'px;dialogLeft:'+px+'px;'
		if(isfile){eval(wname+'=showModelessDialog(loc,window,windowstr)')}
		else{
			eval(wname+'=showModelessDialog("",window,windowstr)')
			eval(wname+'.document.write(styleref)')
			eval(wname+'.document.write(loc)')
			eval(wname+'.document.close()')
		}
		return
	}

	else{windowstr = '"toolbar=no,width='+wx+',height='+wy+',directories=no,status='+stat+',scrollbars='+scrol+',center='+cent+',resizable='+resiz+',menubar=no,screenX='+px+',screenY='+py+',left='+px+',top='+py+'"'}

	if(typ==4){void(window.open(loc,'DME',windowstr));return}

	else{
		if(isfile){eval(wname+'= window.open(loc,wname,windowstr)');}
		else{
//			if(!window[wname]){
			eval(wname+'= window.open("",wname,windowstr)');
//			}
//			eval(wname+'.document.write(styleref)')
			eval(wname+'.document.write(loc)')
			eval(wname+'.document.close()')
		}
	}
	eval(wname+'.focus()')
}

function getarg(str){
 	str += "="
 	var srcString = unescape(location.search)
	if(srcString.indexOf(str)==-1){return('')}
 	var srcStrLen = srcString.length
 	var toExtractLen = str.length
 	var searchStart = srcString.indexOf(str) + toExtractLen
 	var result = ""
 	var compteur = searchStart
 	while (compteur < srcStrLen && srcString.substring(compteur,compteur+1) != "&"){
 		result += srcString.substring(compteur,compteur+1)
 	 	compteur++
 	}
	return result
}

function getCookie(name){
	var cname = name + "=";
	var dc = document.cookie;
    	if (dc.length > 0){
    		begin = dc.indexOf(cname);
        	if (begin != -1){
        		begin += cname.length;
        		end = dc.indexOf(";", begin);
            		if (end == -1){end = dc.length}
            		return unescape(dc.substring(begin, end));
        	}
    	}
return ''
}

function setCookie(name, value) {
	var now = new Date();
	var then = new Date(now.getTime() + 31536000000);
	document.cookie = name + "=" + escape(value) +
	"; expires=" + then.toGMTString() + "; path=/";
}

function getcookValue(element){return(getCookie(element.name))}
function getValue(element){var value = getCookie(element.name);if(value){element.value = value}}
function setValue(element){if(element.value){setCookie(element.name, element.value)};}


function getpagedims(){     

	windowsize()

	if (window.innerHeight && window.scrollMaxY) {
		// Firefox         
		pageh = window.innerHeight + window.scrollMaxY;         
		pagew = window.innerWidth + window.scrollMaxX;     

	} 
	else if (document.body.scrollHeight > document.body.offsetHeight){ 
		// all but Explorer Mac         
		pageh = document.body.scrollHeight;         
		pagew = document.body.scrollWidth;     } 
	else { 
	// works in Explorer 6 Strict, Mozilla (not FF) and Safari         
		pageh = document.body.offsetHeight;         
		pagew = document.body.offsetWidth;       }     

} 


function windowsize() {
  winw = 0, winh = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    winw = window.innerWidth;
    winh = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    winw = document.documentElement.clientWidth;
    winh = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    winw = document.body.clientWidth;
    winh = document.body.clientHeight;
  }
//  window.alert( 'Width = ' + winw );
//  window.alert( 'Height = ' + winh );
}


function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }


function ahah(url, target) {
  document.getElementById(target).innerHTML = ' <div style="text-align:center;width:100%;margin-top:50px;"><img src="/images/loading.gif"></div>';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {ahahDone(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}  

function ahahDone(url,target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
  	if(target=="maintext"){scrollTo(0,0)}
    } else {
      document.getElementById(target).innerHTML="Error:\n"+ req.status + "\n" +req.statusText;
    }
  }

}

function loadp(name,div) {
	ahah(name,div);
	return false;
}


function loadjs(file,callback) {
	
//alert(file+' >> '+callback)	
	loaded=0
	var html_doc = document.getElementsByTagName('head')[0];
	js = document.createElement('script');
	js.setAttribute('type', 'text/javascript');
	js.setAttribute('src', file);
	html_doc.appendChild(js);

	readystates = 'loaded,complete'

	js.onreadystatechange = function () {
//    		alert(js.readyState)
  	      	if(readystates.indexOf(js.readyState)!=-1 && callback) {
        	   eval(callback)
        	   loaded=1
        	}
    	}

	js.onload = function () {
//alert('js.onload')		
		if(callback){eval(callback)}
		loaded=1
	}
return false;
}

function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

