var xmlHttpresponse="";
var withoutresults=0;
var displaydivvariable="";
var displaydivheight="";
var displaydivwidth="";
var displaydivmLeft="";
var displaydivmTop="";
var calendarmarkeddays=new Array("");
var ajax_blocked=0;
var ajax_functions=new Array('','displaydiv','main_search','delete_zkattering','all_zkatterings','show_mapofzkatter','open_view_photo','view_msg','getmutual_friends','del_msg',//0-9
							'delete_friend','setpage_friendlist','getcalendarzkatteringsformonth','setpage_mylist','','send_msg','setpage_list','setpage_listcheck','delete_account','',//10-19
							'','','','','','','','','','',//20-29
							'','','','','','','','','','',//30-39
							"getusers_list",'','','','','','','','',''//40-49 - ADMIN SECTION
							);
var ajax_errfunctions=new Array('','','','','','',"sa_errvmsg",'','','',//0-9
								'','','',"sa_errsetlist","sa_errsetpmyphoto",'','','','','',//10-19
								'','','','','','','','','','',//20-29
								'','','','','','','','','','',//30-39
								'','','','','','','','','',''//40-49 - ADMIN SECTION
								);

function ajaxP(){
	var xmlHttp=null
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		xmlHttp = new XMLHttpRequest();
		if (xmlHttp.overrideMimeType) {
			// set type accordingly to anticipated content type
			//xmlHttp.overrideMimeType('text/xml');
			xmlHttp.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	return xmlHttp
}

function simple_ajax(url,function_id,errfunction_id,extra){
	alertd('"'+function_id+' | '+ajax_functions[function_id]+'" from ajax_functions[function_id]', '_gajarrays.js', '880088', 0, 1);
	var xmlHttp=ajax();
	xmlHttp.open('get',url); // .open(RequestType, Source);
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4)
			try { // In some instance, status cannot be retrieve and will produce an error (ex: Port is not responsive)
				if (xmlHttp.status == 200){
					//Set the main HTML of the body to the info provided by the AJAX Request
					if(typeof(function_id)=="number"){
						if(function_id){
							xmlHttpresponse=xmlHttp.responseText;
							window[ajax_functions[function_id]](extra);
						}
					}else{
						if(window[function_id])
							window[function_id](xmlHttp.responseText,extra);
					}
				}
			} catch (e) {
				if(typeof(errfunction_id)=="number"){
					if(errfunction_id)
						window[ajax_errfunctions[errfunction_id]](extra);
				}else{
					if(window[errfunction_id])
						window[errfunction_id](xmlHttp.responseText,extra);
				}
			}
	};
	xmlHttp.send(null); // Since there is no supplied form, null takes its place as a new form.
}

function simple_ajaxP(url,params,function_id,errfunction_id,extra){
	alertd('"'+ajax_functions1[function_id]+'" from ajax_functions1[function_id]', '_gajarrays.js', '880088', 0, 1);
	var xmlHttp=ajaxP();
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
			try {
				if (xmlHttp.status == 200) {
					if(typeof(function_id)=="number"){
						if(function_id){
							xmlHttpresponse=xmlHttp.responseText;
							window[ajax_functions1[function_id]](extra);
						}
					}else{
						if(window[function_id])
							window[function_id](xmlHttp.responseText,extra);
					}
				}
			} catch (e) {
				if(typeof(errfunction_id)=="number"){
					if(errfunction_id)
						window[ajax_errfunctions1[errfunction_id]](extra);
				}else{
					if(window[errfunction_id])
						window[errfunction_id](xmlHttp.responseText,extra);
				}
			}
		}
	};
      xmlHttp.open('POST', url, true);
      xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xmlHttp.setRequestHeader("Content-length", params.length);
      xmlHttp.setRequestHeader("Connection", "close");
      xmlHttp.send(params);
}

function simple_ajax1(url,function_id,errfunction_id,extra){
	alertd('"'+ajax_functions1[function_id]+'" from ajax_functions1[function_id]', '_gajarrays.js', '880088', 0, 1);
	var xmlHttp=ajax();
	xmlHttp.open('get',url); // .open(RequestType, Source);
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4)
			try { // In some instance, status cannot be retrieve and will produce an error (ex: Port is not responsive)
				if (xmlHttp.status == 200){
					if(typeof(function_id)=="number"){
						if(function_id){
							xmlHttpresponse=xmlHttp.responseText;
							window[ajax_functions1[function_id]](extra);
						}
					}else{
						if(window[function_id])
							window[function_id](xmlHttp.responseText,extra);
					}
				}
			} catch (e) {
				if(typeof(errfunction_id)=="number"){
					if(errfunction_id)
						window[ajax_errfunctions1[errfunction_id]](extra);
				}else{
					if(window[errfunction_id])
						window[errfunction_id](xmlHttp.responseText,extra);
				}
			}
	}
	xmlHttp.send(null); // Since there is no supplied form, null takes its place as a new form.
}

function simple_ajax_eval(url,function_id,errfunction_id,extra){
 $.ajax({
  type: "GET",
  url: url,
  dataType: "html",
  success: function (html){
	xmlHttpresponse = html;
	window.xmlHttpresponse = xmlHttpresponse;
	if(typeof(function_id)=="number"){
		if(function_id){
			window[ajax_functions[function_id]](extra);
		}
	}else{
		if(window[function_id])
			window[function_id](html,extra);
	}
  },
  error: function (XMLHttpRequest, textStatus, errorThrown) {
	if(typeof(errfunction_id)=="number"){
		if(errfunction_id)
			window[ajax_errfunctions[errfunction_id]](extra);
	}else{
		if(window[errfunction_id])
			window[errfunction_id](XMLHttpRequest,extra);
	}
  }
 });
}

function press_php_loading(id){
	document.getElementById(id).style.background = gl_loader_back;
}
function press_php_stoploading(id){
	document.getElementById(id).style.background = '';
}

function CreateAjxTable(divid,respStr,headerstr){
	var html='';
	var resA=respStr.split("<valeman_htmldivider>");
	var before_table=resA[0], tbl=resA[1], after_table=resA[2];
	//alert(resA.length);
	switch (resA.length) {
		case 0:return;
		case 1:respStr=before_table;break;
		case 2:
		case 3:respStr=tbl;html+=before_table;break;
		default:return;
	}
	html+='<table>';
	if(headerstr!='')
		html+= headerstr;
	rows= respStr.substr(0,respStr.length-1);
	rows= rows.split("\n");
	for (r=0; r<rows.length; r++){
		cols= rows[r].substr(0,rows[r].length-1);
		cols= cols.split("\t");
		html+= '<tr>';
		for (c=0; c<cols.length; c++){
			switch(c){
				case 0:break;
				case 1:html+= '<input type="hidden" id="tbl_db_id_'+cols[0]+'" value="'+cols[1]+'">';break;
				default:html+= '<td>' + cols[c] + '</td>';
					break;
			}
		}
		html+= '</tr>';
	}
	html+= '</table>';
	if(resA.length==3)
		html+=after_table;
	document.getElementById(divid).innerHTML = html;
}

function displaydiv(XMLHTTPResp){
	if(XMLHTTPResp){
		xmlHttpresponse=XMLHTTPResp;
	}
	if (jQuery("#modal_dialog")[0]==undefined){
		try {
			//if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			if (jQuery("body").css("maxHeight") === "undefined") {//if IE 6
				jQuery("html").css("overflow","hidden");
				if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
					jQuery("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div>");
					//jQuery("#TB_overlay").click(tb_remove);
				}
			}else{//all others
				if(document.getElementById("TB_overlay") === null){
					jQuery("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
					//jQuery("#TB_overlay").click(tb_remove);
				}
			}
		} catch(e) {
		//nothing here
		}
		jQuery("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		displaydivvariable=xmlHttpresponse;
		jQuery("#TB_window").append(displaydivvariable);
		jQuery("#TB_overlay").show();
		jQuery("#TB_window").css({
			height: displaydivheight,
			width: displaydivwidth,
			display:"block",
			marginLeft:displaydivmLeft,
			marginTop: displaydivmTop
		});
	}
}

/* THE NEW PLACE OF GLOBAL ARRAY JS-FUNCTIONS BEGINS	*/

function sa_display_pop(jslayout,htmllayout,parameters,div_height,div_width,div_left,div_top){
	/*$().ready(function() {alert(3);
		$('#ex2').jqm({ajax: site_absolute_path+_Gp_pcommon+'?jsl='+jslayout+'&hl='+htmllayout+'&lnk_join='+lnk_join, trigger: 'a.ex2trigger'});
	});*/
	displaydivheight=(div_height!=undefined)?div_height+"px":"375px";
	displaydivwidth=(div_width!=undefined)?div_width+"px":"702px";
	displaydivmLeft=(div_left!=undefined)?div_left+"px":"-351px";
	displaydivmTop=(div_top!=undefined)?div_top+"px":"-185px";
	simple_ajax(site_absolute_path+_Gp_pcommon+'?jsl='+jslayout+'&hl='+htmllayout+parameters,'displaydiv',0);
}
function display_pop(XMLHTTPResp){
	
}

function ifrsa_displayfrequestdiv(uid,logged,jsaction){
	displaydivheight="375px";
	displaydivwidth="702px";
	displaydivmLeft="-351px";
	displaydivmTop="-185px";
	simple_ajax(site_absolute_path+'addasfr.php?frid='+uid+'&logged='+logged+'&jsact='+escape(jsaction),1,0);
}
function ifrsa_displaycancelreq(id,zid,logged){
	displaydivheight="375px";
	displaydivwidth="702px";
	displaydivmLeft="-351px";
	displaydivmTop="-185px";
	simple_ajax(site_absolute_path+'delzkat.php?id='+id+'&zid='+zid+'&logged='+logged,1,0);
}
function ifrsa_displaydelzkdiv(id,zid,logged){
	displaydivheight="375px";
	displaydivwidth="702px";
	displaydivmLeft="-351px";
	displaydivmTop="-185px";
	simple_ajax(site_absolute_path+'delzkat.php?id='+id+'&zid='+zid+'&logged='+logged,1,0);
}

function blockunblock(id){
	var tmpblocked=document.getElementById('whole_'+id+'_blocked');
	if(document.getElementById('blocks_'+id).value=='0'){
		$("#blocklink_"+id).mouseover(function(event){
			balloon.showTooltip(event,'Unblock this user');
		});
		sa_blfr();
		document.getElementById('whole_'+id).style.backgroundColor='#ff8080';
		document.getElementById('whole_'+id).style.backgroundImage='';
		document.getElementById('blocks_'+id).value='1';
		tmpblocked.value="1";
	}else{
		$("#blocklink_"+id).mouseover(function(event){
			balloon.showTooltip(event,'Block this user');
		});
		sa_ublfr();
		document.getElementById('whole_'+id).style.backgroundColor='#f3f3f3';
		document.getElementById('whole_'+id).style.backgroundImage='url(images/list_itm_bg.png)';
		document.getElementById('blocks_'+id).value='0';
		tmpblocked.value="0";
	}
}
function sa_blfr(){
	simple_ajax(site_absolute_path+'ajax/unblock_block_friend.php?b=1&friend_id='+document.getElementById('sel_friend').value,0,0);
}
function sa_ublfr(){
	simple_ajax(site_absolute_path+'ajax/unblock_block_friend.php?b=0&friend_id='+document.getElementById('sel_friend').value,0,0);
}

function sa_addfr(friendid){
	simple_ajax(site_absolute_path+'ajax/add_friend.php?friend_id='+friendid,0,0);
}

function sa_delfr(){
	simple_ajax(site_absolute_path+'ajax/delete_friend.php?friend_id='+top.document.getElementById('sel_friend').value,10,0);
}
function delete_friend(){
	removediv(top.document.getElementById('sel_delwholeid').value);
	self.parent.tb_remove();
}

function sa_delzk(id,delzid){
	if (!id)
		{
		simple_ajax(site_absolute_path + 'ajax/del_zkatter.php?delzid=' + delzid, 'deleteZkatterDone', 0, delzid)
		}
	else {
	document.getElementById('sr_id').value=id;
	simple_ajax(site_absolute_path+'ajax/del_zkatter.php?delzid='+delzid,3,0);
	}
}
function delete_zkattering(){
	var id=document.getElementById('sr_id').value;
	removeChildbyParentNode('sr_container_'+id);
}

function sa_setZkatter(action){
	simple_ajax(site_absolute_path+'ajax/setZkatter.php?zkatter='+document.getElementById('activeZkatter').value+'&action='+action,'set_Zkatter',0,action);
}
function set_Zkatter(XMLHTTPResp,action){
	if(XMLHTTPResp=="")
		return;
	explode=XMLHTTPResp.split("\t");
	if (explode[0]){
		document.getElementById('activeZtab').value = 0;
		zMapInit('zMyMap',explode[0],explode[1],explode[2],16,explode[3],explode[4],explode[5]);
		document.getElementById('mapTitle').innerHTML= explode[6];
	}
	simple_ajax(site_absolute_path+'ajax/setZkatter.php?zkatter='+document.getElementById('activeZkatter').value+'&action='+action,'set_ZkatterLink',0,action);
}
function set_ZkatterLink(XMLHTTPResp,action){
	if (XMLHTTPResp!=""){
		if(action=='prv')
			document.getElementById('nxt').style.display= 'inline';
		else
			document.getElementById('prv').style.display= 'inline';
		document.getElementById('slash').style.display= 'inline';
	}else{
		document.getElementById(action).style.display= 'none';
		document.getElementById('slash').style.display= 'none';
	}
}

function sa_showzkmap(sa_time){
	simple_ajax(site_absolute_path+'ajax/map_list_page.php?sa_time='+sa_time,'show_mapofzkatter',0);
}
function show_mapofzkatter(XMLHTTPResp){
	if(XMLHTTPResp=="")
		return;
	document.getElementById('activeZtab').value = 0;
	var tmpres=new Array();
	tmpres=XMLHTTPResp.split('|');					// GETS ALL RESULTS INTO RESULTING JS ARRAY
	foundzid=VjsIntCut(XMLHTTPResp,'<valemancount value="','">total</valemancount>');
	if(foundzid)
		zMapInit('zMap',tmpres[0],tmpres[1],tmpres[2],16,tmpres[3],tmpres[4],tmpres[5]);
}

function sa_openvph(vph_zid,vph_ref,prev_next){
	if(prev_next==undefined)prev_next='';
	var sa_link=site_absolute_path+_Gp_jview_media+'?vph_zid='+vph_zid+"&vph_ref="+vph_ref+"&prev_next="+prev_next+"&prfscrname="+prfscrname;
	alertd(sa_link,"","",1);
	simple_ajax(sa_link,"open_view_photo",0);
}
function open_view_photo(XMLHTTPResp){
	document.getElementById('view_photodiv').innerHTML = XMLHTTPResp;
	if(document.getElementById('vph_zk_for_title_div'))
		document.title=document.getElementById('vph_zk_for_title_div').innerHTML;
	setFaders();
	document.getElementById('sr_menu_1').style.visibility= 'visible';
	document.getElementById('sr_container_1').onmouseover= '';
	document.getElementById('sr_container_1').onmouseout= '';
	document.getElementById('lnkMap_1').style.display= 'none';
	document.getElementById('lnkMed_1').style.display= 'none';
	if (document.getElementById('lnkAddFrnd_1')) document.getElementById('lnkAddFrnd_1').style.display= 'none';
	if (document.getElementById('lnkRspnsB_1')) document.getElementById('lnkRspnsB_1').style.display= 'none';
	if (document.getElementById('lnkRspndB_1')) document.getElementById('lnkRspndB_1').style.display= 'none';
}

function sa_getmutual(page,userid){
	simple_ajax(site_absolute_path+'ajax/mutualfriends_page.php?page='+page+'&txp=5&uid='+userid,8,0);
}
function getmutual_friends(){
	document.getElementById('fancy_ajax').innerHTML=xmlHttpresponse;
}

function sa_spfrPr(page,clicked_link){
	if(scrpt==_Gp_mymap){
		document.getElementById("mapTitle").style.display = "none";
		document.getElementById("mapAll").style.display = "none";
	}
	simple_ajax(site_absolute_path+_Gp_jfriends_pageProfile+'?page='+page+'&txp=10&clicked_link='+clicked_link,'setpage_friendlist','');
	if(document.getElementById("navigation"))
		document.getElementById("navigation").style.display = "none";
}
function sa_spfr(page){
	if(scrpt==_Gp_mymap){
		document.getElementById("mapTitle").style.display = "none";
		document.getElementById("mapAll").style.display = "none";
	}
	simple_ajax(site_absolute_path+_Gp_jfriends_page+'?page='+page+'&txp=10','setpage_friendlist','');
}
function setpage_friendlist(XMLHTTPResp){
	if (substr_count(XMLHTTPResp,'<!-- YOU HAVE NO FRIENDS! -->')) tabFocus('search');
	else document.getElementById('list_found').innerHTML =XMLHTTPResp;
	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
}

var livecheckflag=0;
var newzklive=0;
var refreshview_link=0;
var livediv='';

function sa_getcalzkatts(){
	simple_ajax(site_absolute_path+'ajax/getcalendardates.php?sa_time='+sa_time,'getcalendarzkatteringsformonth',0);
	sa_time='';
}
function getcalendarzkatteringsformonth(XMLHTTPReq){
	if(XMLHTTPReq=="")
		return;
	var tmpres=new Array();
	window.calendarmarkeddays=new Array();
	tmpres=XMLHTTPReq.split('|');					// GETS ALL RESULTS INTO RESULTING JS ARRAY
	for(var i=0; i < tmpres.length; i++){
		window.calendarmarkeddays[i]=(tmpres[i].split(','))[0];
		document.getElementById("cal_day_"+window.calendarmarkeddays[i]).setAttribute('class','zDay');
	}
}

function sa_sendmsg(old_msgid){
	simple_ajax(site_absolute_path+'ajax/send_msg.php?zkatterid=' + document.getElementById('to_zid').value + '&to=' + document.getElementById('to_friend_id').value + '&msg=' + escape(document.getElementById('rsp').value) + '&oldmsgid=' + old_msgid,'send_msg',15,old_msgid);
}
function send_msg(XMLHTTPresp,msgid){
	if (document.getElementById('new_'+msgid)) document.getElementById('new_'+msgid).style.display= 'none';
	sendDone();
}

function sa_deactdelacc(inact,deact_del){
	simple_ajax(site_absolute_path+'ajax/delete_account.php?inact='+inact+'&d_d='+deact_del,18,0);
}
function delete_account(){
	alertd(window.location.href+" | "+self.parent.window.location.href,"redirecting to "+_Gp_settings,"",1);
	self.parent.window.location.href=site_absolute_path+_Gp_settings;
}

function sa_insinto_maillist(){
	var challengeField = $("input#recaptcha_challenge_field").val();
	var responseField = $("input#recaptcha_response_field").val();
	var press_email_inp=document.getElementById('press_email_inp').value;
	var press_name_inp=document.getElementById('press_name_inp').value;
	var press_company_inp=document.getElementById('press_company_inp').value;
	var press_position_inp=document.getElementById('press_position_inp').value;
	simple_ajax(site_absolute_path+'_ajax/insertinto_mailinglist.php?e='+press_email_inp+'&n='+press_name_inp+'&c='+press_company_inp+'&p='+press_position_inp+"&recaptcha_challenge_field="+challengeField+'&recaptcha_response_field='+responseField,'insertinto_maillist',0);
}
function insertinto_maillist(XMLHTTPresp){
	press_php_stoploading('press_php_loader_div_img');
	Recaptcha.reload();
	var len=XMLHTTPresp.toString().length;
	if(len==1&&parseInt(XMLHTTPresp)==1)
		document.getElementById('press_msg_div').innerHTML='You are added successfully to our newsletter!';
	else if(len==1&&parseInt(XMLHTTPresp)==0)
		document.getElementById('press_msg_div').innerHTML='You are already added to our newsletter';
	else if(len>1)
		document.getElementById('press_msg_div').innerHTML='Error: '+XMLHTTPresp;
	setTimeout('document.getElementById("press_msg_div").innerHTML=""', 8000);
}

/*	ADMIN FUNCTIONS BEGINS	*/
function sa_manageacc(uid){
	var obj;
	obj=document.getElementById('adm_protected_dot');if(obj.src.indexOf('full')==-1)prot=0;else prot=1;
	obj=document.getElementById('adm_blocked_dot');if(obj.src.indexOf('full')==-1)blk=0;else blk=1;
	obj=document.getElementById('adm_deactivated_dot');if(obj.src.indexOf('full')==-1)dea=0;else dea=1;
	obj=document.getElementById('adm_deleted_dot');if(obj.src.indexOf('full')==-1)del=0;else del=1;
	obj=document.getElementById('adm_deletedimmediately_dot');if(obj.src.indexOf('full')==-1)delimm=0;else delimm=1;
	if(delimm)del=1;
	simple_ajax(site_absolute_path+'admin/_ajax/manage_account.php?uid='+uid+'&prot='+prot+'&blk='+blk+'&dea='+dea+'&del='+del+'&delimm='+delimm,'manage_account',0);
}
function manage_account(XMLHTTPresp){
	self.parent.tb_remove();
}

function sa_editacc(uid){
	var obj;
	obj=document.getElementById('adm_protected_dot');if(obj.src.indexOf('full')==-1)prot=0;else prot=1;
	obj=document.getElementById('adm_blocked_dot');if(obj.src.indexOf('full')==-1)blk=0;else blk=1;
	obj=document.getElementById('adm_deactivated_dot');if(obj.src.indexOf('full')==-1)dea=0;else dea=1;
	obj=document.getElementById('adm_deleted_dot');if(obj.src.indexOf('full')==-1)del=0;else del=1;
	simple_ajaxP(site_absolute_path+'admin/_ajax/manage_account.php?uid='+uid+'&prot='+prot+'&blk='+blk+'&dea='+dea+'&del='+del,'edit_account',0);
}
function edit_account(XMLHTTPresp){
	self.parent.tb_remove();
}

function sa_managezk(zid){
	var obj;
	obj=document.getElementById('adm_visibility_dot');if(obj.src.indexOf('full')==-1)vis=0;else vis=1;
	obj=document.getElementById('adm_deleted_dot');if(obj.src.indexOf('full')==-1)del=0;else del=1;
	simple_ajax(site_absolute_path+'admin/_ajax/manage_zkattering.php?zid='+zid+'&vis='+vis+'&del='+del,'manage_zkattering',0);
}
function manage_zkattering(XMLHTTPresp){
	self.parent.tb_remove();
}

function sa_manageab(zid,uid){
	var obj;
	obj=document.getElementById('adm_abused_rad_id_0');if(obj.src.indexOf('full')==-1)accept=0;else accept=1;
	obj=document.getElementById('adm_abused_rad_id_1');if(obj.src.indexOf('full')==-1)deny=0;else deny=1;
	obj=document.getElementById('adm_abused_rad_id_2');if(obj.src.indexOf('full')==-1)admin=0;else admin=1;
	simple_ajax(site_absolute_path+'admin/_ajax/manage_abused.php?zid='+zid+'&accept='+accept+'&deny='+deny+'&admin='+admin+'&uid='+uid,'manage_abused',0);
}
function manage_abused(XMLHTTPresp){
	self.parent.tb_remove();
}

function makeall4_delete(){
	simple_ajax(site_absolute_path+'admin/_ajax/admajx_all4del.php',0,0);
}

/*	ADMIN FUNCTIONS ENDS	*/


/*	THE NEW PLACE OF GLOBAL ARRAY JS-FUNCTIONS ENDS	*/