// JavaScript Document

//global path

//var gPath = "http://localhost/ge2/";
var gPath = "http://www.getawayearth.com/";

function siteSearchOn() {
	document.getElementById("searchsite").style.borderColor = "#4c933a";
}
function siteSearchOff() {
	document.getElementById("searchsite").style.borderColor = "";
}
function clearInput (el, val) {
	if (el.value == val) {
		el.value = "";
	}
	//change type frin text to password for passwordfonly fields
	if (el.id == "password") {
		
		//create a new element with the smae specs as password
		newInput = document.createElement("input");
		newInput.setAttribute("type", "password");
		newInput.setAttribute("id", "password");
		newInput.setAttribute("name", "password");
		
		//remove the old element
		document.getElementById('passwrapper').removeChild(el);
		
		//add the new element
		document.getElementById('passwrapper').appendChild(newInput);
		document.getElementById('password').focus()
	}
}
function border(el,clr) {
	
	if (navigator.appName != "Microsoft Internet Explorer") {
	
		pic = el.firstChild.nextSibling
		txt = el.firstChild.nextSibling.nextSibling.nextSibling
	} else {
		pic = el.firstChild
		txt = el.firstChild.nextSibling
	}
	//alert (txt + " " +txt.className);
	
	if (clr=="none") {
		pic.style.border = "1px Solid #666666"
		txt.style.color = "#666666"
	} else {
		pic.style.border = "1px Solid "+clr
		txt.style.color = "#000000"
	}
	/**/
}
function logOut(forgetMe) {
	if (forgetMe) {
		window.location="forgetme.php";
	} else {
		window.location="logout.php";
	}
}
function linkPage(id) {
//	alert(id);
	window.location="property.php?id="+id	
}
function linkPage2 (page, id) {
	p = page+"?id="+id
	window.location = p
}
function numOnly(e) {
	if(window.event)   {
		keynum = e.keyCode;
  	} else if(e.which) {
  		keynum = e.which;
	}
	
	if ((keynum >=48 && keynum <= 57) || keynum == 8) {
	//keychar = String.fromCharCode(keynum);
	//numcheck = /\d/;
		return String.fromCharCode(keynum);
		
	} else {
		alert("Only numeric values can be entered");
		if(window.event)   {
			e.returnValue=false
		}
		return false
		
	}/*
	var e=window.event || e
	var keyunicode=e.charCode || e.keyCode
	//Allow alphabetical keys, plus BACKSPACE and SPACE
	return (keyunicode>=65 && keyunicode<=122 || keyunicode==8 || keyunicode==32)? true : false
	*/
}


function setChkBox (el) {
	cBox = document.getElementById(el)
	//alert (cBox.checked);
	if (cBox.checked == false) {
		cBox.checked = true;
	} else {
		cBox.checked = false
	}
}
/* ========= AJAX =========== */
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;
}

function loadPage (url, loaddivid, userid, propid) { //vars 2 and 3 optional
	//need to use unaltered url so store as another var before manipulating url.
	loadPage=url;
	var post = "";
	post = post + "&user="+userid;
	post = post + "&propid="+propid;
	loadspace = document.getElementById(loaddivid)
	loadspace.innerHTML = "";
	loadspace.innerHTML = "<div class=\"loadergifwrapper\" ><img src=\"images/ajax-loader.gif\" alt=\"loading...\"/></div>";
	
	PAGExmlHttp=GetXmlHttpObject()
	
	if (PAGExmlHttp==null)  {
		  alert ("Your browser does not support AJAX!");
		  return;
	} 
	PAGExmlHttp.onreadystatechange=function () { 
		if (PAGExmlHttp.readyState==4) { 
				loadspace.innerHTML=PAGExmlHttp.responseText;
				
		}
	}
	url=url+"?sid="+Math.random()+post;
	PAGExmlHttp.open("GET",url,true);
	PAGExmlHttp.send(null);/**/
}

function openCC() {
	var cc = window.open("c_converter.php","converter", "toolbar=no,location=no, directories=no,status=no,menubar=no,scrollbars=no, resizable=no,width=575,height=220,left=200,top=100")
	cc.focus()
	//var popup = window.open("", "chatwindow", "dependent=yes,width=410, height=700, resizable=no, menubar=no, status=no, scrollbars=yes, toolbar=yes, directories=yes, titlebar=yes, location=yes, top="+top+", left="+left+"\"");
}

function HtmlEncode(s)
{
  var el = document.createElement("div");
  el.innerHTML = s
  s = el.innerHTML;
  delete el;
  return s;
}
