function show_hide(link,id){
	var obj = document.getElementById(id);
	if((obj != null)){
		 if(obj.className == 'hide'){
		 	obj.className = 'show';
		 	link.className = 'expanded1';
		 }else if (obj.className == 'show'){
		 	obj.className = 'hide';
		 	link.className = 'collapsed1';
		 }
	 }
}

function FP_changeProp() {//v1.0
	var args=arguments,d=document,i,j,id=args[0],o=FP_getObjectByID(id),s,ao,v,x;
	d.$cpe=new Array(); if(o) for(i=2; i<args.length; i+=2) { v=args[i+1]; s="o";
	ao=args[i].split("."); for(j=0; j<ao.length; j++) { s+="."+ao[j]; if(null==eval(s)) {
	s=null; break; } } x=new Object; x.o=o; x.n=new Array(); x.v=new Array();
	x.n[x.n.length]=s; eval("x.v[x.v.length]="+s); d.$cpe[d.$cpe.length]=x;
	if(s) eval(s+"=v"); }
}

function FP_getObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}

function FP_changePropRestore() {//v1.0
 var d=document,x; if(d.$cpe) { for(i=0; i<d.$cpe.length; i++) { x=d.$cpe[i];
 if(x.v=="") x.v=""; eval("x."+x.n+"=x.v"); } d.$cpe=null; }
}

function FP_preloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function FP_swapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

gSlideshowInterval = 4;
gNumberOfImages = 4;

gImages = new Array(gNumberOfImages);
gImages[0] = "/images/img1.jpg";
gImages[1] = "/images/img2.jpg";
gImages[2] = "/images/img3.jpg";
gImages[3] = "/images/img4.jpg";

function canManipulateImages() {
	if (document.images)
		return true;
	else
		return false;
}

/**
  * Response to keypress event of a input field, accept phone numeric keys only
  * input phone number
  * @return true: ok; false: not ok
  * **/
function inputPhoneNumericOnly(e)
{
    if (window.event) 
	 {
	 	keycode = window.event.keyCode;
	 }
	 else if (e)
	 {
	 	keycode = e.which;
	 }
	
	 if(keycode==8 || keycode==0)
	 {
	 	keycode = 55;
	 }
	
	 var keychar = String.fromCharCode(keycode);
	
	 reg=new RegExp("[^0-9\-\(\)\.\+\]");
	
	 if(reg.test(keychar))
	 {
		e.cancelBubble = true
		e.preventDefault? e.preventDefault() : e.returnValue = false; 
	 }  
}

function checkNumInt(e)
{
	if (window.event) 
		keycode = window.event.keyCode;
	else if (e) 
		keycode = e.which;

	if (keycode>31 && (keycode < 48 || keycode > 57))
	{
		e.cancelBubble = true
		e.preventDefault? e.preventDefault() : e.returnValue = false;	
	}		
}

/**
 * Removes leading and ending whitespaces
 * @param: value - string
 * @return: value - string - after remove leading and ending whitespaces
 **/
function Trim(value) {
	a = value.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};


/**
 * Check whether a string is null
 * @param - string to be check
 * @return - true if it's null, else it is not null
 * **/
function isNull(sStr)
{
    if ((sStr == null) || (Trim(sStr) == ''))
    {
        return true;
	}
    else
    {
        return false;
	}
}

/**
 * Check email address
 * @Param: email address
 * @return - true if email valid, false if email invalid
 **/
function isValidEmail(email_address)
{    
	/*var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
    if (email_address.search(emailRegEx) == -1){
		return false;
	}else{
	    return true;
	}*/
    return echeck(email_address);
}

/**
 * Check url
 * @Param: url address
 * @return - true if url valid, false if url invalid
 **/
function CheckValidUrl(strUrl)
{
	var urlRegxp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/;
	if (urlRegxp.test(strUrl) != true) {
		return false;
	} else {
		return true;
	}
}

/*********************************************************
* Function  : Event when User blur on textbox quick search
* Return    : None
* Parameter :
*		idSearch : ID of textbox search
*		mess	 : Message into textbox quick search
*********************************************************/	
function regisOnBlur(idSearch, mess)
{
	str = Trim(document.getElementById(idSearch).value," ");
	if (str == "")	
	{
		document.getElementById(idSearch).value = mess;
		document.getElementById(idSearch).className = "box-register";
	}
}

/*********************************************************
* Function  : Event when User focus on textbox quick search
* Return    : None
* Parameter :
*		idSearch : ID of textbox search
*		mess	 : Message into textbox quick search
*********************************************************/	
function regisOnFocus(idSearch, mess)
{
	strOrg = Trim(document.getElementById(idSearch).value," ");
        var oTextbox = document.getElementById(idSearch);
	strCompare = mess;	
	if (strOrg == strCompare)
	{
		document.getElementById(idSearch).value = "";
		document.getElementById(idSearch).className = "box-field";
	}
    if (oTextbox .createTextRange) {
        var r = (oTextbox.createTextRange());
        r.moveStart('character', (oTextbox.value.length));
        r.select();
    }
}
/*********************************************************
* Function  : Enter focus sang control khac
* Return    : None
* Parameter :
*		field	: ID of control
*		event	: Object event
*********************************************************/		
function handleEnter (field, event) 
{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	} 
	else
		return true;
} 
/**
 * Click on Reset button of Register box
 **/
function resetRegister()
{
	document.getElementById("firstname").value 		= "First Name";
	document.getElementById("firstname").className 	= "box-register";
	document.getElementById("lastname").value 		= "Last Name";
	document.getElementById("lastname").className 	= "box-register";
	document.getElementById("email").value 			= "Email";
	document.getElementById("email").className 		= "box-register";
}
	
/**
 * Click on Submit button of Register box
 **/
 function submitRegister()
 {
 	document.mmc.action = "attend.php";
	document.mmc.submit();
 }

 /**
 * Check Zip code
 **/
function isValidZip(zipcode)
{
    // Check for correct zip code
    var reZip = /((^\d{5}([- |]\d{4})?$)|(^[A-Z]\d[A-Z][- |]\d[A-Z]\d$))/;
    if (!reZip.test(zipcode)) {
    	return false;
    }
	return true;
}

function echeck (emailStr) {

    /* The following variable tells the rest of the function whether or not
    to verify that the address ends in a two-letter country or well-known
    TLD.  1 means check it, 0 means don't. */

    var checkTLD=1;

    /* The following is the list of known TLDs that an e-mail address must end with. */

    var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

    /* The following pattern is used to check if the entered e-mail address
    fits the user@domain format.  It also is used to separate the username
    from the domain. */

    var emailPat=/^(.+)@(.+)$/;

    /* The following string represents the pattern for matching all special
    characters.  We don't want to allow special characters in the address.
    These characters include ( ) < > @ , ; : \ " . [ ] */

    var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

    /* The following string represents the range of characters allowed in a
    username or domainname.  It really states which chars aren't allowed.*/

    var validChars="\[^\\s" + specialChars + "\]";

    /* The following pattern applies if the "user" is a quoted string (in
    which case, there are no rules about which characters are allowed
    and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
    is a legal e-mail address. */

    var quotedUser="(\"[^\"]*\")";

    /* The following pattern applies for domains that are IP addresses,
    rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
    e-mail address. NOTE: The square brackets are required. */

    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

    /* The following string represents an atom (basically a series of non-special characters.) */

    var atom=validChars + '+';

    /* The following string represents one word in the typical username.
    For example, in john.doe@somewhere.com, john and doe are words.
    Basically, a word is either an atom or quoted string. */

    var word="(" + atom + "|" + quotedUser + ")";

    // The following pattern describes the structure of the user

    var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

    /* The following pattern describes the structure of a normal symbolic
    domain, as opposed to ipDomainPat, shown above. */

    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

    /* Finally, let's start trying to figure out if the supplied address is valid. */

    /* Begin with the coarse pattern to simply break up user@domain into
    different pieces that are easy to analyze. */

    var matchArray=emailStr.match(emailPat);

    if (matchArray==null) {

        /* Too many/few @'s or something; basically, this address doesn't
        even fit the general mould of a valid e-mail address. */

        //alert("Email address seems incorrect (check @ and .'s)");
        return false;
    }
    var user=matchArray[1];
    var domain=matchArray[2];

    // Start by checking that only basic ASCII characters are in the strings (0-127).

    for (i=0; i<user.length; i++) {
        if (user.charCodeAt(i)>127) {
            //alert("Ths username contains invalid characters.");
            return false;
       }
    }
    for (i=0; i<domain.length; i++) {
        if (domain.charCodeAt(i)>127) {
            //alert("Ths domain name contains invalid characters.");
            return false;
           }
    }

    // See if "user" is valid

    if (user.match(userPat)==null) {

        // user is not valid

        //alert("The username doesn't seem to be valid.");
        return false;
    }

    /* if the e-mail address is at an IP address (as opposed to a symbolic
    host name) make sure the IP address is valid. */

    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null) {

        // this is an IP address

        for (var i=1;i<=4;i++) {
            if (IPArray[i]>255) {
            //alert("Destination IP address is invalid!");
            return false;
           }
        }
    return true;
    }

    // Domain is symbolic name.  Check if it's valid.

    var atomPat=new RegExp("^" + atom + "$");
    var domArr=domain.split(".");
    var len=domArr.length;
    for (i=0;i<len;i++) {
        if (domArr[i].search(atomPat)==-1) {
            //alert("The domain name does not seem to be valid.");
            return false;
       }
    }

    /* domain name seems valid, but now make sure that it ends in a
    known top-level domain (like com, edu, gov) or a two-letter word,
    representing country (uk, nl), and that there's a hostname preceding
    the domain or country. */

    if (checkTLD && domArr[domArr.length-1].length!=2 &&
        domArr[domArr.length-1].search(knownDomsPat)==-1) {
        //alert("The address must end in a well-known domain or two letter " + "country.");
        return false;
    }

    // Make sure there's a host name preceding the domain.

    if (len<2) {
        //alert("This address is missing a hostname!");
        return false;
    }

    // If we've gotten this far, everything's valid!
    return true;
}

   function setActiveClass(li)
   {
         li.className = "active";
   }
   function clearActiveClass(li)
   {
         document.getElementById(li).className = "";
   }
   function showTab(tabName)
   {
       var tab = document.getElementById(tabName);
       
       tab.style.display = "inline";
   }
   function hideTab(tabName)
   {
       var tab = document.getElementById(tabName);
       
       tab.style.display = "none";
   }
   function openEmailSpeaker(){
		var widScreen = document.body.clientWidth   //Width of Screen
		var heiScreen = parseInt(document.body.clientHeight) //Heigth of Screen
		x = (widScreen-580)/2;
		y = (heiScreen-500)/2;

		window.open('/popup/sendEmailSpeaker/', 'sendMailSpeaker', ' scrollbars=1,menubar=0,width=580, height=500, resizable=0,toolbar=0,status=1, left='+x+', top='+y); 
	}

function checkStatusMultiCheckboxAll(selectedId)
{
	var first = parseInt(document.getElementById("edit-firstRow").value,10);
	var last = parseInt(document.getElementById("edit-lastRow").value,10);
	var idx = 0;
	var objCheck = null;
	var bCheckAll = true;
	if (first == 0 && last == 0){
		return;
	}
	for(idx = first; idx <= last; idx++){
		objCheck = document.getElementById("check_all_" + idx);
		if (objCheck != null){
			if (objCheck.checked == false){
				bCheckAll = false;
				break;
			}
		}
	}
	objCheck = document.getElementById("chk_ALL");
	objCheck.checked = bCheckAll;
	
	//Update hidden field
	objCheck = document.getElementById("check_all_" + selectedId);
	var objHidden = document.getElementById("edit-hdfChecked-" + selectedId);
	if (objCheck.checked == true){
		objHidden.value = "1";
	}else{
		objHidden.value = "0";
	}
}

function checkAllMultiRow(objAll)
{
	var first = parseInt(document.getElementById("edit-firstRow").value,10);
	var last = parseInt(document.getElementById("edit-lastRow").value,10);
	if (first == 0 && last == 0){
		return;
	}
	setCheckList("check_all_",first,last,objAll.checked);
}

function setCheckList(prefix,start,end,bCheck){
	var idx = 0;
	var objCheck = null;
	var objHidden = null;
	for(idx = start; idx <= end; idx++){
		objCheck = document.getElementById(prefix + idx);
		if (objCheck != null){ 
			objCheck.checked = bCheck;
			if (prefix != ""){
				objHidden = document.getElementById("edit-hdfChecked-" + idx);
				if (bCheck == true){
					objHidden.value = "1";
				}else{
					objHidden.value = "0";
				}
			}
		}
	}
}

function updateRole(objCheckbox){
	if ( objCheckbox.id == "edit-roles-5"){
		var objComboCompany = document.getElementById("edit-companyAssign");
		//var objDivCompany = document.getElementById("divCompany");
		if (objCheckbox.checked == true){
			objComboCompany.disabled = false;
			//objDivCompany.style.display = "inline";
		}else{
			objComboCompany.selectedIndex = 0;
			objComboCompany.disabled = true;
			//objDivCompany.style.display = "none";
		}
	}
}

function goto(url)
{
	window.location.href = url;
}

function openEmailPopup(title, url){
		window.open('/popup/sendEmail/' + title + '/' + url, 'emailToFriend', 'width=587,height=585,scrollbars=yes');
	}
	
/*********************************************************
* Function  : Show Popup Search
* Return    : None
* Parameter :
*		e		: Event object
*	    divID	: ID of div tag
*		widPop	: Width of Popup
*		heiPop	: Height of Popup
*********************************************************/
function showPopupSearch(e, divID, widPop, heiPop)
{
	//Get width and height of the screen
	var scroll_Y 	= document.body.scrollTop;
	var widScreen 	= parseInt(document.body.clientWidth);
	var heiScreen 	= parseInt(document.body.clientHeight);
	
	pos_x			= (parseInt(widScreen) - widPop)/2  
	pos_y			= ((parseInt(heiScreen) - heiPop)/2) + parseInt(scroll_Y);

	popup 				= document.getElementById(divID);
	popup.style.top     = pos_y;
	popup.style.left    = pos_x;
	popup.style.display = "block";	
}
	
/*********************************************************
* Function  : Hide Popup Search
* Return    : None
* Parameter :
*	    divID	: ID of div tag
*********************************************************/
function hidePopupSearch(divID)
{
	document.getElementById(divID).style.display = "none"
}

function getValSearchPopup(frameID, frameName, divID, desControl,desControl1)
{
	var chkFlag = false;
	
	window.frames[frameName].document.getElementById('pagesearch-speaker-form').name = 'mmc';
	
	fraID = document.getElementById(frameID);
	if (fraID.tagName=='IFRAME' && fraID.id == frameID)
	{
		var n = window.frames[frameName].document.mmc.raUID.length;
		var list_id = '';
		var list_name = '';
		if(n>0)
		{
			for(i=0; i<n; i++)
			{
				if(window.frames[frameName].document.mmc.raUID[i].checked)
				{
					if(list_id == ''){
						list_id = window.frames[frameName].document.mmc.raUID[i].value;
					}else{
						list_id = list_id + ', ' + window.frames[frameName].document.mmc.raUID[i].value;
					}
					
					if(list_name == ''){
						list_name = window.frames[frameName].document.mmc.raUID[i].title;
					}else{
						list_name = list_name + ', ' + window.frames[frameName].document.mmc.raUID[i].title;
					}
					/*document.getElementById(desControl).value = window.frames[frameName].document.mmc.raUID[i].value;
					if(desControl1 != null && desControl1 != ''){
						document.getElementById(desControl1).value = window.frames[frameName].document.mmc.raUID[i].title;
					}					
					hidePopupSearch(divID);
					chkFlag = true;
					break;*/
				}
			}
			document.getElementById(desControl).value = list_id;
			if(desControl1 != null && desControl1 != ''){
				document.getElementById(desControl1).value = list_name;
			}					
			hidePopupSearch(divID);
			chkFlag = true;
		}
		else
		{
			if(window.frames[frameName].document.mmc.raUID.checked)
			{
				document.getElementById(desControl).value = window.frames[frameName].document.mmc.raUID.value;
				if(desControl1 != null && desControl1 != ''){
					document.getElementById(desControl1).value = window.frames[frameName].document.mmc.raUID.title;
				}
				hidePopupSearch(divID);
				chkFlag = true;
			}
		}
		if(chkFlag==false)
		{
			alert("Please select a user!")
		}
	}	
}
/******************* Start: Popup media on home page **************************************/
//Init ajax
function GetXmlHttpObject()
{  
	var objXMLHttp=null;
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}

//Show tip Home
var gloNodeID;
var requestThumbs = GetXmlHttpObject();
function showThumbHome(e, idThumbnailBg, idThumbnail, objDivImg, nodeID)
{						
	closeThumbnail(idThumbnailBg, idThumbnail);
	if(requestThumbs.readyState != 4 && gloNodeID)
	{
		return;
	}
	var heightScreen = document.body.scrollHeight;
	var widthScreen = document.body.clientWidth;

	var pos_x = obtenerPosicionX(objDivImg); //refer to common
	var pos_y = obtenerPosicionY(objDivImg); //refer to common
	
	//If Sum of x of mouse pointer and length of Tooltip is longer than the length of screen
	if (pos_x + 500 >= widthScreen)
		pos_x = pos_x - 500
	
	popup   = document.getElementById(idThumbnail);	
	popupBg = document.getElementById(idThumbnailBg);
	
	popupBg.style.top      	= 0;
	popupBg.style.left     	= 0;
	//popupBg.style.display  	= "block";	
	popupBg.style.width	 	= widthScreen;
	popupBg.style.height	= heightScreen;
		
	popup.style.top      = pos_y;
	popup.style.left     = pos_x;
	//popup.style.display  = "block";	
	
	if(nodeID != gloNodeID)
	{	
		gloNodeID = nodeID
		popup.innerHTML		 = "";//"<table width='250px' height='150px'><tr><td align='center' valign='middle'><img src='/images/loading.gif'></td></tr></table>";
	}
	requestThumbs.open("GET", "/tip_home.php?nodeID="+nodeID, true);	
	requestThumbs.onreadystatechange = function() {		
		if (requestThumbs.readyState == 4) {	
			popup.innerHTML      = requestThumbs.responseText;
			$("#"+idThumbnail).show(500, function () {
		        $("#"+idThumbnailBg).show();
		    });
		}
	}
	requestThumbs.send(null);
}

//Close Tip
function closeThumbnail(idThumbnailBg, idThumbnail)
{
	//document.getElementById(idThumbnail).style.display = "none";
	$("#"+idThumbnail).hide();
//	document.getElementById(idThumbnailBg).style.display = "none";
	$("#"+idThumbnailBg).hide();
}

//Get X position
function obtenerPosicionX(elemento)
{
	var x=0;
	while(elemento)
	{
		x += elemento.offsetLeft;
		elemento=elemento.offsetParent;
	}
	return x;
}

//Get Y position
function obtenerPosicionY(elemento)
{
	var y=0;
	while(elemento)
	{
		y += elemento.offsetTop;
		elemento=elemento.offsetParent;
	}
	return y;
}
/******************* End: Popup media on home page **************************************/
