var enabled_edit_fields_time = new Array();
var enabled_edit_fields_comment = new Array();
var commentsArray = new Array();
var ajaxWindowLink;
var ajaxWindowYPos = 0;
var ajaxWindowXPos = 0;

// ARRAY EXTENSIONS

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;
}

// 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


//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;
}

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();
}

//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();
}

//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,width=400,height=300,top=200,left=200';
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);
		}
	);

function setSubjectFocus(thisForm)
{
	thisForm.subject.focus();
}

var divToChange = '';
function getRatingDetails(url, pars, divname)
	{
		Ajax.Responders.unregister(myGlobalHandlers);
		divToChange = divname;
		var myAjax = new Ajax.Request(
								url,
								{
								method: 'get',
								parameters: pars,
								onComplete: changeDivInnerHtml
								});
	}

function getQuestionRatingDetails(url, pars, divname)
	{
		Ajax.Responders.unregister(myGlobalHandlers);
		divToChange = divname;
		var myAjax = new Ajax.Request(
								url,
								{
								method: 'get',
								parameters: pars,
								onComplete: changeDivInnerHtml
								});
	}

function call_ajax_populate_sub_categories(url, add_pars,divname)
	{
		a = document.selFormAskQuestion.category;
		divToChange = divname;
		cat = a.value;
		pars = 'cid='+cat+'&'+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 toggleFavorites(url, pars, divname){
		Ajax.Responders.unregister(myGlobalHandlers);
		divToChange = divname;
		$(divToChange).innerHTML = loadingSrc;
		var myAjax = new Ajax.Request(
								url,
								{
								method: 'get',
								parameters: pars,
								onComplete: changeDivInnerHtml
								});
	}

function updatelength()
{
	if(document.getElementById('submit_answer'))
		submit_val = 'submit_answer';
	else
		submit_val = 'submit';
	var ss = 'ss';
	var obj = arguments[0];
	if(arguments.length>=2)
		ss = arguments[1];
	var b =obj.form.name;
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
	var a;
	a= mlength- obj.value.length ;
	if(a < 0 )
		{
			LANG_remaining = LANG_exceed_limit;
		}
	else if( a >=  0)
		{
			LANG_remaining = LANG_remaining_again;
		}
	b= LANG_remaining +" :<span class ='clsCharacterLimit' > "+Math.abs(a)+"</span>";
	var classAdd = ' clsDisableButton' ;
	if (document.getElementById("post_value"+ss )!=null)
		{
			var classname = document.getElementById("post_value"+ss).className;
		}
	else
		{
			var classname = document.getElementById(submit_val).className;
		}
	var len_class = classname.length;
	var x;

	if(a < 0)
		{
			if(classname.indexOf(classAdd)==-1)
				{
					if (document.getElementById("post_value"+ss)!=null)
						document.getElementById("post_value"+ss).className = document.getElementById("post_value"+ss).className +  classAdd;
					else
						document.getElementById(submit_val).className = document.getElementById(submit_val).className +  classAdd;
				}
			if(document.getElementById(ss).className == 'clsZeroColour')
				document.getElementById(ss).className = 'clsNegativeColour';
			if (document.getElementById("post_value"+ss)!=null)
				document.getElementById("post_value"+ss).disabled = true;
			else
				document.getElementById(submit_val).disabled = true;
		}
	else
		{
			x = classname.replace(classAdd, '');
			if(document.getElementById(ss).className == 'clsNegativeColour')
					document.getElementById(ss).className = 'clsZeroColour';
			if (document.getElementById("post_value"+ss)!=null)
				document.getElementById("post_value"+ss).className = x;
			else
				document.getElementById(submit_val).className = x;
			if (document.getElementById("post_value"+ss)!=null)
				document.getElementById("post_value"+ss).disabled = false;
			else
				document.getElementById(submit_val).disabled = false;
		}

	Element.update(ss, b);
}

var updatelengthOnload=function()
{
	var ss = 'ss';
	var obje = arguments[0];
	var obj = $(obje);
	if(arguments.length>=2)
		ss = arguments[1];

	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length>mlength)
		{
			obj.value=obj.value.substring(0,mlength);
			alert_manual(LANG_limit_exceeds);
		}

	var a;
	a=obj.value.length + '   ('+LANG_limit+' '+mlength+')';
	Element.update(ss, a);
}

/**
 *
 * @access public
 * @return void
 **/
var img_src = new Array();
function mouseOver(rating, rate_img_mouse_over, rate_img_mouse_out)
{
	for(var i=1; i<=rating; i++)
		{
			var obj = document.getElementById('rate'+i);
			img_src[i] = obj.src;
			obj.src = rate_img_mouse_over;
		}
	for(; i<=4; i++)
		{
			var obj = document.getElementById('rate'+i);
			img_src[i] = obj.src;
			obj.src = rate_img_mouse_out;
		}
}

function mouseOut()
	{
		for(var i=1; i<=4; i++)
			{
				var obj = document.getElementById('rate'+i);
				obj.src = img_src[i];
			}
	}

/**
 *
 * @access public
 * @return void
 **/
function mouseOverAnswers(rating, start, rate_img_mouse_over, rate_img_mouse_out)
{
	for(var i=1+start; i<=rating; i++)
		{
			var obj = document.getElementById('rate'+i);
			img_src[i] = obj.src;
			obj.src = rate_img_mouse_over;
		}
	for(; i<=4+start; i++)
		{
			var obj = document.getElementById('rate'+i);
			img_src[i] = obj.src;
			obj.src = rate_img_mouse_out;
		}
}

function mouseOutAnswers(start)
	{
		for(var i=1+parseInt(start); i<=4+parseInt(start); i++)
			{
				var obj = document.getElementById('rate'+i);
				obj.src = img_src[i];
			}
	}

var doActionOnQuestion = function(){
	var act_value = arguments[0];
	var anchorLink = arguments[1];
	var msg_confirm = arguments[2];

	var confirm_message = msg_confirm;

	$('confirmMessage').innerHTML = confirm_message;
	document.formConfirm.action.value = act_value;
	Confirmation('selMsgConfirm', 'formConfirm', Array(), Array(), Array());

	return false;
}

var doActionOnAnswer = function(){
	var act_value = arguments[0];
	var anchorLink = arguments[1];
	var msg_confirm = arguments[2];
	var ansId = arguments[3];

	var confirm_message = msg_confirm;

	$('confirmMessage').innerHTML = confirm_message;
	document.formConfirm.action.value = act_value;
	document.formConfirm.aid.value = ansId;
	Confirmation('selMsgConfirm', 'formConfirm', Array(), Array(), Array());

	return false;
}
var doActionOnComment = function(){
	var act_value = arguments[0];
	var anchorLink = arguments[1];
	var msg_confirm = arguments[2];
	var comment_id = arguments[3];
	var confirm_message = msg_confirm;
	$('confirmMessage').innerHTML = confirm_message;
	document.formConfirm.action.value = act_value;
	document.formConfirm.comment_id.value = comment_id;
	Confirmation('selMsgConfirm', 'formConfirm', Array(), Array(), Array());

	return false;
}

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 chkIsAbuseReasonExists = function(){
	var abuseReason = $('reason').value;
	if (!Trim(abuseReason))
		{
			$('validReason').innerHTML = LANG_valid_reason_for_abusing;
			return false;
		}
	$('validReason').innerHTML = '';
}

var removeReasonErrors = function(){
	$('validReason').innerHTML = '';
	$('reason').value = '';
}

/*******for ediit comment functions started***********/
function callAjaxEdit(url, pars, comment_id)
	{
		pars = pars+'&type=edit&comment_id='+comment_id;
		var myAjax = new Ajax.Request(
								url,
								{
								method: 'get',
								parameters: pars,
								onComplete: ajaxResultEdit
								});
		return false;
	}

function ajaxResultEdit(originalRequest)
	{
		var obj;
		data = originalRequest.responseText;

		data = data.split('***--***!!!');

		if(obj = document.getElementById('selEditCommentTxt_'+data[0]))
			obj.style.display = 'none';

		obj = document.getElementById('selEditComments_'+data[0]);
		obj.style.display = 'block';
		var txt = replace_string(data['1'], '<br>', '\n');
		txt = replace_string(txt, '<br />', '\n');
		txt = trim(txt);
		obj.innerHTML = txt;

		obj = document.getElementById('selViewEditComment_'+data[0]);
		obj.style.display = 'none';
		return true;
	}

function discardEdit(comment_id)
	{
		var obj;

		if(obj = document.getElementById('selEditCommentTxt_'+comment_id))
			obj.style.display = '';

		if(obj = document.getElementById('selEditComments_'+comment_id))
			obj.style.display = 'none';

		if(obj = document.getElementById('selViewEditComment_'+comment_id))
			obj.style.display = '';
	}

var addToEdit = function()
	{
		comment_id = arguments[0];

		if(arguments[1])
			addCommentsUrl = arguments[1];

		var f = '';

		var frm = eval("document.addEdit_"+comment_id);
		for (var i=0;i<frm.elements.length;i++)
			{
				var e=frm.elements[i];
				if (e.type!='button')
					{
						var ovalue = Trim(e.value);
						if(ovalue)
							{
								ovalue = replace_string(ovalue, '\n', '<br />');
								f += ovalue;
							}
						else
							{
								e.value = '';
								e.focus();
								return false;
							}
					}
			}
		f = escape(f);
		var currpath = addCommentsUrl+'&comment_id='+comment_id+'&type=edit&f='+escape(f);
		callAjaxUpdate(currpath,'selCommentBlock');
		return false
	}

function callAjaxUpdate(path, block)
	{

		path = path;
		new AG_ajax(path,'callAjaxUpdateResponse');
		return false;
	}

function callAjaxUpdateResponse(data)
	{
		data = unescape(data);
		if(data.indexOf(session_check)>=1)
			{
				data = data.replace(session_check_replace,'');
			}
		else
			{
				return;
			}
		data = data.split('***--***!!!');

		if(obj = document.getElementById('selEditCommentTxt_'+data['0']))
			obj.innerHTML = data['1'];

		discardEdit(data['0']);
		return;
	}

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_manual("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();
	}

//timer for delete blogs start
function changeTimer(){
	if(enabled_edit_fields_comment.length){
		doTimerFunction();
	}
	setTimeout('changeTimer()',1000);
}

function setEditTimerValue(comment_id){
	enabled_edit_fields_comment[enabled_edit_fields_comment.length] = comment_id;
	enabled_edit_fields_time[comment_id] = max_timer;
}

function doTimerFunction(){
	var val;
	var comment_id;
	for(var i in enabled_edit_fields_comment){
		comment_id = enabled_edit_fields_comment[i];
		if(i!='undefined' && i!='has' && i!='find'){
		val = enabled_edit_fields_time[comment_id];
		if(val<=1)
			hideDeleteEditLinks(comment_id);
		else if(val!=null)
			decrementTime(comment_id);
		}
	}
}

function decrementTime(comment_id){
	var obj;
	var val = enabled_edit_fields_time[comment_id];
	if(obj = document.getElementById('selViewTimerComment_'+comment_id)){
		obj.innerHTML = val-1;
		obj.innerHTML = obj.innerHTML+' '+LANG_seconds;
	}
	enabled_edit_fields_time[comment_id] = val-1;
}
function hideDeleteEditLinks(comment_id){
	var obj;
	var val = enabled_edit_fields_time[comment_id];
	if(obj = document.getElementById('selViewDeleteComment_'+comment_id))
		obj.style.display = 'none';
	if(obj = document.getElementById('selViewEditComment_'+comment_id))
		obj.style.display = 'none';
	if(obj = document.getElementById('selViewTimerComment_'+comment_id))
		obj.style.display = 'none';
	if(obj = document.getElementById('cmd'+comment_id))
		obj.className = 'clsNotEditable';
	enabled_edit_fields_time[comment_id] = null;
}
//timer for delete blogs End

function showUserInfoPopup(url, pars, divname){
	// 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 = '';

	// if content exists
	if ($(divname).innerHTML){
		return;
	}

	//if there is no content
	$(divname).innerHTML = processingSrc;
	ajaxUpdateDiv(url, pars, divname);
}
function hideUserInfoPopup(divname){
	closeUserPopupAndTimer();
	//if ($(divname))
		//hide(divname);
}

function ajaxUpdateDiv(url, pars, divname){
	var myAjax = new Ajax.Updater(
									{success: divname},
									url,
									{
										method: 'get',
										parameters: pars,
										evalScripts: true
									});
}

function ajaxUpdateVotingDiv(url, pars, divname, srcid, ancid, anc_id,value){
	var myAjax = new Ajax.Updater(
									{success: divname},
									url,
									{
										method: 'get',
										parameters: pars,
										evalScripts: true,
										asynchronous: false,
										onComplete :changeImageANdSrcStatus(srcid, ancid,anc_id, value)
									});
}

function changeImageANdSrcStatus(srcid, ancid, anc_id,value)
	{
		var a = document.getElementById(ancid);
		var b = document.getElementById(anc_id);
		a.onclick = function() { displayAlertMsg() };
		b.onclick = function() { displayAlertMsg1() };

		if(value==1)
			document.getElementById(srcid).src=SITE_URL+'design/templates/'+SITE_TEMPLATE+'/root/images/'+SITE_SCREEN+'/up-disable.gif';
		else if(value == -1)
			document.getElementById(srcid).src=SITE_URL+'design/templates/'+SITE_TEMPLATE+'/root/images/'+SITE_SCREEN+'/down-disable.gif';
	}
function displayAlertMsg()
	{
		alert_manual(LANG_already_voted);
		return false;
	}
function displayAlertMsg1()
	{
		alert_manual(LANG_already_voted);
		return false;
	}

function ajaxpopularUpdateDiv(url, divname){
	pars = '';
	var myAjax = new Ajax.Updater(
									{success: divname},
									url,
									{
										method: 'post',
										parameters: pars,
										evalScripts: true
									});
}
var updateVideoTitleAndActivate = function(){
	var hrefId = arguments[0];
	var thisObj = arguments[1];
	$('selVideoTitle').innerHTML = $(hrefId).innerHTML;
	var popularImages = document.getElementsByClassName('clsPopularActiv');
	var popularImagesLength = popularImages.length;
	for (var i = 0; i < popularImagesLength; i++){
		popularImages[i].className = 'clsPopularInactiv';
	}
	thisObj.className = 'clsPopularActiv';
}

function ajaxSubmitExternalForm(url, frmName, divname){
	var reply = document.forms[frmName].audio_url.value;
	if (!Trim(reply))
		{
			$('validReply').innerHTML = LANG_compulsory;
			return false;
		}
	$('validReply').innerHTML = '';
	var pars = $(frmName).serialize();
	var myAjax = new Ajax.Updater(
									{success: divname},
									url,
									{
										method: 'post',
										parameters: pars,
										evalScripts: true
									});
}
function ajaxSubmitExternalVideoForm(url, frmName, divname){
	var reply = document.forms[frmName].video_flv_url.value;
	if (!Trim(reply))
		{
			$('validReply').innerHTML = LANG_compulsory;
			return false;
		}
	$('validReply').innerHTML = '';
	var pars = $(frmName).serialize();
	var myAjax = new Ajax.Updater(
									{success: divname},
									url,
									{
										method: 'post',
										parameters: pars,
										evalScripts: true
									});
}
function ajaxAnswersSubmitForm(url, frmName, divname){
	var reply = document.forms[frmName].share_answer.value;
	if (!Trim(reply))
		{
			$('validAnswer').innerHTML = LANG_compulsory;
			return false;
		}
	$('validAnswer').innerHTML = '';

	var pars = $(frmName).serialize();
	if (url.indexOf('?') == -1)
		url+='?postYourAnswer=1';
	else
		url+='&postYourAnswer=1';

	document.forms[frmName].share_answer.value = '';
	$('shareBtn').style.display = 'none';
	$('shareAnswerProcessing').style.display = 'block';
	$('shareAnswerProcessing').innerHTML = LANG_update_text;

	var myAjax = new Ajax.Updater(
									{success: divname},
									url,
									{
										method: 'post',
										parameters: pars,
										evalScripts: true,
										onComplete: showShareDiv
									});
}

function showShareDiv(){
	$('shareBtn').style.display = 'block';
	$('shareAnswerProcessing').style.display = 'none';
	$('shareAnswerProcessing').innerHTML = '';
}
function openUploadPage(url, pars){
	var myAjax = new Ajax.Request(
								url,
								{
								method: 'get',
								parameters: pars,
								onComplete: ajaxResultOpenUploadPage
								});
								return false;
}

function ajaxResultOpenUploadPage(originalRequest){
	data = originalRequest.responseText;
	Confirmation('selMsgConfirm', 'msgConfirmform', Array('selConfirmText'), Array(data), Array('innerHTML'));
	//alert(data);
}

var updateContent = function(){
	var divname = arguments[0];
	var extra_pars = '';
	var filter = '';
	if(arguments.length>=2){
		filter = arguments[1];
		extra_pars = '&filter='+filter;
	}

	//resize the sidebar
	toggleNavBar();

	//if there is content
	if (Trim($(divname).innerHTML) != '' && filter == ''){
		return;
	}

	//if there is no content
	$(divname).innerHTML = processingSrc;
	url = ajax_url;
	pars = 'ajax_page=true&show='+divname+extra_pars;
	var myAjax = new Ajax.Updater(
									{success: divname},
									url,
									{
										method: 'post',
										parameters: pars,
										evalScripts: true,
										onComplete: toggleNavBar
									});
}

function deleteComments(url, pars){
	var commentId = document.msgConfirmform.comment_id.value;
	var mainCommentId = document.msgConfirmform.main_comment_id.value;
	divname =  'selReplyId'+mainCommentId;

	pars = pars+'&comment_id='+commentId+'&main_comment_id='+mainCommentId;

	ajaxUpdateDiv(url, pars, divname);
}

function deleteQuestionAttachments(url, pars){
	var info_id = document.msgInfoConfirmform.info_id.value;
	var ques_id = document.msgInfoConfirmform.ques_id.value;
	var fname = document.msgInfoConfirmform.filename.value;
	//divname =  'selReplyQuesId'+ques_id;
	divname =  'allInfos';

	pars = pars+'&attachment_id='+info_id+'&ques_id='+ques_id+'&attachment_name='+fname;
	$('attach_'+info_id).remove();
	$('brsBtn').style.display = '';
	ajaxUpdateDiv(url, pars, divname);
}
function deleteAnswerAttachments(url, pars){
	var info_id = document.msgAttachConfirmform.attach_id.value;
	var ques_id = document.msgAttachConfirmform.attach_content_id.value;
	var fname = document.msgAttachConfirmform.attach_name.value;
	divname =  'allInfos';

	pars = pars+'&attachment_id='+info_id+'&attach_content_id='+ques_id+'&attachment_name='+fname;
	$('attach_'+info_id).remove();
	$('brsBtn').style.display = '';
	ajaxUpdateDiv(url, pars, divname);
}

var manualLiveValidation=function(){

	if(featured_livevalidation == '')
	       return false;

	elem = arguments[0];
	var cat_field = 'category';
	if(arguments[1])
			cat_field = 'blog_category_id';

	var spanmessage = '<span id="selectspan" class="LV_validation_message LV_invalid">'+LANG_compulsory+'</span>';
	if($('selectspan') != null)
	{
		$('selectspan').remove();
		//$('cat_field').removeClassName('LV_invalid_field');

	}


	if(elem.value == '' && $('selectspan') == null)
	{
		new Insertion.After('selGeneralCategory', spanmessage);
	//	$('cat_field').addClassName('LV_invalid_field');
	}
}

var processingRequestForComment = 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_updating_msg;
}

var resetAnswserEntered = function(){
	$('answer').value='';
	if( $('source')) $('source').value='';
}
function answerCancel(length){
	$('answer').value='';
	$('ss').innerHTML=LANG_remaining +" :<span class ='clsCharacterLimit' > "+ length + "</span>";
}
var resetSearch = function(){
	$('video_side').value = 0;
	$('audio_side').value = 0;
	$('textsearch').className = 'clsInactiveSearch';
	if($('audiosearch')) $('audiosearch').className = 'clsInactiveSearch';
	if($('videosearch')) $('videosearch').className = 'clsInactiveSearch';
}
var setSearch = function(){
	var activeSearch = arguments[0];
	resetSearch();
	$(activeSearch).className = 'clsActiveSearch';
	if (activeSearch == 'audiosearch')
		$('audio_side').value = 1;
	else if (activeSearch == 'videosearch')
		$('video_side').value = 1;
}
function displayImageGallery(imgLinkId){
	if (navigator.appName == "Microsoft Internet Explorer")
		{
			var innerheight = document.documentElement.clientHeight;
			if(innerheight == 0)
				{
					innerheight = document.body.scrollHeight;
				}
			var innerwidth  = document.documentElement.clientWidth;
			if(innerwidth == 0)
				innerwidth = document.body.scrollWidth;
		}
	else
		{
			var innerheight = window.innerHeight;
			var innerwidth = window.innerWidth;
		}
	var pars = '&w='+innerwidth+'&h='+innerheight;
	return openImageAjaxWindow(imgLinkId, pars);
}

function openImageAjaxWindow(linkid, pars){
	ajaxWindowLink = linkid;
	linkobj = document.getElementById(linkid);
	url = linkobj.href;
	Confirmation('selAjaxWindow', 'frmAjaxWindow', Array('selAjaxWindowInnerDiv'), Array(loadingInfoSrc), Array('innerHTML'));
	var myAjax = new Ajax.Request(
								url,
								{
								method: 'get',
								parameters: pars,
								onComplete: ajaxResultOpenAnovaAjaxWindow
								});
								return false;
}
function copyValueToMainForm(mType) {
	mediaType = mType;
	if (mediaType == 'Video') {
		$('video_external_flv_url').value = $('video_flv_url').value;
		$('flv_upload_type').value = $('external_upload_type').value;
		$('external_video_add').style.display = 'none';
		$('external_video_add1').style.display = 'none';
		$('external_video_add2').style.display = '';
		$('external_video_delete').style.display = '';
		if (($('external_video_preview'))) {
			$('external_video_preview').style.display = '';
			$('external_video_preview').href = externalVideoPreviewUrl;
			$('external_video_preview').onclick = showVideoExternalPreview;
		}
	} else if (mediaType == 'Audio') {
		$('audio_external_url').value = $('audio_url').value;
		$('external_audio_add').style.display = 'none';
		$('external_audio_add1').style.display = 'none';
		$('external_audio_add2').style.display = '';
		$('external_audio_delete').style.display = '';
		if (($('external_audio_preview'))) {
			$('external_audio_preview').style.display = '';
			$('external_audio_preview').href = externalAudioPreviewUrl;
			$('external_audio_preview').onclick = showAudioExternalPreview;
		}
	}
}
function showVideoExternalPreview(){
	alert_manual(video_not_encoded_info, 'external_video_preview', -50, -150);
	return false;
}
function showAudioExternalPreview(){
	alert_manual(audio_not_encoded_info, 'external_audio_preview', -50, -150);
	return false;
}
function call_ajax_populate_debate_sub_categories(url, add_pars,divname)
	{
		a = document.selFormCreateDebate.category;
		divToChange = divname;
		cat = a.value;
		pars = 'cid='+cat+'&'+add_pars;
		var myAjax = new Ajax.Request(
							url,
							{
							method: 'get',
							parameters: pars,
							onComplete: changeDivInnerHtml
							});

	}
var doActionOnDebateResponse = function(){
	var act_value = arguments[0];
	var anchorLink = arguments[1];
	var msg_confirm = arguments[2];
	var rid = arguments[3];
	var confirm_message = msg_confirm;
	$('confirmMessageResponse').innerHTML = confirm_message;
	document.formConfirm.action.value = act_value;
	Confirmation( 'selMsgConfirmResponse', 'formConfirmResponse', Array('action','rid'), Array('deleteResponse',rid), Array());

	return false;
}

var doActionOnDebateResolve = function(){
	var act_value = arguments[0];
	var anchorLink = arguments[1];
	var msg_confirm = arguments[2];
	var rid = arguments[3];
	var confirm_message = msg_confirm;
	$('confirmMessageResolve').innerHTML = confirm_message;
	document.formConfirm.action.value = act_value;
	Confirmation('selMsgConfirmResolve', 'formConfirmResolve', Array(), Array(), Array());

	return false;
}

var editDebateResponse = function(){
	var act_value = arguments[0];
	var content_id = arguments[1];
	var content = arguments[2];
	var anchorLink = arguments[3];
	var msg_confirm = arguments[4];

	var confirm_message = msg_confirm;

	$('confirmUpdateMessage').innerHTML = confirm_message;
	document.formUpdateConfirm.action.value = act_value;
	document.formUpdateConfirm.content_id.value = content_id;
	document.formUpdateConfirm.response.value = content;
	document.formUpdateConfirm.max_res_length.value= max_res_length;
	Confirmation('selMsgUpdateConfirm', 'formUpdateConfirm', Array(), Array(), Array());

	return false;
}

var chkIsDebateResponseExists = function(){
	var abuseReason = $('response').value;
	var res_length = $('response').value.length;
	var max_res_length = $('max_res_length').value;

	if (!Trim(abuseReason))
		{
			$('validResponse').innerHTML = LANG_valid_response_for_debate;
			return false;
		}
	if(parseInt(res_length)>parseInt(max_res_length))
		{
			$('validResponse').innerHTML = LANG_limit_exceeds;
			return false;
		}
	$('validResponse').innerHTML = '';
}
var removeResponseErrors = function(){
	$('validResponse').innerHTML = '';
	$('response').value = '';
}
function deleteAnswerReplies(url, pars){
	var ansId = document.msgConfirmform.ans_id.value;
	var mainAnsId = document.msgConfirmform.main_ans_id.value;
	divname =  'selReplyId'+mainAnsId;

	pars = pars+'&ans_id='+ansId+'&main_ans_id='+mainAnsId;

	ajaxUpdateDiv(url, pars, divname);
}

var selectActive = function(){
	var activeObj = $(arguments[0]);
	$('selRecentAll').className = 'clsInActiveMenuPopup';
	if ($('selRecentAudio'))
		$('selRecentAudio').className = 'clsInActiveMenuPopup';
	if ($('selRecentVideo'))
		$('selRecentVideo').className = 'clsInActiveMenuPopup';
	activeObj.className = 'clsActiveMenuPopup';
}
function hideRecentFilter(){
	if ($('selFilterQuestions')) {
		$('selFilterQuestions').style.display = 'none';
		$('selFilterOption').className = 'clsLink';
	}
}
function showRecentFilter(){
	$('selFilterQuestions').style.display = '';
	$('selFilterOption').className = 'clsLinkHover';
}

function disableAll(isEnable,frmname)
	{
		//alert('inside disable');
		var make = isEnable;

		if(frmname == '')
			return false;

		var targetForm = document.getElementById(frmname);

		for (var i=0; i<targetForm.elements.length; i++)
			{
				if (targetForm.elements[i].type == "checkbox")
					{
						if(make == '0')
						targetForm.elements[i].disabled=true;
						else
						targetForm.elements[i].disabled=false;

					}
			}
	}

var myGlobalHandlers = {
		onCreate: function(){
			Element.show('systemWorking');
			Element.hide('content');
		},

		onComplete: function() {
			if(Ajax.activeRequestCount == 0){
				Element.hide('systemWorking');
				Element.show('content');

			}
		}
	};
function openAnovaAjaxWindow(linkid){
	ajaxWindowLink = linkid;
	linkobj = document.getElementById(linkid);
	url = linkobj.href;
	pars = '';
	var myAjax = new Ajax.Request(
								url,
								{
								method: 'get',
								parameters: pars,
								onComplete: ajaxResultOpenAnovaAjaxWindow
								});
								return false;
}

function ajaxResultOpenAnovaAjaxWindow(originalRequest){
	data = originalRequest.responseText;
	Confirmation('selAjaxWindow', 'frmAjaxWindow', Array('selAjaxWindowInnerDiv'), Array(data), Array('innerHTML'));
	if ((catObj = $('category')) || (sub_catObj = $('sub_category'))){
		br=getBrowser();
		if (br[0] == 'msie' && getMajorVersion(br[1]) == '6'){
			if (catObj = $('category'))
				catObj.style.display = 'none';

			if (sub_catObj = $('sub_category'))
				sub_catObj.style.display = 'none';
		}
	}
	data.evalScripts();
}
function show(element){
	if(obj = document.getElementById(element))
		obj.style.display = '';
}

function hide(element){
	if(obj = document.getElementById(element))
		obj.style.display = 'none';
}

function popupWindow(url){
	 window.open (url, "","status=0,toolbar=0,resizable=0,scrollbars=1");
	 return false;
}
function ajaxFormSubmit(frmName, divname){
	var pars = $(frmName).serialize();
	var url = $(frmName).action;
	var myAjax = new Ajax.Updater(
									{success: divname},
									url,
									{
										method: 'post',
										parameters: pars,
										evalScripts: true
									});
}

function ajaxSubmitForm(url, frmName, divname, id){
	var reply = document.forms[frmName].user_reply.value;
	if(url.indexOf("cancelOptionToComment") == -1 )
		{
		if (!Trim(reply))
			{
				$('validReply'+id).innerHTML = LANG_compulsory;
				return false;
			}
		}
	$('validReply'+id).innerHTML = '';
	var pars = $(frmName).serialize();
	var myAjax = new Ajax.Updater(
									{success: divname},
									url,
									{
										method: 'post',
										parameters: pars,
										evalScripts: true
									});
}

function openAnovaAjaxWindowLogin(linkid, url){
	ajaxWindowLink = linkid;
	linkobj = document.getElementById(linkid);
	linkobj.value='';
	url = url;
	pars = '';
	var myAjax = new Ajax.Request(
								url,
								{
								method: 'get',
								parameters: pars,
								onComplete: ajaxResultOpenAnovaAjaxWindow
								});
								return false;
}