var http_request = false;
var xmldoc = false;

function make_http_request()
{
	http_request = false;

	if (window.XMLHttpRequest)  // Mozilla, Safari,...
	{
	    http_request = new XMLHttpRequest();
	    if (http_request.overrideMimeType) 
	        http_request.overrideMimeType('text/xml');
	} 
	else if (window.ActiveXObject)  // IE
	{
	    try {http_request = new ActiveXObject("Msxml2.XMLHTTP");} 
	    catch (e)
	    {
	        try {http_request = new ActiveXObject("Microsoft.XMLHTTP");}
	        catch (e) {}
	    }
	}
	return http_request;
}

/**
function createXMLroot()
@description Create XML doc root
@author Igal Liberman
@param none
@return connector
**/
function createXMLroot()
{

	if (window.ActiveXObject) // code for IE*/
	{
	 	xmldoc = new ActiveXObject("Microsoft.XMLDOM");
		xmldoc.async="false";
		xmldoc.loadXML(xml);
	}
	else if(window.XMLHttpRequest)//for MOZILLA
	{
		xml = xml.replace(/<\?(.*)\?>/,'');//delete the xml header
		var dom  = new DOMParser();
		xmldoc = dom.parseFromString(xml,'text/xml');
		
	}

}

function switch_div_display(div_id)
{
	var display_status = document.getElementById(div_id).style.display;
	if(display_status == "none" || display_status == "")
		display_status = "block";
	else
		display_status = "none";
	document.getElementById(div_id).style.display = display_status;
}

/**
function move_to_page_type()
@description change page mode
@author Igal Liberman
@param uin,part_key
@return none
**/
function move_to_page_type(uin,part_key)
{
	user_mode_date = new Date();
	user_mode_date.setMinutes(user_mode_date.getMinutes()+60);
	page_tp =  document.getElementById("page_type").value;
	destination = false;

	switch (part_key)	
	{
		case 1: // User page
			switch (page_tp)
			{
				case "0":
					destination = "about_me.php?uin="+uin;
				break;
				case "1":
					destination = "about_admin.php";
				break;
			}
		break;

		case 2: // Blog page
			switch (page_tp)
			{
				case "0":
					destination = "full_user_blog.php?uin="+uin;
				break;
				case "1":
					destination = "full_blog.php";
				break;
			}
		break;

		case 3: // Pictures - gallery
			switch (page_tp)
			{
				case "0":
					destination = "photos.php?uin="+uin;
				break;
				case "1":
					destination = "photos_admin.php";
				break;
			}
		break;
		
		case 4: // Pictures - single image
			switch (page_tp)
			{
				case "0":
					destination = "view_photo.php?uin="+uin;
				break;
				case "1":
					destination = "admin_photo.php";
				break;
			}
		break;

		case 5: // Pictures - single image
			switch (page_tp)
			{
				case "0":
					destination = "full_details_show.php?uin="+uin;
				break;
				case "1":
					destination = "full_details_update.php";
				break;
			}
		break;

		case 6: // Pictures - single image
			switch (page_tp)
			{
				case "0":
					destination = "user_friends.php?uin="+uin;
				break;
				case "1":
					destination = "user_friends_admin.php?mode=2";
				break;
			}
		break;
	}

	if(destination)
	{
		document.getElementById("page_type").disabled = true;
		SetCookie("user_mode_view", page_tp , user_mode_date);
		document.location = destination;
	}
}

function self_no_send()
{
	alert(get_text('user_page','no_self_msg'));
}


function login_to_add()
{
	alert(get_text('user_page','must_login_to_add'));
}


function add_friend(uin_from,uin_to,uin,action_type)
{
	http_request = make_http_request();
    if (http_request != null) 
    {
    	url = "http_request.php?uin_from="+uin_from+"&uin_to="+uin_to+"&uin="+uin+"&action_type="+action_type;
		http_request.onreadystatechange = finish_add_friend;
		http_request.open('GET', url, true);
		http_request.send(null);
	}
}


function controll_friends(uin_from,uin_to,uin,action_type,ufr_id,check_confirm)
{
	if(check_confirm)
	{
		if(!confirm(get_text('user_friends','delete_user')))
			return false;
	}
	http_request = make_http_request();
    if (http_request != null) 
    {
    	url = "http_request.php?uin_from="+uin_from+"&uin_to="+uin_to+"&uin="+uin+"&action_type="+action_type+"&ufr_id="+ufr_id;
		http_request.onreadystatechange = finish_friend_action;
		http_request.open('GET', url, true);
		http_request.send(null);
	}
}

function finish_friend_action() 
{
	try
	{
		if (http_request.readyState == 4)
		{
//			ufr_id = http_request.responseText;
			if (http_request.status == 200)			// only if "OK"
			{
				xml = http_request.responseText;
				createXMLroot();
				var results = xmldoc.getElementsByTagName('results');
				if(results.length > 0)
				{
					// Get the id
					var id_node = results[0].getElementsByTagName('id');
					if(id_node.length > 0)
						ufr_id = id_node[0].childNodes[0].nodeValue;	
	
					// Get the action
					var action_node = results[0].getElementsByTagName('action');
					if(action_node.length > 0)
						action = action_node[0].childNodes[0].nodeValue;	
				}
				
				
				if(action == 'a')
				{
					document.getElementById('ufr-'+ufr_id+'-a').style.display = 'inline';
					document.getElementById('ufr-'+ufr_id+'-d').style.display = 'none';
				}
				else if(action == 'd')
				{
					document.getElementById('ufr-'+ufr_id+'-a').style.display = 'none';
					document.getElementById('ufr-'+ufr_id+'-d').style.display = 'inline';
				}

			}
		}
	}
	catch(e){}
}

function finish_add_friend() 
{
	try
	{
		if (http_request.readyState == 4)
		{
			if (http_request.status == 200)			// only if "OK"
			{
				xml = http_request.responseText;
				createXMLroot();
				var results = xmldoc.getElementsByTagName('results');
				if(results.length > 0)
				{	
					// Get the stat
					var stat_node = results[0].getElementsByTagName('stat');
					if(stat_node.length > 0)
						stat = stat_node[0].childNodes[0].nodeValue;	
				}
				
				if(stat == '1')
				{
					document.getElementById('add-fr-1').style.display = 'none';
					document.getElementById('add-fr-2').style.display = 'none';
					document.getElementById('add-fr-3').style.display = 'block';
				}

			}
		}
	}
	catch(e){}
}

function get_text(dep,sub_dep)
{
	try{ret = lang[dep][sub_dep];}
	catch(e){ret = '';}
	return ret;
}

function change_to_lang(lang)
{
	var gl_expireDate = new Date;
	gl_expireDate.setMonth(gl_expireDate.getMonth()+1);
	SetCookie("icq_lang", lang , gl_expireDate,"/");
	window.location.reload(true);
}

// ADDED BY KATYA KODNER 09.05.13 because of the new index in Rexx that doesn't support 0 in search fields (from now on there's no search without home_country_code)
function people_fillcountries(field_id,selected_id)
{
	count = new Array("93","Afghanistan"   , "355","Albania"   , "213","Algeria"   , "684","American Samoa"   , "376","Andorra" ,"244","Angola","101","Anguilla","102","Antigua"   , "1021","Antigua & Barbuda"   , "5902","Antilles"   , "54","Argentina"   , "374","Armenia"   , "297","Aruba" ,"247","AscensionIsland"   ,"61","Australia"   , "43","Austria"   , "994","Azerbaijan"   , "103","Bahamas"   , "973","Bahrain"   , "880","Bangladesh"   , "104","Barbados","120","Barbuda"   ,"375","Belarus"   , "32","Belgium"   , "501","Belize"   , "229","Benin"   , "105","Bermuda"   , "975","Bhutan"   , "591","Bolivia"   ,"267","Botswana" , "55","Brazil"   ,"673","Brunei"   , "359","Bulgaria"   , "226","Burkina Faso"   , "257","Burundi"   , "855","Cambodia"   , "237","Cameroon"   ,"107","Canada" ,"178","Canary Islands"   ,"108","Cayman Islands"   , "235","Chad"   , "56","Chile, Rep. of"   , "86","China"   , "672","Christmas Island"   ,"57","Colombia"  ,"2691","Comoros"   , "682","CookIslands"   , "506","Costa Rica"   , "385","Croatia"   , "53","Cuba"   , "357","Cyprus"   , "42","Czech Rep."   ,"45","Denmark"  ,"246","Diego Garcia"   , "253","Djibouti"  , "109","Dominica"   , "110","Dominican Rep."   , "593","Ecuador"   , "20","Egypt"   , "503","El Salvador"  , "291","Eritrea", "372","Estonia"   , "251","Ethiopia"   ,"298","Faeroe Islands"   , "500","Falkland Islands"   , "679","Fiji"   , "358","Finland"   , "33","France"  ,"5901","FrenchAntilles"   , "594","French Guiana"   ,"689","French Polynesia"   , "241","Gabon"   , "220","Gambia"   , "995","Georgia"   , "49","Germany"   ,"233","Ghana"  ,"350","Gibraltar"   , "30","Greece"   ,"299","Greenland"   , "111","Grenada"   , "590","Guadeloupe"   , "502","Guatemala"   , "224","Guinea"   ,"245","Guinea-Bissau"  ,"592","Guyana"   , "509","Haiti"   ,"504","Honduras"   , "852","Hong Kong"   , "36","Hungary"   , "354","Iceland"   , "91","India"   ,"62","Indonesia"   , "964","Iraq"  , "353","Ireland"   , "972","Israel"  , "39","Italy"   , "112","Jamaica"   , "81","Japan"   , "962","Jordan"   , "705","Kazakhstan"  , "254","Kenya"   , "686","Kiribati" , "850","Korea, North"   , "82","Korea, South"   , "965","Kuwait"   , "706","Kyrgyzstan"   , "856","Laos"   , "371","Latvia"   ,"961","Lebanon"   , "266","Lesotho"  ,"231","Liberia"   , "4101","Liechtenstein"   , "370","Lithuania"   , "352","Luxembourg"   , "853","Macau"   , "261","Madagascar"   ,"265","Malawi"   , "60","Malaysia"  ,"960","Maldives"   , "223","Mali"   , "356","Malta"   , "692","Marshall Islands"   , "596","Martinique"   , "222","Mauritania"   ,"230","Mauritius"   ,"269","MayotteIsland"   , "52","Mexico"   , "373","Moldova, Rep. of"   , "377","Monaco"   , "976","Mongolia"   , "113","Montserrat"   ,"212","Morocco"   ,"258","Mozambique"   ,"95","Myanmar"   , "264","Namibia"   , "674","Nauru"   , "977","Nepal"   , "31","Netherlands"   , "114","Nevis"   , "687","NewCaledonia"   ,"64","New Zealand"   ,"505","Nicaragua"   , "227","Niger"   , "234","Nigeria"   , "683","Niue"   , "6722","Norfolk Island"   , "47","Norway"   ,"968","Oman"   ,"92","Pakistan"   ,"680","Palau"   , "507","Panama"   , "675","Papua New Guinea"   , "595","Paraguay"   , "51","Peru"   , "63","Philippines"   , "48","Poland"   ,"351","Portugal"   ,"121","Puerto Rico"   , "974","Qatar"   , "262","Reunion Island"   , "40","Romania"   , "6701","Rota Island"   , "7","Russia"   ,"250","Rwanda"   , "122","Saint Lucia"  , "670","Saipan Island"   , "378","San Marino"   , "966","Saudi Arabia"   , "442","Scotland"   , "221","Senegal"   ,"248","Seychelles"   , "232","Sierra Leone"   ,"65","Singapore"   , "4201","Slovakia"   , "386","Slovenia"   , "677","Solomon Islands"   , "252","Somalia"   , "27","SouthAfrica"   , "34","Spain"   , "94","Sri Lanka"  , "290","St. Helena"   , "115","St. Kitts"   , "249","Sudan"   , "597","Suriname"   , "268","Swaziland"   , "46","Sweden"  , "41","Switzerland"   , "963","Syrian ArabRep."   , "886","Taiwan"   , "708","Tajikistan"   , "255","Tanzania"   , "66","Thailand"   , "6702","Tinian Island"   ,"228","Togo"  , "690","Tokelau"   , "676","Tonga"  , "216","Tunisia"   , "90","Turkey"   , "709","Turkmenistan"   , "688","Tuvalu"   , "256","Uganda"   , "380","Ukraine"  , "44","United Kingdom"   , "598","Uruguay"   ,"1","USA"   , "711","Uzbekistan"   , "678","Vanuatu"   , "379","Vatican City"   , "58","Venezuela"   , "84","Vietnam"   ,"441","Wales"   , "685","Western Samoa"   ,"967","Yemen"   , "381","Yugoslavia"   , "382","Yugoslavia - Montenegro"   , "3811","Yugoslavia - Serbia"   , "260","Zambia"   ,"263","Zimbabwe"   , "9999","Other" );
	
	var temp = document.getElementById(field_id);
	x = (count.length / 2);
	try{
			temp.options.length=x;
			for (i=0;i<x;i++) 
			{
				temp.options[i].text=count[i*2+1];
				temp.options[i].value=count[i*2];
				if( temp.options[i].value == selected_id)
				{
					temp.options[i].selected = true;
				}
			}
		}
	catch(e){}
}