﻿
//Javascript Function
var highlightbehavior="TR"

var ns6=document.getElementById&&!document.all;
var isIE = (document.getElementById && document.all);
var ie=document.all;
var pop;

function changeto(e,highlightcolor){
	source=ie? event.srcElement : e.target
	if (source.tagName=="TABLE")
	return
	while(source.tagName!=highlightbehavior && source.tagName!="HTML")
	source=ns6? source.parentNode : source.parentElement
		
	if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore"){
		source.style.backgroundColor=highlightcolor;
	}
}
function contains_ns6(master, slave) { //check if slave is contained by master
	while (slave.parentNode)
	if ((slave = slave.parentNode) == master)
	return true;
	return false;
}

function changeback(e,originalcolor){
	if (ie&&(event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")||source.tagName=="TABLE")
	return
	else if (ns6&&(contains_ns6(source, e.relatedTarget)||source.id=="ignore"))
	return
	if (ie&&event.toElement!=source||ns6&&e.relatedTarget!=source)
	source.style.backgroundColor=originalcolor;
}
//Ajax process
function CreatojbXMLHttp()
{
	var xmlHttp=false;
	// xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
       // alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
 return xmlHttp;
}
function LoadObject(pid,szURL,szRequest,szHttpMethod,addhistory)
{
	var objHTTP= CreatojbXMLHttp();
	var obj= AdFindObjectID(pid);
		//obj.innerHTML="";
	if (objHTTP)
	 {
	  	
		objHTTP.open(szHttpMethod, szURL,true);
		objHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	  	objHTTP.onreadystatechange=function() {
		  if (objHTTP.readyState==4) {
		   var szReply = objHTTP.responseText;
		   //alert(szReply);
		   obj.innerHTML = szReply;
		   //obj.style.display='';
		   	szReply	= null;
		  }
		 }
		objHTTP.send(szRequest);

	 }
	else
	 {
	  alert("Your browser does not support XMLHTTP.");
	 }
}
function getstrTime()
{
	var curTime=new Date();
	var nhours=curTime.getHours();
	var nmins=curTime.getMinutes();
	var nsecn=curTime.getSeconds();
	var strTime=''+nhours+nmins+nsecn;
	return strTime;
	
}
function LoadRecord(pid,typeid,n,l,p)
{
	var szURL = "module/record.php?pid="+pid+"&id="+typeid+"&n="+n+"&l="+l+"&p="+p+"&ct="+getstrTime();
	var szHttpMethod = "GET";
 	var szRequest = null;
	LoadObject(pid,szURL,szRequest,szHttpMethod,false);	
}
//End Ajax process

function AdFindObjectID(idName)
{
	//return document.getElementById(idName);
	return document.getElementById?document.getElementById(idName):document.all?d.all[idName]:document.layers[idName];
}
function displayOnOff(objName){
	var obj=AdFindObjectID(objName);
	if(obj!=null)
	{
		if(obj.style.display=='none'){
			obj.style.display='';
		}
		else{
			obj.style.display='none';
		}
	}
}

function isValid(frm,frmId, msg, flag){
	if (frm[frmId].value == ''){
		alert(msg);
		frm[frmId].focus();
		return false;
	}
	return true;
}
function isValidDefault(frm,frmID,dvalue,msg)
{
	if (frm[frmID].value == dvalue){
		alert(msg);
		frm[frmID].focus();
		return false;
	}
	return true;	
}

function CheckEmailAddress(Email){
	Email = Email.replace(" ","");
	while (Email != '')	{
		c = Email.charAt(0);	
		if (c==' ' || c=='<' || c==39 || c==':' || c=='.'){
			Email = Email.substr(1);
		}else{
			break;
		}
	}

	i = Email.indexOf('>');
	if (i==-1){
		while (Email != ''){
			c = Email.charAt(Email.length - 1);
			if (c==' ' || c==39 || c=='.'){
				Email = Email.substr(0, Email.length - 1);
			}else{
				break;
			}
		}
	}else{
		Email = Email.substr(0, i);
	}

	if (Email.length > 96)
		return '';
	i = Email.lastIndexOf('@');
	j = Email.lastIndexOf('.');
	if (i < j)
		i = j;

	switch (Email.length - i - 1){
	case 2:
		break;
	case 3:
		switch (Email.substr(i)){
		case '.com':
		case '.net':
		case '.org':
		case '.edu':
		case '.mil':
		case '.gov':
		case '.biz':
		case '.pro':
		case '.int':
			break;
		default:
			return '';
		}
		break;
	default:
		switch (Email.substr(i)){
		case '.name':
		case '.info':
			break;
		default:
			return '';
		}
		break;
	}

	Email = Email.toLowerCase();

	if (Email == '')
		return '';
	if (Email.indexOf(' ') != -1)
		return '';
	if (Email.indexOf('..') != -1)
		return '';
	if (Email.indexOf('.@') != -1)
		return '';
	if (Email.indexOf('@.') != -1)
		return '';
	if (Email.indexOf(':') != -1)
		return '';
	for (i=0; i < Email.length; i++){
		c = Email.charAt(i);
		if (c >= '0' && c <= '9')
			continue;
		if (c >= 'a' && c <= 'z')
			continue;
		if ('`~!#$%^&*-_+=?/\\|@.'.indexOf(c) != -1)
			continue;

		return '';
	}

	if ((i=Email.indexOf('@'))==-1)
		return '';
	if (Email.substr(i + 1).indexOf('@')!=-1)
		return '';
	if (Email.charAt(0)=='.' || Email.charAt(Email.length - 1)=='.')
		return '';
	return Email;
}

function movePage(frm,page){
	if (!isNaN(page)){
		frm.Page.value = page;
		frm.submit();
	}
}

function modalDialog(URL,objWindow,width,height){
	var top=(screen.height - height)/2;
	var left=(screen.width - width)/2;
	
	return window.showModalDialog(URL, window, "dialogHeight: " + height + "px; dialogWidth: " + width + "px; dialogTop: " + top + "px; dialogLeft: " + left + "px; edge: Raised; center: Yes; help: No; resizable: No; status: No; scroll: yes");
}

function modalDialog1(URL,objWindow,width,height){
	var top=(screen.height - height)/2;
	var left=(screen.width - width)/2;
	
	return window.showModalDialog(URL, window, "dialogHeight: " + height + "px; dialogWidth: " + width + "px; dialogTop: " + top + "px; dialogLeft: " + left + "px; edge: Raised; center: Yes; help: No; resizable: No; status: No; scroll: no	");
}

function openwindow(url,width,height){
	var top=(screen.height - height)/2;
	var left=(screen.width - width)/2;
	if((pop!=null)&&(!pop.closed)){
		pop.close();
	}
	pop = window.open(url,"","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no,left=" + left + ", top=" + top + ", width=" + width + ", height=" + height)
}

function openwindow1(url,width,height){
	var top=(screen.height - height)/2;
	var left=(screen.width - width)/2;
	
	window.open(url,"","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no,left=" + left + ", top=" + top + ", width=" + width + ", height=" + height)
}


function openwindowfull(url){
	window.open(url,"","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, fullscreen=yes")
}


function swapOptions(obj,i,z) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var z_selected = o[z].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[z].text, o[z].value, o[z].defaultSelected, o[z].selected);
	o[i] = temp2;
	o[z] = temp;
	o[i].selected = z_selected;
	o[z].selected = i_selected;
}
function verifyIP(IPValue){
	var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
	var ipArray = IPValue.match(ipPattern);
	if (IPValue=='0.0.0.0'){
		return false;
	}else if(IPValue=='255.255.255.255'){
		return false;
	}else if(ipArray == null){
		return false;
	}else{
		if(ipArray.length==5){
			for(i = 1; i < ipArray.length; i++){
				thisSegment = ipArray[i];
				if(thisSegment > 255){
					return false;
				}
			}
		}else{
			return false;
		}			
	}
	return true;
}
function Trim(iStr){
	while (iStr.charCodeAt(0) <= 32){
		iStr=iStr.substr(1);
	}
	while (iStr.charCodeAt(iStr.length - 1) <= 32){
		iStr=iStr.substr(0, iStr.length - 1);
	}
	return iStr;
}


function openImage(vLink, vHeight, vWidth){
	var sLink = (typeof(vLink.href) == 'undefined') ? vLink : vLink.href;
	if (sLink == ''){
		return false;
	}
	winDef = 'status=no,resizable=no,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	newwin = open('', '_blank', winDef);
	newwin.document.writeln('<title>Xem ảnh</title>');
	newwin.document.writeln('<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">');
	newwin.document.writeln('<a href="" onClick="window.close(); return false;"><img src="', sLink, '" alt="', (isIE) ? '' : '', '" border=0 title=\'Đóng lại\'></a>');
	newwin.document.writeln('</body>');
	if (typeof(vLink.href) != 'undefined'){
		return false;
	}
}
