// JavaScript Document

// map popup
function map_popup(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600,left = 400,top = 192');");
	return false;
}


var defValues = {"firstname":"First Name","lastname":"Last Name",
	"email":"Email Address","email_confirm":"Confirm Email",
	"password":"Password","password_confirm":"Confirm",
	"username":"User Name", "name":"Your Name","message":"Your question",
	"captcha":"Enter the code"};

function setText(obj) {
	if (obj.value.length == 0) {
		obj.value = defValues[obj.id];
	}
	else if (obj.value == defValues[obj.id])
		obj.value = "";
}

function chkForm(obj) {
	obj.getElements("input").each(function(el) {
		if (defValues[el.id]!=undefined) {
			if (el.value == defValues[el.id])
				el.value = "";
		}
	});
}

function hideContent(pc,isIE6) {
	if (!isIE6) {
		if (pc.innerHTML.replace(/\n/g,"").replace(/\t/g,"") == "") {
			pc = pc.getParent();
			pc.setStyle("display","none");
			pc.setStyle("margin","0px");
			pc.setStyle("padding","0px");
			pc.className = pc.className.replace("rounded","");
		}
	}
	else {
		var hideIt = pc.innerHTML.replace(/\n/g,"").replace(/\t/g,"") == "";
		if (!hideIt) {
			//check for iepngfix tiles
			hideIt = true;
			pc.getChildren().each(function(el,idx) {
				if (el.getStyle("filter") == "")
					hideIt = false;
			});
		}
		if (hideIt) {
			pc = pc.getParent();
			pc.setStyle("display","none");
			pc.setStyle("margin","0px");
			pc.setStyle("padding","0px");
			pc.className = pc.className.replace("rounded","");
		}
		else {
			if ($("page-content").getHeight() > $("scroller").getHeight() - 29) {
				$("page-content").setStyle("height",$("scroller").getHeight()-40); // top padding + height of bottom image
				$("page-content").setStyle("overflow","auto");
			}
		}
	}
}

window.addEvent("domready",function() {
	var pc = $("page-content");
	//alert("inner content = ["+pc.innerHTML.replace(/\n/g,"").replace(/\t/g,"")+"]");
	if ($chk(pc)) {
		var editing = document.forms["cmsform"];
		if (editing == null || $("editing").value == 0) {
			//else
			//alert("inner content = ["+pc.innerHTML.replace(/\n/g,"").replace(/\t/g,"")+"]");
			if (Browser.Engine.name == "trident" && Browser.Engine.version <= 4) {
				//ie6 specific changes
				hideContent(pc,true);
			}
			else {
				hideContent(pc,false);
				var s = $("scroller");
				if ($chk(s)) {
					var myScroll = new Scroller("scroller",{area:75,velocity:.5});
					myScroll.start();
				}
				//rounding();
			}
		}
    }
});

function rounding() {
	var settings = {
		tl: { radius: 20 },
		tr: { radius: 20 },
		bl: { radius: 20 },
		br: { radius: 20 },
		antiAlias: true
	}
	$$(".rounded").each(function(el){
		curvyCorners(settings,el);
	});
}
