//string functions --------------------------------------------------------------------------------------------------------                                                                                                                                                                               
function common_ltrim(sString) {
	while (sString.substring(0,1) == ' ') sString = sString.substring(1, sString.length);
	return sString;
}
function common_rtrim(sString) {
	while (sString.substring(sString.length-1, sString.length) == ' ') sString = sString.substring(0,sString.length-1);
	return sString;
}
function common_trim(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 common_isNumber(iString) {
    // no leading 0s allowed
    return (("" + parseInt(iString)) == iString);
}
//---------------------------------------------------------------------------------------------------------------------------

//
function common_addTag(val) {
	var target = document.form1.Tags;
	if(target.value.indexOf(val) == -1) {
		target.value += " " + val;
	}
	if(target.value.substring(0,1) == " ") {
		target.value = target.value.substring(1);
	}
}
function common_clearTags() {
	document.form1.Tags.value = "";
}

// visual style for enabled/disabled fields
// to disable a field, blur it on focus:
// onfocus="if(!document.form1.cbEnabled.checked)this.blur()"

function common_enable(fieldName, bEnabled) {
	if(bEnabled) {
		setStyle(fieldName, "color", "#000000");
		setStyle(fieldName, "background", "#F0F0FF");
	} else {
		setStyle(fieldName, "color", "#999999");
		setStyle(fieldName, "background", "#CCCCCC");
	}
}
function setStyle(objId, style, value) {
    document.getElementById(objId).style[style] = value;
}

//function called from flash windows
function flashPutHref(url) {
	//do nothing
}


//opens the zoom window and asks it to display the image
function zoom(w,h,imgsrc) {
	var theLink = "http://www.esoundz.com/details/zoom.php?src=" + imgsrc + "&w=" + w + "&h=" + h;
	var params = "height=" + h + ",width=" + w + ",scrollbars=no,toolbars=no,status=no";
	var win = window.open(theLink,"zoomWin",params);
	win.focus();
}


//opens the url in a new window with the specified height and width
function info(w,h,url) {
	var theLink = "http://www.esoundz.com/" + url;
	var params = "height=" + h + ",width=" + w + ",toolbars=no,status=no,scrollbars=yes";
	var win = window.open(theLink,"zoomWin",params);
	win.focus();
}

function toggleModule(modname) {
	var modLayer = MM_findObj('l' + modname);
	modLayer.style.display = modLayer.style.display == "none" ? "block" : "none";
	if(window.modules) {
		for(x=0;x<modules.length;x++) {
			if(modname == modules[x].name) {
				var modImage = MM_findObj('img' + modname);
				modImage.src = (modImage.src == modules[x].imgOpen.src) ? modules[x].imgClosed.src : modules[x].imgOpen.src;
			}
		}
	}
}

function openModule(modname) {
	var modLayer = MM_findObj('l' + modname);
	modLayer.style.display = "block";
	for(x=0;x<modules.length;x++) {
		if(modname == modules[x].name) {
			var modImage = MM_findObj('img' + modname);
			modImage.src = modules[x].imgOpen.src;
		}
	}
}

function closeModule(modname) {
	var modLayer = MM_findObj('l' + modname);
	modLayer.style.display = "none";
	for(x=0;x<modules.length;x++) {
		if(modname == modules[x].name) {
			var modImage = MM_findObj('img' + modname);
			modImage.src = modules[x].imgClosed.src;
		}
	}
}

function checkSearch(val) {
	if(val == "") {
		alert("Please type a sound to search for.");
		return false;
	}
	if(val.length < 3) {
		alert("Please type 3 or more letters to search by");
		return false;
	}
	if(val.indexOf("_") != -1 || val.indexOf("%") != -1 ) {
		alert("We're sorry, the underscore and % characters are not allowed\nPlease type your search again");
		return false;
	}
	return true;
}


 function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
 function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
 function setTable(obj,lyr)
{
	var coors = findPos(obj);
	if (lyr == '') coors[1] += 1;
	var x = document.getElementById(lyr);
	x.style.top = coors[1] + 'px';
	x.style.left = coors[0] + 'px';
	return x.style.left;
}
// ------------------------------------   Show Hide

function showhide(id)
{
	if (document.getElementById)
	{
		obj = document.getElementById(id);
		if (obj.style.display == "none")
		{
			obj.style.display = "";
		} else 
		{
			obj.style.display = "none";
		}
	}
}
// cookies management

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

// tabs management
function init_sliding_tabs(){
	new sliding_tabs($$('#tab_1 .tab'),$$('#tab_1 .tab_body'),{
		tab_margin_right:'10px',
		tab_margin_left:'10px',
        initial_tab:0
	});
	new sliding_tabs($$('.img_tab'),$$('.img_tab_body'),{
		active_tab_class:'none',
		tab_margin_right:'30px',
		tab_margin_left:'30px',
		container_reposition:true,
		container:'tab_2',
		outer_container:'tab_2_outer_container',
		offset:100,
		scroll_fx_duration:30
	});
	new sliding_tabs($$('#tab_3 .inner_tab'),$$('#tab_3 .inner_tab_body'),{
		orientation:'vertical',
		tab_margin_top:'10px',
		tab_margin_bottom:'10px',
        initial_tab:0,
        classes:{
			tab_overflow:'inner_tab_overflow',
			tab_container:'inner_tab_container',
			tab_body_container:'inner_tab_body_container'
		}
	});
}

/*-----------------------------------------------------------
    Toggles element's display value
    Input: any number of element id's
    Output: none 
    ---------------------------------------------------------*/
function toggleDisp() {
    for (var i=0;i<arguments.length;i++){
        var d = $(arguments[i]);
        if (d.style.display == 'none')
            d.style.display = 'block';
        else
            d.style.display = 'none';
    }
}
/*-----------------------------------------------------------
    Toggles tabs - Closes any open tabs, and then opens current tab
    Input:     1.The number of the current tab
                    2.The number of tabs
                    3.(optional)The number of the tab to leave open
                    4.(optional)Pass in true or false whether or not to animate the open/close of the tabs
    Output: none 
    ---------------------------------------------------------*/
function toggleTab(num,numelems,opennum,animate) {
    if ($('tabContent'+num).style.display == 'none'){
        for (var i=1;i<=numelems;i++){
            if ((opennum == null) || (opennum != i)){
                var temph = 'tabHeader'+i;
                var h = $(temph);
                if (!h){
                    var h = $('tabHeaderActive');
                    h.id = temph;
                }
                var tempc = 'tabContent'+i;
                var c = $(tempc);
                if(c.style.display != 'none'){
                    if (animate || typeof animate == 'undefined')
                        Effect.toggle(tempc,'blind',{duration:0.5, queue:{scope:'menus', limit: 3}});
                    else
                        toggleDisp(tempc);
                }
            }
        }
        var h = $('tabHeader'+num);
        if (h)
            h.id = 'tabHeaderActive';
        h.blur();
        var c = $('tabContent'+num);
        c.style.marginTop = '2px';
        if (animate || typeof animate == 'undefined'){
            Effect.toggle('tabContent'+num,'blind',{duration:0.5, queue:{scope:'menus', position:'end', limit: 3}});
        }else{
            toggleDisp('tabContent'+num);
        }
    }
}
