function SelectAll_nonHighlight(spanChk,name)
{
    var xState=spanChk.checked;    
    var elm=spanChk.form.elements;    
    for(i=0;i<elm.length;i++)
      if(elm[i].type=="checkbox" && elm[i].id!=spanChk.id && elm[i].id.indexOf(name,0)>0)
            elm[i].checked = xState;
}
function SelectAll_2(spanChk,name)
{
    var xState=spanChk.checked;    
    var elm=spanChk.form.elements;    
    for(i=0;i<elm.length;i++)
      if(elm[i].type=="checkbox" && elm[i].id!=spanChk.id && elm[i].id.indexOf(name,0)>0)
      {
            elm[i].checked = xState;
            HighlightRow_FF(elm[i]);
      }   
}
function SelectAll_3(spanChk,name)
{
    var xState=spanChk.checked;    
    var elm=spanChk.form.elements;    
    for(i=0;i<elm.length;i++)
      if(elm[i].type=="checkbox" && elm[i].id!=spanChk.id && elm[i].id.indexOf(name,0)>0)
      {
            elm[i].checked = xState;
            HighlightRow_FF_3(elm[i]);
      }   
}
function SelectAll(chkAll, checkelementid, uncheckelementid,uncheckAllID)
{
	var state = chkAll.checked ;

	for (j = 0 ; j < document.all.length ; j++)
	{
		var str_id = document.all(j).id ;
		if (document.all(j).type=="checkbox" && str_id.substring(str_id.length-checkelementid.length,str_id.length) == checkelementid) 
		{
			document.all(j).checked = state ; 
			HighlightRow_FF(document.all(j));
		}
		if (document.all(j).type=="checkbox" && str_id.substring(str_id.length-uncheckelementid.length,str_id.length) == uncheckelementid) 
		{
			document.all(j).checked = false; 
		}
		if (document.all(j).type=="checkbox" && str_id.substring(str_id.length-uncheckAllID.length,str_id.length) == uncheckAllID) 
		{
			document.all(j).checked = false; 	
		}
	}
}
function RemoveSelectAll(elementid, elementallid)
{
	for (j = 0 ; j < document.all.length ; j++)
	{
		var str_id = document.all(j).id ;
		if (document.all(j).type=="checkbox")
		{
		  if ((str_id.substring(str_id.length-elementid.length,str_id.length) == elementid)||
			  (str_id.substring(str_id.length-elementallid.length,str_id.length) == elementallid))
			  { 		
				document.all(j).checked = false;				
			  }
		}		
	}
}

function RemoveAllCheck()
{
	for (j = 0 ; j < document.all.length ; j++)
	{
		document.all(j).checked = false;						
	}
}
function HighlightRow(chkB)	
{
	var xState=chkB.checked;
		
	if(xState == true)
	{					
		chkB.parentElement.parentElement.className='highlightItem';
	}
	else 
	{					
		chkB.parentElement.parentElement.className='normalItem';
	} 
}
function HighlightRow_3(chkB)	
{
	var xState=chkB.checked;
		
	if(xState == true)
	{					
		chkB.parentElement.parentElement.parentElement.className='highlightItem';
	}
	else 
	{					
		chkB.parentElement.parentElement.parentElement.className='normalItem';
	} 
}
function DisplayCalendar(obj,cul)		
{
	var lang = 1;
	var cal;
	if(cul == 'EN-US' || cul == "en-US")
	{
		cal = new calendar2(obj);
		lang = 1;
	}
	else if(cul == 'fr-FR' || cul == 'vi-VN')
	{
		cal = new calendar1(obj);
		lang = 2;
	}
	else 
	{
		if(lang == 1)
		{
			cal = new calendar2(obj);
		}
		else if(lang==2)
		{
			cal = new calendar1(obj);
		}
	}
	cal.year_scroll = true;
	cal.time_comp = true;
	cal.popup();
}
		
function ShowDialog_CheckCustomer()		
{				
	var width,height;
	var top, left;
	var locate;	
						
	var frm = window.document.forms[0];
	width = document.body.offsetWidth;
	height= document.body.offsetWidth;										
	top = 100;
	left = 200;										
	locate = "dialogLeft:" + left + "px;" +"dialogTop:" + top + "px";
	locate= locate + ";dialogHeight:300px;dialogWidth:440px;center:Yes;help:No;scroll:No;resizable:no;status:Yes;title=''";
	window.showModalDialog('./SelectCustomer.aspx', 'document.all[names].value',locate);					
	location.href = location.href;
	return false;
}
function Confirm_Delete(itemid,confirm_msg,required_msg)
{
	var i = 0;
	var isSelected = false;
	for (i=0;i<document.all.length;i++)
	{
		var str_id = document.all(i).id ;
		if (document.all(i).type == "checkbox" && str_id.indexOf(itemid,0) > 0)
		{		
			if (document.all(i).checked)
			{
				isSelected = true;			
				break;
			}
		}
	}
	
	if (isSelected==true)
	{
		return confirm(confirm_msg);
	}
	else
	{
		alert(required_msg);
		return false;
	}
}	

function onSubmit(myObhect)
{
	if (event.keyCode == 13)
	{
		document.forms[0].elements[myObhect].click();
	}
}

function ShowDialog_NewRoomRate()		
{					
	var width,height;
	var top, left;
	var locate;	
						
	var frm = window.document.forms[0];
	width = document.body.offsetWidth;
	height= document.body.offsetWidth;										
	top = 100;
	left = 200;										
	locate = "dialogLeft:" + left + "px;" +"dialogTop:" + top + "px";
	locate= locate + ";dialogHeight:230px;dialogWidth:440px;center:Yes;help:No;scroll:No;resizable:no;status:Yes;title=''";
	window.showModalDialog('./NewRoomRate.aspx', 'document.all[names].value',locate);					
	return false;
}
function ShowDialog_NewRoomTypeRate()		
{					
	var width,height;
	var top, left;
	var locate;	
						
	var frm = window.document.forms[0];
	width = document.body.offsetWidth;
	height= document.body.offsetWidth;										
	top = 100;
	left = 200;										
	var agt=navigator.userAgent.toLowerCase();
	var is_gecko = agt.indexOf('gecko')!=-1;//more detail in : http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
	if(is_gecko)
	{
		locate = "left:" + left + "px;" +"top:" + top + "px";
		locate= locate + ";height:400px;width:440px;center:Yes;help:No;scroll:No;resizable:no;status:Yes;title=''";
		window.open('./NewRoomTypeRate.aspx',locate);					
	}
	else
	{
		locate = "dialogLeft:" + left + "px;" +"dialogTop:" + top + "px";
		locate= locate + ";dialogHeight:400px;dialogWidth:440px;center:Yes;help:No;scroll:No;resizable:no;status:Yes;title=''";
		window.showModalDialog('./NewRoomTypeRate.aspx', 'document.all[names].value',locate);					
	}
	return false;
}

function HighlightRow_FF_3(chkB)	
{
	var xState=chkB.checked;
	var agt=navigator.userAgent.toLowerCase();
	var is_gecko = agt.indexOf('gecko')!=-1;//more detail in : http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
	var parent;
	if(is_gecko)
		parent = chkB.parentNode.parentNode.parentNode;
	else
		parent = chkB.parentNode.parentNode;
	if(xState == true)
	{					
		parent.className='highlightItem';
	}
	else 
	{					
		parent.className='normalItem';
	} 
}
function HighlightRow_FF(chkB)	
{
	var xState=chkB.checked;

	var parent = chkB.parentNode.parentNode;
		
	if(xState == true)
	{					
		parent.className='highlightItem';
	}
	else 
	{					
		parent.className='normalItem';
	} 
}
function EnableControl_BestIn(chk,txtTotal,ddlOur,ddlCus,txtLoc,txtRateDes,ddlCate)
{
	var checked = !chk.checked;
	for (var i=0;i<document.all.length;i++)
	{
		var str_id = document.all(i).id ;
		if (str_id.indexOf(txtTotal,0) >= 0)
			document.all(i).disabled = checked;
		if (str_id.indexOf(ddlOur,0) >= 0)
			document.all(i).disabled = checked;
		if (str_id.indexOf(ddlCus,0) >= 0)
			document.all(i).disabled = checked;
		if (str_id.indexOf(txtLoc,0) >= 0)
			document.all(i).disabled = checked;
		if (str_id.indexOf(txtRateDes,0) >= 0)
			document.all(i).disabled = checked;
		if (str_id.indexOf(ddlCate,0) >= 0)
			document.all(i).disabled = checked;
	}
}
		
function ShowDialog_UploadImages()		
{				
	var width,height;
	var top, left;
	var locate;	
						
	var frm = window.document.forms[0];
	width = document.body.offsetWidth;
	height= document.body.offsetWidth;										
	top = 100;
	left = 200;										
	locate = "dialogLeft:" + left + "px;" +"dialogTop:" + top + "px";
	locate= locate + ";dialogHeight:250px;dialogWidth:500px;center:Yes;help:No;scroll:No;resizable:no;status:Yes;title=''";
	window.showModalDialog('./Upload_Image.aspx', 'document.all[names].value',locate);					
	location.href = location.href;
	return false;
}
		
function ShowDialog_UploadSubImages()		
{				
	var width,height;
	var top, left;
	var locate;	
						
	var frm = window.document.forms[0];
	width = document.body.offsetWidth;
	height= document.body.offsetWidth;										
	top = 100;
	left = 200;										
	locate = "dialogLeft:" + left + "px;" +"dialogTop:" + top + "px";
	locate= locate + ";dialogHeight:420px;dialogWidth:500px;center:Yes;help:No;scroll:No;resizable:no;status:Yes;title=''";
	window.showModalDialog('./UploadSubImage.aspx', 'document.all[names].value',locate);					
	location.href = location.href;
	return false;
}
		
function ShowDialog_EventLocation()		
{				
	var width,height;
	var top, left;
	var locate;					
	var frm = window.document.forms[0];
	width = document.body.offsetWidth;
	height= document.body.offsetWidth;										
	top = 100;
	left = 200;										
	locate = "dialogLeft:" + left + "px;" +"dialogTop:" + top + "px";
	locate= locate + ";dialogHeight:170px;dialogWidth:300px;center:Yes;help:No;scroll:No;resizable:yes;status:Yes;title=''";
	window.showModalDialog('./EventLocation.aspx', 'document.all[names].value',locate);					
	location.href = location.href;
	return false;
}
function SelectAll(spanChk,name,highlight_function)
{
    var xState=spanChk.checked;    
    var elm=spanChk.form.elements;    
    for(i=0;i<elm.length;i++)
      if(elm[i].type=="checkbox" && elm[i].id!=spanChk.id && elm[i].id.indexOf(name,0)>0)
      {
            elm[i].checked = xState;
            highlight_function(elm[i]);
      }   
}

var oldText;//use for handle autocomplete and pressing enter key

function KeyDownHandler(objTextbox)
{       
    oldText = objTextbox.value;    
}

function KeyPressHandler(e,objTextbox,btnName)
{       
    var objButton;
	var elm = objTextbox.form.elements;
	for(i=0;i<elm.length;i++)
		if(elm[i].id.indexOf(btnName,0)>0)
		{
			objButton = elm[i];
			break;
		}
	
	if (e.keyCode == 13 || e.which == 13)
	{
	    if(objTextbox.value != '' && objTextbox.value == oldText)
	    {    
		    objButton.focus();
		    objButton.click();
		}
		e.returnValue=false;
		e.cancel = true;					
	}	
}

//Get count of checked items(checkbox) in the list
function CountOfCheckedItems(objName)
{    
    try
    {
        // Go through all items of a check list control
        var table = document.getElementById (objName);
        var cells = table.getElementsByTagName("td");
        var ctlr;
        var count = 0;
        for (var i = 0; i < cells.length; i++)
        {
           ctrl = cells[i].firstChild;
           if (ctrl.type == 'checkbox' && ctrl.checked==true)
                count++;                       
        }
        return count;
    }
    catch(err)
    {
        return 0;
    }
}

function IsEmailValid(emailStr) 
{
    var emailPat=/^(.+)@(.+)$/
    var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
    var validChars="\[^\\s" + specialChars + "\]"
    var quotedUser="(\"[^\"]*\")"
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
    var atom=validChars + '+'
    var word="(" + atom + "|" + quotedUser + ")"
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
    
    var matchArray=emailStr.match(emailPat)
    if (matchArray==null)
    	return false

    var user=matchArray[1]
    var domain=matchArray[2]

    if (user.match(userPat)==null)     
        return false
    
    var IPArray=domain.match(ipDomainPat)
    if (IPArray!=null) {    
	  for (var i=1;i<=4;i++)
	  {
	    if (IPArray[i]>255) 
	        return false	  
      }
      return true
    }

    var domainArray=domain.match(domainPat)
    if (domainArray==null) 
	    return false

    var atomPat=new RegExp(atom,"g")
    var domArr=domain.match(atomPat)
    var len=domArr.length
    if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
      return false

    // Make sure there's a host name preceding the domain.
    if (len<2) 
        return false

    return true;
}