if (!Array.prototype.push) Array.prototype.push = function() {
    for (var i=0; i<arguments.length; i++) this[this.length] = arguments[i];
    return this.length;
}
Array.prototype.find = function(value, start) {
    start = start || 0;
    for (var i=start; i<this.length; i++)
        if (this[i]==value)
            return i;
    return -1;
}
Array.prototype.has = function(value) {
    return this.find(value)!==-1;
}
function map(list, func) {
    var result = [];
    func = func || function(v) {return v};
    for (var i=0; i < list.length; i++) result.push(func(list[i], i, list));
    return result;
}

function filter(list, func) {
    var result = [];
    func = func || function(v) {return v};
    map(list, function(v) { if (func(v)) result.push(v) } );
    return result;
}
function getElem(elem) {
    if (document.getElementById) {
        if (typeof elem == "string") {
            elem = document.getElementById(elem);
            if (elem===null) throw 'cannot get element: element does not exist';
        } else if (typeof elem != "object") {
            throw 'cannot get element: invalid datatype';
        }
    } else throw 'cannot get element: unsupported DOM';
    return elem;
}
function hasClass(elem, className) {
    return getElem(elem).className.split(' ').has(className);
}
function getElementsByClass(className, tagName, parentNode) {
    parentNode = !isUndefined(parentNode)? getElem(parentNode) : document;
    if (isUndefined(tagName)) tagName = '*';
    return filter(parentNode.getElementsByTagName(tagName),
        function(elem) { return hasClass(elem, className) });
}
function listen(event, elem, func) {
    elem = getElem(elem);
    if (elem.addEventListener)  // W3C DOM
        elem.addEventListener(event,func,false);
    else if (elem.attachEvent)  // IE DOM
        elem.attachEvent('on'+event, function(){ func(new W3CDOM_Event(elem)) } );
        // for IE we use a wrapper function that passes in a simplified faux Event object.
    else throw 'cannot add event listener';
}
function mlisten(event, elem_list, func) {
    map(elem_list, function(elem) { listen(event, elem, func) } );
}
function W3CDOM_Event(currentTarget) {
    this.currentTarget  = currentTarget;
    this.preventDefault = function() { window.event.returnValue = false }
    return this;
}
function isUndefined(v) {
    var undef;
    return v===undef;
}
//Open popup. Can be called directly
function Popup(url, target, features)
{
	var theWindow = window.open(url, target, features);
	theWindow.focus();
	return theWindow;
}
//Holder for Popup(). As it's to be registered with event listener
function PopupHolder(e)
{
	Popup(e.currentTarget.getAttribute('href'), e.currentTarget.getAttribute('target') || J_POPUP_TARGET, J_POPUP_FEATURES);
	e.preventDefault();
}
//show balloon. Can be called directly
function ShowBalloon(objA, x, y)
{
	gTmp_ATitle = objA.title; //preserve the title in global var
	objA.title = ''; //empty it, so that it won't popup
	var tmp_title = 'Help', tmp_desc = gTmp_ATitle, pos_colon; //safe init
	//e.g., gTmp_ATitle = 'Help: Help is a help...'
	if ((pos_colon=gTmp_ATitle.indexOf(':')) !=-1 )
		{
			tmp_title = gTmp_ATitle.substring(0, pos_colon);
			tmp_desc = gTmp_ATitle.substring(pos_colon+1);
		}
	var balloon = document.getElementById(J_BALLOON);
	balloon.className = J_CLSBALLOON;
	balloon.style.display = 'inline';
	balloon.style.width = J_BALLOONWIDTH + 'px';
	balloon.style.top = y + 'px';
	balloon.style.left = x + 'px';
	balloon.innerHTML = '<span class="' + J_CLSBALLOONTITTLE + '">'+ tmp_title +'<\/span><div class="' + J_CLSBALLOONDESC + '">'+ tmp_desc + '<\/div>';
	return true;
}
//For the links in myPhotos.php
function ShowPhotoBalloon(objA, x, y)
{
	gTmp_ATitle = objA.title; //preserve the title in global var
	objA.title = ''; //empty it, so that it won't popup
	var tmp_title = 'Help', tmp_desc = gTmp_ATitle, pos_colon; //safe init
	//e.g., gTmp_ATitle = 'Help: Help is a help...'
	if ((pos_colon=gTmp_ATitle.indexOf(':')) !=-1 )
		{
			tmp_title = gTmp_ATitle.substring(0, pos_colon);
			tmp_desc = gTmp_ATitle.substring(pos_colon+1);
		}
	var balloon = document.getElementById(J_BALLOON);
	balloon.className = J_CLSPHOTOLINKBALLOON;
	balloon.style.display = 'inline';
	balloon.style.width = J_PHOTOBALLOONWIDTH + 'px';
	balloon.style.top = y + 'px';
	balloon.style.left = x + 'px';
	balloon.innerHTML = '<div class="' + J_CLSPHOTOBALLOONTEXT + '">'+ tmp_desc + '<\/div>';
	return true;
}
//Holder for ShowBalloon(). As it's to be registered with event listener
function ShowPhotoLinkBalloonHolder(e)
{
	var posx = 0, posy = 0;
	if (e.pageX || e.pageY) //Moz
		{
			posx = e.pageX;
			posy = e.pageY;
		}
	 else if (event.clientX || event.clientY) //IE. Note: event.x not working fine
		{
			posx = event.clientX + document.body.scrollLeft;
			posy = event.clientY + document.body.scrollTop;
		}
	//Note: using the x, y as it is cause the div to flicker in certain border points in FF (IE, Opera works find).
	ShowPhotoBalloon(e.currentTarget, posx+J_BALLOONPOSADJX, posy+J_BALLOONPOSADJY);
	e.preventDefault();
}
//Holder for Links in myPhotos.php page
function getAbsoluteOffsetTopConfirmation(obj){
	var top = obj.offsetTop;
	var parent = obj.offsetParent;
	while (parent != document.body)
		{
			top += parent.offsetTop;
			parent = parent.offsetParent;
		}
	return top;
}
function getAbsoluteOffsetLeftConfirmation(obj){
	var left = obj.offsetLeft;
	var parent = obj.offsetParent;
	while (parent != document.body)
		{
			left += parent.offsetLeft;
			parent = parent.offsetParent;
		}
	return left;
}
function ShowBalloonHolder(e)
{
	var posx = 0, posy = 0;
	if (e.pageX || e.pageY) //Moz
		{
			posx = e.pageX;
			posy = e.pageY;			
		}
	 else if (event.clientX || event.clientY) //IE. Note: event.x not working fine
		{			
			if(document.body.scrollTop==0){
				var targetText = e.currentTarget;
				targetText = targetText + "";
				targetText = targetText.substring(targetText.indexOf('#')+1);
				targetText = 'Help_'+targetText;
				targetText = document.getElementById(targetText);
				var posy = getAbsoluteOffsetTopConfirmation(targetText);
				var posx = getAbsoluteOffsetLeftConfirmation(targetText);
				//alert(posx+'--'+posy+J_BALLOONPOSADJX);
			}
			else{
				posx = event.clientX + document.body.scrollLeft;
				posy = event.clientY + document.body.scrollTop;
			}
		}
	//Note: using the x, y as it is cause the div to flicker in certain border points in FF (IE, Opera works find).
	ShowBalloon(e.currentTarget, posx+J_BALLOONPOSADJX, posy+J_BALLOONPOSADJY);
	e.preventDefault();
}
//Hides balloon.
function HideBalloon(objA)
{
	var balloon = document.getElementById(J_BALLOON);
	balloon.style.display = 'none';
	objA.title = gTmp_ATitle; //re-assign
}
//Holder for HideBaloon. As it's to be registered with event listener
function HideBalloonHolder(e)
{
	HideBalloon(e.currentTarget);
	e.preventDefault();
}
//Function for mailCompose.php, used to set value in username textbox
function setUserName(frmObj)
{
	if (frmObj.contacts.value == '')
		{
			return;
		}
	email_address_value = replaceEmailAddress(frmObj.username.value, frmObj.contacts);
	email_address_value = replaceEmailFriend(email_address_value, frmObj.contacts);
	if (email_address_value.indexOf(',') == -1 && email_address_value != '')
		{
			email_address_value = email_address_value + ', ';
		}
	frmObj.username.value = email_address_value + frmObj.contacts.value + ', ';
	frmObj.username.focus();
}
function replaceEmailAddress(email_address_value, email_groups)
{
	email_address_value = email_address_value.replace(', '+email_groups.value,'');
	email_address_value = email_address_value.replace(email_groups.value+', ','');
	email_address_value = email_address_value.replace(email_groups.value,'');
	return email_address_value;
}
function replaceEmailFriend(email_address_value, email_friends)
{
	email_address_value = email_address_value.replace(', '+email_friends.value,'');
	email_address_value = email_address_value.replace(email_friends.value+', ','');
	email_address_value = email_address_value.replace(email_friends.value,'');
	return email_address_value;
}
// Function to select all check boxes
// called in mailInbox.php, mailSent.php, mailSaved.php, mailTrash.php
function selectAll(thisForm)
	{
		for (var i=0; i<thisForm.elements.length; i++)
			{
				if (thisForm.elements[i].type == "checkbox")
					{
						if(thisForm.checkall.checked)
							{
								thisForm.elements[i].checked=true;
							}
							else
								{
									thisForm.elements[i].checked=false;
								}
					}
			}
	}
function setSizes(){
	if (parseInt(navigator.appVersion)>3) {
		if(navigator.appName=="Netscape"||navigator.userAgent.indexOf("opera")==-1){
			winW = window.innerWidth;
			winH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
	           if (document.documentElement && document.documentElement.clientHeight){
				clientHeight = document.documentElement.clientHeight;
				clientWidth = document.documentElement.clientWidth;
			}
			else if(document.body){
				clientHeight = document.body.clientHeight;
				clientWidth = document.body.clientWidth;
			}
			winW = document.body.offsetWidth;
			winH = clientHeight;
		}
	}
	sizes=new Array(winW,winH);
	return sizes;
}
// new getcode popup
function getcodePopup(type,location,mediaid){
	var popup=document.getElementById('popup_div');
	var blackout=document.getElementById('blackout');
	var width=500;
	var height=150;
	var code='<div class="videoCatWhite" style="width:'+width+'px;height:'+height+'px;background-color:#272F31;border:1px solid #fff;text-align:center"><div style="padding:10px">Embed the following code in your Nichespace, MySpace, Facebook or website:</div><div><textarea style="text-align:center;width:450px;height:70px;overflow:hidden;font-size:8px" onclick="this.select()">';
	switch(type){
		case 'video':
			code+='<object classid=\'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\' codebase=\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\' width=\'500\' height=\'492\' id=\'player\' align=\'middle\'><param name=\'allowScriptAccess\' value=\'always\' /><param name=\'allowFullScreen\' value=\'true\' /><param name=\'quality\' value=\'best\' /><param name=\'movie\' value=\'http://www.nicheflixxx.com/newplayer.swf?xmlPath=http://www.nicheflixxx.com/videoConfig.php?videoid='+mediaid+'\' /><param name=\'quality\' value=\'best\' /><embed src=\'http://www.nicheflixxx.com/newplayer.swf\' width=\'500\' height=\'492\' allowscriptaccess=\'always\' allowfullscreen=\'false\' wmode=\'transparent\' flashvars=\'xmlPath=http://www.nicheflixxx.com/videoConfig.php?videoid='+mediaid+'&small_player=true\'/></object>';
		break;
	}
	code+='</textarea></div><div style="padding:10px"><input type="button" value="Close" onclick="document.getElementById(\'blackout\').style.display=\'none\';document.getElementById(\'popup_div\').style.display=\'none\'"></div></div>';
	blackout.style.display='block';
	blackout.style.visibility='visible';
	popup.style.top=document.getElementById(location).offsetTop+'px';
	popup.style.left=((winW/2)-(width/2))+'px';
	popup.style.display='block';
	popup.style.width=width+'px';
	popup.style.height=height+'px';
	popup.innerHTML=code;
}
//code execution starts here...
var standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body;
var winH;
var winW;
//global vars
var gTmp_ATitle; //temp variable to hold and swap title attributes
//global constants. Used to change behaviors quickly
//presumably IE doesn't support const on strings
var J_BALLOON = 'balloon'; //balloon id
var J_CLSHELP = 'clsHelp';
var J_CLSBALLOON = 'clsBalloon';
var J_CLSBALLOONTITTLE = 'clsBalloonTittle';
var J_CLSBALLOONDESC = 'clsBalloonDesc';
var J_BALLOONPOSADJX = 10;
var J_BALLOONPOSADJY = 10;
var J_POPUP_FEATURES = 'location=0,statusbar=0,menubar=0,scrollbars=1';
var J_POPUP_TARGET = 'help';
var J_BALLOONWIDTH = 200;
var J_CLSPHOTOLINKCLASS = 'clsPhotoVideoEditLinks';
var J_CLSPHOTOLINKBALLOON = 'clsPhotoBalloon';
var J_CLSPHOTOBALLOONTEXT = 'clsPhotoBalloonText';
var J_PHOTOBALLOONWIDTH = '90';
listen('load',
		window,
		function()
		{
			//create balloon div...
			var balloon = document.createElement('div');
			balloon.id = J_BALLOON;
			document.body.appendChild(balloon);
			//listen...
			mlisten('mouseover', getElementsByClass(J_CLSHELP,'a'), ShowBalloonHolder);
			mlisten('mouseout', getElementsByClass(J_CLSHELP,'a'), HideBalloonHolder);
			mlisten('click', getElementsByClass(J_CLSHELP,'a'), PopupHolder);
			mlisten('mouseover', getElementsByClass(J_CLSPHOTOLINKCLASS,'a'), ShowPhotoLinkBalloonHolder);
			mlisten('mouseout', getElementsByClass(J_CLSPHOTOLINKCLASS,'a'), HideBalloonHolder);
		}
	);
//oh my, holy hack http://groups.google.com/group/comp.lang.javascript/msg/923c83ebf78b818a
//CSS2 browsers require 'table-row-group' to display tbody tag properly
//Note: if IE display.style is set to 'table-row-group', it will bug with "Error: Could not get the display property. Invalid argument."
var display_tbl_block = (document.all) ? 'block' : 'table-row-group';
var catch_rules =
	{
		//for admin/depositPlans.php toggling of options...
		'#adminuserProfilesEdit #usr_status' : function(element)
		{
			document.getElementById("activate_user_block").style.display = (element.value=="0-Ok") ? display_tbl_block : 'none';
			//onchange show it only for appropriate values...
			element.onchange = function()
			{
				document.getElementById("activate_user_block").style.display = (this.value=="0-Ok") ? display_tbl_block : 'none';
			}
		}
	};
//Behaviour.register(catch_rules);
function CloseButton()
	{
		window.close();
	}
function openVid(filename, video_id)
	{
		//var path = filename;
		//window.open (path, "","status=0,toolbar=0,resizable=0,scrollbars=0");
		var foo = window.open(filename,'_blank','status=0,toolbar=0,resizable=0,scrollbars=0');
		foo.moveTo(0,0);
		foo.resizeTo(screen.availWidth,screen.availHeight);
	}

function trim(str){
    return str.replace(/^(\s+)?(\S*)(\s+)?$/, '$2');
}

function ltrim(str){
    return str.replace(/^\s*/, '');
}

function rtrim(str){
    return str.replace(/\s*$/, '');
}

function showHide(show_id, link_id, on_class, off_class){
	if(obj = document.getElementById(show_id)){
		if(obj.style.display=='none'){
			obj.style.display='';
			if(obj1 = document.getElementById(link_id)){
				obj1.className = off_class;
			}
			return false;
		}
		obj.style.display='none';
		if(obj1 = document.getElementById(link_id)){
			obj1.className = on_class;
		}
	}
	return false;
}

function show(element){
	if(obj = document.getElementById(element))
		obj.style.display = '';
}
function hide(element){
	if(obj = document.getElementById(element))
		obj.style.display = 'none';
}

/**
 *
 * @access public
 * @return void
 **/
function setClass(li_id, li_class)
{
	document.getElementById(li_id).setAttribute('className',li_class);
	document.getElementById(li_id).setAttribute('class',li_class);
}

function isObject(arg){
		return (typeof arg =='object');
}
function isset(varSet){
	return true;
}
function isValidXmlDocument(doc){
		return (isObject(doc) && isset(doc.nodeType) && (doc.nodeType==9) && (doc.documentElement!=null));
}

//For sorting
function changeOrderbyElements(form_name,field_name){
	 	var obj = eval("document."+form_name+".orderby_field");
	 	obj.value = field_name;
	 	obj = eval("document."+form_name+".orderby");
	 	if(obj.value=="asc")
	 		obj.value="desc";
	 	else
	 		obj.value="asc";
	 	eval("document."+form_name+".submit()");
	 	return false;
	}

//for postmethod to paging
function pagingSubmit(formname, start){
	var obj = eval("document."+formname);
	obj.start.value = start;
	obj.submit();
	return false;
}

function addComment(url, first_par, form_name, divname)
	{
		Ajax.Responders.unregister(myGlobalHandlers);
		commet_str = $F('comment')
		commet_str = commet_str.replace( /^\s+/g, "" );
  		commet_str =  commet_str.replace( /\s+$/g, "" );
		if (commet_str.length == 0)
			{
				alert("Enter comment");
				return false;
			}

		pars = Form.serialize(form_name);
		pars = first_par + pars;
		var myAjax = new Ajax.Updater(
								{success: divname},
								url,
								{
									method: 'post',
									parameters: pars
								});
		form_name.reset();
	}
// sample url = 'http://yourserver/app/get_sales';
// sample pars = 'empID=' + empID + '&year=' + y;
// sample method_type = 'post'
function chnageContentFilter(url, pars, method_type)
	{		
		var myAjax = new Ajax.Request(
							url,
							{
							method: method_type,
							parameters: pars,
							onComplete: chnageContentFilterResponse
							});
	}
var session_check = 'heck||||||||||valid||||||||login';
var session_check_replace = 'check||||||||||valid||||||||login';
function chnageContentFilterResponse(originalRequest){		
		var data = originalRequest.responseText;
		if(data.indexOf(session_check)>=1)
			{
				data = data.replace(session_check_replace,'');
			}
		else
			{
				return;				
			}
		if(data)
			{
				var url = location.href;
				url = url.replace('#','');
				window.location = url;
				$('selContentFilterStatus').innerHTML = data;
			}
	}
function popupWindowUpload(url){
	window.open (url, "","status=0,toolbar=0,resizable=0,scrollbars=1");
}