function trim(sString) {
	if(sString) {
		while (sString.substring(0,1) == ' ')
		{
			sString = sString.substring(1, sString.length);
		}
		while (sString.substring(sString.length-1, sString.length) == ' ')
		{
			sString = sString.substring(0,sString.length-1);
		}
	}
	return sString;
}
function changeText(obj, defaultVal, type) {
	if(trim(obj.value) == '' && type == 'blur') {
		obj.value = defaultVal;
	}
	if(obj.value == defaultVal && type == 'focus') {
		obj.value = '';
	}
}
function popupWindow(url, width, height, resizable, scrollbars , top, left) {
	if(trim(url) != '') {
		
		if(width == '') { width = 150; }
		if(height == '') { height = 150; }
		
		resizable = resizable;
		if(resizable == '') { resizable = 'yes'; }
		
		scrollbars = scrollbars;
		if(scrollbars == '') { scrollbars = 'no'; }
		
		if(top == '') { top = 50; }
		if(left == '') { left = 50; }
		window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + scrollbars + ',resizable=' + resizable + ',copyhistory=no,width=' + width + ',height=' + height + ',top=' + top + ',left=' + left );
	}
}

function OpenHelp(url) {	
	url = "studio_help.php";
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=930,height=625,top=50,left=50');
}

function emailValidate(email) {
	var error = '';
	var emailFilter=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	if (email.search(emailFilter) == -1) {
	       error = "error";
	}
	return error;
}
// Start isNumber function
function isNumber(numstr, errString) {
	
	numdecs = 0;
	for (i = 0; i < numstr.length; i++) {
		mychar = numstr.charAt(i);
		if ((mychar >= "0" && mychar <= "9") || mychar == "." ) {
			if (mychar ==  ".")
				numdecs++;
		} else {
			return errString;
		}
	}
	
	if (numdecs > 1) {
		return errString;
	}
	return '';
}

// Start isNumber function
function isCurrency(numstr, errString, dec_point, thousand_sep) {
	if(dec_point == '' || (thousand_sep != '.' && thousand_sep != "" )) {
		dec_point = '.';
	}
	if(thousand_sep == '' || (dec_point != ',' && dec_point != "" )) {
		thousand_sep = ',';
	}
	numdecs = 0;
	for (i = 0; i < numstr.length; i++) {
		mychar = numstr.charAt(i);
		if ((mychar >= "0" && mychar <= "9") || mychar == dec_point || mychar == thousand_sep ) {
			if (mychar == dec_point)
				numdecs++;
		} else {
			return errString;
		}
	}
	
	if (numdecs > 1) {
		return errString;
	}
	return '';
}
// end isNumber function


// Start : Ajax Object creation Function //
function GetXmlHttpObject(handler)
{
	var objXmlHttp=null

	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("This Site doesn't work in Opera")
		return
	}
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP"
		}
		try
		{
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler
			return objXmlHttp
		}
		catch(e)
		{
			alert("Error. Scripting for ActiveX might be disabled")
			return
		}
	}
	if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler
		return objXmlHttp
	}
}
function getElementsByClassName(classname, node) {
	if(!node) node = document.getElementsByTagName("body")[0];
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	for(var i=0,j=els.length; i<j; i++) {
		if(re.test(els[i].className))a.push(els[i],els[i].innerHTML);
	}
		
	return a;
}
// End : Ajax Object creation Function //

function redirect_page(url, query_string) {
	if(url && url!='') {
		if(query_string.charAt(0) == '?') {
			document.location.href = url+'&'+query_string;	
		} else {
			document.location.href = url+'?'+query_string;
		}
		
	}
	return false;
}

function getPosition(o) {
	 var fixBrowserQuirks = true;
	 if (typeof(o)=="string") { o = document.getElementById(o); }
	 if (o==null) { return null;}
	 var left = 0;
	 var top = 0;
	 var width = 0;
	 var height = 0;
	 var parentNode = null;
	 var offsetParent = null;
	 offsetParent = o.offsetParent;
	 var originalObject = o;
	 var el = o; // "el" will be nodes as we walk up, "o" will be saved for offsetParent references
	 while (el.parentNode!=null) {
	   el = el.parentNode;
	   if (el.offsetParent==null) {
	   }
	   else {
	     var considerScroll = true;
	     /*
	     In Opera, if parentNode of the first object is scrollable, then
	offsetLeft/offsetTop already
	     take its scroll position into account. If elements further up
	the chain are scrollable, their
	     scroll offsets still need to be added in. And for some reason,
	TR nodes have a scrolltop value
	     which must be ignored.
	     */
	     if (fixBrowserQuirks && window.opera) {
	       if (el==originalObject.parentNode || el.nodeName=="TR") {
	         considerScroll = false;
	       }
	     }
	     if (considerScroll) {
	       if (el.scrollTop && el.scrollTop>0) {
	         top -= el.scrollTop;
	       }
	       if (el.scrollLeft && el.scrollLeft>0) {
	         left -= el.scrollLeft;
	       }
	     }
	   }
	   // If this node is also the offsetParent, add on the offsets and reset to the new offsetParent
	   if (el == offsetParent) {
	     left += o.offsetLeft;
	     if (el.clientLeft && el.nodeName!="TABLE") {
	       left += el.clientLeft;
	     }
	     top += o.offsetTop;
	     if (el.clientTop && el.nodeName!="TABLE") {
	       top += el.clientTop;
	     }
	     o = el;
	     if (o.offsetParent==null) {
	       if (o.offsetLeft) {
	         left += o.offsetLeft;
	       }
	       if (o.offsetTop) {
	         top += o.offsetTop;
	       }
	     }
	     offsetParent = o.offsetParent;
	   }
	 }
	 
	 if (originalObject.offsetWidth) { 
	   width = originalObject.offsetWidth;
	 }
	 if (originalObject.offsetHeight) {
	   height = originalObject.offsetHeight;
	 }
	 return {'left':left, 'top':top, 'width':width, 'height':height};
}
function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return {'width':myWidth, 'height':myHeight};
}
function setText(a, b) {
	x = document.getElementById(a);
	if (x)
		x.innerHTML = b.options[b.selectedIndex].innerHTML;
}
