// alert for IE users
//if (document.all) alert("The IxDA Beta only works with Firefox and Safari. The full version will support Internet Explorer.");



// page navigation
	if (document.images) {
	//Deactivated Images
	img1out = new Image();
	img1out.src = "img/h_about_off.gif";
	
	img2out = new Image();
	img2out.src = "img/h_discussion_off.gif";
	
	img3out = new Image();
	img3out.src = "img/h_members_off.gif";
	
	img4out = new Image();
	img4out.src = "img/h_local_off.gif";
	
	img5out = new Image();
	img5out.src = "img/h_join_off.gif";	
	
	logoout = new Image();
	logoout.src = "img/logoixda_off.gif";
	
	
	//Activated Images
	img1over = new Image();
	img1over.src = "img/h_about_on.gif";

	img2over = new Image();
	img2over.src = "img/h_discussion_on.gif";
	
	img3over = new Image();
	img3over.src = "img/h_members_on.gif";
	
	img4over = new Image();
	img4over.src = "img/h_local_on.gif";
	
	img5over = new Image();
	img5over.src = "img/h_join_on.gif";	

	logoover = new Image();
	logoover.src = "img/logoixda_home.gif";


	//Selected Images
	img1click = new Image();
	img1click.src = "img/h_about_select.gif";

	img2click = new Image();
	img2click.src = "img/h_discussion_select.gif";
	
	img3click = new Image();
	img3click.src = "img/h_members_select.gif";
	
	img4click = new Image();
	img4click.src = "img/h_local_select.gif";
	
	img5click = new Image();
	img5click.src = "img/h_join_select.gif";	

	
	}



// Function to activate images
function imgOn(imgName) {
     if (document.images) {
     	
     	//if (imgName!=floater)
    	 document[imgName].src = eval(imgName + "over.src");
     	
     	//else
     	// document[imgName].src = eval(imgName + "click.src");
     }
}

// Function to deactivate images
function imgOff(imgName) {
     if (document.images) {
     
     	if (imgName!=floater)
     	document[imgName].src = eval(imgName + "out.src");
     }
}


var logoloop = false;

// Function to activate images
function logoOn(imgName) {
     if (document.images) {
         logoloop = true;
    	 startLogoLoop(1);
    	 //document[imgName].src = eval(imgName + "over.src");
     }
}

function startLogoLoop(ct) {
	if (logoloop) {
		if (ct < 25) {
			ct++;
			setTimeout("startLogoLoop("+ct+")",20);
		}
		else {
			document.logo.src = logoover.src;
		}
	}
}


// Function to deactivate images
function logoOff(imgName) {
     if (document.images) {
 	    logoloop = false;
     	document[imgName].src = eval(imgName + "out.src");
     }
}



// Function to deactivate images
function imgClick(imgName) {
	 // don't do anything onclick...
     if (document.images && false) {
     	document[imgName].src = eval(imgName + "over.src");
     	document[floater].src = eval(floater + "out.src");
     	
     	floater = imgName;
     }
}

var floater = "";



function doSearch(val) {

	if (val == "Search Archives...") {
		document.searchform.tag.value = "";	
		document.getElementById("search").style.color = "#333";
	}
}

function endSearch(val) {
	if (val == "" || val== " ") {
		document.searchform.tag.value = "Search Archives...";
		document.getElementById("search").style.color = "#888";	
	}
}


function doMemberSearch(val) {
	if (val == "Search Members...") {
		document.searchform.tag.value = "";	
		document.getElementById("search").style.color = "#333";
	}
}

function endMemberSearch(val) {
	if (val == "" || val== " ") {
		document.searchform.tag.value = "Search Members...";
		document.getElementById("search").style.color = "#888";	
	}
}





function donate() {
	document.payPalForm.submit()
}




function doLogin() {
	
	var thename = document.theform.name.value;
	var theemail = document.theform.email.value;
	
	if (thename.length<3 || theemail.indexOf("@") < 0) {
	
		if (thename.length<3 && theemail.indexOf("@"))
		msg = "Please enter your information and try again."
	
		else if (thename.length<3) msg = "Please enter your name.";
		else if (theemail.indexOf("@")<0) msg = "Please enter your e-mail address.";
		
		
		
		
		document.getElementById("error").innerHTML = msg + "<p>";
	}
	
	else {
		var loc = location.href;
		loc = loc.split("#");
		loc = loc[0];
		
		var anchor = ""; 
		if (loc.indexOf("discuss")>0) anchor = "#response";
		
		document.theform.action = loc + anchor;
		
		setTimeout("document.theform.submit()",50);
	}
}


function unsubscribeCheck() {

	var theemail = document.theform.email.value;
	
	if (theemail.length<3 || theemail.indexOf("@")<0) {
	
		if (theemail.length<3) msg = "Please enter your e-mail address.";
		else if (theemail.indexOf("@")<0) msg = "Please enter a valid e-mail address.";
		
		document.getElementById("error").innerHTML = msg + "<p>";
	}
	
	else {
	
		var loc = location.href;
		loc = loc.split("#");
		loc = loc[0];
	
		document.theform.action = loc;
		setTimeout("document.theform.submit()",50);
	}
	
}





function mark() {
	// this is a cosmetic function
	// it does nothing, but looks better
	// than using javascript:void()
}

function email() {
	// this is a cosmetic function
	// it does nothing, but looks better
	// than using javascript:void()
}


var doCheck = true;
function checkForEmail(elm) {

	if (document.theform[elm].value.indexOf("@")>0 && document.theform[elm].value.indexOf(".")>0) {
		var loc = location.href;
		loc = loc.split("#");
		loc = loc[0];
	
		document.theform.action = loc;// + "#response";
		doCheck = false;
	}
	else {
		document.theform.action = "javascript:doLogin()";
		doCheck = true;
	}
	if (doCheck) {
		setTimeout("checkForEmail('"+elm+"')",100);	
	}
	
}









function stopCheck() {
	doCheck = false;
}






function tagThread() {
	var gettag = prompt("Add tags for this thread","");
	
	if (gettag!=null && gettag!="") {
		if (gettag.indexOf(", ") > -1) {
			tags = gettag.split(", ");
			nospace=true;
		}
		else if (gettag.indexOf(",") > -1) {
			tags = gettag.split(",");
			nospace=true;
		}
		else {
			nospace = false;
			tags = gettag.split(" ");
		}
		
		existing = document.getElementById("taglist");
				
		addition = "";
		
		for (i=0; i<tags.length; i++) {
			if (nospace==true) {
				newtag = "";
				tag = tags[i].split(" ");
				for (n=0; n<tag.length; n++) {	
					newtag += tag[n];	
				}
				tags[i] = newtag;
			}
			tagArray.push(tags[i]);
		}
		
		for (i=0; i<tagArray.length; i++) {	
			addition += "<a href='search.php?tags="+tagArray[i].toLowerCase()+"'>" + tagArray[i].toLowerCase() + "<\/a>, ";	
		}	
		existing.innerHTML = addition;
		updateDatabase();
	}
}


function updateDatabase() {
addition = "";
for (i=0; i<tagArray.length; i++) {	
	addition += tagArray[i].toLowerCase();
	if (i<tagArray.length-1) addition += ",";	
}
//alert(addition);
updateServer(postid,addition)
}






doshow = true;
function showRSS() {
if (doshow) {
	j = document.getElementById("jobs");
	j.style.display = "block";
	
	p = document.getElementById("popular");
	p.style.display = "block";
	
	t = document.getElementById("topics");
	t.style.display = "block";
	
	f = document.getElementById("full");
	f.style.display = "block";
	doshow = false;
}
else {
	j = document.getElementById("jobs");
	j.style.display = "none";
	
	p = document.getElementById("popular");
	p.style.display = "none";
	
	t = document.getElementById("topics");
	t.style.display = "none";
	
	f = document.getElementById("full");
	f.style.display = "none";
	doshow = true;
}
	
	

}


var themark = "";

function addFavorite(post,parent,email,title) {
	id = "comment" + post;
	div = document.getElementById(id);
	
	if (div.className!="response_fav") {
		div.className="response_fav";
		document.getElementById("fvc"+post).innerHTML=" (1)";
		document.getElementById("marklabel"+post).innerHTML = "<em>Unmark</em> favorite";
		theaction = "favorite";
	}
	
	
	else {
		curcnt = document.getElementById("fvc"+post).innerHTML;
		if (curcnt==" (1)") {
			// you just hit the button again
			document.getElementById("fvc"+post).innerHTML="";
			document.getElementById("marklabel"+post).innerHTML = "Mark as favorite";
			div.className="response";
			theaction = "unfavorite";
		}
		else {
			curcnt*=1;
			curcnt++;
			if (themark!=post) {
				document.getElementById("fvc"+post).innerHTML = curcnt;
				theaction = "favorite";
			}
		}	
	}
	
	themark = post;
	flashfav(post);
	
	attr = "&parent="+parent+"&email="+email;
	updateServer(theaction,post,attr);

}



function setCategory(select) {
	var post = document.ixda.post.value;
	var cat = document.ixda.elements[select];
	var cgory = cat.options[cat.selectedIndex].value;

	if (cat.selectedIndex != 0) {

		attr = "&category="+cgory;
		updateServer("category",post,attr);

		
		cgory = cgory.toLowerCase();
	
		if (document.images)
		document.images.catimg.src = "img/pic_" + cgory + ".jpg";



	}

}







function flashfav(post) {
	id = "tools" + post;
	div = document.getElementById(id);
	
	div.className = "tools_fav";
	setTimeout("div.className = 'tools'",600);
}







function emailThread() {
	cancel();
	document.getElementById("emailThread").style.display = "block";
	document.emailThreadForm.recipient.focus();	
	
}


function addTag() {
	cancel();
	document.getElementById("addtag").style.display = "block";
	document.tagForm.tag.focus();	
}


function emailComment(id) {
	cancel();
	div = document.getElementById(id)
	div.style.display = "block";
	box = div.getElementsByTagName("input");
	box[0].focus();
	
}

function cancel() {
	divs = document.getElementsByTagName("div");
	for (i=0; i<divs.length; i++) {
		if (divs[i].className == "drawer") divs[i].style.display="none";
	}
}







doshow = true;
function showRSS() {
if (doshow) {
	j = document.getElementById("jobs");
	j.style.display = "block";
	
	p = document.getElementById("popular");
	p.style.display = "block";
	
	t = document.getElementById("topics");
	t.style.display = "block";
	
	f = document.getElementById("full");
	f.style.display = "block";
	doshow = false;
}
else {
	j = document.getElementById("jobs");
	j.style.display = "none";
	
	p = document.getElementById("popular");
	p.style.display = "none";
	
	t = document.getElementById("topics");
	t.style.display = "none";
	
	f = document.getElementById("full");
	f.style.display = "none";
	doshow = true;
}

}





function scanMail() {
		
	allmail = document.getElementsByTagName("dfn");
	
	for (i=0; i<allmail.length; i++) {
	
		replacemail = allmail[i].innerHTML;
		
		spt = replacemail.split(" | ");
		
		lbl = spt[0];
		lbl = lbl.replace(" at ","@");
		
		if (spt.length>1)
			replacemail = spt[1];
		else replacemail = lbl;
		
		replacemail = replacemail.replace(" at ","@");
		
		newmail = "<a class='link' href='mailto:"+replacemail+"'>" + lbl + "<\/a>";
		
		allmail[i].innerHTML = newmail;
	
	}	
	
}
