function hideElement (overDiv)
{

      $('select').filter(function()
                  {
                     var selPos = $(this).offset();
                     objLeft   = selPos.left;
                     objTop    = selPos.top;
                     objHeight = $(this).height();
                     objWidth = $(this).width();
                     
                     var divPos = $(overDiv).offset();
                     divLeft   = divPos.left;
                     divTop    = divPos.top;
                     divHeight = $(overDiv).height();
					
                     divWidth = $(overDiv).width();
                     
                     if ((divLeft + divWidth) <= objLeft)
                     {
                        return false;
                     }
                     else if ((divTop + divHeight) <= objTop)
                     {
                        return false;
                     }
                     else if (divTop >= (objTop + objHeight))
                     {
                        return false;
                     }
                     else if (divLeft >= (objLeft + objWidth))
                     {
                        return false;
                     }
                     else
                     {
                        return true;
                     }
                  }).css('visibility','hidden');
   
}



function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   
   function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}



var timeout    = 2500;
var closetimer = 0;
var menuItems = 0;
var sper = 3;
function menuOver(obj) {
	var img = $(obj).find('img:first');
	img.attr('src', getImgPath(img) + img.attr('overImg'))
}

function menuOut(obj) {
	var img = $(obj).find('img:first');
	if (img.attr('status') != 'on') {
		img.attr('src', getImgPath(img) + img.attr('orgImg'))
	}
}

function getImgPath(obj) {
	var index = obj.attr('src').lastIndexOf('/');
	return obj.attr('src').substring(0, index) + '/'
}

	function dropDownOver()
	{
	cancelDropDownTimer();
	dropDownOut();
	menuOver(this)
	hideElement($(this).find("ul"));
	 
	var pos = $(this).position();
	var x = pos.left;
	var y = pos.top;	
	menuItems = $(this).find("ul").css({'visibility':'visible', 
									   	  'top':(y+ $(this).height()-sper) + "px"
										  })
	//var maxLength = getCharMaxLength($(this).find("ul").find("a"))
    //$(this).find("ul").width(maxLength*10) 
	if($(".cs-hkmex-menu > li").index(this) == ($(".cs-hkmex-menu > li").size()-1))
	{
	var x = x- ($(this).find("ul").width() - $(this).width())
	$(this).find("ul").css({'left': x +"px"})
	}
	
	}
	function dropDownOut()
	{
		if(menuItems)
		menuItems.css({'visibility':'hidden'})
		$("select").css({ visibility: "visible" });
	}
	function timer()
	{
		menuOut(this)
		closetimer = window.setTimeout(dropDownOut, timeout);
	}
	function  cancelDropDownTimer(){
		if(closetimer)
		{
	  	window.clearTimeout(closetimer);
      	closetimer = null;
	    }
	}

var styleID = "font-size-container";

function fontsControl(isIncrease)
{
	var fontSize = 0
	
	if($.cookie('fontsize') == "" || $.cookie('fontsize') == null)
	{
		var currentSize = $('#'+styleID).css('font-size').split('px')
		if(isIncrease){fontSize =currentSize[0]*3/4+0.5 }else
		{fontSize =currentSize[0]*3/4-0.5 }
	    
	}
	/*
	else
	{
		
		//if(isIncrease){fontSize = 	$.cookie('fontsize')+0.5;}else
		//{fontSize = 	$.cookie('fontsize')-0.5 }
	}
	$.cookie('fontsize', fontSize);
	
	*/
	$('#'+styleID).css('font-size',fontSize+"pt")
	//alert(fontSize)
	
}

function getCharMaxLength(obj)
{
	var maxLength = 0;
	$.each(obj,
		   function()
		   {
			   if($(this).text().length > maxLength)
			   {
					maxLength = $(this).text().length; 
				
			   }
			   
		   }
		   
    )

	return maxLength;
}

function getQuery(keyValue)
{
	try
	{
	var index =-1
	var _all = window.location.href.toString()
	var _query = window.location.search.substring(1)
	if(_query)	
	{
		var parmas = _query.split("&")
		for(i=0;  i< parmas.length; i++)
		{
			var key = parmas[i]
			
			if((index = key.indexOf("=")) >0)
			{
				var paramKey = key.substring(0, index)
				var paramVal = key.substring(index+1)
				if(paramKey == keyValue)
				{
					return paramVal;
				}
			}
		}
	}else
	return false;
	}catch(e){}
	
	
	
}


