
//====================================================================================================
//	File Name		:	functions.js
//----------------------------------------------------------------------------------------------------

//====================================================================================================
//	Function Name	:	popupWindowURL
//	Purpose			:	Whenever you wanna open a link into a new window just call this function
//								you need to pass some arguemnts as described below.
//	Parameters		:
//								url  = url to be open in the new window
//								winname = winname is the window name for the reference of that window
//								w is the width
//								h is the height
//								menu is the parameter, if you want menubar to be enabled on the window
//								resize if you wanna resize the window
//								scroll i fyou needed
//	Return			:	true or false
//----------------------------------------------------------------------------------------------------
function popupWindowURL(url, winname,  w, h, menu, resize, scrollbar) {

    var x = (screen.width-w)/2;
    var y = (screen.height-h)/3;

	if (winname == null) winname = "newWindow";
	if (w == null) w = 800;
	if (h == null) h = 600;
	if (resize == null) resize = 1;

	menutype   = "nomenubar";
	resizetype = "noresizable";
	scrolltype = "noscrollbars";
	if (menu) menutype = "menubar";
	if (resize) resizetype = "resizable";
	if (scrollbar) scrolltype = "scrollbars";
	//alert(url+","+x+","+winname);
    cwin=window.open(url,winname,"top=" + y + ",left=" + x + ",screenX=" + x + ",screenY=" + y + "," + "status," + menutype + "," + scrolltype + "," + resizetype + ",width=" + w + ",height=" + h);

	if (!cwin.opener) cwin.opener=self;
	cwin.focus();

	return true;
}
//====================================================================================================
//	Function Name		:	removeElement
//----------------------------------------------------------------------------------------------------
function removeElement(eleId)
{
	var el	= document.getElementById(eleId);

	if(el)
   		el.parentNode.removeChild(el);
}
//====================================================================================================
//	Function Name	:	Menu_ShowHide
//----------------------------------------------------------------------------------------------------
function Menu_ShowHide(menu, img, imgUp, imgDown)
{
	if(menu)
	{
		if(menu.style.display == 'none')
		{
			menu.style.visibility	= 'visible';
			menu.style.display		= 'block';
			img.src = imgUp;
			setCookie(menu.id, 'open');
		}
		else
		{
			menu.style.visibility 	= 'hidden';
			menu.style.display 		= 'none';
			img.src = imgDown;
			setCookie(menu.id, 'close');
		}
	}
}

//====================================================================================================
//	Function Name	:	CheckUncheck_Click
//----------------------------------------------------------------------------------------------------
function CheckUncheck_Click(fld, status)
{
	if(fld.length)
		for(i=0; i < fld.length; i++)
			fld[i].checked = status;
	else
		fld.checked = status;
}

//====================================================================================================
//	File Name		:	truebody.js
//----------------------------------------------------------------------------------------------------
function truebody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

//====================================================================================================
//	File Name		:	addToWimpy.js
//----------------------------------------------------------------------------------------------------
function addToWimpy(some_id)
{
	return true;
}

//====================================================================================================
/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
 //----------------------------------------------------------------------------------------------------
 function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}


//====================================================================================================
/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
 //----------------------------------------------------------------------------------------------------
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
	{
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
	else
	{
        begin += 2;
    }
	
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
	{
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

//====================================================================================================
/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
//----------------------------------------------------------------------------------------------------
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


function attachEventListener(target, eventType, functionRef, capture) 
{ 
	if (typeof target.addEventListener != "undefined") 
	{ 
		target.addEventListener(eventType, functionRef, capture); 
	} 
	else if (typeof target.attachEvent != "undefined") 
	{ 
		var functionString = eventType + functionRef; 
		target["e" + functionString] = functionRef; 
		
		target[functionString] = function(event) 
		{ 
			if (typeof event == "undefined") 
			{ 
				event = window.event; 
			} 
			target["e" + functionString](event); 
		}; 
		
		target.attachEvent("on" + eventType, target[functionString]); 
	} 
	else 
	{ 
		eventType = "on" + eventType; 
		
		if (typeof target[eventType] == "function") 
		{ 
			var oldListener = target[eventType]; 
			
			target[eventType] = function() 
			{ 
				oldListener(); 
				
				return functionRef(); 
			} 
		} 
		else 
		{ 
			target[eventType] = functionRef; 
		} 
	} 
} 

function detachEventListener(target, eventType, functionRef, capture) 
{ 
	if (typeof target.removeEventListener != "undefined") 
	{ 
		target.removeEventListener(eventType, functionRef, capture) 
	} 
	else if (typeof target.detachEvent != "undefined") 
	{ 
		var functionString = eventType + functionRef; 
		
		target.detachEvent("on" + eventType, target[functionString]); 
		
		target["e" + functionString] = null; 
		target[functionString] = null; 
	} 
	else 
	{ 
		target["on" + eventType] = null; 
	} 
}

function resizeImage(img, width, height)
{
	thumbWidth 	= width;
	thumbHeight	= (thumbWidth/img.width)*img.height;
	
	if(thumbHeight > height)
	{
		thumbHeight	= height;
		thumbWidth 	= (thumbHeight/img.height)*img.width;
	}
	img.width 	= thumbWidth;
	img.height	= thumbHeight;
}

function ToggleLoader(flg, msg)
{
	if(flg)
	{
		DisableBodyArea(true);

		var x = (truebody().clientWidth - 200)/2;
		var y = (truebody().clientHeight - 100)/2;
		//var y = 475;
//		var y = 475+120;
		if(msg)
			document.getElementById('stdLoaderMsg').innerHTML = msg;
		else
			document.getElementById('stdLoaderMsg').innerHTML = LM_LOADING;

		document.getElementById('stdLoader').style.left = x+"px";
		document.getElementById('stdLoader').style.top = y+"px";
		document.getElementById('stdLoader').style.display = '';
	}
	else
	{
		document.getElementById('stdLoader').style.display = 'none';
		DisableBodyArea(false) ;
	}
}

function DisableBodyArea(flg)
{
	if(flg)
	{
		document.getElementById('stdDisableArea').style.width	= truebody().scrollWidth + 'px';
		document.getElementById('stdDisableArea').style.height	= truebody().scrollHeight + 'px';
		document.getElementById('stdDisableArea').style.display = '';
	}
	else
	{
		document.getElementById('stdDisableArea').style.display = 'none';
	}
}

var t_id = setInterval(animate, 20);
var pos=0;
var dir=2;
var len=0;

function animate()
{
	return;
	var elem = document.getElementById('progress');

	if(elem != null) {
//		alert('here');
		if (pos==0) len += dir;
		if (len>32 || pos>79) pos += dir;
		if (pos>79) len -= dir;
		if (pos>79 && len==0) pos=0;
		elem.style.left = pos;
		elem.style.width = len;
	}
}

function remove_loading() {
	this.clearInterval(t_id);
	var targelem = document.getElementById('loader_container');
	targelem.style.display='none';
	targelem.style.visibility='hidden';
	var t_id = setInterval(animate,60);
}

//====================================================================================================
//	Function Name	:	GoToDloadManager()
//----------------------------------------------------------------------------------------------------
function GoToDloadManager()
{
	//with(document.frmHomeTab2)
	{
		setCookie('mTab',3);
		document.location.href='home.php';
	}
}
//====================================================================================================
//	Function Name	:	trim()
//----------------------------------------------------------------------------------------------------
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
