
var SiteDomain = "http://protoglobe.com";

// ----------------------------------------------------------------------------------




function rotateAlbumPhoto(folderName, imageFile, imageID, rotation)
{
	url = "ajax/album.php?action=rotateAlbumImage&folder=" + folderName + "&imageFile=" + imageFile + "&rotation="+rotation;
//	document.getElementById('debug').innerHTML = "Please wait...";
	tempMsg = "Please wait...";
	tempMsg = ajax("active",url,"debug");
	while(tempMsg=="Please wait...") { }
	newImgSource = SiteDomain + "/album/" + folderName + "/thumbs/" + imageFile;
	document.getElementById(imageID).src = newImgSource + "?" + Math.random();
//	document.getElementById('debug').innerHTML = "";
}




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 cssHasClass(d,c)
{
	if (!(d.className)) { d.className = ""; }
	var dc = d.className.split(" ");
	for (var i=0;i<dc.length;i++)
	{
		if (dc[i]==c)
		{
			return true;
		}
	}
	return false;
}

function cssAddClass(d,c)
{
	cssRemoveClass(d,c);
	d.className = trim(d.className + " " + c);
}

function cssRemoveClass(d,c)
{

	var cn = "" + d.className;
	if ( (cn=="undefined") )
	{
		cn = "";
	}
	var dc = cn.split(" ");
	cn = "";
	for (var i=0;i<dc.length;i++)
	{
		if (dc[i]!=c)
		{
			cn += (" " + dc[i]);
		}
	}

	try
	{
		d.className = trim(cn);
	}
	catch(err)
	{
//		document.getElementById("debug").innerHTML = "(test): " + err + "<hr />";
		try
		{
			d.setAttribute("class",trim(cn));
		}
		catch(err)
		{
	//		document.getElementById("debug").innerHTML = "(test): " + err + "<hr />";
		}
	}


}



// ----------------------------------------------------------------------------------





// ----------------------------------------------------------------------------------

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 exitFB()
{
	if (confirm("Are you sure you want to log out of Facebook? Your Facebook user account will no longer be recognized, and you'll need to create a separate account on the site."))
	{
		self.location.replace("index.php?action=nofb");
	}
}

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 yahooContact(d,t)
{
	var em = "<a href='mailto:" + t + "@yahoo.com;'>" + t + "@yahoo.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;
}



/*
divContent = new Array();
divContent['someDivID'] = "";

togglerTexts = new Array();
togglerTexts[0] = new Array();
togglerTexts[1] = new Array();
togglerTexts[0]['faqDiv'] = "Click here to open";
togglerTexts[1]['faqDiv'] = "Click here to close";

setTimeout("toggleVisibility('faqDiv')",100);

*/




function updateGuideSavedPlaceOrder(gspid)
{
	var gspo = document.getElementById('GuideSavedPlaceOrder_'+gspid).value;
//	alert(gspid + " | " + gspo);
	var u = "http://protoglobe.com/ajax/guides.php?action=updateGuideSavedPlaceOrder&gspo="+gspo+
	"&gspid="+gspid;
	var d = "gspoConfirmation_"+gspid;	
	var v =	ajax('get',u,'');
}

function saveGuidePlace(gpid)
{
	
	gsname = "";
	gsid = document.getElementById('GuideSaved_'+gpid).value;
	if (gsid==0)
	{
		gsname = prompt("Please name your new guide:");
	}
	
	if ( (gsid > 0) || ((gsname!="null") && (trim(gsname)!="")) )
	{
	
		var m = ajax('get','http://protoglobe.com/ajax/guides.php?action=saveGuidePlace&gsname='+gsname+'&gsid='+gsid+'&gpid='+gpid,'');

		alert(m);
		if ((gsid==0)&&(m!="Sorry, that guide name is already taken."))
		{
			window.location.reload();
		}

	}


}




function saveTransportNotes(g,a,b,n,dbd)
{
	ajax('active','http://protoglobe.com/ajax/guides.php?action=saveTransportNotes&gid='+g+'&placeA='+a+'&placeB='+b+'&tNotes='+n,dbd);
	alert("Saved");
}








function openGuide(gsid)
{
	document.getElementById('savedGuidePlaceList').innerHTML = "Please wait...";
	aj = ajax('get','http://protoglobe.com/ajax/guides.php','action=openGrabbedPlaces&gsid='+gsid);	
	document.getElementById('savedGuidePlaceList').innerHTML = aj;
}


function removeGrabbedPlace(gspid,gsid)
{
	document.getElementById('savedGuidePlaceList').innerHTML = "Please wait...";
	aj = ajax('get','http://protoglobe.com/ajax/guides.php','action=removeGrabbedPlace&gspid='+gspid+'&gsid='+gsid);
	document.getElementById('savedGuidePlaceList').innerHTML = aj;

}


function moveGrabbedPlaceUp(posnum)
{
	document.getElementById('savedGuidePlaceList').innerHTML = "Please wait...";
	aj = ajax('get','http://protoglobe.com/ajax/guides.php','action=moveGrabbedPlaceUp&posnum='+posnum);
	document.getElementById('savedGuidePlaceList').innerHTML = aj;
}

function moveGrabbedPlaceDown(posnum)
{
	document.getElementById('savedGuidePlaceList').innerHTML = "Please wait...";
	aj = ajax('get','http://protoglobe.com/ajax/guides.php','action=moveGrabbedPlaceDown&posnum='+posnum);
	document.getElementById('savedGuidePlaceList').innerHTML = aj;
}









function closeTransportDiv(g,a,b)
{
	document.getElementById('transportText_'+b).innerHTML = "";
	document.getElementById('transportToggler_'+b).innerHTML = "<a href='javascript:;' onclick='openTransportDiv("+g+","+a+","+b+")'>[Open Transportation Notes]</a>";
}

function openTransportDiv(g,a,b)
{
	document.getElementById('transportToggler_'+b).innerHTML = "<a href='javascript:;' onclick='closeTransportDiv("+g+","+a+","+b+")'>[Close Transportation Notes]</a>";
	ajax('active','http://protoglobe.com/ajax/guides.php?action=openTransportDiv&gid='+g+'&placeA='+a+'&placeB='+b,'transportText_'+b);

}







function closeDirectionsDiv(dcount,gpid,originLat,originLong,destLat,destLong,originAddress,destAddress)
{
	document.getElementById('directionsMap_'+dcount).innerHTML = "";
	document.getElementById('directionsText_'+dcount).innerHTML = "";
	document.getElementById('directionsMap_'+dcount).style.height="0px";
	document.getElementById('directionsMapToggler_'+dcount).innerHTML = "<a href=\"javascript:openDirectionsDiv("+dcount+","+gpid+",'"+originLat+"','"+originLong+"','"+destLat+"','"+destLong+"','"+originAddress+"','"+destAddress+"');\">[Open Directions]</a>";
}

function openDirectionsDiv(dcount,gpid,originLat,originLong,destLat,destLong,originAddress,destAddress)
{

	document.getElementById('directionsMapToggler_'+dcount).innerHTML = "<a href=\"javascript:closeDirectionsDiv("+dcount+","+gpid+",'"+originLat+"','"+originLong+"','"+destLat+"','"+destLong+"','"+originAddress+"','"+destAddress+"');\">[Close Directions]</a>";
	document.getElementById('directionsMap_'+dcount).style.height="600px";

	var dmap;
	var dmapPanel;
	var directions;
	dmap = new GMap2(document.getElementById('directionsMap_'+dcount));
//	dmap.setCenter(new GLatLng(originLat,originLong), 15);


	var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
	dmap.addControl(new GMapTypeControl(), topRight);
	dmap.addControl(new GLargeMapControl());
	
	

	dmapPanel = document.getElementById('directionsText_'+dcount);
	directions = new GDirections(dmap, dmapPanel);

	if ((destLat=="")||(destLong==""))
	{
		directions.load(originAddress+" to "+destAddress);	
	}
	else
	{
		directions.load(originLat+","+originLong+" to "+destLat+","+destLong);
	}

}



function verifyReturnMapCoordinates(f_lat,f_long,c_lat,c_long)
{
	if (confirm("Return these coordinates?: " + c_lat + "," + c_long))
	{
		returnMapCoordinates(f_lat,f_long,c_lat,c_long);
	}
}

function returnMapCoordinates(f_lat,f_long,c_lat,c_long)
{
	window.opener.document.getElementById(f_lat).value = c_lat;
	window.opener.document.getElementById(f_long).value = c_long;
	window.close();
}

function getMapCoordinates(updateField_lat,updateField_long)
{
	window.open(SiteDomain + "/gCoordsGet.php?updateField_lat="+updateField_lat+"&updateField_long="+updateField_long,"getMapCoordinates","height=400px, width=500px");	
}


















function closeMapDiv(mDivID,gHeight,gWidth,gZoom,gCoords_latitude,gCoords_longitude)
{
	document.getElementById("mapToggle_"+mDivID).innerHTML = "<a href=\"javascript:openMapDiv('"+mDivID+"','"+gHeight+"','"+gWidth+"','"+gZoom+"','"+gCoords_latitude+"','"+gCoords_longitude+"');\">[Open Map]</a>";
	document.getElementById("mapDiv_"+mDivID).innerHTML = "";
}
function openMapDiv(mDivID,gHeight,gWidth,gZoom,gCoords_latitude,gCoords_longitude)
{
	document.getElementById("mapToggle_"+mDivID).innerHTML = "<a href=\"javascript:closeMapDiv('"+mDivID+"','"+gHeight+"','"+gWidth+"','"+gZoom+"','"+gCoords_latitude+"','"+gCoords_longitude+"');\">[Close Map]</a>";
	aj = ajax("get","http://protoglobe.com/ajax/guides.php?action=generateMapFrame&gHeight="+gHeight+"&gWidth="+gWidth+"&gZoom="+gZoom+"&gCoords_latitude="+gCoords_latitude+"&gCoords_longitude="+gCoords_longitude,'');

	document.getElementById("mapDiv_"+mDivID).innerHTML = aj;

}




function closePhotoDiv(pDivID)
{
	document.getElementById("photoToggle_"+pDivID).innerHTML = "<a href='javascript:;' onclick=\"openPhotoDiv('"+pDivID+"');\">[Open Photos]</a>";
	document.getElementById("photoDiv_"+pDivID).innerHTML = "";
}
function openPhotoDiv(pDivID)
{
	document.getElementById("photoToggle_"+pDivID).innerHTML = "<a href='javascript:;' onclick=\"closePhotoDiv('"+pDivID+"');\">[Close Photos]</a>";
	aj = ajax("get","ajax/guides.php?action=generatePhotoDiv&guide_place_id="+pDivID,'');
	document.getElementById("photoDiv_"+pDivID).innerHTML = aj;
	
	
}

function closeInfoDiv(iDivID)
{
	document.getElementById("infoToggle_"+iDivID).innerHTML = "<a href=\"javascript:openInfoDiv('"+iDivID+"');\">[Open Info]</a>";
	document.getElementById("infoDiv_"+iDivID).innerHTML = "";
}
function openInfoDiv(iDivID)
{
	document.getElementById("infoToggle_"+iDivID).innerHTML = "<a href=\"javascript:closeInfoDiv('"+iDivID+"');\">[Close Info]</a>";

	document.getElementById('infoDiv_'+iDivID).innerHTML = "Opening...";
	aj = ajax("get","http://protoglobe.com/ajax/guides.php?action=generateInfoDiv&guide_place_id="+iDivID,'');
	document.getElementById("infoDiv_"+iDivID).innerHTML = aj;
	
}

// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------




function infoPopup(x)
{
 var m = "";
 if (x=="group_status_options")
 {
  m = "Group Status Options include: \n\n";
  m += "OPEN: anyone can join \n\n";
  m += "CLOSED: by invitation only \n\n";
  m += "RESTRICTED: members must match any indicated criteria (school, age, gender, major) to join \n\n";
 }
 if (m!="")
 {
  alert(m); 
 }
}


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://protoglobe.com/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://protoglobe.com/helpfile.php?page="+x,"helpfile","height=400,width=400,resizable=1,scrolling=1,scrollbars=1");
}



function displayTagInterface()
{
 window.open("http://protoglobe.com/tag_interface.php","tag_interface","height=300,width=400,resizable=1,scrolling=1,scrollbars=1");
}

function openPic(p,n)
{
 window.open('http://protoglobe.com/pictures/'+p,n,'resizable=1, height=300px, width=300px');
}

function jetAdClick()
{
 alert('Test');
// window.open("http://protoglobe.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 getStringFromTags(str,startTag,endTag)
{
	r = "";
	if (str.length > 0)
	{
		if ( (str.search(startTag) >= 0) && (str.search(endTag) > str.search(startTag)) )
		{
			stringStart = str.search(startTag) + startTag.length;
			stringEnd = str.search(endTag);
			r = str.substring(stringStart, stringEnd);
			str = str.substring((stringEnd+endTag.length),str.length);
		}
	}
	return r;
}









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);
}







/* -------------------- CURRENT AJAX FUNCTIONS --------------------------- */

// ------------------------------------------------------------------------
// HELPFUL: http://www.aleixcortadellas.com/main/2009/03/01/ajax-post/
// ------------------------------------------------------------------------

var xmlHttp

function ajax(method,url,params)
{

	if (!(params) || (params==null))
	{
		params = "";
	}

	xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=function ()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
		
		}
	};
	// defaults to 'get' in case of 'passive/active' nonsense from before
	if (method=="POST")
	{
		xmlHttp.open("POST", url, false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);		
	}
	else
	{
		if (params!="")
		{
			xmlHttp.open("GET",url+"?"+params,false);
		}
		else
		{
			xmlHttp.open("GET",url,false);
		}
		xmlHttp.send(null);
	}
	ajaxReturnValue = trim(xmlHttp.responseText);
	return ajaxReturnValue;
}



function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
  {
    // Firefox, Opera 8.0+, Safari, etc
    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 --------------------------- */






/* -------------------- OLD AJAX FUNCTIONS --------------------------- */
/*
var xmlHttp



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 --------------------------- */

