
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_old(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML=" AHAH Error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}

function ahahDone(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
    
    resp = req.responseText.substring(req.responseText.indexOf('\''),req.responseText.lastIndexOf('\''))
      document.getElementById(target).innerHTML = resp
    } else {
      document.getElementById(target).innerHTML=" AHAH Error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}



function loadp(name, div) {
	ahah(name,div);
	return false;
}

function initsite(){
	loadp('http://convert.rss-to-javascript.com/?simple_chan=1&src=http%3A%2F%2Ffeeds.bbc.co.uk%2Fweather%2Ffeeds%2Frss%2F5day%2Fworld%2F0524.xml&target=_blank','weather')
	loadp('http://convert.rss-to-javascript.com/?simple_chan=1&src=http%3A%2F%2Fwww.surfline.com%2Frss%2Fregion.cfm%3Falias%3Dhermosacrcam&target=_blank','surf')	

//	loadp('http://feeds.bbc.co.uk/weather/feeds/rss/5day/world/0524.xml','weather')
//	loadp('http://www.surfline.com/rss/region.cfm?alias=hermosacrcam','surf')	


}

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)};}

