
SiteDomain = "http://jetweedy.com";


// ------------------------------------------------------------------------------------


function submitWeblogComment(wei)
{

	tempurl = SiteDomain + "/weblog/weblog_ajax.php?action=submitWeblogComment&weblog_entry_id="+wei+"&weblog_comment_text="+document.getElementById('weblog_comment_text_'+wei).value+"&wortpruf="+document.getElementById('wortpruf_'+wei).value+"&todaysdate="+document.getElementById('todaysdate_'+wei).value+"&weblog_comment_email="+document.getElementById('weblog_comment_email_'+wei).value;

	aj = ajax("passive",tempurl,"");	
		
	cd = document.getElementById('weblogComments_'+wei);

	cd.innerHTML = aj;

	alert('Your comment has been submitted for moderation.');
	cd.style.display = "none";
	openWeblogCommentBox(wei);


}


function openWeblogCommentBox(wei)
{
	if (document.getElementById('weblogComments_'+wei))
	{	
		cd = document.getElementById('weblogComments_'+wei);
		if (cd.style.display=="block")
		{
			cd.innerHTML = "";
			cd.style.display = "none";
			document.getElementById('addCommentLink_'+wei).innerHTML = "Add Comment";
		}
		else
		{		
			tempurl = SiteDomain + "/weblog/weblog_ajax.php?action=openWeblogCommentBox&weblog_entry_id="+wei;
			aj = ajax("passive",tempurl,"");
			cd.innerHTML = aj;
			cd.style.display = "block";
			document.getElementById('addCommentLink_'+wei).innerHTML = "Close Comment Box";
		}
	}
}


// ------------------------------------------------------------------------------------


document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
};


function toggleDisplay(d,p,v)	// div/object; position anchor object; vertical offset
{
	
	
	var toggleItems = document.getElementsByClassName(document.getElementById(d).className);
	if (document.getElementById(d).className!="")
	{
		for (i=0;i<toggleItems.length;i++)
		{
			if (toggleItems[i].id!=d)
			{
				document.getElementById(toggleItems[i].id).style.display = "none";
			}
		}
	}
	
	if (document.getElementById(d))
	{
		if ((p)&&(v))
		{
			var posLeft = document.getElementById(p).offsetLeft;
			var posTop = document.getElementById(p).offsetTop + v;
			document.getElementById(d).style.left = posLeft.toString(10) + "px";
			document.getElementById(d).style.top = posTop.toString(10) + "px";
		}
		var dv = document.getElementById(d).style.display;
		if (dv=="none")
		{
			document.getElementById(d).style.display = "block";
		}
		else
		{
			document.getElementById(d).style.display = "none";
		}
	}
}

function toggleVisibility(d,p,v)	// div/object; position anchor object; vertical offset
{
	
	

	if (document.getElementById(d))
	{
		if ((p)&&(v))
		{
			var posLeft = document.getElementById(p).offsetLeft;
			var posTop = document.getElementById(p).offsetTop + v;
			document.getElementById(d).style.left = posLeft.toString(10) + "px";
			document.getElementById(d).style.top = posTop.toString(10) + "px";
		}
		var dv = document.getElementById(d).style.display;
		if (dv=="none")
		{
			document.getElementById(d).style.display = "block";
		}
		else
		{
			document.getElementById(d).style.display = "none";
		}
	}
}







function embedVideo(url,h,w)
{
	var r = "";
	r += "<embed class='embeddedVideo'";
	r += " src='" + url + "'";
	r += " autostart='false'";
	r += " loop='false'";
//	r += " height='"+h+"' width='"+w+"'";
	r += "></embed>";
	
	document.write(r);
}

function prevPic()
{
 currentPic = (currentPic-1);
 if (currentPic<0) { currentPic = (totalPics-1); } 
 document.getElementById('photoDiv').innerHTML = picArray[currentPic];
}

function nextPic()
{
 currentPic = (currentPic+1);
 if (currentPic>=totalPics) { currentPic = 0; } 
 document.getElementById('photoDiv').innerHTML = picArray[currentPic];
}



function updateSuggestion(id_f,id_v,name_f,name_v,clear_div)
{
 document.getElementById(id_f).value = id_v;	
 document.getElementById(name_f).value = name_v;	
 document.getElementById(clear_div).innerHTML = "";
}

/*
suggbox = (name) = the element ('this') whose value is being compared for suggestion
suggdiv = the id of the div that will be filled with the suggestions
valuefield = the actual value field (usually an id) that will be filled for form submission
tbl = name of table with data
tbl_displaycolumn --> tbl_dc = column that will be compared and displayed
tbl_valuecolumn --> tbl_vc = column that contains the value to be used in the form
*/
function suggestFromTable(suggbox,suggdiv,valuefield,tbl,tbl_displaycolumn,tbl_valuecolumn)
{
 var v = document.getElementById(suggbox).value;
 if (v!="")
 {
  var url = "http://jetweedy.com/ajax/suggest.php?v=" + v + "&valuefield=" + valuefield + "&suggbox=" + suggbox + "&suggdiv=" + suggdiv + "&tbl=" + tbl + "&tbl_dc=" + tbl_displaycolumn + "&tbl_vc=" + tbl_valuecolumn;
  ajax("active",url,suggdiv);
 }
}




function openHelp(x)
{
 window.open("http://jetweedy.com/helpfile.php?page="+x,"helpfile","height=400,width=400,resizable=1,scrolling=1,scrollbars=1");
}

function contactMe()
{
 alert('jetweedy@gmail.com');
}


function displayTagInterface()
{
 window.open("http://jetweedy.com/tag_interface.php","tag_interface","height=300,width=400,resizable=1,scrolling=1,scrollbars=1");
}

function openPic(p,n)
{
 window.open('http://jetweedy.com/pictures/'+p,n,'resizable=1, height=300px, width=300px');
}

function jetAdClick()
{
 alert('Test');
// window.open("http://jetweedy.com/jetAdClick.php","jetAdClick","height=400px, width=600px, left=50px, top=50px, resizable=1, scrolling=1, scrollbars=1");
}


function toggleFillDivChangeClass(d,c,t)
{
 if (document.getElementById(d).innerHTML=="")
 {
  fillDivChangeClass(d,c,t);
 } 
 else
 {
  fillDivChangeClass(d,c,"");
  document.getElementById(d).className = "";
 }
}

function fillDivChangeClass(d,c,t)
{
 document.getElementById(d).innerHTML = t;
 document.getElementById(d).className = c;
}

function toggleFillDiv(d,t)
{
 if (document.getElementById(d).innerHTML=="")
 {
  fillDiv(d,t);
 } 
 else
 {
  fillDiv(d,"");
 }
}

function fillDiv(d,t)
{
 document.getElementById(d).innerHTML = t;
}













function setCookie(name,value) {
	var v = ""+value;
	document.cookie = name+"="+escape(v);
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return false;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}








function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function gmailContact(d,t)
{
	var em = "<a href='mailto:" + t + "@gmail.com'>" + t + "@gmail.com</a>"
	document.getElementById(d).innerHTML = em;	
}

function contactEmail(d,t)
{
	var em = "<a href='mailto:" + t + "@protoglobe.com'>" + t + "@protoglobe.com</a>"
	document.getElementById(d).innerHTML = em;
}












/* -------------------- BEGIN AJAX FUNCTIONS --------------------------- */
var xmlHttp
var outputField;
// mode: 'active' or not (active causes a change in an ID'd div
// callScript: the backend script called to get info
// fieldID: the ID of the field whose innerHTML should be changed


/*----- SIMPLE AJAX ------------------------*/



function ajax(mode,callScript,fieldID)
{
 xmlHttp=GetXmlHttpObject();
 outputField = fieldID;
 var url = callScript;		// <-- defines the backend script location
 xmlHttp.onreadystatechange=emptyFunction;	// <-- (See below)
 xmlHttp.open("GET",url,false);
 xmlHttp.send(null);
 ajaxReturnValue = trim(xmlHttp.responseText);
 if (mode=="active")
 {
	document.getElementById(outputField).innerHTML = ajaxReturnValue;
 }
 return ajaxReturnValue;
}


function stateChanged() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
  document.getElementById(outputField).innerHTML=xmlHttp.responseText;
 }
} 



function emptyFunction()
{
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 

 }
}


function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
  {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
    // Internet Explorer
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}


/* -------------------- END AJAX FUNCTIONS --------------------------- */

