function insertTemplate(id) {
	$.post('/pages/page?action=getTemplatePage',{pageId:id},function(result){
    	parent.updateEditor(result);
    	hideInfoWindow();
	});
}

function openInfoPane(message) {

	var pane = document.getElementById("infoPaneContainer");
	var content = document.getElementById("infoPaneContent");
	var paneWidth = 577;
	var xAxis = getViewportWidth()/2-paneWidth/2;

	pane.style.width = paneWidth + "px";
	centerAbsoluteEl(pane);
	bytefx.move(pane,{x:xAxis,y:0},10,function(){});
	content.innerHTML = "<b>" + message + "</b>";
		
	setTimeout("closeInfoPane()",7000);
}

function closeInfoPane() {
	var pane = document.getElementById("infoPaneContainer");
	var paneWidth = 577;
	var xAxis = getViewportWidth()/2-paneWidth/2;
	bytefx.move(pane,{x:xAxis,y:-200},1, function(){});
}


function getViewportWidth()
{
	if (typeof window.innerWidth != 'undefined') {
		return window.innerWidth;
	} else if (typeof document.documentElement != 'undefined'
		&& typeof document.documentElement.clientWidth !=
		'undefined' && document.documentElement.clientWidth != 0)
	{
		return document.documentElement.clientWidth;
	} else {
		return document.getElementsByTagName('body')[0].clientWidth;
	}
}

function getViewportHeight() {
	if (typeof window.innerWidth != 'undefined') {
		return window.innerHeight;
	} else if (typeof document.documentElement != 'undefined'
		&& typeof document.documentElement.clientWidth !=
		'undefined' && document.documentElement.clientWidth != 0)
	{
		return document.documentElement.clientHeight;
	} else {
		return document.getElementsByTagName('body')[0].clientHeight;
	}
}

function centerAbsoluteEl(el) {
	var elWidth = el.style.width;
	var viewportWidth = getViewportWidth();
	var offset = (viewportWidth < 800)? 0: 1;
	elWidth = elWidth.substring(0,elWidth.lastIndexOf("p"));
	el.style.left = viewportWidth/2 - elWidth/2 + offset + "px";
}

function submitGoogleCheckoutForm() {
	document.getElementById("googleCheckoutForm").submit();
}

function submitSchoolGoogleForm() {
	document.getElementById("schoolGoogleForm").submit();
}

function submitLoginForm(username, pwd, url, anchor) {
	 var submitForm = document.createElement("FORM");
	 submitForm.method = "POST";
	 submitForm.action = url;
	 	 
	 var userBox = document.createElement("INPUT");
	 userBox.setAttribute("value", username);
	 userBox.setAttribute("type", "hidden");
	 userBox.setAttribute("name", "username");
	 
	 var pwdBox = document.createElement("INPUT");
	 pwdBox.setAttribute("value", pwd);
	 pwdBox.setAttribute("type", "hidden");
	 pwdBox.setAttribute("name", "pwd");
	
	 if(anchor != null && anchor.length > 1) {
		 var anchorBox = document.createElement("INPUT");
		 anchorBox.setAttribute("value", anchor);
		 anchorBox.setAttribute("type", "hidden");
		 anchorBox.setAttribute("name", "anchor");
		 
		 submitForm.appendChild(anchorBox);
	 }
	 
	 submitForm.appendChild(userBox);
	 submitForm.appendChild(pwdBox);
	 
	 document.body.appendChild(submitForm);
	 
	 submitForm.submit();
}

function submitJoinForm(url, username, pwd, firstName, lastName, email, inviteCode) {
	 var submitForm = document.createElement("FORM");
	 submitForm.method = "POST";
	 submitForm.action = url;
	 	 
	 var userBox = document.createElement("INPUT");
	 userBox.setAttribute("value", username);
	 userBox.setAttribute("type", "hidden");
	 userBox.setAttribute("name", "username");
	 
	 var pwdBox = document.createElement("INPUT");
	 pwdBox.setAttribute("value", pwd);
	 pwdBox.setAttribute("type", "hidden");
	 pwdBox.setAttribute("name", "pwd");
	
	 var firstNameBox = document.createElement("INPUT");
	 firstNameBox.setAttribute("value", firstName);
	 firstNameBox.setAttribute("type", "hidden");
	 firstNameBox.setAttribute("name", "firstName");
	 
	 var lastNameBox = document.createElement("INPUT");
	 lastNameBox.setAttribute("value", lastName);
	 lastNameBox.setAttribute("type", "hidden");
	 lastNameBox.setAttribute("name", "lastName");

	 var emailBox = document.createElement("INPUT");
	 emailBox.setAttribute("value", email);
	 emailBox.setAttribute("type", "hidden");
	 emailBox.setAttribute("name", "email");
	 
	 var inviteBox = document.createElement("INPUT");
	 inviteBox.setAttribute("value", inviteCode);
	 inviteBox.setAttribute("type", "hidden");
	 inviteBox.setAttribute("name", "schoolPwd");
	 
	 submitForm.appendChild(userBox);
	 submitForm.appendChild(pwdBox);
	 submitForm.appendChild(firstNameBox);
	 submitForm.appendChild(lastNameBox);
	 submitForm.appendChild(emailBox); 
	 submitForm.appendChild(inviteBox);
	 
	 document.body.appendChild(submitForm);

	 submitForm.submit();
}

function loadVideo(id) {
	document.getElementById("videoFrame").src = "http://www.youtube.com/embed/" + id;
	window.scrollTo(0,0);
}


var websiteWinDisplay;
var portalWinDisplay;
var userWinDisplay;
var langWinDisplay;
var helpWinDisplay;

function closeWindows() {
	if(portalWinDisplay != "block") {
		document.getElementById("portalSetWindow").style.display = "none";
	} else if(portalWinDisplay == "block"){
		portalWinDisplay = "none";
	}

	if(websiteWinDisplay != "block") {
		document.getElementById("siteSetWindow").style.display = "none";
	} else if(websiteWinDisplay == "block"){
		websiteWinDisplay = "none";
	}
	
	if(userWinDisplay != "block") {
		document.getElementById("userSetWindow").style.display = "none";
	} else if(userWinDisplay == "block"){
		userWinDisplay = "none";
	}
	
	if(langWinDisplay != "block") {
		document.getElementById("langSetWindow").style.display = "none";
	} else if(langWinDisplay == "block"){
		langWinDisplay = "none";
	}
	
	if(helpWinDisplay != "block") {
		document.getElementById("helpSetWindow").style.display = "none";
	} else if(helpWinDisplay == "block"){
		helpWinDisplay = "none";
	}
}

function showWindow(id) {
		document.getElementById(id).style.display = "block";

		if(id == "siteSetWindow") websiteWinDisplay = "block";
		if(id == "portalSetWindow") portalWinDisplay = "block";
		if(id == "userSetWindow") userWinDisplay = "block";
		if(id == "langSetWindow") langWinDisplay = "block";
		if(id == "helpSetWindow") helpWinDisplay = "block";
}

//(C) bytefx 0.4
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('g=1s a(){j.V=a(6,H){q e=$6(6).e;e.H=e.13=e.14=H/N;e.1k="V(H="+H+")"};j.15=a(6){q u=["b","n","O","D","h"],r=u.P;R(r--)F($6(6).g[u[r]])};j.h=a(6,e,f,o,l,c){o=g.h$(o);F($6(6).g.h);6.g.h=z(a(){q h=g.h$(f),r=3;R(r--)h[r]=$o(h[r],o[r],l);6.e[e]=f=g.$h(h);k(""+h==""+o)$c(6,"h",c)},1)};j.W=a(6,f,o,c,8){a $c(p,c){k(c)c.G(6,p);m X};q 7=$6(6).g.W;g.$E(6,"B",a(p){7.f=19;7.B=d.B;7.v=d.v;d.v=6.v;d.B=$c;m $c(p,f)});g.$E(6,"v",a(p){7.f=X;d.B=7.B;d.v=7.v;m $c(p,o)});g.$E(d,"1c",a(p){q x=p.1d,y=p.10,b={x:x-7.x,y:y-7.y};k(7.f){k(8){b.x=C(b.x,8.$x);b.y=C(b.y,8.$y);b.x=A(b.x,8.x$);b.y=A(b.y,8.y$)};g.8(6,b);$c(p,c)}17{7.x=x-6.T;7.y=y-6.U};m X})};j.D=a(6,f,o,l,c){F($6(6).g.D);6.g.D=z(a(){f=$o(f,o,l);g.V(6,f);k(f==o)$c(6,"D",c)},1)};j.O=a(6,8,l,c){q f=g.$8($6(6));$z(6,"O",l/N,f,8,["x","y"],"8",c)};j.8=a(6,8){q e=$6(6).e;e.8="1h";e.1i=8.x+"M";e.1j=8.y+"M"};j.n=a(6,l,c){a n(8){m d.J?d.J[8]:d.K[8]};q f=g.$n(),o={x:f.x,y:A(g.$8(6).y,C(n("Y"),d.K.Y)-A(n("Z"),d.K.Z))};$z($6(g),"n",l/N,f,o,["x","y"],"n$",c?a(){c.G(6)}:1r)};j.b=a(6,b,l,c){q f=g.$b($6(6)),7=w.1l;k(!/1m/i.1n(1o.1p)||(7&&I(7.1q())>=9)){k(b.$t)f.t-=b.$t;k(b.$s)f.s-=b.$s;k(b.t$)b.t-=b.t$;k(b.s$)b.s-=b.s$};6.e.1t="1u";$z(6,"b",l/N,f,b,["t","s"],"b$",c)};j.$h=a(h){a 7(r){q 7=h[r].1w(16);m 7.P==1?"0"+7:7};m"#"+7(0)+7(1)+7(2)};j.h$=a(h){a 7(r){m h.1x(r)};h=h.1y(1);k(h.P==3)h=7(0)+7(0)+7(1)+7(1)+7(2)+7(2);m[I(7(0)+7(1),16),I(7(2)+7(3),16),I(7(4)+7(5),16)]};j.$E=a(6,7,c){q Q=6[7];6[7]=a(p){k(!p)p=w.E;k(Q)Q.G(j,p);m c.G(j,p)}};j.$8=a(6){q 8={x:6.T,y:6.U};R(6=6.12){8.x+=6.T;8.y+=6.U};m 8};j.$n=a(){a n(8,n){m(d.J?d.J[8]:w[n]||d.K[8])||0};m{x:n("18","1a"),y:n("1b","1e")}};j.n$=a(6,8){w.1f(8.x,8.y)};j.$b=a(6){m{t:6.1g,s:6.Y}};j.b$=a(6,b){q e=6.e;e.t=b.t+"M";e.s=b.s+"M"};a $c(6,u,c){F(6.g[u]);k(c)c.G(6)};a $6(6){k(!6.g)6.g={h:0,W:{},D:0,O:0,n:0,b:0};m 6};a $o(x,y,l){m x<y?A(x+l,y):C(x-l,y)};a $z(6,u,l,f,8,e,7,c){F(6.g[u]);6.g[u]=z(a(){f[e[0]]+=(8[e[0]]-f[e[0]])*l;f[e[1]]+=(8[e[1]]-f[e[1]])*l;g[7](6,f);k(L(f[e[0]])==8[e[0]]&&L(f[e[1]])==8[e[1]]){g[7](6,8);$c(6,u,c)}},1)};q w=1v,d=11,C=S.C,A=S.A,L=S.L};',62,97,'||||||element|tmp|position||function|size|callback||style|start|bytefx|color||this|if|speed|return|scroll|end|evt|var|index|height|width|interval|onmouseup||||setInterval|min|onmousedown|max|fade|event|clearInterval|call|opacity|parseInt|documentElement|body|round|px|100|move|length|value|while|Math|offsetLeft|offsetTop|alpha|drag|false|offsetHeight|clientHeight|clientY|document|offsetParent|MozOpacity|KhtmlOpacity|clear||else|scrollLeft|true|pageXOffset|scrollTop|onmousemove|clientX|pageYOffset|scrollTo|offsetWidth|absolute|left|top|filter|opera|msie|test|navigator|userAgent|version|null|new|overflow|hidden|window|toString|charAt|substring'.split('|')));
