﻿// JavaScript Document

function getFileEx(filename)
{
	if (filename != "")
	{
		var pos = filename.indexOf(".");
		var pos2 = pos;
		while (pos2 > 0) 
		{
			pos = pos2;
			pos2 = filename.indexOf(".", pos2 + 1);
		}
		var ext = filename.substring(pos);
		return ext;
	}
	
	return "";
}

function validImgFile(ext)
{
	var imgarr = new Array(".jpg", ".gif", ".png");
	var flag = false;
	for (var i = 0; i < imgarr.length; i ++)
	{
		if (ext.toLowerCase() == imgarr[i]) 
		{
			flag = true;
			break;
		}
	}
	
	return flag;
}

function validEmail(email)
{
	var a = new Array(" ", "!", "#", "$", "%", "^", "&", "*", "(", ")", "+", "[", "]", "{", "}", ":", "'", ";", "|", "\\", "/", ">", "<");
	for (var i = 0; i < a.length; i ++)
	{
		if (email.indexOf(a[i]) != -1) 
		{
			return false;
		}
	}
	var pos = email.indexOf('@');
	var pos2 = email.indexOf('.', (pos + 1));
	if (pos > 0 && pos2 > (pos + 1) && pos2 < (email.length - 1)) return true;
	else 
	{
		return false;
	}

}

function validURL(url)
{
	var a = new Array("@", " ", "!", "#", "$", "%", "^", "&", "*", "(", ")", "+", "[", "]", "{", "}", ":", "'", ";", "|", "\\", "/", ">", "<");
	for (var i = 0; i < a.length; i ++)
	{
		if (url.indexOf(a[i]) != -1) 
		{
			return false;
		}
	}
	var pos = url.indexOf('.');
	if (pos > 0 && pos < (url.length - 2)) return true;
	else 
	{
		return false;
	}

}

var ppimgNW;
function popupImg(src, note, title, css, border) {
try {
  if (border==null) border = 0;
  if (note==null) note = '';
  if (ppimgNW != null) ppimgNW.close();

  ppimgNW = window.open('','POPUPIMAGE','width=1,height=1,resizable=1');
  var doc = ppimgNW.document;
  doc.write('<html>');
  doc.write('<head>');
  if (title!=null) doc.write('<title>'+ title +'</title>');
  doc.write('<style> body {'+css+'} #ppImgText{'+ css +'} #ppImg{cursor:hand} .toolbar {display:none; position:absolute; left:2;top:2; background:#808080} </style></head>');
  doc.write('<body leftmargin="0" topmargin="' + border + '" oncontextmenu=return(showtb())>');
  doc.write('<table class=toolbar id=eToolbar><tr><td>[+]</td><td>[-]</td><td>CW</td><td>CCW</td></tr></table>');
  doc.write('<table cellspacing=0 cellpadding=0 width="100%" height="100%" unselectable=on><tr><td align=center><div align="center">');
  doc.write('<img src="' + src + '" id="ppImg" onclick="window.close();" title="Close" unselectable=on>');
  doc.write('</div>');
  doc.write('<div style="height:1; width:' + border + '; font-size:4pt;">');
  doc.write('</div>');
  doc.write('<div id="ppImgText" align="center">');
  doc.write(note);
  doc.write('</div></td></tr></table>');
  doc.write('</body>');
  doc.write('</html>');

  doc.write('<' + 'script>');
  doc.write('function showtb() {eToolbar.style.display=eToolbar.style.display==\'inline\'?\'none\':\'inline\'; return false;}');
  doc.write('var resized = false;');
  doc.write('function doResize() {');
  doc.write('  var imgW = ppImg.width, imgH = ppImg.height;');     
  doc.write('  window.resizeTo(imgW + 8 +' + border*2 +', imgH + ppImgText.offsetHeight + 26 + '+ border*2 +');');
  doc.write('  if(!imgW) setTimeout("doResize()",1000);');

  doc.write('}');
  doc.write('doResize(); ');
  doc.write('</' + 'script>');

} catch (e) {
	window.status = 'E';
}

}
/*
function popupImg(imgpath)
{
	var w = window.open(imgpath, "", "scrollbars=yes, resizable=yes");//, "width=450, height=350, scrollbars=yes, resizable=yes");
		w.document.write("<html><head><title>&gt; &gt;   Q u e H u o n g  H o t e l s</title></head><body leftmargin='0' topmargin='0' bottommargin='0' rightmargin='0'>");
		w.document.write("<table align='center'><tr><td>");
		w.document.write("<img src=" + imgpath + ">");
		w.document.write("</td></tr></table></body></html>");
}
*/
function popupPage(page)
{
	window.open(page, "newpage", "width=500, height=550, scrollbars=yes, resizable=yes");
}


function checkAll(form_name, array_name)
{
	for (var i = 0; i < form_name.elements.length; i++)
	{
		var c = form_name.elements[i];//alert(c.name);
		if (c.name == array_name) {c.checked = true;  }
	}
}

function uncheckAll(form_name, array_name)
{
	for (var i = 0; i < form_name.elements.length; i++)
	{
		var c = form_name.elements[i];//alert(c.name);
		if (c.name == array_name) {c.checked = false;  }
	}
}