function menuActive(item)
{
    item.className = "menu-active-item";
}
function menuDisable(item)
{
    item.className = "menu-item";
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

function showConfirm(confType)
{
	var s = "";
	switch (confType)
	{
		case "delete":
			s = "Are you sure you want to delete selected item(s)?";
			break;
		case "delete_branch":
			s = "Are you sure you want to delete all the branch?";
			break;
		case "block_user":
			s = "Are you sure you want to block all the messages from this member?";
			break;
		case "delete_partners":
			s = "Are you sure you want to remove selected partners from Your contacts (You will be removed from their contact list too)? ";
			break;
		case "unblock":
			s = "Are you sure you want to unblock selected member(s)?";
			break;
		case "cancel_site":
			s = "Are you sure you want to cancel?";
			break;
	}
	return confirm(s);
}

function showAlert(aType)
{
	var s = "";
	switch (aType)
	{
		case "under_construction":
			s = "This module is unser construction. Please try again later";
			break;
	}
	alert(s);
	return false;
}

function getRequestStr(params)
{
	if (params == '') return;
	var str = '';
	for(key in params)
	{
		str += key+"="+params[key];
	}
	
	return str;
}
	
function pa(_obj)
{
	var str = '';
	var i=0;
	for(key in _obj)
	{
		i++;
		blank = '';
		for(j=0;j<(30-key.length);j++)blank +='  ';
		str += key+blank;
		if(i%5 == 0)str += '\n';
	}	
	alert(str);		
}

function NewWindow(url, width, height)
{
	var l = 0;
	var t = 0;
	debugWindow = window.open(url, "_blank", "resizable=yes, scrollbars=yes, titlebar=no, location=no, menubar=no, toolbar=no, height=" + height + ", width=" + width + ", top=" + t + ", left=" + l);
}

function SetWindowSize(width, height) {
	//alert('resize' + width + ':' + height);
	if (window.innerWidth) {
		window.innerWidth = width;
		window.innerHeight = height;
	}
	else if (window.resizeTo) {
		window.resizeTo(width,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 getPostArray(_form)
	{
		_form = document.getElementById(_form);
		if (!_form) return

		post = new Array();
		for(i = 0; i < _form.elements.length; i++)
		{
			elem = _form.elements[i];
			if(elem.type == "textarea")continue;
			if(elem.type == "radio" && !elem.checked)continue;
			if(elem.type == "checkbox" && !elem.checked)continue;
			if(elem.name == "")continue;
			post[elem.name] = elem.value; 
		}

		return post;	
	}

//=====================================================================================

function JsScrollBy(anch)
{
	var anchor = document.getElementById(anch);
	var apos = findPos(anchor);
	window.scrollBy(0, apos[1]);
}

//=====================================================================================

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 getElementsByAttribute (attrN,attrV,multi)
{
    attrV=attrV.replace(/\|/g,'\\|').replace(/\[/g,'\\[').replace(/\(/g,'\\(').replace(/\+/g,'\\+').replace(/\./g,'\\.').replace(/\*/g,'\\*').replace(/\?/g,'\\?').replace(/\//g,'\\/');
    var
        multi=typeof multi!='undefined'?
            multi:
            false,
        cIterate=document.getElementsByTagName('*'),
        aResponse=[],
        attr,
        re=new RegExp(multi?'\\b'+attrV+'\\b':'^'+attrV+'$'),
        i=0,
        elm;
    while((elm=cIterate.item(i++))){
        attr=elm.getAttributeNode(attrN);
        if(attr &&
            attr.specified &&
            re.test(attr.value)
        )
            aResponse.push(elm);
    }
    return aResponse;
}

//=====================================================================================

function FieldErrorRequired(id, title)
{
	alert('Please fill in ' + title);
	var obj = document.getElementById(id);
	if (obj)
	{
		obj.focus();
	}
}

//=====================================================================================

function Dump(d,l) {
    if (l == null) l = 1;
    var s = '';
    if (typeof(d) == "object") {
        s += typeof(d) + " {\n";
        for (var k in d) {
            for (var i=0; i<l; i++) s += "  ";
            s += k+": " + Dump(d[k],l+1);
        }
        for (var i=0; i<l-1; i++) s += "  ";
        s += "}\n"
    } else {
        s += "" + d + "\n";
    }
    return s;
}

//=====================================================================================

function ShowHide(id)
{
	var obj = document.getElementById(id);
	if (obj)
	{
		if (obj.style.display == "none" || !obj.style.display)
		{
			obj.style.display = "block";
			obj.style.visibility = "visible";
			return true;
		}
		else
		{
			obj.style.display = "none";
			obj.style.visibility = "hidden";
			return false;
		}
	}
}

//=====================================================================================

function truncate(str, len, end)
{
	if (str.length > len)
	{
		str = str.substring(0, len);
		str = str.replace(/\w+$/, '');
		if (!end) end = '...';
		str += end;
	}
	
	return str;
}
//=====================================================================================

function htmlspecialchars(str,typ)
{
	if(typeof str=="undefined") str="";
	if(typeof typ!="number") typ=2;
	typ=Math.max(0,Math.min(3,parseInt(typ)));
	var from=new Array(/&/g,/</g,/>/g);
	var to=new Array("&amp;","&lt;","&gt;");
	if(typ==1 || typ==3) {from.push(/'/g); to.push("&#039;");}
	if(typ==2 || typ==3) {from.push(/"/g); to.push("&quot;");}
	for(var i in from) str=str.replace(from[i],to[i]);
	return str;
}
//=====================================================================================
