var thedom = "http://mailboxconnection.info/";
var cntIMGs = 0;

function dopage(thepage,params,resdiv,restxt,noFade) {	
	new Ajax.Request(thepage, {
		  method: 'post',
		  evalScripts: true,
		  parameters: params,
		  onSuccess: function (res){
			if (resdiv!=""){
				if (restxt==""){restxt=res.responseText;}
				if (noFade=="1"){updDiv(resdiv,restxt);}else{updDiv(resdiv,restxt,1);}
			}
		}
	});
}

function dopageCh(deltxt,thepage,params,resdiv,restxt) {
	var answer = confirm("Are you sure you want to\npermanently Delete this "+deltxt)
	if (answer){dopage(thepage,params,resdiv,restxt);}else{return false;}
}

function theNav(thediv,thefile,params,cir,updr) { 
	if (cir!="1" && cir!= undefined){updDiv(thediv,'999');}
	if (updr!="" && updr!= undefined){updDiv(updr,'999');}
	new Ajax.Updater(thediv,thedom+'we/ajax/'+thefile+'.php', {
		method: 'post', evalScripts: true, parameters: params,
		onSuccess: function (res){if (updr!=""){updDiv(updr,'');}}
	});	
}

function theNav2(thediv,thefile,params,cir,updr) {
	if (cir!="1" && cir!= undefined){updDiv(thediv,'999');}
	if (updr!="" && updr!= undefined){updDiv(updr,'999');}
	new Ajax.Updater(thediv,thedom+thefile+'.php', {
		method: 'post', evalScripts: true, parameters: params,
		onSuccess: function (res){if (updr!=""){updDiv(updr,'');}}
	});	
}

function addDiv(xdiv,thetxt,theid){
	if (thetxt==999){thetxt="<img src='"+thedom+"/images/loading.gif'/>";}
	var newdiv = document.createElement("div");
	var thediv = $(xdiv);
	if (thetxt.match('</id>')){
		theid = thetxt.substr(4,thetxt.indexOf('</id>')-4);
		thetxt = thetxt.substr(thetxt.indexOf('</id>')+5);}
	newdiv.innerHTML = thetxt;		
	newdiv.id = "item_"+theid;
	thediv.appendChild(newdiv);	
	newdiv = null;
}
function updDiv(xdiv,thetxt,doFade){
	if (doFade==undefined){doFade=0;}
	if ($(xdiv)!=null){
		if (thetxt==999){thetxt="<img src='"+thedom+"/images/loading.gif'/>";}
		var newdiv = document.createElement("tag");
		var thediv = $(xdiv);
		while(thediv.firstChild){ thediv.removeChild(thediv.firstChild);}
		newdiv.innerHTML = thetxt;	
		thediv.appendChild(newdiv);
		if (doFade==1){
			Effect.Appear($(xdiv), {duration: .05});
			setTimeout("Effect.Fade('"+xdiv+"', {duration: 0.5})", 4000);
			$(xdiv).style.display=''; Effect.Appear(xdiv);
		}
		newdiv = null; thediv = null; 
	}
}
function delDiv(xdiv,theid){
	xdiv = $(xdiv);
	theid = $(theid);	
	Effect.Fade(theid, {duration: 0.5, afterFinish: function(){xdiv.removeChild(theid);} });
}
function chasect(xdiv,theurl,params){
	var thediv = "section_" + xdiv + "C";
	new Ajax.Updater(thediv,theurl, {
		method: 'post',
		evalScripts: true,
		parameters: params
	});	
}

function divTog(thediv) {
	if ($(thediv).style.display=="none"){	
		Effect.SlideDown($(thediv), {duration: .5});	
	}else{
		Effect.SlideUp($(thediv), {duration: .5});	
	}
}

function divFad(thediv,thecon) {
	Effect.Fade($(thediv), {duration: .5});
	setTimeout("Effect.Appear($('"+thecon+"'), {duration: .5})",500);
		
}

function goFade(thediv) {
	$(thediv).style.display="";
	setTimeout("Effect.Fade($('"+thediv+"'), {duration: 1})",5000);
		
}

function divSH(thediv) {
	if ($(thediv).style.display=="none"){	
		$(thediv).style.display="";
	}else{
		$(thediv).style.display="none";}
}

function div_S(thediv) { $(thediv).style.display=""; }
function div_H(thediv) { $(thediv).style.display="none"; }

function divSH2(thediv,chTxt) {
	if ($(thediv).style.display=="none"){	
		$(thediv).style.display="";
		if (chTxt){updDiv(chTxt,'(less info...)');}	
	}else{
		$(thediv).style.display="none";
		if (chTxt){updDiv(chTxt,'(more info...)');}
	}
}

function getCheckedValue(radioObj) {
	if(!radioObj) {return "";}
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked){
			return radioObj.value;
		}else{
			return "";}
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {return radioObj[i].value;}
	}
	return "";
}

function updRes(thediv,thetxt){
	div_S(thediv);
	updDiv(thediv,thetxt);
	goFade(thediv);
}

function stripHTML(thestr) {     
	return thestr.replace(/<\/?[^>]+>/gi, ""); 
}
function escapeHTML(thestr) {     
	return thestr.escapeHTML(); 
}


function chkImg(file) {
	extArray = new Array(".jpg", ".jpeg", ".gif");
    allowSubmit = false;
    if (!file){ return;}
    while (file.indexOf("\\") != -1)
    file = file.slice(file.lastIndexOf("\\") + 1);
    ext = file.slice(file.lastIndexOf(".")).toLowerCase();
    for (var i = 0; i < extArray.length; i++) {
    	if (extArray[i] == ext) { allowSubmit = true; break; }
    }
    if (allowSubmit){
		return true;
	}else{
		alert("Please only upload files that end in types:  "
		+ (extArray.join("  ")) + "\nPlease select a new "
		+ "file to upload and submit again.");
		return false;
	}
}
