var divArray=new Array("generalSetting", "generalMember", "generalLanguage", "generalMenu", "generalAnnouncement", "generalLogin", "generalList", "generalManageBugs", "generalPlugin", "generalDeals", "generalAffiliate","translate","forumList","bugsList","manageCouponList","commList");
//onfocus, onblur, issues fixed
var form_name_array = new Array();
if(!block_arr) {
	var block_arr = new Array();
}
var allowChannelHide = true;
var channelDivSet = false;
var allowMenuMoreHide = true;
var menuMoreDivSet = false;
var allowHeaderSearchHide = true;
var headerSearchDivSet = false;
var allowFooterSearchHide = true;
var footerSearchDivSet = false;
var contentSeparator = '#~#';

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

var displayLoadingImage = function(){
$Jq("#selLoading").show();
};

var hideLoadingImage = function(){
$Jq("#selLoading").hide();
};

function urlencode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'

    var histogram = {}, histogram_r = {}, code = 0, tmp_arr = [];
    var ret = str.toString();

    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };

    // The histogram is identical to the one in urldecode.
    histogram['!']   = '%21';
    histogram['%20'] = '+';

    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);

    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }

    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });

    return ret;
};

function urldecode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urldecode('Kevin+van+Zonneveld%21');
    // *     returns 1: 'Kevin van Zonneveld!'
    // *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
    // *     returns 2: 'http://kevin.vanzonneveld.net/'
    // *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
    // *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'

    var histogram = {}, histogram_r = {}, code = 0, str_tmp = [];
    var ret = str.toString();

    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };

    // The histogram is identical to the one in urlencode.
    histogram['!']   = '%21';
    histogram['%20'] = '+';

    for (replace in histogram) {
        search = histogram[replace]; // Switch order when decoding
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }

    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);

    return ret;
};

/******* 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********/
String.prototype.capitalize = function(){
   return this.replace( /(^|\s)([a-z])/g , function(m,p1,p2){ return p1+p2.toUpperCase(); } );
  };



//Get multible check box value with comma seperator
var multiCheckValue='';
// form_name, check_all_name, alert_value, place
var getMultiCheckBoxValue = function(){
	var form_name = arguments[0];
	var check_all_name = arguments[1];
	if(arguments.length>2){
		var alert_value = arguments[2];
	}
	var frm = eval('document.'+form_name);
	var ids = '';
	multiCheckValue = '';
	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;
	}
	if(arguments.length>2){
		alert_manual(alert_value);
	}
	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";
		}
	}
};

//onfocus, onblur, issues fixed


/**
 * attaches the tooltip to the form elements that have a corresponding
 * help tip div e.g., if the id is user_name, checks for user_name_Help and shows
 * the html of this as the tip on mouse over.
 * jQuery Plugin used: jquery.tooltip
 **/
function helpTipInitialize() {
	$Jq(":input").each(function(){
		var tip_id = $Jq(this).attr('id');
		if(tip_id){
			var tip_id = '#'+tip_id+'_Help';
			//check if the help div exists
			if($Jq(tip_id).length){
				$Jq(this).tooltip({
					bodyHandler: function() {
						return $Jq(tip_id).html();
					},
					showURL: false
					});
			}
		}
	});
};

function windowOpen(obj){
	window.open(obj.href,'mywindow','toolbar=no, location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no, resizable=no');
	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
	$Jq("#"+elmt).fadeOut(5000);
};


function addClassNameForDataTable(){
	$Jq(this).addClass('clsDataMouseoverRow');
};

function removeClassNameForDataTable(){
	$Jq(this).removeClass('clsDataMouseoverRow');
};

function getHTML(url, pars, divname, method_type){
	//need to replace with the code using jQuery
};

var Redirect2URL = function(){
	if(arguments[0])
		location.replace(arguments[0]);
	else
		window.back();
	return false;
};

function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
};





/* ************** Start Search text functions ************** */
//for search text box

//for search text box
var clearDefaultValue = function(obj, dValue){
	var objValue = obj.value;
	objValue = objValue.toLowerCase()
	if (objValue == dValue)
		obj.value = '';
};

/* ************** End Search text functions ************** */
//function for disable the select all checkbox column
function disableHeading(frmname) {
	var targetForm = document.getElementById(frmname);
	for (var i=1; i<targetForm.elements.length; i++)
		{
			if (targetForm.elements[i].type == "checkbox")
			{	//alert(i);
				if (targetForm.elements[i].checked)
				{	//alert('chekall');
					targetForm.elements[0].checked=true;
				}
				else
				{
					targetForm.elements[0].checked=false;
					break;
				}
			}
		}
};







var img_src = new Array();
function mouseOver(count) {
	for(var i=1; i<=count; i++) {
		var obj = document.getElementById('img'+i);
		img_src[i] = obj.src;
		obj.src = rateimagehover_url;
	}
	for(; i<=total_images; i++) {
		var obj = document.getElementById('img'+i);
		img_src[i] = obj.src;
		obj.src = rateimage_url;
	}
};

function mouseOut(count) {
	for(var i=1; i<=total_images; i++) {
		var obj = document.getElementById('img'+i);
		obj.src = img_src[i];
	}
};
//functions for rating
var rate_click = true;










//To select Content inside DIV element like Textarea


//To un-select selected Content inside DIV element







//Hide all confirmation blocks
var hideAllBlocks = function(){
	var obj;

	if(obj = $Jq('#selAlertbox')){
		obj.hide();
	}

	for(var i=0;i<block_arr.length;i++){
		if(obj = $Jq("#"+block_arr[i])) {
			obj.hide();
			$Jq(obj).dialog("close");
		}
	}
	if(obj = $Jq('#hideScreen')){
		obj.hide();
	}

	if(obj = $Jq('#selAjaxWindow')){
		obj.hide();
	}

	if(obj = $Jq('#selAjaxWindowInnerDiv')){
		obj.html('');
	}

	return false;
};
var alert_manual = function() {
	var obj;
	var alert_value = arguments[0];
	if(obj = $Jq('#selAlertMessage')){
		obj.html(alert_value);
	}

	$Jq("#selAlertbox").dialog({
		modal: true,
		buttons: {
			Ok: function() {
				$Jq(this).dialog('close');
			}
		}
	});
	return false;
};

//Display confirmation Block for login
//Not used right now, we can remove later after confirmation

//Display confirmation Block
//block, form_name, id_array, value_array, property_array
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 = $Jq("#"+id_array[inc])){
			switch(property_array[inc]){
				case 'innerHTML':
				case 'html':
					$Jq("#"+id_array[inc]).html(value_array[inc]);
					break;
				case 'text':
					$Jq("#"+id_array[inc]).text(value_array[inc]);
					break;
				case 'val':
				case 'value':
					$Jq("#"+id_array[inc]).val(value_array[inc]);
					break;
				default:
					alert('This ' + property_array[inc] + ' property not added in this function. Add this ' + property_array[inc] + ' property in switch case. This is for testing.. need to remove.. ');
			} // switch
		}
	}

	fromObj = $Jq("#"+block);
	if (fromObj.title == '' || fromObj.title == undefined){
		fromObj.attr("title", cfg_site_name);
	}
	fromObj.dialog({
		modal: true,
		position: 'center'
	});

	$Jq("#"+block).find('.rmsSubmitButton').focus();
	$Jq("#"+block).find('.rmsCancelButton').focus();

	return false;
};

var isMember = false;
var callBackArray = new Array();
var callBackArguments = new Array();
//Possible arguments and usage
//openAjaxWindow(loginRequired, actionRequested, agrs1, agrs2, agrs3, etc...)
//loginrequired = 'true' / 'false' 								*** compulsory ****
//actionRequested = 'redirect' / 'ajaxpopup' / 'ajaxupdate' 	*** compulsory ****
//agrs1 = linkID / function name to call 						*** compulsory ****
//agrs2 = pars / args to pass 									***  Optional  ****
var openAjaxWindow = function(){

	if (arguments.length < 3){
		alert_manual('Required arguments missing! Check your code');
		return false;
	}
	//Initialize callBackArray
	callBackArray = new Array();
	//Login required or not
	callBackArray[0] = arguments[0];
	//Possible values are redirect, ajaxpopup, ajaxupdate
	callBackArray[1] = arguments[1];
	//ID of the object clicked or function name to be called
	callBackArray[2] = arguments[2];
	//Stored the remaining arguments in callBackArray
	if (arguments.length > 3){
		for (var i = 3; i < arguments.length; i++){
			callBackArray[i] = arguments[i];
		}
	}

	if (callBackArray[0] == 'true' || callBackArray[0] == true){
		checkIsMember();
	} else {
		proceedRequest();
	}
	return false;
};

//This function will proccess the requested action.
var proceedRequest = function(){

	//check callBackArray contains value
	if (callBackArray.length) {

		//Possible values are redirect, ajaxpopup, ajaxupdate
		var actionRequested = callBackArray[1];

		switch(actionRequested){
			case 'redirect':
				//ID of the object clicked
				var linkID = callBackArray[2];
				//href of the url clicked
				var url = $Jq("#"+linkID).attr("href");
				//Redirect to the requested url
				window.location.href = url;
				break;
			case 'ajaxpopup':
				//Close the dialog if opened
				$Jq("#selAjaxLoginWindow").dialog('close');
				//ID of the object clicked
				var linkID = callBackArray[2];
				//href of the url clicked
				var url = $Jq("#"+linkID).attr("href");
				pars = '';
				$Jq.ajax({
				   	type: "POST",
				   	url: url,
				   	data: pars,
				   	success: function(originalRequest){
						    	Confirmation('selAjaxWindow', 'frmAjaxWindow', Array('selAjaxWindowInnerDiv'), Array(originalRequest), Array('html'));
						   	}
				 });
				break;
			case 'ajaxupdate':

				//function name to call
				var functionNameToCall = callBackArray[2];
				//Form the arguments for the function to call from callBackArray
				var agrumentsToPass = '';
				//callBackArray length
				var callBackArrayLength = callBackArray.length;

				callBackArguments = new Array();
				if (callBackArrayLength > 3){
					for (var i = 3; i < callBackArrayLength; i++){
						callBackArguments[i-3] = callBackArray[i];
					}
				}
				//Create the function call from function name and parameter.
				//var funcCall = functionNameToCall + "(" + agrumentsToPass + ");";
				var funcCall = functionNameToCall + "();";
				//Call the function
				var ret = eval(funcCall);
				break;
		} // switch

	} else {
		window.location.href = cfg_site_url;
	}
};

//Check session exists or not
var checkIsMember = function(){

	url = cfg_login_check_url;
	pars = 'check_is_member=1';
	$Jq.ajax({
	   	type: "POST",
	   	url: url,
	   	data: pars,
	   	success: function(originalRequest){
	   				if (originalRequest == 'true') {
			    		isMember = true;
			    		//Process the requested url
		    			proceedRequest();
			    	} else {
			    		//Show login form
			    		showLoginForm();
			    	}
			   	}
	 });
	return isMember;
};

//It will display login popup
var showLoginForm = function(){
	url = cfg_login_url;
	//pars = '';
	pars = '';
	$Jq.ajax({
	   	type: "POST",
	   	url: url,
	   	data: pars,
	   	success: function(originalRequest){
			    	Confirmation('selAjaxWindow', 'frmAjaxWindow', Array('selAjaxWindowInnerDiv'), Array(originalRequest), Array('html'));
			   	}
	 });
};

//Function that called in login popup to validate username & password
//On failure displays login window again
//On success proccess the requested action
var doAjaxLogin = function(frmName){
	url = cfg_login_url;
	var pars = 'login_submit=1&'+$Jq("#"+frmName).serialize();
	$Jq.ajax({
	   	type: "POST",
	   	url: url,
	   	data: pars,
	   	success: function(originalRequest){
	   				$Jq("#selAjaxWindow").dialog('close');
	   				agrs = originalRequest.split('|##|');
	   				//check logged in successfully
	   				if (agrs[1] == 'true' || agrs[1] == true) {
			    		isMember = true;
			    		//Process the requested url
			    		proceedRequest();
			    	} else {
			    		//Show login form again with error message
			    		Confirmation('selAjaxWindow', 'frmAjaxWindow', Array('selAjaxWindowInnerDiv'), Array(originalRequest), Array('html'));
			    	}
			   	}
	 });
};

var jquery_ajax = function()
	{
		var url = arguments[0];
		var pars = function_name = '';
		if (arguments.length > 1)
			pars = arguments[1];
		if (arguments.length > 2)
			function_name = arguments[2];
				 
		$Jq.ajax({
			type: "POST",
			url: url,
			data: pars,
			beforeSend:displayLoadingImage(),
			success: eval(function_name)
		 });
		return false;
	};

function getUsers(data)
	{
		$Jq("#block_coupon_add").html(data);
		$Jq("#adduser").hide();
	};
function getDeals(data)	
	{
		hideLoadingImage();
		$Jq("#blkDealsView").html(data);
	};
function getAddUser(data)
	{
		$Jq("#block_coupon_add").html(data);
		$Jq("#adduser").hide();
	};

var postAjaxForm = function(){
	var frmname = arguments[0];
	var divname = arguments[1];
	var data = $Jq("#"+frmname).serialize();
	$Jq.ajax({
		type: "POST",
		url: $Jq("#"+frmname).attr('action'),
		data: data,
		beforeSend:displayLoadingImage(),
		success: function(html){
					hideLoadingImage();
				 	$Jq("#"+divname).html(html);
				}
	 });
	 return false;
}



/*** content filter settings ***/


//*** function to show option to edit info ***//


//*** function to check and call update profile function ***//


function showHideLang() {
	var i=0, total_lang_li =0;
	while($Jq('#langlist li')[i++]){
		total_lang_li++;
	}
	if(total_lang_li<=0){
		return false;
	}
	$Jq('#showhidelang').toggle();
	if($Jq('#showhidetheme')){
		$Jq('showhidetheme').hide();
	}
}






/* apply class for first and last list in ul */
var applyClassForFirstAndLastLi = function(){
	$Jq(document).ready(function(){
		$Jq('ul').each(function(){
			var inc = 1;
			var totalli = $Jq('li', this).length;
			$Jq('li', this).each(function(){
				if(inc == 1){
					$Jq(this).addClass('clsLiFirst');
					$Jq(this).hover(
						function() { $Jq(this).addClass('clsLiFirstActive'); },
						function() { $Jq(this).removeClass('clsLiFirstActive'); }
					);
				}else if(inc == totalli){
					$Jq(this).addClass('clsLiLast');
					$Jq(this).hover(
						function() { $Jq(this).addClass('clsLiLastActive'); },
						function() { $Jq(this).removeClass('clsLiLastActive'); }
					);
				}
				else{
					$Jq(this).hover(
						function() { $Jq(this).addClass('clsLiAcive'); },
						function() { $Jq(this).removeClass('clsLiAcive'); }
					);
				}
				inc++;
			});
		});
	});
};
var hideShowDropDown = function(){
	var browserdata = getBrowser();
	if(!(browserdata[0]=='msie' && browserdata[1]=='6.0')){
		return;
	}
	var ulobj = arguments[0];
	var status = arguments[1];
	if(ulobj.attr('dropdownhide')){
		var dropdownhide = ulobj.attr('dropdownhide');
		dropdownhide = dropdownhide.split(',');
		for(var i=0; i<dropdownhide.length; i++){
			var dropdownid = $Jq.trim(dropdownhide[i]);
			if(dropdownid){
				if(status == 'hide'){
					$Jq('#'+dropdownid).addClass('clsDropDownHide');
				}
				else{
					$Jq('#'+dropdownid).removeClass('clsDropDownHide');
				}
			}
		}
	}
};
var dropDownLinkClick = function(event) {

		var $target = $Jq(event.target).parent();
		if($Jq(event.target).hasClass('rmsSubLists')){
			return;
		}
		if($Jq($target[0]).hasClass('selDropDownLinkClick')){
			
			if($Jq('ul', $target[0]).css('display') == 'none'){
				$Jq('ul', $target[0]).css('display', 'block');
			}else{
				$Jq('ul', $target[0]).css('display', 'none');
			}
			$Jq('li', document).each(function(){
				if(this!=$target[0]){
					$Jq('ul', this).css('display', 'none');
				}
			});
			hideShowDropDown($Jq('ul', $target[0]), 'hide');
			return;
		}
		$Jq('li', document).each(function(){
			if($Jq(this).hasClass('selDropDownLinkClick')){
				var obj = this;
				setTimeout(function(){
					$Jq('ul', obj).css('display', 'none');
					hideShowDropDown($Jq('ul', obj), 'show');
				}, 500);
			}
		});
		return;
	}
$Jq(document).ready(function(){
		/* drop down menu link */
		$Jq('li.selDropDownLink').hover(
			function() {
				
				$Jq('ul', this).css('display', 'block');
				hideShowDropDown($Jq('ul', this), 'hide');
			},
			function() {
				$Jq('ul', this).css('display', 'none');
				hideShowDropDown($Jq('ul', this), 'show');
			}
		);

		/* For input field character limiter */
		$Jq('.selInputLimiter').each(function(){
			$Jq(this).inputlimiter({
				limit: $Jq(this).attr('maxlimit'),
				remText: LANG_JS_common_remaining_char_count,
				remFullText: LANG_JS_common_stop_typing_after_reached_limit,
				limitText: LANG_JS_common_allowed_char_limit});
		});

		/* apply class for first and last list in ul */
		applyClassForFirstAndLastLi();

		/* Auto Fill text */
		$Jq('input.selAutoText').focus(function(){
				if($Jq(this).val() == $Jq(this).attr('title')){
					$Jq(this).val('');
				}
			}
		);
		$Jq('input.selAutoText').blur(function(){
				if($Jq(this).val() == ''){
					$Jq(this).val($Jq(this).attr('title'));
				}
			}
		);

		/* color picker */
		$Jq('form#colorPicker').bind('submit', function(){
          alert($(this).serialize());
          return false;
        });

        /* png fix */
        $Jq("img").pngfix();
	});

/**
 *
 * @access public
 * @return void
 **/
function sendFaceBookFeed(name, desc, img, url, new_kootany_path, action, body, link_name, target_id){
  	var template_data = {
	    'name':name,
	    'href':url,
	    'description':desc,
	    'media':[{'type':'image', 'src':img, 'href':url}]
	};
  	if (new_kootany_path) {
    	var action_links = [{'text':link_name, 'href':new_kootany_path},
                      		{'text':'View Deal', 'href':url}];
  	}else{
    	var action_links = ''
  	};
  	function redirectTo(post_id, exception) {
    	if (post_id) {
      		if (action == 'send') {
        		window.location.reload();
      		};
      		if (action == 'created') {
				//        window.top.location = '/?act=' + action;
        		return;
      		};
      		if (action == 'updated') {
        		window.top.location = '/?act=' + action;
      		};
    	};
  	}
  	FB.Connect.requireSession(function() {
    	if (action == 'send') {
      		FB.Connect.streamPublish(body,template_data, action_links,target_id,'',redirectTo, false);
    	}else{
      		FB.Connect.streamPublish(body,template_data, action_links,target_id,'',redirectTo,true);
    	};
  	});
}

function installKey(val, url){
	var value = $Jq('#api'+val).val();
	var site_name = $Jq('#site'+val).text();
	var pars = 'api='+value+'&pid='+val+'&site='+site_name;
	$Jq.ajax({
	   	type: "POST",
	   	url: url,
	   	data: pars,
	   	success: function(originalRequest){
			    	feederStatus(originalRequest, val);
			   	}
	 });

}

function feederStatus(data, id) {
	if (data.indexOf("@#@")==-1) {
		$Jq('#feed'+id).html(data);
		$Jq('#feed'+id).attr('class', 'clsErrorMsg');
	} else {
		$Jq('#feed'+id).html(data.replace("@#@", ""));
		$Jq('#feed'+id).attr('class', 'clsSuccessMsg');
	}
}

function getCityValue(val,id)
	{
		document.getElementById(id).innerHTML = val.value;
	}

function unsetValue(val,txt)
	{
		var id= val.id;
		if(val.value == txt)
			document.getElementById(id).value = '';
	}

function setValue(val,text)
	{
		var value = Trim(val.value);
		if(value == "")
			{
				document.getElementById(val.id).value = text;
			}
	}

function changeLocation(val,url)
	{
		url = url.replace('VAR_CITY',val.value);
		window.location = url;
	}
	
//This is for index pageselect tag	
//SELECT BOX SCRIPT START
(function($Jq){
 $Jq.fn.extend({
 
 	customStyle : function(options) {
	  if(!$Jq.browser.msie || ($Jq.browser.msie&&$Jq.browser.version>6)){
	  return this.each(function() {
	  
			var currentSelected = $Jq(this).find(':selected');
			$Jq(this).after('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">'+currentSelected.text()+'</span></span>').css({position:'absolute',opacity:0, fontSize:$Jq(this).next().css('font-size')});
			var selectBoxSpan = $Jq(this).next();
			var selectBoxWidth = parseInt($Jq(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));			
			var selectBoxSpanInner = selectBoxSpan.find(':first-child');
			selectBoxSpan.css({display:'inline-block'});
			selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
			var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
			$Jq(this).height(selectBoxHeight).change(function(){
				//selectBoxSpanInner.text($Jq(this).val()).parent().addClass('changed');
selectBoxSpanInner.text($Jq(this).find(':selected').text()).parent().addClass('changed');
// Thanks to Juarez Filho & PaddyMurphy
			});
			
	  });
	  }
	}
 });
})(jQuery);


$Jq(function(){

$Jq('.indexformsection_selectfox').customStyle();

});
// SELECT BOX SCRIPT END	
//SELECT BOX SCRIPT START
(function($Jq){
 $Jq.fn.extend({
 
 	customStyle : function(options) {
	  if(!$Jq.browser.msie || ($Jq.browser.msie&&$Jq.browser.version>6)){
	  return this.each(function() {
	  
			var currentSelected = $Jq(this).find(':selected');
			$Jq(this).after('<span class="customStyleSelectBoxs_deals"><span class="customStyleSelectBoxInner">'+currentSelected.text()+'</span></span>').css({position:'absolute',opacity:0, fontSize:$Jq(this).next().css('font-size')});
			var selectBoxSpan = $Jq(this).next();
			var selectBoxWidth = parseInt($Jq(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));			
			var selectBoxSpanInner = selectBoxSpan.find(':first-child');
			selectBoxSpan.css({display:'inline-block'});
			selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
			var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
			$Jq(this).height(selectBoxHeight).change(function(){
				//selectBoxSpanInner.text($Jq(this).val()).parent().addClass('changed');
selectBoxSpanInner.text($Jq(this).find(':selected').text()).parent().addClass('changed');
// Thanks to Juarez Filho & PaddyMurphy
			});
			
	  });
	  }
	}
 });
})(jQuery);


$Jq(function(){

$Jq('.deels_selectfox').customStyle();

});
// SELECT BOX SCRIPT END	
//DEAL MENU START

$Jq(document).ready(function(){
	$Jq(".deal_inner_cl").css({"visibility;":"hidden","display":"block"});
	$Jq(".deal_lmenuc a").css('background-position','0 bottom');
	$Jq(".deal_lmenuc a").toggle(function(){
		$Jq(this).css('background-position','0 0');
		//$Jq(this).parent().css({"margin":"0px 0 10px 0"});
		$Jq(this).parent().next(".deal_inner_cl").slideUp("slow");
	},function(){
		$Jq(this).css('background-position','0 bottom');
		//$Jq(this).parent().css({"margin":"0px 0 10px 0"});
		$Jq(this).parent().next(".deal_inner_cl").slideDown("slow");
	});
});
//DEAL MENU END
//Commission validation start 
function searchValidate()
	{
		formname = document.searchComm;
		var tagname = document.getElementsByTagName("button");
		if(formname.fromdate.value != "" || formname.todate.value != "")
			{
				formname.listby.disabled = "disabled";
			}
		if(formname.listby.value != "")
			{
				formname.fromdate.disabled = "disabled";
				formname.todate.disabled = "disabled";
				for(i=0;i<tagname.length;i++)
					{
						tagname[i].disabled="disabled";
					}
						
			}
	};


//Script.js Coding

//Function for mailCompose.php, used to set value in username textbox
function listen(event, elem, func) {
    elem = document.getElementById(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 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);
	email_address_last_char = email_address_value.charAt(RTrim(email_address_value).length-1);
	if ((email_address_value.indexOf(',') == -1 || email_address_last_char != ',') && 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)
	{
		//need to replace with the code using jQuery
	}
function popupWindowUpload(url){
	window.open (url, "","status=0,toolbar=0,resizable=0,scrollbars=1");
}
function changeCategoryRequest(url, pars, method_type)
	{
		//need to replace with the code using jQuery
	}
function changeCategoryResponse(originalRequest){
		//need to replace with the code using jQuery
	}
function populateSubCategoryRequest(url, pars, method_type)
	{
		//need to replace with the code using jQuery
	}
function populateSubCategoryResponse(originalRequest){
		//need to replace with the code using jQuery
	}
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)
	{
	//need to replace with the code using jQuery
	}

function displayGetCode(data)
	{
		//need to replace with the code using jQuery
	}


function setProfileImage(url){
//need to replace with the code using jQuery
}

function updateSetProfile(data){
//need to replace with the code using jQuery
}


//function to disable submit button and to show processing image
var processingRequest = function(){
	//need to replace with the code using jQuery
}

var replayDiv = '';
var div_id = '';
function ajaxSubmitForm(url, frmName, divname, id){
//need to replace with the code using jQuery

}

function ajaxRelatedResult(data)
	{
		//need to replace with the code using jQuery
	}

function ajaxReplayDiv(url, pars, divname)
	{
		//need to replace with the code using jQuery
	}

function ajaxReplayDivResult(data)
	{
		//need to replace with the code using jQuery
	}

function hideChannel()
	{
		if(channelDivSet && allowChannelHide)
			{
				hideChannelDiv();
			}
	}

function hideChannelDiv()
	{
	   var channelMoreContentDiv = $Jq('#channelMoreContent').get(0);
	    if (channelDivSet) {
		if(channelMoreContentDiv!=null)
	        //channelMoreContentDiv.style.display = 'none';
	        $Jq(channelMoreContentDiv).css('display', 'none')
	        //if (doiframe) {
	            var iframe = $Jq('selBackgroundIframe').get(0);
				if(iframe!=null){
	            	$Jq(iframe).css('display','none');
	            }
	        //}//EOF if-doiframe
	    }//EOF if-noClose
		channelDivSet = false;
	}

function hideMenuMore()
	{
		if(menuMoreDivSet && allowMenuMoreHide)
			{
				hideMenuMoreDiv();
			}
	}

function hideMenuMoreDiv()
	{
	   var menuMoreContentDiv = $Jq('#menuMoreContent').get(0);
	    if (menuMoreDivSet) {
			if(menuMoreContentDiv!=null)
		        //menuMoreContentDiv.style.display = 'none';
		        $Jq(menuMoreContentDiv).css('display', 'none')
		        var iframe = $Jq('#selBackgroundIframe').get(0);
				if(iframe!=null){
		           	$Jq(iframe).hide();
		        }
	    }
		menuMoreDivSet = false;
	}

function displayMenuMore()
	{
		menuMoreDivSet = true;
		allowMenuMoreHide = false;;
		$Jq('#'+pageId).mouseover(function(){
			hideMenuMore();
		});
		//listen('mousemove', pageId, hideMenuMore);
		//listen('mouseout', $('menuMoreContent'), hideMenuMore);
		var menu_more_anchor = $Jq('#menu_more_anchor').get(0);
		var selBackgroundIframe = $Jq('#selBackgroundIframe').get(0);
		var menuMoreContent = $Jq('#menuMoreContent').get(0);
		$Jq(menuMoreContent).show();
		$Jq(selBackgroundIframe).css('width', menuMoreContent.offsetWidth + "px");
		$Jq(selBackgroundIframe).css('height', menuMoreContent.offsetHeight + "px");
		$Jq(selBackgroundIframe).css('top', (findPosChildElementTop(menu_more_anchor) + parseInt(menu_more_top_position)) + "px");
    	$Jq(selBackgroundIframe).css('left', (findPosChildElementLeft(menu_more_anchor) + parseInt(menu_more_left_position)) +"px");
		$Jq(menuMoreContent).css('top', (findPosChildElementTop(menu_more_anchor) + parseInt(menu_more_top_position)) + "px");
    	$Jq(menuMoreContent).css('left', (findPosChildElementLeft(menu_more_anchor) + parseInt(menu_more_left_position)) + "px");
		$Jq(selBackgroundIframe).show();
	}
function displayChannel()
	{
		channelDivSet = true;
		allowChannelHide = false;;
		//listen('mousemove', pageId, hideChannel);
		$Jq('#'+pageId).mouseover(function(){
			hideChannel();
		});
		var channel_menu_anchor = $Jq('channel_menu_anchor').get(0);
		var selBackgroundIframe = $Jq('selBackgroundIframe').get(0);
		var channelMoreMenuContent = $Jq('channelMoreContent').get(0);
		channelMoreMenuContent.show();
		$Jq(selBackgroundIframe).css('width', channelMoreMenuContent.offsetWidth + "px");
		$Jq(selBackgroundIframe).css('height',channelMoreMenuContent.offsetHeight + "px");
		$Jq(selBackgroundIframe).css('top', (findPosChildElementTop(channel_menu_anchor) + parseInt(menu_channel_top_position)) + "px");
    	$Jq(selBackgroundIframe).css('left', (findPosChildElementLeft(channel_menu_anchor) + parseInt(menu_channel_left_position)) +"px");
		$Jq(channelMoreMenuContent).css('top', (findPosChildElementTop(channel_menu_anchor) + parseInt(menu_channel_top_position)) + "px");
    	$Jq(channelMoreMenuContent).css('left', (findPosChildElementLeft(channel_menu_anchor) + parseInt(menu_channel_left_position)) + "px");
		$Jq(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;
	}

var subscription_action = function()
	{
		//need to replace with the code using jQuery
	}

function subscription_result(data)
	{
		///need to replace with the code using jQuery
	}

var sub_action = '';
var sub_confirm_top = '';
var sub_confirm_left = '';
var sub_confirm_toObj = '';
var get_subscription_options = function() {
	var sub_owner_id = arguments[0];
	sub_confirm_top = arguments[1];
	sub_confirm_left = arguments[2];
	sub_confirm_toObj = arguments[3];

	pars = 'owner_id='+sub_owner_id+'&action=get_subscription_details';

	$Jq.ajax({
		type: "POST",
		url: member_manipulation_url,
		data: pars,
		success: function(originalRequest){
					$Jq('#common_confirm_yes').hide();
					$Jq('#common_confirm_no').hide();
					Confirmation('selAjaxWindow', 'frmAjaxWindow', Array('selAjaxWindowInnerDiv'), Array(originalRequest), Array('innerHTML'));
				}
 	});
}

function toggleSubscriptionCheckBox(sub_field_id) {
	if($Jq('#sub_'+sub_field_id).is(':checked')) {
		$Jq('#sub_label_'+sub_field_id).removeClass('clsSubscriptionUnChecked');
		$Jq('#sub_label_'+sub_field_id).addClass('clsSubscriptionChecked');
		$Jq('#sub_label_'+sub_field_id).attr('title', LANG_JS_SUBSCRIBE);
	} else {
		$Jq('#sub_label_'+sub_field_id).removeClass('clsSubscriptionChecked');
		$Jq('#sub_label_'+sub_field_id).addClass('clsSubscriptionUnChecked');
		$Jq('#sub_label_'+sub_field_id).attr('title', LANG_JS_UNSUBSCRIBE);
	}
}

var sub_scontent_id = '';
var sub_saction = '';
var sub_smodule = '';
var sub_sstype = '';
var subscription_sep_action = function()
	{
		//need to replace with the code using jQuery
	}

function subscription_sep_result(data)
	{
		//need to replace with the code using jQuery
	}

var subscriptionOptionEle = '';
var sub_opt_delay = '';
var subscription_timeout = '';
var subscription_hover = false;
var getSubscriptionOption = function()
	{
		//need to replace with the code using jQuery
	}

function showSubscriptionOption(data)
	{
		//need to replace with the code using jQuery
	}

function hideSubscriptionOption()
	{
		//need to replace with the code using jQuery
	}

var showDefaultSubscriptionOption = function()
	{
	//need to replace with the code using jQuery
	}

var sub_cat_elem = '';
var getCategoriesForSubscription = function()
	{

		var sub_url = member_manipulation_url;
		if(arguments[1] == 'sub_category')
			{
				sub_cat_ele = '#sub_category_container';
				sub_url += '?action=get_sub_categories&sub_module='+$Jq('#sub_module').val()+'&category_id='+arguments[0];
			}
		else
			{
				var sub_module = arguments[0];
				sub_cat_ele = '#category_container';
				sub_url += '?action=get_categories&sub_module='+sub_module;
			}

		new jquery_ajax(sub_url, '', 'subscription_categories_result');
	}

function subscription_categories_result(data)
	{
		$Jq(sub_cat_ele).html(data);
	}


function checkDate(entry) {
    var mo, day, yr;
    var reDate = /\b\d{4}[-]\d{1,2}[-]\d{1,2}\b/;
    var valid = reDate.test(entry);
    if (valid) {

        var delimChar = "-";
        var delim1 = entry.indexOf(delimChar);
        var delim2 = entry.lastIndexOf(delimChar);

        yr = parseInt(entry.substring(0, delim1), 10);
        mo = parseInt(entry.substring(delim1+1, delim2), 10);
        day = parseInt(entry.substring(delim2+1), 10);

        var testDate = new Date(yr, mo-1, day);
        if (testDate.getDate() == day){
            if (testDate.getMonth() + 1 == mo){
                if (testDate.getFullYear() == yr){
                    return true;
				}
			}
		}
	}
    return false;
}


function getAge(value)
	{
		var yy, mm, dd;
		var delimChar = "-";

        var delim1 = value.indexOf(delimChar);
        var delim2 = value.lastIndexOf(delimChar);

        yy = parseInt(value.substring(0, delim1), 10);
        mm = parseInt(value.substring(delim1+1, delim2), 10);
        dd = parseInt(value.substring(delim2+1), 10);

  		days = new Date();
		gdate = days.getDate();
		gmonth = days.getMonth();
		gyear = days.getFullYear();
		if (gyear < 2000) gyear += 1900;
		age = gyear - yy;
		if ((mm == (gmonth + 1)) && (dd <= parseInt(gdate)))
			{
				age = age;
			}
		else
			{
				if (mm <= (gmonth))
					{
						age = age;
					}
				else
					{
						age = age - 1;
   					}
			}
		if (age == 0) age = age;

		return age;
	}	
