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 trimLeft(str){
  if (str==null){return null;}
  for(var i=0;str.charAt(i)==" ";i++);
  return str.substring(i,str.length);
}
	
function trimRight(str){
  if (str==null){return null;}
  for(var i=str.length-1;str.charAt(i)==" ";i--);
  return str.substring(0,i+1);
}

function trim(str){
	return trimLeft(trimRight(str));
}

function setCookie (name, value, lifespan, access_path) {      
  var cookietext = name + "=" + escape(value)  
  if (lifespan != null) {  
    var today=new Date()     
    var expiredate = new Date()      
    expiredate.setTime(today.getTime() + 1000*60*60*24*lifespan)
    cookietext += "; expires=" + expiredate.toGMTString()
  }
  if (access_path != null) { 
    cookietext += "; PATH="+access_path 
  }
  document.cookie = cookietext 
  return null  
}
function getCookie(Name) {
  var search = Name + "="                       
  var CookieString = document.cookie            
  var result = ""                               
  if (CookieString.length > 0) {                
    offset = CookieString.indexOf(search)       
    if (offset != -1) {                         
      offset += search.length                   
      end = CookieString.indexOf(";", offset)   
      if (end == -1)                            
        end = CookieString.length               
      result = unescape(CookieString.substring(offset, end))         
      } 
    }
   return result                                
}

function deleteCookie(Name, Path) {
  isDeleteCookies = true;
  setCookie(Name,"Deleted", -1, Path)
}
function getChkAnnouncement(chkAnnounmentId){
		chkAnnounmentId = "announcement_" + chkAnnounmentId;
		var numberAnnounment =  document.getElementById("edit-hdf-number-announcement").value;
		var objchkAnnounment = document.getElementById(chkAnnounmentId);
		var idAnnounment;
		var objAnnounment;		
		for(var j = 0; j < numberAnnounment; j++){
			idAnnounment = "announcement_" + j;
			if (idAnnounment != chkAnnounmentId){
				objAnnounment =  document.getElementById(idAnnounment);
				if (objchkAnnounment.checked){
					objAnnounment.checked = false;
					objAnnounment.disabled = true;
				}else{
					objAnnounment.disabled = false;
				}
			}
		}
	}

/*
 * Only input phone numeric
 */
function checkFoneNum(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 forcusFirstControl()
{	
	var node_list = document.getElementsByTagName('input');
	
	for (var i = 0; i < node_list.length; i++) 
	{
        if ( i > 0 && node_list[i].getAttribute('type') == 'text' && node_list[i].getAttribute('disabled') == false)
        {        	
        	try{
        		node_list[i].focus();
        	}catch(err){}
			break;
       	}
    }
}
function check_item_status(cbx)
{
	var new_value = cbx.value;
	if(new_value == 0)//In Use
	{
		alert('Can not change status to In Use');
	}
}

/*********************************************************
* 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.documentElement.scrollTop;
	var widScreen 	= parseInt(document.documentElement.clientWidth);
	var heiScreen 	= parseInt(document.documentElement.scrollTop)+ parseInt(document.documentElement.clientHeight)
	pos_x			= (parseInt(widScreen) - widPop)/2  
	pos_y			= ((parseInt(heiScreen) - heiPop)/2) + parseInt(scroll_Y) - 50;

	popup 				= document.getElementById(divID);
	popup.style.top     = pos_y + "px";
	popup.style.left    = pos_x + "px";
	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)
{
	var chkFlag = false;
	fraID = document.getElementById(frameID);
	if (fraID.tagName=='IFRAME' && fraID.id == frameID)
	{
		var n = window.frames[frameName].document.drv.raUID.length;
		if(n>0)
		{
			for(i=0; i<n; i++)
			{
				if(window.frames[frameName].document.drv.raUID[i].checked)
				{
					document.getElementById(desControl).value = window.frames[frameName].document.drv.raUID[i].value;
					hidePopupSearch(divID);
					chkFlag = true;
					break;
				}
			}
		}
		else
		{
			if(window.frames[frameName].document.drv.raUID.checked)
			{
				document.getElementById(desControl).value = window.frames[frameName].document.drv.raUID.value;
				hidePopupSearch(divID);
				chkFlag = true;
			}
		}
		if(chkFlag==false)
		{
			alert("Please select a user!")
		}
	}
}

function openEmailPopup(title, url){
	window.open('/popup/sendEmail/' + title + '/' + url, 'emailToFriend', 'width=720,height=570,scrollbars=yes');
}
function openTwiterPopup(nid){
    window.open('/popup/twitter_post/' + nid , 'post_tweiter', 'width=720,height=310,scrollbars=yes');
}
function openContactPopup(){
    window.open('/popup/contactpop', 'Feedback', 'width=720,height=650,scrollbars=yes');
}