
if((location.pathname.length-3)==location.pathname.lastIndexOf('hta')){
	Application_Mode = true;
	Application_Version = App_Object.version;
	ThemeName = "silver";
}

if(location.search != "") ThemeName = location.search.substr(1);
var ThemeFolder = "../themes/";
var b_close = new Image();
var b_close_glow = new Image();
var b_close_pressed = new Image();
var c_left = new Image();
var c_mid = new Image();


function AppModeChange(border){
	if(Application_Mode) App_Object.outerHTML = "<?xml:namespace prefix = hta /><hta:application id=\"App_Object\" application=\"yes\" applicationname=\"Hindi Editor\" border=\""+(border?"thick":"none")+"\" borderstyle=\"normal\" caption=\"yes\" contextmenu=\"yes\" icon=\"hindi_editor.ico\" innerborder=\"yes\" maximizebutton=\"yes\" minimizebutton=\"yes\" navigable=\"no\" scroll=\"no\" scrollflat=\"yes\" selection=\"no\" showintaskbar=\"yes\" singleinstance=\"yes\" sysmenu=\"yes\" version=\"1.23\" windowstate=\"normal\"></hta:application>"
	if(border){
		document.all.AppWindow_CaptionBar.style.display="none";
		document.all.AppWindow_ClientArea.style.borderWidth=0;
	}
	else{
		document.all.AppWindow_CaptionBar.style.display="block";
		document.all.AppWindow_ClientArea.style.borderWidth=3;
		document.all.AppWindow_ClientArea.style.borderTopWidth=0;
	}
}

function ApplyTheme(Theme){
var NewCaption = "";
	ThemeName = Theme;
	AppModeChange(Theme=="none");
	document.all.ThemeScript.src="../themes/"+((Theme=="none")?"":(Theme+"/"))+"theme.js";
	document.all.ThemeStyleSheet.href="../themes/"+((Theme=="none")?"":(Theme+"/"))+"theme.css";
	b_close.src = ThemeFolder + Theme + "/b_close.gif"
	b_close_glow.src = ThemeFolder + Theme + "/b_close_glow.gif"
	b_close_pressed.src = ThemeFolder + Theme + "/b_close_pressed.gif"
	c_left.src = ThemeFolder + Theme + "/c_left.gif"
	c_mid.src = ThemeFolder + Theme + "/c_mid.gif"
	document.all.AppWindow_CaptionBar.all.tags("td")[0].style.backgroundImage = "url(" + c_left.src + ")";
	document.all.AppWindow_CaptionBar.all.tags("td")[1].style.backgroundImage = "url(" + c_mid.src + ")";
	document.all.dlgBtnBar.src = b_close.src;
}


var btnCloseDragEnded = true;
function HandleBar(obj){
var Source = "";
var Ele = null;
	event.cancelBubble=true;
	if(obj.tagName == "BODY" && event.type == "mouseup"){
		btnCloseDragEnded = true;
		return;
	}
		
	if(obj.id == "areaDlgClose")
		Ele = document.all.dlgBtnBar;
	if(event.type == "mouseover")
		if(btnCloseDragEnded)
			Ele.src = b_close_glow.src;
		else
			Ele.src=b_close_pressed.src;
	if(event.type == "mousedown")
		if(event.button == 1){
			Ele.src=b_close_pressed.src;
			btnCloseDragEnded = false;
		}
	if(event.type == "mouseout")
		Ele.src = b_close.src;
}

var StartX = -1;
var StartY = -1;
function MoveWindow(){
	if(!Application_Mode) return;
	if(event.button != 1){
		StartX = StartY = -1;
		return;
	}
	if(event.type == "mousedown"){
		StartX = event.x;
		StartY = event.y;
	}
	else if(event.type == "mousemove" && !(StartX < 0 || StartY < 0)){
		window.moveBy((event.x - StartX), (event.y - StartY));
	}
}

function AppWindowStart(AppIcon){

	b_close.src = ThemeFolder + ThemeName + "/b_close.gif"
	b_close_glow.src = ThemeFolder + ThemeName + "/b_close_glow.gif"
	b_close_pressed.src = ThemeFolder + ThemeName + "/b_close_pressed.gif"
	c_left.src = ThemeFolder + ThemeName + "/c_left.gif"
	c_mid.src = ThemeFolder + ThemeName + "/c_mid.gif"

	document.write('<map name="WinButtonXP">');
	document.write('	<area id="areaDlgClose" shape="rect" coords="7,6, 28,27" nohref title="Close" onmouseover="HandleBar(this);" onmouseout="HandleBar(this);" onmousedown="HandleBar(this);" onmouseup="HandleBar(this);" onclick="if(Application_Mode) window.close(); else alert(\'This will work only in Application mode.\');">');
	document.write('	<area shape="rect" coords="0,0, 34,30" nohref>');
	document.write('</map>');
	document.write('<table id="AppWindow" style="width:100%;height:100%;" align="center" border="0" cellpadding="0" cellspacing="0">');
	document.write('<tr id="AppWindow_CaptionBar" oncontextmenu="return false;" onselectstart="return false;" style="display:'+(Application_Mode?'none':'block')+';height:30px;table-layout:fixed;overflow:hidden;" onmousedown="MoveWindow();" ondblclick="if(Application_Mode){window.moveTo(0, 0);window.resizeTo(screen.availWidth, screen.availHeight);}"><td>');
	document.write('	<table width="100%" border="0" cellpadding="0" cellspacing="0">');
	document.write('	<tr style="height:30px;cursor:inherit;">');
	document.write('		<td style="width:34px;background-image:url('+c_left.src+');"><span style="width:34px;"><img src="'+unescape(AppIcon)+'" align="right" hspace="5" border="0" height="16" width="16"></span></td>');
	document.write('		<td class="AppWindowCaption" style="width:100%;background-image:url('+c_mid.src+');padding-left:0;white-space:nowrap;">'+document.title+'</td>');
	document.write('		<td style="width:34px"><img id="dlgBtnBar" src="'+b_close.src+'" border=0 height="30" width="34" usemap="#WinButtonXP"></td>');
	document.write('	</tr>');
	document.write('	</table>');
	document.write('</td></tr>');

	document.write('<tr><td id="AppWindow_ClientArea" class="AppWindowBorder" style="width:100%;height:100%;"><div id="AppWindow_InnerClientArea" style="margin:0px;padding:0px;overflow:auto;">');
}

function AppWindowFinish(){
	document.write('</div></td></tr>');
	document.write('</table>');
	ApplyTheme(ThemeName);
}

function Resize_Window(){
	with(document.all){
		AppWindow_InnerClientArea.style.width = 0;
		AppWindow_InnerClientArea.style.height = 0;
		AppWindow_InnerClientArea.style.width = AppWindow_ClientArea.offsetWidth;
		AppWindow_InnerClientArea.style.height = AppWindow_ClientArea.offsetHeight;
	}
}

