//Name : Le Minh Tam
//Date : 5/6/2002
//Email: leminhtam@sglp.com
ie = document.all?1:0
// Kiem tra ngay thang
function CheckDate(Giatri)
{
	var N;
	var Mang=new Array();
	N=Giatri ;
	cd=N.value.length;
	var co, co1,co2;
	co=false;
	co1=false;
	co2=false;
	var re = /^([0-9]+\/)+[0-9]+(\/[0-9])$/;
	if ((N.value.length < 6)||(N.value.length >10)||(!isCharsInBag (N.value, '012345/6789')))
		{
		alert("Ngay thang nam khong hop le !");
		N.focus();
		return false;
	}
	else for (var i=0 ; i < N.value.length; i++)
		{
			Mang[i]=N.value.charAt(i);
		}
	
	if (Mang[0]=="/"){
		alert("Ngay nhap bi loi !");
		N.focus();
		return false;}
	else if (Mang[1]=="/")
	{
		Ngay=Mang[0];
		co=true;
	}
	else if (Mang[2]=="/"){
		Ngay=Mang[0]+Mang[1];
		co1=true;}
	else 
		{
			alert("Ngay nhap bi loi !");
			N.focus();
			return false;
		}
	//kiem tra thang
	if ((co==true)&&(Mang[3]=="/"))
		{
			Thang=Mang[2];
		}
	else if((co==true)&&(Mang[4]=="/"))
			Thang=Mang[2]+Mang[3];
	else if((co1==true)&&(Mang[5]=="/"))
		Thang=Mang[3]+Mang[4];
	else if (Mang[4]=="/")
		Thang=Mang[3];
	else
		{
		alert("Thang nhap bi loi !");
		N.focus();
		return false;
		}
	if (Mang[cd-3]=="/")
	{
		Nam=Mang[cd-2]+Mang[cd-1];
	}
	else if(Mang[cd-4]=="/")
		Nam=Mang[cd-3]+Mang[cd-2]+Mang[cd-1];
	else
		Nam=Mang[cd-4]+Mang[cd-3]+Mang[cd-2]+Mang[cd-1];
	if (Nam < 99)
	{
		Nam="20"+Nam;
	}
	else if ((Nam >99) &(Nam < 2002))
		{
		alert("Nam nhap bi loi !");
		N.focus();
		return false;
		}
	if ((Thang < 10) && (Thang.length < 2))
	{
		Thang="0"+Thang;
	}
	if ((Ngay < 10) && (Ngay.length < 2))
	{
		Ngay="0"+Ngay;
	}
	Ngaythangnam =Ngay+"/"+Thang+"/"+Nam;
	if (Ngay > 31)
		{
			alert("Nhap ngay qua lon !");
			N.focus();
			return false;
		}
	else if (Ngay == 0)
		{
			alert("Ngay nhap phai khac 0 !");
			N.focus();
			return false;	
		}
	else if (Thang>12)
		{
			alert("Nhap thang qua lon");
			N.focus();
			return false;
		}
	else  if (Thang == 0)
		{
			alert("Thang nhap phai khac 0 !")
			N.focus();
			return false;
		}
	else  
		{	
			Giatri.value= Ngaythangnam;
		}
	
}
//So sanh xem co thoa dieu kien cua chuong tring
function isCharsInBag (s, bag)
{  
	var i;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) return false;
    }
    return true;
}
// Kiem tra gia rong
function Test(Giatri,Error){
	var co;
	co=false;
	if (Giatri.value=="")
		{
			Giatri.focus();
			alert(Error);
			co=false;
			return false;
		}
	else
		Giatri.value=Giatri.value;
}
//kiem tra  dia chi email
function EC(e, message){
    var re = /^([A-Za-z0-9\_\-]+\.)*[A-Za-z0-9\_\-]+@[A-Za-z0-9\_\-]+(\.[A-Za-z0-9\_\-]+)+$/;
    var sEMail = e.value;
    if (sEMail==""){
		alert("Chua nhap dia chi Email !");
		e.focus();
		return (false);
    }
    else if (sEMail.search(re) == -1){
			alert(message);
			e.select()
			e.focus()
			return (false);
		}
	else{
		return (true);
    }
}
//Kiem tra so dien thoai voi dang so
function CheckPhone(obj,Error){
	if (!isCharsInBag(obj.value, '0123456789'))
		{
		alert('So dien thoai khong hop le chi chap nhan dang so!');
		obj.focus();
		return false;
		}
	else if (obj.value==""){
			obj.focus();
			alert(Error);
			co=false;
			return false;
		}
	
	else
		obj.value=obj.value;
}
//Ham select
function select(){
		if (document.B.Vitri.value!=""){
			document.B.bOk.disabled=false;
		}
		else document.B.bOk .disabled=true;
	}

function CheckNam(Giatri,Nam)
	{
		var co=true;
		var Ngay = new Date();
		if ((Nam.value=="") | (Nam.value < Ngay.getYear()))
		{
			alert("Nam dang ky bi loi ");
			Nam.select();
			Nam.focus();
			return false;
		}
		else if ((Giatri.value < Ngay.getMonth() + 2) & (Nam.value==Ngay.getYear()))
		{
			alert("Thang dang ky nho hon thang hien tai !");
			Giatri.select();
			Giatri.focus();
			return false
		}
		else if (Nam.value > Ngay.getYear()+1)
		{
			alert("Nam dang ky vuot qua muc cho phep !");
			Nam.select();
			Nam.focus();
			return false;
		}
		else
		{
			Nam.value=Nam.value;
			co=true;
		}
	}
function Trove()
{
	window.history.back();
}
//Tat ca lien hoan den test du lieu mo phong trong yahoo.com
//Soan thao
function initEditor(bWhichEditor) {
			if (bWhichEditor)
		                idEdit = EditCtrl.DOM.parentWindow 
			else {
				EditCtrl.document.designMode="On"
				idEdit = EditCtrl
				
			}
			//idEdit.document.open()
		    //idEdit.document.write("")
			//idEdit.document.close()
		}
//Load font ban dau
		function doLoad() {
			idBox.style.visibility=''
			initEditor(false)	
			bLoad=true;
			//idEdit.value=4
			//idEdit.focus()
		}


function Editor() {
	  		this.put_html=put_html;
	  		this.get_html=get_html;
	  		this.testHTML=testHTML
	  		this.bReady = false
	  	}

	  	function cleanupHTML() {
	  	  bodyTags=idEdit.document.body.all, i
	  	  for (i=bodyTags.tags("FONT").length-1;i >= 0;i--)
	  		if (bodyTags.tags("FONT")[i].style.backgroundColor="#ffffff") {
	  			bodyTags.tags("FONT")[i].style.backgroundColor=""
	  			if (bodyTags.tags("FONT")[i].outerHTML.substring(0,6)=="<FONT>")
	  				bodyTags.tags("FONT")[i].outerHTML=bodyTags.tags("FONT")[i].innerHTML
	  		}
	  	}

	  	function testHTML(bAllowHead,extras) {
	  	  mW.click()
	  	  var badStuff=new Array("IFRAME","SCRIPT","LAYER","ILAYER","OBJECT","APPLET","EMBED","FORM","INPUT","BUTTON","TEXTAREA"),headStuff=new Array("HTML","BODY","TITLE","BASE","LINK","META","STYLE"),hasStuff=new Array(),bodyTags=idEdit.document.body.all,i=0
	  	  for (i=0;i<badStuff.length;i++)
	  	    if (bodyTags.tags(badStuff[i]).length>0)
	  	      hasStuff[hasStuff.length]=badStuff[i]
	  	  if (!bAllowHead)
	  	    for (i=0;i<headStuff.length;i++)
	  	      if (bodyTags.tags(headStuff[i]).length>0)
	  	        hasStuff[hasStuff.length]=headStuff[i]
	  	  if (extras!=null)
	  	    for (i=0;i<extras.length;i++) 
	  	      if (bodyTags.tags(extras[i]).length>0)
	  	        hasStuff[hasStuff.length]=extras[i]
	  	  var str=""
	  	  if (hasStuff.length>0) {
	  	    str="Please remove the following HTML Tags from your message and resubmit:"
	  	    for (i=0;i<hasStuff.length;i++)
	  	       str+="\n "+hasStuff[i]
	  	    str+= "\nRemember, when using HTML Mode you may need to escape \nthe brackets surrounding tags (< and >) with &lt; and &gt;"
	  	    setTimeout("mH.click()",0)
	  	  }
	  	  return str
	  	}

	  	function get_html() {

	  	if (bMode) {
	  		cleanupHTML()
	  		return idEdit.document.body.innerHTML 
	  	}
	  	else 
	  		return idEdit.document.body.innerText;
	  	}
	  	function put_html(sVal) {
	  		if (bMode) 
	  			idEdit.document.body.innerHTML=sVal 
	  		else 
	  			idEdit.document.body.innerText=sVal
	  	}

	  	var sHeader="<BODY STYLE=\"font:10pt Tahoma,geneva,arial,sans-serif\">",bMode=true,sel=null

	  	function displayError() {alert("Chi Format duoc o dang WYSIWYG ");idEdit.focus()}

	  	function format(what,opt) {
	  	 if (!bMode) {
	  	   displayError()
	  	   return
	  	 }
	  	 if (opt=="removeFormat"){
	  	   what=opt;opt=null
	  	 }
	  	 if (opt=="CustomFont")
	  		opt = prompt("Ban muon Format text theo Fonts?","Tahoma, Geneva, Arial")
	  	 if ((opt=="") && (what=="forecolor"))
	  		opt = prompt("Ban muon Format van ban theo mau ?","Black")
	  	 if (bMode) {
	  	   if (opt==null)
	  	     idEdit.document.execCommand(what)
	  	   else
	  	     idEdit.document.execCommand(what,"",opt)
	  	   var s=idEdit.document.selection.createRange(),p=s.parentElement()  
	  	   idEdit.focus()
	  	 } 
	  	 sel=null
	  	}
	  	function getEl(sTag,start) {
	  	  while ((start!=null) && (start.tagName!=sTag))
	  	    start = start.parentElement
	  	  return start
	  	}

	  	function createLink() {
	  	 if (!bMode) {
	  	   displayError()
	  	   return
	  	 }
	  	 var isA = getEl("A",idEdit.document.selection.createRange().parentElement())
	  	 var str=prompt("Ban muon tao mot moi Link Internet? (Vi du http:\/\/www.bancanbiet.com\/)",isA ? isA.href : "http:\/\/")
	  	 if ((str!=null) && (str!="http://")) {
	  	   if ((idEdit.document.selection.type=="None") && (!isA)) {
	  	     var sel=idEdit.document.selection.createRange()
	  	     sel.pasteHTML("<A HREF=\""+str+"\">"+str+"</A> ")
	  	     sel.select()
	  	   }
	  	   else
	  	     format("CreateLink",str)
	  	 }
	  	 else
	  	   idEdit.focus()
	  	}

	  	function setMode(bNewMode) {
	  	 if (bNewMode!=bMode) {
	  	  if (bNewMode) {
	  	   var sContents=idEdit.document.body.innerText 
	  	   idEdit.document.open()
	  	   idEdit.document.write(sHeader)
	  	   idEdit.document.close()
	  	   idEdit.document.body.innerHTML=sContents
	  	  }
	  	  else {
	  	   cleanupHTML()
	  	   var sContents=idEdit.document.body.innerHTML
	  	   idEdit.document.open()
	  	   idEdit.document.write("<BODY style=\"font:10pt Tahoma, courier, monospace\">")
	  	   idEdit.document.close()
	  	   idEdit.document.body.innerText=sContents
	  	  }
	  	  bMode=bNewMode
	  	  for (var i=0;i<htmlOnly.children.length;i++)
	  	   htmlOnly.children[i].disabled=(!bMode)
	  	 }
	  	 modeA.className=bMode?"current":"";modeB.className=bMode?"":"current"
	  	 idEdit.focus()
	  	}

//Kiem tra so dien thoai.

function Checkso(d,inum){
	var checkOK = inum;
  var checkStr = d.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }  
  if (!allValid)
  {
    alert("Chi chap nhan gia tri dang so .");
	d.value="";
    d.focus();
    return (false);
  }
  return (true);
}
function Checklike(d,inum){
	var checkOK = inum;
  var checkStr = d.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }  
  if (!allValid)
  {
    alert("Chi chap nhan gia tri dang so .");
	d.value="";
    d.focus();
    return (false);
  }
  document.B.Mark2.value=d.value;
  return (true);
}