function getText(oNode){
	var sInnerText=oNode.innerText;
	if(sInnerText==undefined)
		sInnerText=oNode.textContent;
	return sInnerText;
}


function showWait(){
		/*
		var oWt = document.createElement("img");
		oWt.src = "http://baynyc.com/jmsa/images/wait.gif";
		oWt.style.position = "static";
				oWt.style.position = "fixed";
		oWt.style.top = "35%";
		oWt.style.left = "48%";
		oWt.style.zIndex = "5000";				
		document.body.appendChild(oWt);
		*/
		//document.body.innerHTML = "";
		//document.body.background = "#595a5e";
		var oDv = document.createElement("div");
		oDv.innerHTML = "";
		oDv.style.background = "#ffffff";
		oDv.style.color = "#222627";
		//oDv.style.border = "#595a5e double 1px";
		
				
		oDv.style.top = "35%";
		oDv.style.left = "48%";
		//oDv.style.height = "33%";
		oDv.style.width = "33%";
		oDv.style.textAlign = "center";
		//oDv.style.fontSize = "24px";		
		oDv.style.zIndex = "5000";				
		oDv.style.position = "static";
		oDv.style.position = "fixed";
		
		var oWt = document.createElement("img");
		oWt.src = "http://baynyc.info/com/jmsa/images/wait.gif";
		oDv.appendChild(oWt);
		document.body.appendChild(oDv);
		
}


function adminShowWait(sLabel){
		document.body.innerHTML = "";
		document.body.background = "#595a5e";
		var oDv = document.createElement("div");
		oDv.innerHTML = "Please Wait<br />"+sLabel+" ...<br />";
		oDv.style.background = "#ffb82e";
		oDv.style.color = "#222627";
		oDv.style.border = "#595a5e double 1px";
		
				
		oDv.style.top = "33%";
		oDv.style.left = "33%";
		//oDv.style.height = "33%";
		oDv.style.width = "33%";
		oDv.style.textAlign = "center";
		oDv.style.fontSize = "24px";		
		oDv.style.zIndex = "5000";				
		oDv.style.position = "static";
		oDv.style.position = "fixed";
		
		var oWt = document.createElement("img");
		oWt.src = "http://baynyc.info/com/jmsa/images/yobspinwait.gif";
		oDv.appendChild(oWt);
		document.body.appendChild(oDv);
}
	
function focusInput(oIE,bF){
     if(bF){
      oIE.setAttribute("class","txtinf");
	}else{
      oIE.setAttribute("class","txtinb");
	}

}

function buttonOn(oBtn,bO){
     if(bO){
      oBtn.setAttribute("class","btnOn");

	}else{
      oBtn.setAttribute("class","btn");

	}
}	

function showChosen($sId){
	var aDat = window.location.toString().split("/");
	var sKey = aDat[aDat.length-1];
	var aChain = document.getElementById($sId);
	var aKeys = aChain.getElementsByTagName("a");	
	for(i=0;i<aKeys.length;i++){
		if(sKey.toLowerCase() == aKeys[i].getAttribute("href").toLowerCase()){
				aKeys[i].style.background = "url('images/hover.jpg') no-repeat top right";
				aKeys[i].innerHTML = aKeys[i].innerHTML + "<span style='font-size:20px;padding-bottom:5px'>&#9997;</span>";				
			}
		}
}

function editEntryCheck(oRchk){
	//clear previous
	var aNtry = document.getElementsByTagName("div");
	for(i=0;i<aNtry.length;i++){		
		if(aNtry[i].id.toString().indexOf("Entry")!='1'){
			aNtry[i].style.background = "none";					 
		}	
	}	

	
	var sId = oRchk.value.toString().replace(/Edit/g,"");
	var oTargt = document.getElementById("Entry"+sId);
	oTargt.style.background = "#ffb82e";
	
	var aCachedVals = document.getElementById("Entry"+sId).getElementsByTagName("input");
	
	for(iv = 0; iv < aCachedVals.length;iv++){
			if(aCachedVals[iv].getAttribute("type")=="radio")
				continue;
			var sFieldNam = aCachedVals[iv].getAttribute("id");
			var sFieldVal = aCachedVals[iv].getAttribute("value");
			try{
				if((sFieldNam.indexOf("SearchTerm")==-1)&&(sFieldNam.indexOf("_")!=-1)){		
					var sTgId = sFieldNam.split("_")[1].toString()+"_update";
					document.getElementById(sTgId).value = sFieldVal;
				}
			}catch(e){
				alert(aCachedVals[iv].type);
				}						
	}	
	document.getElementById('FormTask').innerHTML = "Editing Entry # " + sId;	
		document.getElementById("btnSave").value = "Save Change(s)";		
	
}

function cleanUp(oFrm){
	aElm = oFrm.getElementsByTagName("input");
	for(i = 0; i < aElm.length; i++){
			if(aElm[i].getAttribute("type")=="text")
				aElm[i].value = "";
			if(aElm[i].getAttribute("name")	== "DisplayPriority")
				aElm[i].value = 10;
		}
	if(oFrm.getAttribute("id")=="AddEditForm"){
		document.getElementById("FormTask").innerHTML = "Creating New Entry";
		document.getElementById("EntryTime_update").value = document.getElementById("NewTimeStamp").value;
		document.getElementById("btnSave").value = "Save New";
	}
}

function submitForm(oFrm,sMsg){
	//added to allow zh entry for image caption and description
	if(oFrm.getAttribute("id")=="frmAddImage"){
		var sCJKables = "Caption,Description";
		var aCJKables = sCJKables.split(",");
		while(aCJKables.length>0){                
			var oTmp = document.getElementById(aCJKables.shift());
			var sTmp = oTmp.value;
			sTmp = entitizeCJK(sTmp);
			oTmp.value = sTmp;
		}		
	}
	
	oFrm.submit();
	adminShowWait(sMsg);
	//showSubmitted(oFrm);
	
}
/*For diagnostic purposes, shows values  in form prior to submitting*/
function showSubmitted(oFrm){
	var aFrVa = oFrm.elements;
	var sPrn = "Values in Form " + oFrm.getAttribute("name") + "\n";
	for(i=0;i<aFrVa.length;i++){
		var oElm = aFrVa[i];
		sPrn += oElm.getAttribute("name")  + ": " +  oElm.getAttribute("value") + "\n";	
	}
	sPrn += "\n\tDo you want to send these values to the server?";
	if(confirm(sPrn))
		oFrm.submit();
	else
		alert("Form was not submitted");
}

function submitFeedForm(oFrm){
	var sCity = "";
	var oSel = document.getElementById("CityID");
	for(i=0; i < oSel.options.length; i++){
	      if(oSel.options[i].selected == true)
	           sCity = oSel.options[i].text;
	}
	oFrm.submit();	
	adminShowWait("Attempting " + sCity + " Data Feed");
}

function saveChanges(oFrm){
	var sCJKables = "Description_update,OpenerText_update,Style_update,Construction_update";
	var aCJKables = sCJKables.split(",");
	while(aCJKables.length>0){                
		var oTmp = document.getElementById(aCJKables.shift());
		var sTmp = oTmp.value;
		sTmp = entitizeCJK(sTmp);
		oTmp.value = sTmp;
	}
	
	//added to handdle conversion to manual entry(5/23/2010)
	/*
	var oDP = document.getElementById("DisplayPriority_update");
	if(parseInt(oDP.value)>=200)
		oDP.value = 10;
	*/	
	document.getElementById("hdSaving").value = "true";	
	submitForm(oFrm,"Saving Data");
}


function openAd(oFrm){
	   	document.getElementById("DoThis").value = "open";
	   	var iCId = null;
	   	var sLbl = document.getElementById("TemplateVersion").value;
	   	var aLbl = sLbl.split(".");
	   	if(sLbl.indexOf(".")!=-1)
	   		iCId = aLbl[0];
	   	document.getElementById("ContentID").value = iCId;
		oFrm.submit();	   	
	   	adminShowWait("Opening "+aLbl[1]);	
	}
	
function saveAd(oFrm){
		document.getElementById("DoThis").value = "save";
	   	var sCLbl = null;
	   	var oVer = document.getElementById("TemplateVersion");
	   	var oItm = document.getElementById("TemplateLabel");
	   	var sLbl = oVer.value;
	   	var aLbl = sLbl.split(".");
	   	if(sLbl.indexOf(".")!=-1){	   		
	   		sCLbl = aLbl[1]; 		
	   	}
	   	
	   	for(tvi=0;tvi < oVer.options.length;tvi++){
	   		if(oVer.options[tvi].selected == true){
	   				document.getElementById("VersionID").value = oVer.options[tvi].text.split(".")[0].replace(/ /g,"");
		   	}
	   	}   	 
		
	   	for(i=0;i< oItm.options.length;i++){
	   		if(oItm.options[i].selected == true){
	   			document.getElementById("ItemName").value = oItm.options[i].text;	   					
	   		}
	   	}

		
	   	document.getElementById("ContentLabel").value = sCLbl;
	   	document.getElementById('HTMLMarkup').value = entitizeCJK(document.getElementById('HTMLWYSIWYG').innerHTML);	
		oFrm.submit();			   	 
	   	adminShowWait("Saving new version of "+ sCLbl);   		
				
}	
	
function updateMarkUp(){
	var oWysiwyg = document.getElementById('HTMLWYSIWYG');
	var oMarkUp = 	document.getElementById('HTMLMarkup');
	oMarkUp.value = oWysiwyg.innerHTML;
}	

function updateWysiwyg(){
	var oWysiwyg = document.getElementById('HTMLWYSIWYG');
	var oMarkUp = 	document.getElementById('HTMLMarkup');
	oWysiwyg.innerHTML = oMarkUp.value;
}	

function updateVersions(oDd){
		var sLabel = oDd.value;
		var oVersions = document.getElementById("TemplateVersion");
		for(i=0;i < oVersions.options.length; i++){
			oOpt = oVersions.options[i]; 
			if(oOpt.value.indexOf(sLabel)==-1){
				oOpt.disabled = true;
			}else{
				oOpt.disabled = false;
			}	
		}
}

function updateLabels(oDd){
	var sLabel = oDd.value.split(".")[1];
	var oLabels = document.getElementById("TemplateLabel"); 
	for(i=0;i<oLabels.options.length;i++){
		if(sLabel.indexOf(oLabels.options[i].value)!=-1){
			oLabels.options[i].selected = true;
		}	
	}
}

function entitizeCJK(sHTML){
	var sBuffer = "";	
	for(i = 0;i < sHTML.length;i++){
		if(sHTML.charCodeAt(i)>600){
			sBuffer += 	"&#"+sHTML.charCodeAt(i)+";";
		}else{
			sBuffer += sHTML.charAt(i);
		}
	}	
	return sBuffer;
}

function DEncode(si,ic){ 
	var so=''; 
	if(ic<0){ 	
		for(i=0; i < si.length; i++){
			 	so+='&#'+si.charCodeAt(i)+'; ';  
		}  
	} else{ 	
		ao=[]; 
		asi = si.split('; '); 
		for(j=0; j < asi.length; j++){ 	
			tc=String(asi[j]).replace(/&#/,''); 
			so+=String.fromCharCode(tc);  
		}  
	} 
	return so;
}


function MD5Encrypt(sStr){
	var oScr = document.createElement("script");
	var sRet = "";
	document.body.appendChild(oScr);
	oScr.id='scCrypto';
	oScr.language='javascript';		
	oScr.src = "mdfv.js";
	sRet = MD5_hexhash(sStr);
	return sRet;
}

function submitLogin(oFrm){
		var oPass = document.getElementById("txtPassword");
		var sMD5edPass = MD5_hexhash(oPass.value);
		document.getElementById("hdPassword").value = sMD5edPass; 
		var sUserName = document.getElementById("txtUserName").value; 	
		oFrm.submit();			   	 
	   	adminShowWait("Loggin in  "+ sUserName);   
}

function showStats(oCallr){
	var iId = oCallr.value;
	var oTgt = document.getElementById("FeedStats");
	
	var tbl = document.createElement("table");
	var buildRow = function(sName,sValue){
		var rw = document.createElement("tr");
		var rh = document.createElement("th");
		rh.innerHTML = sName;	
		var rd = document.createElement("td");
		rd.innerHTML = sValue;
		rw.appendChild(rh);
		rw.appendChild(rd);		
		return rw;
	}
	
	oTgt.innerHTML = ""; //clear for new data 
	//get new data and pub			
	var sCity = document.getElementById("City_"+iId).value;
	tbl.appendChild(buildRow("City/Neighborhood:",sCity));
	var iProps = document.getElementById("Properties_"+iId).value;
	tbl.appendChild(buildRow("Properties Listed:",iProps));	
	var iAge = 	document.getElementById("Age_"+iId).value;
	tbl.appendChild(buildRow("Days Since Last Data Feed:",iAge));			
	var sLast = document.getElementById("LastFeed_"+iId).value;
	tbl.appendChild(buildRow("Time Stamp of Last Data Feed:",sLast));
	oTgt.appendChild(tbl);
	document.getElementById("btnAction").value = "Get "+ sCity + " Data Feed"; 		
	
}




function popUpImageIframe(sTask){
	var sId = document.getElementById("EntryID_update").value;
	if(sId == "")
		return;
	var sTkn = document.getElementById("tkn").value;
	if(sTkn == "undefined")
		return;
		
	var oVeneer = document.createElement("div");
		oVeneer.setAttribute("id","dvFrameBg");
		oVeneer.setAttribute("style","background:#000000;opacity:0.5;filter:alpha(opacity=50);position:fixed;top:0px;left:0px;width:100%;height:100%;z-index:20000;");
	var oFrame = document.createElement("iframe");
		oFrame.setAttribute("style","background:#000000;position:fixed;top:17%;left:33%;width:33%;height:67%;z-index:21000;border:solid 1px #000000;");
		oFrame.setAttribute("src","imageform.php?tsk="+sTask+"&eid="+sId+"&tkn="+sTkn);
		oFrame.setAttribute("scrolling","no");		
		oFrame.setAttribute("id","ifrPopup");

	document.body.appendChild(oVeneer);
	document.body.appendChild(oFrame);		
					
}

function closeIframe(){
		var oIframe = document.getElementById("ifrPopup");
		oIframe.parentNode.removeChild(oIframe);
		var oBg = document.getElementById("dvFrameBg");
		oBg.parentNode.removeChild(oBg);
}


function popDetailIframe(iPropId){
		 //doModalPpUp("http://baynyc.com/com/_jmsa/propdetail.php?propid="+iPropId);
	//return;	
	var oVeneer = document.createElement("div");
		oVeneer.setAttribute("id","dvFrameBg");
		oVeneer.setAttribute("style","background:#000000;opacity:0.5;filter:alpha(opacity=50);position:fixed;top:0px;left:0px;width:100%;height:100%;z-index:20000;");
	var oFrame = document.createElement("iframe");
		oFrame.setAttribute("style","background:#000000;position:fixed;top:17%;left:20%;width:60%;height:67%;z-index:21000;border:solid 3px #000000;");
		oFrame.setAttribute("src","http://baynyc.com/com/_jmsa/propdetail.php?propid="+iPropId);
		oFrame.setAttribute("scrolling","auto");		
		oFrame.setAttribute("id","ifrPopup");

	document.body.appendChild(oVeneer);
	document.body.appendChild(oFrame);		
					
}


