/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

/*
	Set one value in combo box as the selected value
*/
function setSelect(listElement, listValue)
{
	for (i=0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue)	{
			listElement.selectedIndex = i;
		}
	}	
}


function getElementLeft(elm) 
{
    var x = 0;

    //set x to elm's offsetLeft
    x = elm.offsetLeft;

    //set elm to its offsetParent
    elm = elm.offsetParent;

    //use while loop to check if elm is null
    // if not then add current elm's offsetLeft to x
    //offsetTop to y and set elm to its offsetParent

    while(elm != null)
    {
        x = parseInt(x) + parseInt(elm.offsetLeft);
        elm = elm.offsetParent;
    }
    return x;
}

function getElementTop(elm) 
{
    var y = 0;

    //set x to elm's offsetLeft
    y = elm.offsetTop;

    //set elm to its offsetParent
    elm = elm.offsetParent;

    //use while loop to check if elm is null
    // if not then add current elm's offsetLeft to x
    //offsetTop to y and set elm to its offsetParent

    while(elm != null)
    {
        y = parseInt(y) + parseInt(elm.offsetTop);
        elm = elm.offsetParent;
    }

    return y;
}


function Large(obj)
{
    var imgbox=document.getElementById("imgbox");
    imgbox.style.visibility='visible';
    var img = document.createElement("img");
    img.src=obj.src;
    //img.style.width='200px';
    //img.style.height='200px';
    
    if(img.addEventListener){
        img.addEventListener('mouseout',Out,false);
    } else {
        img.attachEvent('onmouseout',Out);
    }             
    imgbox.innerHTML='';
    imgbox.appendChild(img);
    imgbox.style.left=(getElementLeft(obj)-50) +'px';
    imgbox.style.top=(getElementTop(obj)-50) + 'px';
}


function Out()
{
    document.getElementById("imgbox").style.visibility='hidden';
}

<!--tooltip-->


$("#demo img[title]").tooltip();

function toggle() {
	var ele = document.getElementById("toggleText");
	var text = document.getElementById("displayText");
	if(ele.style.display == "block") {
    		ele.style.display = "none";
		text.innerHTML = "see slab";
  	}
	else {
		ele.style.display = "block";
		text.innerHTML = "close slab";
	}
} 



/*function popitup(url,ht,wd,nm) {
	newwindow=window.open(url,nm,ht+10,wd+35,left=0,top=0);
	if (window.focus) {newwindow.focus()}
	return false;
}
*/
function popitup(url) {
	newwindow=window.open(url,'name','height=650,width=650');
	if (window.focus) {newwindow.focus()}
	return false;
}
function enlargeImage(Url,width,height){
var enlarged = new Image(); enlarged.src = ''+Url+''
var prevW = window.open("","newWin","width="+width+",height="+height+",top=140,left=200,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0"); 
prevW.document.write('<html><head><title>Preview Image</title><style type="text/css">body{margin: 0px; padding:0px;} img{margin: 0px; padding: 0px;}</style></head><body><img alt="Click to Close" title="Click to Close" style="border: 0px; padding: 0px;" src="'+Url+'" width="'+width+ '" height="'+height+'" onClick="javascript:window.close();" /></body></html>');
}





