function playFlashVideo(regionId, videoFile, previewImage, flashType) {
    videoFile = escape(videoFile);
    var s1 = new SWFObject("flash/flvplayer.swf",flashType,"320","240","7");
	s1.addParam("allowfullscreen","true");
	s1.addVariable("file",videoFile);
	s1.addVariable("image",previewImage);
	s1.addVariable("width","320");
	s1.addVariable("height","240");
	s1.addVariable("displayheight","240");
	s1.addVariable("bufferlength","3");
	s1.addVariable("autostart ","true");
	//s1.addVariable("logo","http://www.we-r-you.com/webspace/images/cyprus/portal_logo.gif");
	//s1.addVariable("link","http://www.we-r-you.com");

	s1.write(regionId);
}


function filterSpecials(str) {
	re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
	// remove special characters like "$" and "," etc...
	return str.replace(re, "");
}
    
function removeSpaces(string) {
	var tstring = "";
	if (string == null) {
		return "";
	}
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}

function openWindowCentered(location, windowName, windowWidth, windowHeight, parameters) {
    windowTop = Math.ceil((screen.height-windowHeight)/2);
    windowLeft = Math.ceil((screen.width-windowWidth)/2);
    if (parameters.length > 0)
		parameters = ',' + parameters;
	parameters = 'width='+windowWidth+',height='+windowHeight+',top='+windowTop+',left='+windowLeft+parameters;
	if(navigator.appVersion.match("Windows") && windowName == ''){
		windowName = "weryou";
	}else{
		windowName = ""+windowName;
	}

	windowName = removeSpaces(windowName);
	windowName = filterSpecials(windowName);
	
    var win=window.open(location,windowName,parameters) ; 
    win.focus();
    return win;
}

var interval;

function checkForNewMessages(initFunction){
	//alert('there are no new messages :(');
	//alert('interval before start = '+interval);
	interval = self.setInterval(initFunction,30000);
	//alert('interval after start = '+interval);
}
function stopCheckForNewMessages(){
	//alert('there are new messages :)');
	//alert('interval before stop = '+interval);
	interval = window.clearInterval(interval);
	//alert('interval after stop = '+interval);
}

function showDescription(descriptionValue) {
	document.getElementById('operationDescription').innerHTML = descriptionValue;
}

function closePopupWindow() {
	var browser = navigator.appVersion;
	if(browser.match("Mac OS") != null){
		window.location = 'start.do';
	}else{
		window.close();
	}
}
/*
function changeContactsByArrow(id){
	document.getElementById('selectContacts').value = id;
	changeContacts(id);
}
function changeContactsByArrowModTwenty(id){
	if(id == 0)id = 20;
	document.getElementById('selectContacts').value = id;
	changeContacts(id);
}
*/
function selectGroups(newTab){
	var oldTab;
	if (newTab == 1) {
		oldTab = 2;
	} else { oldTab = 1; }


	try {
	if (newTab == 1) {
		document.getElementById("group_TabMyGroups1").setAttribute("className", "tab-dark-left");
		document.getElementById("group_TabMyGroups2").setAttribute("className", "tab-dark-right");
		document.getElementById("group_TabMyGroups3").setAttribute("className", "tab-dark-back");
	
		document.getElementById("group_TabAllGroups1").setAttribute("className", "tab-light-left");
		document.getElementById("group_TabAllGroups2").setAttribute("className", "tab-light-right");
		document.getElementById("group_TabAllGroups3").setAttribute("className", "tab-light-back");


		document.getElementById("group_TabMyGroups1").setAttribute("class", "tab-dark-left");
		document.getElementById("group_TabMyGroups2").setAttribute("class", "tab-dark-right");
		document.getElementById("group_TabMyGroups3").setAttribute("class", "tab-dark-back");
	
		document.getElementById("group_TabAllGroups1").setAttribute("class", "tab-light-left");
		document.getElementById("group_TabAllGroups2").setAttribute("class", "tab-light-right");
		document.getElementById("group_TabAllGroups3").setAttribute("class", "tab-light-back");

	} else {
		document.getElementById("group_TabMyGroups1").setAttribute("className", "tab-light-left");
		document.getElementById("group_TabMyGroups2").setAttribute("className", "tab-light-right");
		document.getElementById("group_TabMyGroups3").setAttribute("className", "tab-light-back");

		document.getElementById("group_TabAllGroups1").setAttribute("className", "tab-dark-left");
		document.getElementById("group_TabAllGroups2").setAttribute("className", "tab-dark-right");
		document.getElementById("group_TabAllGroups3").setAttribute("className", "tab-dark-back");

		document.getElementById("group_TabMyGroups1").setAttribute("class", "tab-light-left");
		document.getElementById("group_TabMyGroups2").setAttribute("class", "tab-light-right");
		document.getElementById("group_TabMyGroups3").setAttribute("class", "tab-light-back");

		document.getElementById("group_TabAllGroups1").setAttribute("class", "tab-dark-left");
		document.getElementById("group_TabAllGroups2").setAttribute("class", "tab-dark-right");
		document.getElementById("group_TabAllGroups3").setAttribute("class", "tab-dark-back");
	}
	} catch(err){
		//alert(err);
	}
	
	if(newTab == 1){
		init_paging_groups();
	}else{
		init_paging_all_groups();
	}
}

function changeContacts(id,text){
	var selectedValue = id;
	if(selectedValue < 10){
	
		if(selectedValue < 4){
			selectedValue = 1;
		}else if(selectedValue > 4 ){
			selectedValue = 5;
		}else{
			selectedValue = 4;
		}
		for(var i = 0; i < 9; i++){
			if(i!=1 && i!=4 && i!=5){continue;}
			if(i == selectedValue){
				document.getElementById('changeContactsLeft'+i).className='tab-darkl-left';
				document.getElementById('changeContactsRight'+i).className='tab-darkl-right';
				document.getElementById('changeContactsBack'+i).className='tab-dark-back';
				document.getElementById('changeContactsBack'+i).innerHTML = text;
			}else{
				document.getElementById('changeContactsLeft'+i).className='tab-darkl2-left';
				document.getElementById('changeContactsRight'+i).className='tab-darkl2-right';
				document.getElementById('changeContactsBack'+i).className='tab-dark2-back';		
			}
		}
		selectedValue = id;
	}
	
	if(selectedValue == 1){
		init_paging_new_contacts(5);
	}else if(selectedValue == 2){
		init_paging_second_level_contacts(5);
	}else if(selectedValue == 3){
		init_paging_third_level_contacts(5);
	}else if(selectedValue == 4){
		init_paging_visitors(5);
	}else if(selectedValue == 5){
		init_paging_favourites(5);
	}else if(selectedValue == 6){
		init_paging_recent_interactions();
	}else if(selectedValue == 7){
		init_paging_interesting_people(5);
	}else if(selectedValue == 8){
		init_paging_most_visited_profiles(5);
	}else if(selectedValue == 9){
		init_paging_neglected_persons(5);
	}else if(selectedValue == 20){
		init_paging_group_members(20);
	}else if(selectedValue == 21){
		init_paging_my_contacts_in_group(5);
	}else if(selectedValue == 22){
		init_paging_group_banned_contacts(5);
	}else if(selectedValue == 33){
		for(var i = 0; i < 9; i++){
			if(i!=1 && i!=4 && i!=5){continue;}
			document.getElementById('changeContactsLeft'+i).className='tab-darkl2-left';
			document.getElementById('changeContactsRight'+i).className='tab-darkl2-right';
			document.getElementById('changeContactsBack'+i).className='tab-dark2-back';		
		}
		init_paging_dummy_people(5);
		
	}
}

function changeTopStuffView(id){
	if(id == 'random'){
		init_paging_top_stuff_global_today();
		init_paging_random_photos();
	}else if(id == 'myToday'){
		init_paging_top_stuff_in_my_network_today();
		init_paging_photo_top_in_my_network_today();
	}else if(id == 'wholeToday'){
		init_paging_top_stuff_global_today();
		init_paging_photo_top_global_today();
	}
}

function changeTopPhotoView(id){
	if(id == 'myToday'){
		init_paging_photo_top_in_my_network_today();
	}else if(id == 'wholeToday'){
		init_paging_photo_top_global_today();
	}else if(id == 'myMonth'){
		init_paging_photo_top_in_my_network_month();
	}else if(id == 'wholeMonth'){
		init_paging_photo_top_global_month();
	}else{
		//init_paging_photo_top_in_group_today();
	}
}
function changeTopWebLinkView(id){
	if(id == 'myToday'){
		init_paging_weblink_top_in_my_network_today();
	}else if(id == 'wholeToday'){
		init_paging_weblink_top_global_today();
	}else if(id == 'myMonth'){
		init_paging_weblink_top_in_my_network_month();
	}else if(id == 'wholeMonth'){
		init_paging_weblink_top_global_month();
	}else{
		//init_paging_weblink_top_in_group_today();
	}
}
function changeTopVideoView(id){
	if(id == 'myToday'){
		init_paging_video_top_in_my_network_today();
	}else if(id == 'wholeToday'){
		init_paging_video_top_global_today();
	}else if(id == 'myMonth'){
		init_paging_video_top_in_my_network_month();
	}else if(id == 'wholeMonth'){
		init_paging_video_top_global_month();
	}else{
		//init_paging_video_top_in_group_today();
	}
}

function timeoutAndClosePopup(){
	setTimeout('closePopupWindow()',1000);
}
function timeoutAndClosePopup(time){
	setTimeout('closePopupWindow()',time);
}

function refreshParentWindow(url) {
	try{					
		opener.top.mainframe.siteContent.location.href=url;
	}catch(err){
		try{					
			opener.top.mainframe.location.href=url;
		}catch(err){
		}
	}
}

function refreshParentAndClosePopup(url) {
	refreshParentWindow(url);
	closePopupWindow();
}

function showHideTable(id){
    var tbl = document.getElementById(id);
    var browserName=navigator.appName; 
	if(tbl.style.display=='none'){
	      if (browserName=="Microsoft Internet Explorer"){
    		tbl.style.display='inline';
 		 }else{
   			 tbl.style.display='table';
  		}
	}else{
	    tbl.style.display='none';
	}
}

function changeImage(beforeId, afterId){
	 var before = document.getElementById(beforeId);
	 var after = document.getElementById(afterId);
		before.style.display='none';
		after.style.display='inline';
}

//************************ ADD IMAGES AND FILES TO PRIVATE MESSAGE ****************

var mediaRowInsertIndex = 0;
var imageRowInsertIndex = 1;

function addMediaTableRowPrivateMessage(id, name) {
		if ((id != null) && (id != "") && (name != null) && (name != "")) {
			var editPrivateMessageTable = document.getElementById("fileTable"); 
		    var newRow = editPrivateMessageTable.insertRow(mediaRowInsertIndex);
		    var newCell = newRow.insertCell(0);
		    var html = "";
		    html = "<a onclick=\"deleteMediaPrivateMessage('messageEditMediaRow" + id + "'," + id + ")\"><img src=\"images/delete.png\" alt=\"<bean:message key='button.delete'/> \"title=\"<bean:message key='button.delete'/>\" width=\"10\" height=\"10\"></a>&nbsp;&nbsp;<a href='#' class='BLUE_SMALL_LINK' onclick=\"javascript:executeAction('downloadSparcFile.do', '', 'sparc_file_id', '" + id + "')\">" + name + "</a>";
			newCell.innerHTML = html;
			newRow.id = 'messageEditMediaRow' + id;
			imageRowInsertIndex += 1;
			mediaRowInsertIndex += 1;
		}
	}

	function addImageTableRowPrivateMessage(id, name, fullPath) {
		if ((id != null) && (id != "")) {
			var editPrivateMessageTable = document.getElementById("fileTable"); 
		    var newRow = editPrivateMessageTable.insertRow(imageRowInsertIndex);
		    var newCell = newRow.insertCell(0);
		    var html = "";
		    html = "<a onclick=\"deleteImagePrivateMessage('messageEditImageRow" + id + "'," + id + ")\"><img src=\"images/delete.png\" alt=\"<bean:message key='button.delete'/> \"title=\"<bean:message key='button.delete'/>\" width=\"10\" height=\"10\"></a>&nbsp;&nbsp;" 
		    		+ "<a style=\"cursor: pointer\" onClick=\"javascript:openWindowCentered('viewPhoto.do?imageId=" + id + "','',640,640,'location=no,status=no,toolbar=no,menubar=no')\" >"
  				 	+ "<img src=\""+fullPath+"\" width=\"25\" height=\"25\">"
			  		+ "</a>&nbsp;"
			  		+ "<a class=\"NAVIGATION_A\" >"+name+"</a>";
			newCell.innerHTML = html;
			newRow.id = 'messageEditImageRow' + id;
			imageRowInsertIndex += 1;
		}
	}

	function addPhotoFromPrivateMessage(id, name, fullPath){
		photoIds = document.forms.sendMessageForm.photoIds;
		if (addFromPrivateMessage(id, photoIds) == true){
			addImageTableRowPrivateMessage(id, name, fullPath);
		}
	}

	function addFileFromPrivateMessage(id, name) {
		var mediaIds = document.forms.sendMessageForm.mediaIds;
		if (addFromPrivateMessage(id, mediaIds) == true){
			addMediaTableRowPrivateMessage(id, name);
		}
	}

	function addFromPrivateMessage(id, ids){
		if (ids.value != null){
			var exists = false;
			var temp = new Array();
			temp = ids.value.split(',');
			for (x in temp){
				if (temp[x]==id){
					exists = true;
				}
			}
			if (exists == false){
				ids.value = ids.value +  ',' + id;
				return true;
			} else {return false;}
		} else {
			ids.value = '' + id;
			return true;
		}
	}
		
	function deleteImagePrivateMessage(id, idValue){
		var photoIds = document.forms.sendMessageForm.photoIds;
		deleteRowX(id, photoIds, idValue);
		imageRowInsertIndex -= 1;
	}
	
	function deleteMediaPrivateMessage(id, idValue){
		var mediaIds = document.forms.sendMessageForm.mediaIds;
		deleteRowX(id, mediaIds, idValue);
		imageRowInsertIndex -= 1;
		mediaRowInsertIndex -= 1;
	}
	
	function deleteRowX(id, ids, idValue){
		var row = document.getElementById(id);
		if (row != null) {
			row.parentNode.removeChild(row);
		}
		var temp = new Array();
		var valStr = ids.value.toString();
		temp = valStr.split(',');
		for (x in temp){
			if (temp[x] == idValue){
				temp.splice(x,1);
			}
		}
		ids.value = temp.join(',');
	}
	
	function changeRefresh(object){
		object.src='images/r_refresh_blue.png';
	}
	function changeSetting(num){
	
	for(var i=0; i < 4; i++){
		if(i == num){
			document.getElementById('settingText'+i).style.visibility='visible';
		}else{
			document.getElementById('settingText'+i).style.visibility='collapse';
		}
	}
	switch(num){
		case 0: 
			document.forms.templateType.custom.value='true';
			document.forms.templateType.template[0].checked='true';
			//document.forms.settingForm.submit();
			break;
		case 1:
			document.forms.templateType.ghost.value='true';
			document.forms.templateType.submit();
			break;
		case 2:
			document.forms.templateType.enhanced.value='true';
			document.forms.templateType.submit();
			break;
		case 3:
			document.forms.templateType.normal.value='true';
			document.forms.templateType.submit();
			break;
	}
}

function checkPageToNavigate(pageToNavigate, pageQuantity){
	if(pageToNavigate < 1){
		return 1;
	}
	if(pageToNavigate <= pageQuantity){
		return pageToNavigate;
	}
	return pageQuantity;
}
