if(!block_arr)
{
	var block_arr = new Array();
}
var ajaxWindowLink;
var ajaxWindowYPos = 0;
var ajaxWindowXPos = 0;

//function for check box manage
function CheckAll(form_name,check_all,isO,noHL)
	{
		var trk=0;
		var frm = eval('document.'+form_name);
		var check_frm = eval('document.'+form_name+'.'+check_all);

		for (var i=0;i<frm.elements.length;i++)
		{
			var e=frm.elements[i];
			if ((e.name != check_all) && (e.type=='checkbox'))
			{
				if (isO != 1)
				{
					trk++;
					if(e.disabled!=true)
						e.checked=check_frm.checked;
				}
			}
		}
	}

/******* Start Trim Functions ************/
function Trim(TRIM_VALUE)
	{
		if(TRIM_VALUE.length < 1)
			{
				return "";
			}
		TRIM_VALUE = RTrim(TRIM_VALUE);
		TRIM_VALUE = LTrim(TRIM_VALUE);
		if(TRIM_VALUE=="")
			{
				return "";
			}
		else
			{
				return TRIM_VALUE;
			}
	}

function RTrim(VALUE)
	{
		var w_space = String.fromCharCode(32);
		var v_length = VALUE.length;
		var strTemp = "";
		if(v_length < 1)
			{
				return "";
			}
		var iTemp = v_length -1;
		while(iTemp > -1)
			{
				if(VALUE.charAt(iTemp) == w_space)
					{
					}
				else
					{
						strTemp = VALUE.substring(0,iTemp +1);
						break;
					}
				iTemp = iTemp-1;

			}
		return strTemp;
	}

function LTrim(VALUE)
	{
		var w_space = String.fromCharCode(32);
		if(v_length < 1)
			{
				return "";
			}
		var v_length = VALUE.length;
		var strTemp = "";

		var iTemp = 0;

		while(iTemp < v_length)
			{
				if(VALUE.charAt(iTemp) == w_space)
					{
					}
				else
					{
						strTemp = VALUE.substring(iTemp,v_length);
						break;
					}
				iTemp = iTemp + 1;
			}
		return strTemp;
	}
/***********End trim functions********/
function RegularExpressionReplace(expression, subject, replaced)
	{
	  var re = new RegExp(expression, "g");
	  return subject.replace(re, replaced);
	}
function StringReplcae(find_string, replace_string, subject)
	{
		return RegularExpressionReplace(find_string, subject, replace_string);
	}
function replace_string(str, search_str, replace_str)
	{
			var condition = true;
			var inc= 1;
			while(condition)
				{
					str = str.replace(search_str,replace_str);
					if(str.indexOf(search_str)<0)
						condition = false;
					inc++;
				}
			return str;
	}
//**************** confirmation box related functions Start *******************/
//Change position of the confirmation block
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;
	}

//Hide all confirmation blocks
function hideAllBlocks(){
		var obj;
		if(obj = $('selAlertbox'))
			obj.style.display = 'none';
		for(var i=0;i<block_arr.length;i++){
				if(obj = $(block_arr[i]))
					obj.style.display = 'none';
			}
		if(obj = $('hideScreen'))
			obj.style.display='none';

		if(obj = $('selAjaxWindow'))
			obj.style.display='none';

		if(obj = $('selAjaxWindowInnerDiv'))
			obj.innerHTML='';

		return false;
	}

//**************** confirmation box related functions Start *******************/
//Change position of the confirmation block
//Get multible check box value with comma seperator
var multiCheckValue='';
var minimum_top = 20;
var minimum_left = 20;
var zIndexValue = 200;
// form_name, check_all_name, alert_value, place
var getMultiCheckBoxValue = function(){
	multiCheckValue = '';
	var form_name = arguments[0];
	var check_all_name = arguments[1];
	var alert_value = arguments[2];

	var frm = eval('document.'+form_name);
	var ids = '';
	for(var i=0;i<frm.elements.length;i++){
		var e=frm.elements[i];
		if ((e.name != check_all_name) && (e.type=='checkbox') && e.checked)
			ids += e.value+',';
	}
	if(ids){
		multiCheckValue =ids.substring(0,ids.length-1);
		return true;
	}
		alert_manual(alert_value);
	return false;

}

var alert_manual = function()
	{
		var obj;
		var alert_value = arguments[0];
		if(obj = $('selAlertMessage'))
			obj.innerHTML = alert_value;
		if(fromObj = $('selAlertbox'))
			changePosition(fromObj);
		if(obj = $('selAlertOkButton'))
			obj.focus();
		return false;
	}
function changePosition(fromObj)
	{
		var obj = fromObj;
		obj.style.display = 'block';
		if (navigator.appName == "Microsoft Internet Explorer")
			{
				var scrolltop = document.body.scrollTop;
				var scrollleft = document.body.scrollLeft;
				var innerheight = document.body.offsetHeight;
				var innerwidth = document.body.offsetWidth;
				var divwidth = obj.offsetWidth;
				var divheight = obj.offsetHeight;
			}
		else
			{
				var scrolltop = window.pageYOffset;
				var scrollleft = window.pageXOffset;
				var innerheight = window.innerHeight;
				var innerwidth = window.innerWidth;
				var divwidth = obj.offsetWidth;
				var divheight = obj.offsetHeight;
			}

		if(obj.style.position == 'fixed')
			{
				var movedivleft = (parseInt(innerwidth)/2)-(parseInt(divwidth)/2);
				var movedivtop = (parseInt(innerheight)/2)-(parseInt(divheight)/2);
			}
		else
			{
				var movedivleft = (parseInt(innerwidth)/2)+(parseInt(scrollleft))-(parseInt(divwidth)/2);
				var movedivtop = (parseInt(innerheight)/2)+(parseInt(scrolltop))-(parseInt(divheight)/2);
			}
		obj.style.top = movedivtop + 'px';
		obj.style.left = movedivleft + 'px';
		obj.style.zIndex = zIndexValue;
		if(obj = $('hideScreen'))
			{
				var ss = getPageSizeWithScroll();
				var ua = navigator.userAgent.toLowerCase();

				if(ua.indexOf("msie") != -1){
					obj.style.width=ss[0]+"px";
				}
				obj.style.height=ss[1]+"px";
				obj.style.display='block';
			}
		//fade, slide, glide, wipe, unfurl, grow, shrink, highlight
		//Zapatec.Effects.show(fromObj.id, 10, 'grow')
		return false;
	}
function showHideScreen(divElm){
	var fromObj = $(divElm);
	fromObj.style.zIndex = zIndexValue;
	fromObj.style.display = 'block';
	if(obj = $('hideScreen')){
		var ss = getPageSizeWithScroll();
		var ua = navigator.userAgent.toLowerCase();

		if(ua.indexOf("msie") != -1){
			obj.style.width=ss[0]+"px";
		}
		obj.style.height=ss[1]+"px";
		obj.style.display='block';
		return false;
	}
}
function makeQueryAsFormFieldValues(form_name)
	{
		var query = '';
		var frm = eval('document.'+form_name);
		for(var i=0;i<frm.elements.length;i++){
				var e=frm.elements[i];
				if (e.type!='button' && e.type!='checkbox'){
						query += e.name+'='+e.value+'&';
					}
			}
		query =query.substring(0,query.length-1);
		return query;
	}

//Display confirmation Block
//place, block, form_name, id_array, value_array, property_array, add_top_position, add_left_position
//property_array, add_top_position, add_left_position --- optional
var Confirmation = function(){
	var obj, inc, form_field;
	hideAllBlocks();

	var block = arguments[0];
	var form_name = arguments[1];
	var id_array = arguments[2];
	var value_array = arguments[3];

	var property_array = new Array();
	multiCheckValue ='';

	if(arguments.length>=5)
		property_array = arguments[4];

	for(inc=0; inc<value_array.length;inc++){
		if(!property_array[inc])
			property_array[inc] = 'value';
		form_field = eval('document.'+form_name+'.'+id_array[inc]);
		if(form_field && form_field[property_array[inc]]!=null)
			form_field[property_array[inc]] = value_array[inc];
		else if(obj = $(id_array[inc]))
			obj[property_array[inc]] = value_array[inc];
	}
	if(fromObj = $(block))
		{
			changePosition(fromObj);
			popupFrmObj = eval('document.'+form_name);
			popupFrmElementsLength = popupFrmObj.elements.length;
			for (inc=0; inc<popupFrmElementsLength-1; inc++)	{
				if (popupFrmObj.elements[inc].className == 'clsCancelButton' || popupFrmObj.elements[inc].className == 'clsPopupcancel' || popupFrmObj.elements[inc].className == 'clsPopCancelButton')
					popupFrmObj.elements[inc].focus();
				else if (popupFrmObj.elements[inc].className == 'clsSubmitButton' || popupFrmObj.elements[inc].className == 'clsPopupsubmit' || popupFrmObj.elements[inc].className == 'clsPopSubmitButton')
					popupFrmObj.elements[inc].focus();
			}
		}
	return false;
}
function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}
//**************** confirmation box related functions End *******************/
function changeWidth(){
	var width_value = document.formGetCode.image_width.value;
	if(parseInt(max_width_value)>=parseInt(width_value)){
		var expression = 'width="([0-9]+)"';
		var subject = document.formGetCode.image_code.value;
		var replaced = 'width="'+width_value+'"';
		document.formGetCode.image_code.value = RegularExpressionReplace(expression, subject, replaced);
	}
}

var getCheckBoxValue = function(){
	var form_name = arguments[0];
	var check_all_name = arguments[1];
	var frm = eval('document.'+form_name);
	var ids = '';
	for(var i=0;i<frm.elements.length;i++){
		var e=frm.elements[i];
		if ((e.name != check_all_name) && (e.type=='checkbox') && e.checked)
			ids += e.value+',';
	}
	if(ids){
		multiCheckValue =ids.substring(0,ids.length-1);
		return true;
	}
	return false;
}

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

// Open External Links as Blank Targets
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		var anchor_href = anchor.getAttribute("href");
		if (anchor_href && anchor_href.indexOf(cfg_site_url)==-1 && anchor_href.indexOf('http://')==0){
			//alert(anchor_href+"--"+anchor_href.indexOf(cfg_site_url));
			anchor.target = "_blank";
		}
	}
}

function helpTipInitialize(){
	var forms_length = document.forms.length;
	for (var i=0; i<forms_length; i++) {
		var elements_length = document.forms[i].elements.length;
		for (var j=0; j<elements_length; j++) {
		if(document.forms[i].name != 'selFormSearchQuestion' && document.forms[i].name != 'selFormAskQuestion' && document.forms[i].name != 'selFormSearchBlog' &&  document.forms[i].name != 'selFormSearchForum' &&  document.forms[i].name != 'frmIndexAskQuestion')
			{
				document.forms[i].elements[j].onfocus = showTip;
				document.forms[i].elements[j].onblur = hideTip;
			}
		}
	}
}

function showTip(){
	if (this.type == 'radio') {
		var tip_id = this.name;
	} else {
		var tip_id = this.id;
	}
	var pos = tip_id.indexOf('_opt_');
	if(pos!=-1){
		tip_id = tip_id.substr(0, pos);
	}
	var tip_id = $(tip_id+'_Help');
	if(tip_id){
		tip_id.style.visibility = 'visible';
	}
}

function hideTip(){
	if (this.type == 'radio') {
		var tip_id = this.name;
	} else {
		var tip_id = this.id;
	}
	var pos = tip_id.indexOf('_opt_');
	if(pos!=-1){
		tip_id = tip_id.substr(0, pos);
	}
	var tip_id = $(tip_id+'_Help');
	if(tip_id){
		tip_id.style.visibility = 'hidden';
	}
}

function windowOpen(obj){
	window.open(obj.href)
	return false;
}

function setFullScreenBrowser(){
	window.moveTo(0,0);
	window.resizeTo(screen.width,screen.height);
}

function hideAnimateBlock(elmt){
	//fade, slide, glide, wipe, unfurl, grow, shrink, highlight
	Zapatec.Effects.hide(elmt, 0.4, 'fade')
}

var captcha_count = 0;
function resetCaptcha(elmt, url){
	captcha_count++;
	$(elmt).src = 'ss';
	$(elmt).src = url+'?'+captcha_count;
	return false
}

function addClassNameForDataTable(){
	this.addClassName('clsDataMouseoverRow')
}

function removeClassNameForDataTable(){
	this.removeClassName('clsDataMouseoverRow')
}

function getHTML(url, pars, divname, method_type){
	var myAjax = new Ajax.Updater(
						divname,
						url,
						{
						method: method_type,
						parameters: pars
						});
}

function twcOpenEmailApi(){
	var url = cfg_site_url + admin_index_anova_module+'/api.emails.php#';
	var theApiWindow = window.open(url, 'theApiWindow', "width=600,height=700,status=yes,toolbar=no,menubar=no,scrollbars=yes,resizable=yes");
	theApiWindow.focus();
}
//function to change top menu style
var activeTopMenu = function(){
	var menuid = arguments[0];
	$(menuid).className += ' clsTopNavigationHover';
}
var inActiveTopMenu = function(){
	var menuid = arguments[0];
	var str = $(menuid).className;
	$(menuid).className = str.replace(/clsTopNavigationHover/, "");
}
function updateVote(url, pars, id)
	{
		var myAjax = new Ajax.Request(
								url,
								{
								method: 'get',
								parameters: pars,
								evalScripts: true,
								asynchronous: false
								});

	}
function removeBr(){
	var documentHTML=document.getElementsByTagName('html')[0];
  	brtag = document.getElementsByTagName('br')[0];
	if (brtag)
  		documentHTML.removeChild(brtag);
}
if (window.opera){
	removeBr();
}
function facebookLogout() {
	facebook_logout.document.location = SITE_URL + 'facebookLogout.php';
}
function facebookProfilePageSet(url, pars) {
	var myAjax = new Ajax.Request(
							url,
							{
							method: 'get',
							parameters: pars
							});
							return false;
}
function setfacebookImageStatus(url, pars) {
	var myAjax = new Ajax.Request(
							url,
							{
							method: 'get',
							parameters: pars
							});

}
function setTwitterImageStatus(url, pars)
	{
		var myAjax = new Ajax.Request(
								url,
								{
								method: 'get',
								parameters: pars
								});

	}