/*
This lib for cross browser handling taken from http://www.alistapart.com/articles/popuplinks
extended version is at http://v2studio.com/k/code/lib/


ARRAY EXTENSIONS

push(item [,...,item])
    Mimics standard push for IE5, which doesn't implement it.


find(value [, start])
    searches array for value starting at start (if start is not provided,
    searches from the beginning). returns value index if found, otherwise
    returns -1;


has(value)
    returns true if value is found in array, otherwise false;


FUNCTIONAL

map(list, func)
    traverses list, applying func to list, returning an array of values returned
    by func

    if func is not provided, the array item is returned itself. this is an easy
    way to transform fake arrays (e.g. the arguments object of a function or
    nodeList objects) into real javascript arrays.

    map also provides a safe way for traversing only an array's indexed items,
    ignoring its other properties. (as opposed to how for-in works)

    this is a simplified version of python's map. parameter order is different,
    only a single list (array) is accepted, and the parameters passed to func
    are different:
    func takes the current item, then, optionally, the current index and a
    reference to the list (so that func can modify list)


filter(list, func)
    returns an array of values in list for which func is true

    if func is not specified the values are evaluated themselves, that is,
    filter will return an array of the values in list which evaluate to true

    this is a similar to python's filter, but parameter order is inverted


DOM

getElem(elem)
    returns an element in document. elem can be the id of such element or the
    element itself (in which case the function does nothing, merely returning
    it)

    this function is useful to enable other functions to take either an    element
    directly or an element id as parameter.

    if elem is string and there's no element with such id, it throws an error.
    if elem is an object but not an Element, it's returned anyway


hasClass(elem, className)
    Checks the class list of element elem or element of id elem for className,
    if found, returns true, otherwise false.

    The tested element can have multiple space-separated classes. className must
    be a single class (i.e. can't be a list).


getElementsByClass(className [, tagName [, parentNode]])
    Returns elements having class className, optionally being a tag tagName
    (otherwise any tag), optionally being a descendant of parentNode (otherwise
    the whole document is searched)


DOM EVENTS

listen(event,elem,func)
    x-browser function to add event listeners

    listens for event on elem with func
    event is string denoting the event name without the on- prefix. e.g. 'click'
    elem is either the element object or the element's id
    func is the function to call when the event is triggered

    in IE, func is wrapped and this wrapper passes in a W3CDOM_Event (a faux
    simplified Event object)


mlisten(event, elem_list, func)
    same as listen but takes an element list (a NodeList, Array, etc) instead of
    an element.


W3CDOM_Event(currentTarget)
    is a faux Event constructor. it should be passed in IE when a function
    expects a real Event object. For now it only implements the currentTarget
    property and the preventDefault method.

    The currentTarget value must be passed as a paremeter at the moment    of
    construction.


MISC CLEANING-AFTER-MICROSOFT STUFF

isUndefined(v)
    returns true if [v] is not defined, false otherwise

    IE 5.0 does not support the undefined keyword, so we cannot do a direct
    comparison such as v===undefined.
*/

// ARRAY EXTENSIONS
if(!block_arr)
{
	var block_arr = new Array();
}
var getCodeFormName='';

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.findGivenValue = 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.findGivenValue(value)!==-1;
}

// FUNCTIONAL

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;
}


// DOM

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) });
}


// DOM EVENTS

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;
}

// MISC CLEANING-AFTER-MICROSOFT STUFF
function isUndefined(v) {
    var undef;
    return v===undef;
}

//<--lib ends

//Our functions starts....

//Open popup. Can be called directly
function Popup(url, target, features)
{
	var theWindow = window.open(url, target, features);
	//http://developer.mozilla.org/en/docs/DOM:window.open
	//window.open will return null on popup blocker and sort of
	if (theWindow==null)
			location.href = url;
		else if (window.focus)
			theWindow.focus();
	return theWindow;
}

function CreateBalloon()
{
	var balloon = document.createElement('div');
	balloon.id = J_BALLOON;
	document.body.appendChild(balloon);
}
//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);
		}
	if(tmp_desc == '')
		return false;
	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
		{
			if(document.body && ( document.body.scrollLeft || document.body.scrollTop))
				{
					posx = event.clientX + document.body.scrollLeft;
					posy = event.clientY + document.body.scrollTop;
				}
			//FIX FOR IE SCROLL POSITION - ADDED BY SHANKAR
			else //if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ))
				{
					posx = event.clientX + document.documentElement.scrollLeft;
					posy = event.clientY + document.documentElement.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 checkCheckBox(thisForm, check_all)
	{
		var checkBoxSelected = 0;
		var totalCheckBoxes = 0;
		for (var i=0; i<thisForm.elements.length; i++)
			{
				if(thisForm.elements[i].type == "checkbox" )
					{
						if(i!=0)
							{
								totalCheckBoxes++;
								if(thisForm.elements[i].checked == true)
									{
										checkBoxSelected++;
									}
							}
					}
			}
		if(totalCheckBoxes == checkBoxSelected)
			{
				$(check_all).checked = true;
			}
		else
			{
				$(check_all).checked = false;
			}
	}
//code execution starts here...

//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';

var total_baloons=0;
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);
			mlisten('mouseover', getElementsByClass(J_CLSPHOTOLINKCLASS,'input'), ShowPhotoLinkBalloonHolder);
			mlisten('mouseout', getElementsByClass(J_CLSPHOTOLINKCLASS,'input'), HideBalloonHolder);
			mlisten('mouseover', getElementsByClass(J_CLSPHOTOLINKCLASS,'p'), ShowPhotoLinkBalloonHolder);
			mlisten('mouseout', getElementsByClass(J_CLSPHOTOLINKCLASS,'p'), HideBalloonHolder);
		}
	);
//to call listen handlers after adding a video to quick link
function listenBaloon_divAgain()
	{
		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);
		mlisten('mouseover', getElementsByClass(J_CLSPHOTOLINKCLASS,'input'), ShowPhotoLinkBalloonHolder);
		mlisten('mouseout', getElementsByClass(J_CLSPHOTOLINKCLASS,'input'), HideBalloonHolder);
		mlisten('mouseover', getElementsByClass(J_CLSPHOTOLINKCLASS,'p'), ShowPhotoLinkBalloonHolder);
		mlisten('mouseout', getElementsByClass(J_CLSPHOTOLINKCLASS,'p'), HideBalloonHolder);
	}

//to call listen balloon container for the passed container and element Ex: $$('#container_id a')
function listen_balloon_using_container(container)
	{
		mlisten('mouseover', $$(container), ShowPhotoLinkBalloonHolder);
		mlisten('mouseout', $$(container), HideBalloonHolder);
	}
//	====Need cssQuery and Behaviour====

/**
 * @author		rajesh_04ag02
 * @copyright 	Copyright (c) 2009 - 2010 {@link http://www.agriya.com Agriya Infoway}
 * @version		SVN: $Id: script.js 2796 2006-12-04 08:15:27Z selvaraj_35ag05 $
 * @todo		Possibly replace help tips' libs with Behaviour
 */

//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 togggleThis(show_id){
	if(obj = document.getElementById(show_id))
		{
			if(obj.style.display=='none')
				obj.style.display='';
				else
					obj.style.display='none';
		}
}

function ShowBaloon(id,hide_option)
	{
		var hide_count=false;
		for(var no=0;no<=total_baloons;no++)
			{
				if(no != id)
					{
				var divs = document.getElementById('selCoolMemberActive_'+no);
				divs.style.display='none';
					}
			}
		if(hide_option!='hideall')
			{
				var divs = document.getElementById('selCoolMemberActive_'+id);
				divs.style.display='block';
			}
	}
function initializeBalloons(total)
	{
		total_baloons=total;
	}

function showHideLnBar(show_id, link_id, on_class, off_class, url)
	{
		if(obj = document.getElementById(show_id))
			{
				if(obj.style.display=='none')
					{
						obj.style.display='';
						if(obj1 = document.getElementById(link_id))
							{
								obj1.className = off_class;
							}
						//--Start AjaxUpater----
						var pars='lnbar='+show_id;
						var method_type='get';
						var myAjax = new Ajax.Request(
							url,
							{
							method: method_type,
							parameters: pars,
							onComplete: generateResponse
							});
						//-End AjaxUpdater------
						return false;
					}
				obj.style.display='none';
				if(obj1 = document.getElementById(link_id))
					{
						obj1.className = on_class;
					}
			}
		return false;
	}
function generateResponse(originalRequest)
	{
		return true;
	}
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();
	}*/
//Ajax
// 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('#','');
				$('selContentFilterStatus').innerHTML = data;
				window.location = url;
			}
	}
function popupWindowUpload(url){
	window.open (url, "","status=0,toolbar=0,resizable=0,scrollbars=1");
}
function changeCategoryRequest(url, pars, method_type)
	{
		var myAjax = new Ajax.Request(
							url,
							{
							method: method_type,
							parameters: pars,
							onComplete: changeCategoryResponse
							});
	}
function changeCategoryResponse(originalRequest){
		var data = originalRequest.responseText;
		if(data.indexOf(session_check)>=1)
			{
				data = data.replace(session_check_replace,'');
			}
		else
			{
				return;
			}
		if(data)
			{
				$('selCategoryList').innerHTML = data;
			}
	}
function populateSubCategoryRequest(url, pars, method_type)
	{
		var myAjax = new Ajax.Request(
							url,
							{
							method: method_type,
							parameters: pars,
							onComplete: populateSubCategoryResponse
							});
	}
function populateSubCategoryResponse(originalRequest){
		var data = originalRequest.responseText;
		if(data.indexOf(session_check)>=1)
			{
				data = data.replace(session_check_replace,'');
			}
		else
			{
				return;
			}
		if(data)
			{
				$('selSubCategoryBox').innerHTML = data;
				helpTipInitialize();
			}
	}
function populatePriceTypeRequest(url, pars, method_type)
	{
		var myAjax = new Ajax.Request(
							url,
							{
							method: method_type,
							parameters: pars,
							onComplete: populatePriceTypeResponse
							});
	}
function populatePriceTypeResponse(originalRequest){
		var data = originalRequest.responseText;
		if(data.indexOf(session_check)>=1)
			{
				data = data.replace(session_check_replace,'');
			}
		else
			{
				return;
			}
		if(data)
			{

				$('selPriceTypeBox').innerHTML = data;
			}
	}

function populate_article_sub_categories(url, add_pars, divname)
	{
		//a = document.article_writing_form.article_category_id;
		divToChange = divname;
		category_id = document.article_writing_form.article_category_id.value;
		pars = 'category_id='+category_id+'&'+add_pars;
		var myAjax = new Ajax.Request(
							url,
							{
							method: 'get',
							parameters: pars,
							onComplete: changeDivInnerHtml
							});

	}
function populate_photo_sub_categories(url, add_pars, divname,type)
	{
		//a = document.article_writing_form.article_category_id;
		divToChange = divname;
		if(type =='pron')
		category_id = $('photo_category_id_pron').value
		else
		category_id = $('photo_category_id_general').value

		pars = 'category_id='+category_id+'&'+add_pars;
		var myAjax = new Ajax.Request(
							url,
							{
							method: 'get',
							parameters: pars,
							onComplete: changeDivInnerHtml
							});

	}

function changeDivInnerHtml(originalRequest){
		var data = originalRequest.responseText;
		$(divToChange).innerHTML = data;
	}
function populate_blog_sub_categories(url, add_pars, divname)
	{
		//a = document.article_writing_form.article_category_id;
		divToChange = divname;
		category_id = document.frmBlogsEditor.blog_category_id.value;
		pars = 'category_id='+category_id+'&'+add_pars;
		var myAjax = new Ajax.Request(
							url,
							{
							method: 'get',
							parameters: pars,
							onComplete: changeBlogDivInnerHtml
							});

	}

function changeBlogDivInnerHtml(originalRequest){
		var data = originalRequest.responseText;
		$(divToChange).innerHTML = data;
	}
function populate_music_sub_categories(url, add_pars, divname)
	{
		divToChange = divname;
		category_id = document.music_upload_form.music_category_id.value;
		pars = 'category_id='+category_id+'&'+add_pars;
		var myAjax = new Ajax.Request(
							url,
							{
							method: 'get',
							parameters: pars,
							onComplete: changeMusicDivInnerHtml
							});

	}

function changeMusicDivInnerHtml(originalRequest){
		var data = originalRequest.responseText;
		$(divToChange).innerHTML = data;
	}

function deleteMultiCheck(check_atleast_one,anchor,delete_confirmation,formName,id,action)
{

	if(getMultiCheckBoxValue(formName, 'check_all',check_atleast_one, anchor, -100, -500))
	{
		Confirmation('selMsgConfirmMulti', 'msgConfirmformMulti', Array(id,'act', 'msgConfirmTextMulti'),
		Array(multiCheckValue, action, delete_confirmation), Array('value','value', 'innerHTML'), 50,300,anchor);
	}
}

function callAjaxGetCode(path, delLink,formName)
	{
		getCodeFormName=formName;
		delLink_value = delLink;
		new prototype_ajax(path,'displayGetCode');
		return false;
	}

function displayGetCode(data)
	{
		data = unescape(data.responseText);
		var obj = document.getElementById(getCodeFormName);

		if(data.indexOf(session_check)>=1)
			data = data.replace(session_check_replace,'');
		else
			return;
		data = data.strip();
		obj.innerHTML = '<div id="selDisplayWidth">'+data+'</div>';
		Confirmation(getCodeFormName, 'msgConfirmform', Array(getCodeFormName), Array('<div id="selDisplayWidth">'+data+'</div>'), Array('innerHTML'), -100, -500);
		return false;
	}
/**************** Start of user popup functions ***********/
var timeout	= 100;
var infoTimer	= 0;
var divObj	= 0;

// close showed layer
function closeUserPopup()
	{
		if(divObj) divObj.style.display = 'none';
	}

// close user info and reset timer
function closeUserPopupAndTimer()
	{
		infoTimer = window.setTimeout(closeUserPopup, timeout);
	}

// reset timer
function resetUserInfoTimer()
	{
		if(infoTimer)
			{
				window.clearTimeout(infoTimer);
				infoTimer = null;
			}
	}
function showUserInfoPopup(url, uid, divname, viewOption)
	{
		// reset timer
		resetUserInfoTimer();

		// close old layer
		if(divObj) divObj.style.display = 'none';

		// get new layer and show it
		divObj = document.getElementById(divname);

		if(divObj)
			divObj.style.display = '';

		var user_div_content = $(divname).innerHTML;
		user_div_content = user_div_content.strip();
		// if content exists
		if (user_div_content != '')
			{
				return;
			}
		pars = 'uid=' + uid + '&option=' + viewOption
		ajaxUpdateDiv(url, pars, divname);
	}
function ajaxUpdateDiv(url, pars, divname)
	{
		result_div = divname;
		path = url+'?'+pars;
		/*var myAjax = new Ajax.Updater({success: divname},
										url,
										{
											method: 'post',
											parameters: pars,
											evalScripts: true
										}
									);*/
		new prototype_ajax(path, 'ajaxUpdateResult')
	}

function ajaxUpdateResult(data)
	{
		data = unescape(data.responseText);
		var obj = document.getElementById(result_div);
		obj.innerHTML = data;
	}

function hideUserInfoPopup(divname)
	{
		closeUserPopupAndTimer();
	}

/*************** End of user popup functions ***********/
var abuseContent = function(){
	var act_value = arguments[0];
	var content_id = arguments[1];
	var anchorLink = arguments[2];
	var msg_confirm = arguments[3];

	var confirm_message = msg_confirm;

	$('confirmAbuseMessage').innerHTML = confirm_message;
	document.formAbuseConfirm.action.value = act_value;
	document.formAbuseConfirm.content_id.value = content_id;
	Confirmation('selMsgAbuseConfirm', 'formAbuseConfirm', Array(), Array(), Array());

	return false;
}
var removeReasonErrors = function(){
	$('validReason').innerHTML = '';
	$('reason').value = '';
}

function hideBlogMonth2(liID){
	alert(liID);
	document.getElementById(liID).style.display='none';
}
function hideBlogYear(liID){
	$(liID).toggle();
}

function hideBlogMonth(liID){
	$(liID).toggle();
}

function setProfileImage($url){
prototype_ajax($url,'updateSetProfile');
}

function updateSetProfile(data){
data = unescape(data.responseText);
var obj = document.getElementById('selEditPhotoComments');
if(data.indexOf(session_check)>=1)
{
	data = data.replace(session_check_replace,'');
	alert(data);
}
	else
	return;
}

function changeUploadType(enableId,disableId){
	$(enableId).disabled=false;
	$(disableId).disabled=true;
	$(enableId).addClassName('required');
	$(disableId).removeClassName('required');

}

function toggleSubCategory(channelID)
	{
/*		var open_category_img = cfg_site_url+'design/templates/'+template_default+'/images/open.gif';
		var close_category_img = cfg_site_url+'design/templates/'+template_default+'/images/close.gif';*/
		var open_category_img = 'clsSideLinkOpen';
		var close_category_img = 'clsSideLinkOpen';


		$('divSubCategeory'+channelID).toggle();

		if($('imgCategory'+channelID).hasClassName('clsSideLinkOpen'))
			{
				$('imgCategory'+channelID).className = 'clsSideLinkClose';
/*				$('imgCategory'+channelID).removeClassName('clsSideLinkClose');
				$('imgCategory'+channelID).addClassName('clsSideLinkOpen');		*/
			}
		else if($('imgCategory'+channelID).hasClassName('clsSideLinkClose'))
			{
				$('imgCategory'+channelID).className = 'clsSideLinkOpen';
/*				$('imgCategory'+channelID).removeClassName('clsSideLinkOpen');
				$('imgCategory'+channelID).addClassName('clsSideLinkClose');*/
			}
		/*if($('imgCategory'+channelID).src == close_category_img)
			$('imgCategory'+channelID).src = open_category_img;
		else
			$('imgCategory'+channelID).src = close_category_img;*/

	}

function toggleSubCategoryClass(channelID)
	{
		if($('imgCategory'+channelID).hasClassName('clsSideLinkClose'))
			{
				$('imgCategory'+channelID).className = 'clsSideLinkHover';
			}
		else if($('imgCategory'+channelID).hasClassName('clsSideLinkHover'))
			{
				$('imgCategory'+channelID).className = 'clsSideLinkOpen';
			}
	}
//Populate game sub category..
function populate_game_sub_categories(url, tab_index, divname)
		{
			//a = document.article_writing_form.article_category_id;
			divToChange = divname;
			category_id = document.getElementById('game_category_id').value;
			document.getElementById('game_sub_category_id').value = '';
			if(category_id == 0)
				return;
			pars = 'game_category_id='+category_id+'&tab_index='+tab_index;
			var myAjax = new Ajax.Request(
								url,
								{
								method: 'get',
								parameters: pars,
								onComplete: changeDivInnerHtml
								});
		}
function deleteVideoMultiCheck(check_atleast_one,anchor,delete_confirmation, formname, id, act)
	{
		if(getMultiCheckBoxValue(formname, 'check_all', check_atleast_one, anchor, -100, -500))
			{
				Confirmation('selMsgConfirmMulti', 'msgConfirmformMulti', Array(id, 'act', 'msgConfirmTextMulti'),
				Array(multiCheckValue, act, delete_confirmation), Array('value', 'value', 'innerHTML'), 0, 0);
			}
	}

//function to disable submit button and to show processing image
var processingRequest = function(){
	var btnSubmitObj = arguments[0];
	var btnResetObj = arguments[1];
	var selProcessingRequestID = arguments[2];
	$(btnSubmitObj).style.display = 'none';
	$(btnResetObj).style.display = 'none';
	//$(selProcessingRequestID).innerHTML = processingSrc + ' ' + LANG_sending_email;
	$(selProcessingRequestID).innerHTML = '';
}

var replayDiv = '';
var div_id = '';
function ajaxSubmitForm(url, frmName, divname, id){
	replayDiv = divname;
	div_id = id;
	var reply = document.forms[frmName].user_reply.value;
	if (!Trim(reply))
		{
			$('validReply'+id).innerHTML = LANG_compulsory;
			return false;
		}
	$('validReply'+id).innerHTML = '';
	var pars = $(frmName).serialize();
	new Ajax.Request(url,{method: 'post',
	  parameters: pars,
	  onComplete: ajaxRelatedResult
	});

}

function ajaxRelatedResult(data)
	{

		data = unescape(data.responseText);
		$('selListStaticForm'+div_id).innerHTML = '';
		var obj = document.getElementById(replayDiv);
		//obj.style.display = 'block';

		if(data.indexOf(session_check)>=1)
			{
				data = data.replace(session_check_replace,'');
			}
		else
			{
				return;
			}
		obj.innerHTML = data;
	}

function ajaxReplayDiv(url, pars, divname)
	{
		result_div = divname;
		path = url+'?'+pars;
		new prototype_ajax(path, 'ajaxReplayDivResult')
	}

function ajaxReplayDivResult(data)
	{
		data = unescape(data.responseText);
		var obj = document.getElementById(result_div);

		if(data.indexOf(session_check)>=1)
			{
				data = data.replace(session_check_replace,'');
			}
		else
			{
				return;
			}

		obj.innerHTML = data;
	}

function hideChannel()
	{
		if(channelDivSet && allowChannelHide)
			{
				hideChannelDiv();
			}
	}

function hideChannelDiv()
	{
	   var channelMoreContentDiv = $('channelMoreContent');
	    if (channelDivSet) {
		if(channelMoreContentDiv!=null)
	        channelMoreContentDiv.style.display = 'none';
	        //if (doiframe) {
	            var iframe = $('selBackgroundIframe');
				if(iframe!=null)
	            iframe.style.display = 'none';
	        //}//EOF if-doiframe
	    }//EOF if-noClose
		channelDivSet = false;
	}

function hideMenuMore()
	{
		if(menuMoreDivSet && allowMenuMoreHide)
			{
				hideMenuMoreDiv();
			}
	}

function hideMenuMoreDiv()
	{
	   var menuMoreContentDiv = $('menuMoreContent');
	    if (menuMoreDivSet) {
		if(menuMoreContentDiv!=null)
	        menuMoreContentDiv.style.display = 'none';
	        //if (doiframe) {
	            var iframe = $('selBackgroundIframe');
				if(iframe!=null)
	            iframe.style.display = 'none';
	        //}//EOF if-doiframe
	    }//EOF if-noClose
		menuMoreDivSet = false;
	}

function hideHeaderSearchModule()
	{
		if(headerSearchDivSet && allowHeaderSearchHide)
			{
				hideHeaderSearchModuleDiv();
			}
	}

function hideHeaderSearchModuleDiv()
	{
	   var searchModuleContentDiv = $('searchHeaderModuleList');
	    if (headerSearchDivSet) {
		if(searchModuleContentDiv!=null)
	        searchModuleContentDiv.style.display = 'none';
	    }//EOF if-noClose
		headerSearchDivSet = false;
	}

function hideFooterSearchModule()
	{
		if(footerSearchDivSet && allowFooterSearchHide)
			{
				hideFooterSearchModuleDiv();
			}
	}

function hideFooterSearchModuleDiv()
	{
	   var searchModuleContentDiv = $('searchFooterModuleList');
	    if (footerSearchDivSet) {
		if(searchModuleContentDiv!=null)
	        searchModuleContentDiv.style.display = 'none';
	    }//EOF if-noClose
		footerSearchDivSet = false;
	}

function displaySearchModule(searchPosition)
	{
		var searchAnchorPosition = searchPosition+'SearchSubmit';
		var searchModuleDiv = 'search'+searchPosition.capitalize()+'ModuleList';
		if(searchPosition == 'header')
			{
				headerSearchDivSet = true;
				allowHeaderSearchHide = false;
				listen('mousemove', pageId, hideHeaderSearchModule);
				search_left_pos = search_header_left_pos;
				search_top_pos = search_header_top_pos;
			}
		else if(searchPosition == 'footer')
			{
				footerSearchDivSet = true;
				allowFooterSearchHide = false;
				listen('mousemove', pageId, hideFooterSearchModule);
				search_left_pos = search_footer_left_pos;
				search_top_pos = search_footer_top_pos;
			}


		var search_anchor = $(searchAnchorPosition);
		var selBackgroundIframe = $('selBackgroundIframe');
		var searchModuleContent = $(searchModuleDiv);
/*			searchModuleContent.show();
		selBackgroundIframe.style.width = channelMoreMenuContent.offsetWidth + "px";
		selBackgroundIframe.style.height = channelMoreMenuContent.offsetHeight + "px";
		selBackgroundIframe.style.top = getAbsoluteOffsetTop(search_anchor) + 30 + "px";
		selBackgroundIframe.style.left = getAbsoluteOffsetLeft(search_anchor) + -12 +"px";
		searchModuleContent.hide();*/
		searchModuleContent.style.top = getAbsoluteOffsetTop(search_anchor) + search_top_pos + "px";
		searchModuleContent.style.left = getAbsoluteOffsetLeft(search_anchor) + search_left_pos + "px";
//			selBackgroundIframe.toggle();
		searchModuleContent.show();
	}
function hideModuleSearch(id)
	{
		document.getElementById(id).style.display = 'none';
	}
function displayMenuMore()
	{
		menuMoreDivSet = true;
		allowMenuMoreHide = false;;
		listen('mousemove', pageId, hideMenuMore);
		//listen('mouseout', $('menuMoreContent'), hideMenuMore);
		var menu_more_anchor = $('menu_more_anchor');
		var selBackgroundIframe = $('selBackgroundIframe');
		var menuMoreContent = $('menuMoreContent');
		menuMoreContent.show();
		selBackgroundIframe.style.width = menuMoreContent.offsetWidth + "px";
		selBackgroundIframe.style.height = menuMoreContent.offsetHeight + "px";
		selBackgroundIframe.style.top = (findPosChildElementTop(menu_more_anchor) + parseInt(menu_more_top_position)) + "px";
    	selBackgroundIframe.style.left = (findPosChildElementLeft(menu_more_anchor) + parseInt(menu_more_left_position)) +"px";
		menuMoreContent.style.top = (findPosChildElementTop(menu_more_anchor) + parseInt(menu_more_top_position)) + "px";
    	menuMoreContent.style.left = (findPosChildElementLeft(menu_more_anchor) + parseInt(menu_more_left_position)) + "px";
		selBackgroundIframe.show();
	}
function displayChannel()
	{
		channelDivSet = true;
		allowChannelHide = false;;
		listen('mousemove', pageId, hideChannel);
		var channel_menu_anchor = $('channel_menu_anchor');
		var selBackgroundIframe = $('selBackgroundIframe');
		var channelMoreMenuContent = $('channelMoreContent');
		channelMoreMenuContent.show();
		selBackgroundIframe.style.width = channelMoreMenuContent.offsetWidth + "px";
		selBackgroundIframe.style.height = channelMoreMenuContent.offsetHeight + "px";
		selBackgroundIframe.style.top = (findPosChildElementTop(channel_menu_anchor) + parseInt(menu_channel_top_position)) + "px";
    	selBackgroundIframe.style.left = (findPosChildElementLeft(channel_menu_anchor) + parseInt(menu_channel_left_position)) +"px";
		channelMoreMenuContent.style.top = (findPosChildElementTop(channel_menu_anchor) + parseInt(menu_channel_top_position)) + "px";
    	channelMoreMenuContent.style.left = (findPosChildElementLeft(channel_menu_anchor) + parseInt(menu_channel_left_position)) + "px";
		selBackgroundIframe.show();
	}

//Fix for IE 7 and IE 8 to get elements position which is inside other elements
function findPosChildElementLeft(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;
	}

//Fix for IE 7 and IE 8 to get elements position which is inside other element (Child Elements)
function findPosChildElementTop(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;
	}