
function encrypt(a) {
//var a = escape(form1.first.value); <!-- Get textbox1 string -->
var b = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ%@#$^&*()-_=+.:1234567890"; <!-- letters to compare to -->
var c = "zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA +=_-)(*&^$#@:.7359201486"; <!-- letter to change string to -->
var d;
var h;
var i;
var j = "";

var f = a.length; <!-- get length of the textbox1 string -->
var e = 0; 
var g = 1;

while (e != f) { <!-- while e is not equal to the string length loop --> 
	d = a.substring(e,g); <!-- get each letter in the text box -->
	h = b.indexOf(d); <!-- find that letter in var b -->
	i = c.charAt(h); <!-- change it to the letter in var c -->
	e++; <!-- add one to var e -->
	g++; <!-- add one to var g -->
	j += i; <!-- write out each letter -->
	}
	return(j)
//	form1.second.value = j; <!-- the final output put in textbox2 -->
}


function decrypt(aa) {
//var aa = form1.second.value;
var bb = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ%@#$^&*()-_=+.:1234567890";
var cc = "zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA +=_-)(*&^$#@:.7359201486";
var dd;
var hh;
var ii;
var jj = "";

var ff = aa.length;
var ee = 0; 
var gg = 1;

while (ee != ff) { 
	dd = aa.substring(ee,gg);
	hh = cc.indexOf(dd); <!-- just switch var b with c to unencode ex(h = b.indexOf(d); now  ='s hh = cc.indexOf(dd);)-->
	ii = bb.charAt(hh); <!-- just switch var c with b to unencode  -->
	ee++;
	gg++;
	jj += ii;
	}
	return(jj)
//	form1.second.value = jj;
}



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)
}


// vars for HTML entity conversion

fchars = "—,œ,®,©,«,»,µ,À,Á,Â,Ã,Ä,Å,Æ,Ç,È,É,Ê,Ë,Ì,Í,Î,Ï,Ñ,Ò,Ó,Ô,Õ,Ö,×,Ø,Ù,Ú,Û,Ü,à,á,â,ã,ä,å,æ,ç,è,é,ê,ë,ì,í,î,ï,ñ,ò,ó,ô,õ,ö,÷,ø,ù,ú,û,ü,ý,þ,ÿ,€"
hchars = "&mdash;,&#156;,&reg;,&copy;,&laquo;,&raquo;,&micro;,&Agrave;,&Aacute;,&Acirc;,&Atilde;,&Auml;,&Aring;,&AElig;,&Ccedil;,&Egrave;,&Eacute;,&Ecirc;,&Euml;,&Igrave;,&Iacute;,&Icirc;,&Iuml;,&Ntilde;,&Ograve;,&Oacute;,&Ocirc;,&Otilde;,&Ouml;,&times;,&Oslash;,&Ugrave;,&Uacute;,&Ucirc;,&Uuml;,&agrave;,&aacute;,&acirc;,&atilde;,&auml;,&aring;,&aelig;,&ccedil;,&egrave;,&eacute;,&ecirc;,&euml;,&igrave;,&iacute;,&icirc;,&iuml;,&ntilde;,&ograve;,&oacute;,&ocirc;,&otilde;,&ouml;,&divide;,&oslash;,&ugrave;,&uacute;,&ucirc;,&uuml;,&yacute;,&thorn;,&yuml;,&euro;"
cchars = "—,œ,®,©,«,»,µ,A,A,A,A,A,A,AE,C,E,E,E,E,I,I,I,I,N,O,O,O,O,O,X,O,U,U,U,U,a,a,a,a,a,a,ae,c,e,e,e,e,i,i,i,i,n,o,o,o,o,o,÷,ø,u,u,u,u,y,þ,y,€"




fchars = fchars.replace(/,/g,'","')
eval('fchars = new Array("'+fchars+'")')
hchars = hchars.replace(/,/g,'","')
eval('hchars = new Array("'+hchars+'")')
cchars = cchars.replace(/,/g,'","')
eval('cchars = new Array("'+cchars+'")')

//alert(fchars.length+'>'+hchars.length+'>'+cchars.length)


function htmlentities(tx){
	for(var i = 0 ; i < fchars.length; i++){
		rx  = new RegExp(fchars[i],"g")	
		tx = tx.replace(rx,hchars[i]); 	
	}
	
	//Fix apostrophes
//	rx  = new RegExp("'","g")		
//	tx = tx.replace(rx,"&#39;");
	
return(tx)
}

function removeaccents(tx){
	for(var i = 0 ; i < fchars.length; i++){
		rx  = new RegExp(fchars[i],"g")	
		tx = tx.replace(rx,cchars[i]); 	
	}
	
	//Fix apostrophes
	rx  = new RegExp("'","g")		
	tx = tx.replace(rx,"&#39;");
return(tx)
}


function accententities(tx){
	for(var i = 0 ; i < hchars.length; i++){
		rx  = new RegExp(hchars[i],"g")	
		tx = tx.replace(rx,fchars[i]); 	
	}
return(tx)
}

