    function openWindow(url, w, h) {
        var windowprops = "width=" + w + ",height=" + h +",,left=10,top=10,scrollbars=no,status=yes,toolbar=no,location=no,directories=no,resizable=yes";
          popup = window.open(url,'newWin',windowprops);
          popup.focus();
           } 
        
	function openPicture(pic,w,h) {
     
		var windowprops = "left=160,top=100,scrollbars=no,status=yes,toolbar=no,location=no,directories=no,resizable=yes,width=" + w + ",height=" + h;
          
		picture = window.open('','newPicture',windowprops);
		picture.close();
        picture = window.open('','newPicture',windowprops);  
        picture.focus();
        
		picture.document.write("<html><head><title>Picture<\/title><\/head><body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>")
		picture.document.writeln("<img src=" + pic + " width=" + w + " height=" + h + ">")
		picture.document.write("<\/body><\/html>")
	}                
 
function validateEmail(email)
{
	if ((email.length < 3) || (email.length > 50) || 
			(email.charAt(0) == '@') || (email.charAt(email.length-1) == '@') || 
			(email.charAt(0) == '.') || (email.charAt(email.length-1) == '.') || 
			(email.indexOf('.') == -1) || (email.indexOf('@') == -1) ||
			(email.indexOf('@') != email.lastIndexOf('@')) || 
			(email.indexOf(' ') > 0) || (email.indexOf('?') > 0) || (email.indexOf('..') > 0)
			)
	{
		return false;
	}
	else
	{
		return true;
	}
} 
 
 
function showdate()
{
	
		// Determine the current date and display it
   	var today = new Date();
   	var day = today.getDay();
   	var date = today.getDate();
   	var month = today.getMonth();
   	var year = today.getFullYear();
   	
   		//January,February,March,April,May,June,July,August,September,October,November,December
   	if (month == 0) {month='Jan'};
   	if (month == 1) {month='Feb'};
   	if (month == 2) {month='Mar'};
   	if (month == 3) {month='Apr'};
   	if (month == 4) {month='May'};
   	if (month == 5) {month='Jun'};
   	if (month == 6) {month='Jul'};
   	if (month == 7) {month='Aug'};
   	if (month == 8) {month='Sept'};
   	if (month == 9) {month='Oct'};
   	if (month == 10) {month='Nov'};
   	if (month == 11) {month='Dec'};
   
   	if (day == 0) {day='Sunday'};
   	if (day == 1) {day='Monday'};
   	if (day == 2) {day='Tuesday'};
   	if (day == 3) {day='Wednesday'};
   	if (day == 4) {day='Thursday'};
   	if (day == 5) {day='Friday'};
   	if (day == 6) {day='Saturday'};
   
   if ( document.all ) {
		document.write ('<span class="small">&nbsp;&nbsp;' + day + ', ' + month +  ' ' + date + ', ' + year + '</span>');
	} else {
		document.write ('<span class="smallNC">&nbsp;&nbsp;' + day + ', ' + month +  ' ' + date + ', ' + year +  '</span>');
	}
   
   
}

function switchClass(obj,strClassName) {
		obj.className	= strClassName;
	}
	
function gotoURL(strUrl) {
		location = strUrl;
	}

function copyrightYear(startYear)
	{
		d = new Date();
		
		if (startYear != d.getFullYear())
			{
			return startYear + " - " + d.getFullYear();
			}
		else
			{
			return startYear;
			}
	}
	
	// Show current date in format "Nov 15, 2003".		
function nsDate()
{
		// Get today's date.
	var sDate = new Date();
	var sToday = "";
	
		// Array with months.
	var aMonths = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	
		// Get current month.
	var iMonth = sDate.getMonth();
		
		// Get current hour,minute,second.
	var iHours   = sDate.getHours();
	var iMinutes = sDate.getMinutes();
	var iSeconds = sDate.getSeconds();
			
	sToday = "";
		// Get today's date string.
	sToday += aMonths[iMonth] + " ";
	sToday += sDate.getDate() + ", ";
	sToday += sDate.getFullYear() + " ";

		// Display the date on the screen.
	document.write("<b>"+sToday+"</b>");	
}

	// Get the current date in format "Nov 15, 2003  12:53:23 pm".
function today()
{
	var ie4=document.all;
    var ns4=document.layers;
    var ns6=document.getElementById&&!document.all;
    	
		// Get today's date.
	var sDate = new Date();
	var sToday = "";
	
		// Array with months.
	var aMonths = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	
		// Get current month.
	var iMonth = sDate.getMonth();
		
		// Get current hour,minute,second.
	var iHours   = sDate.getHours();
	var iMinutes = sDate.getMinutes();
	var iSeconds = sDate.getSeconds();
	
		// If iHour > 12.
	if(iHours>12)
		iHours = iHours - 12;
	
	if(iMinutes < 10)
		iMinutes = "0" + iMinutes;
		
	if(iSeconds < 10)
		iSeconds = "0" + iSeconds;
	
	sToday = "";
		// Get today's date string.
	sToday += aMonths[iMonth] + " ";
	sToday += sDate.getDate() + ", ";
	sToday += sDate.getFullYear() + " ";
	
	sToday += iHours + ":";
	sToday += iMinutes + ":" ;
	sToday += iSeconds; 

	
		// Set am or pm
	if(sDate.getHours() < 12)
		sToday += " am ";
	else
		sToday += " pm ";
	
		// Display the date on the screen.
	
		// Write the clock to the layer:
	if (ns4) 
	{
		return;
	} 
	else 
		if (ie4) 
		{
			document.getElementById("LiveClock").innerHTML = "<b>"+sToday+"</b>";
		}	 
		else 
			if (ns6)
			{
				document.getElementById("LiveClock").innerHTML = "<b>"+sToday+"</b>";
            }            
	
		setTimeout("today()",1000);
		//window.setInterval(today(),100);
}	


function openWindow2(url,wname,w,h,props) 
{
	var winTop=(screen.height-h)/2;
	var winLeft=(screen.width-w)/2;
	
	var windowprops = "width=" + w + ",height=" + h +",left="+winLeft+",top="+winTop+","+props;
	return window.open(url,wname,windowprops);
}


// End hiding script from old browsers -->

/*
* change image source
* 
* @param string mainImageId - image id
* @param string imageUrl - url of the image that have to be put as a sourse to original image
*/
function changeMainImage(mainImageId, imageUrl) {
	var mainImage = document.getElementById(mainImageId);
	if (mainImage) {
		// change image source to imageUrl
		mainImage.src = imageUrl;
	}
}


function disableEdit(sel)
{
	return;
	
	if((sel.value == 225)||(sel.value == 100)||(sel.value == 38)||(sel.value == 245))
	{				
		if(sel.value == 225)
		{	
			document.ProfileForm.USAStates.disabled = false;
			document.ProfileForm.IndiaStates.disabled = true;
			document.ProfileForm.UKStates.disabled = true;
			document.ProfileForm.CanadaStates.disabled = true;
			document.ProfileForm.ZIP.disabled = false;
		}
		
		if(sel.value == 100)
		{
			document.ProfileForm.IndiaStates.disabled = false;
			document.ProfileForm.USAStates.disabled = true;
			document.ProfileForm.UKStates.disabled = true;
			document.ProfileForm.CanadaStates.disabled = true;
			document.ProfileForm.ZIP.disabled = true;
		}
		
		if(sel.value == 38)
		{
			document.ProfileForm.IndiaStates.disabled = true;
			document.ProfileForm.USAStates.disabled = true;
			document.ProfileForm.UKStates.disabled = true;
			document.ProfileForm.CanadaStates.disabled = false;
			document.ProfileForm.ZIP.disabled = true;
		}
		
		if(sel.value == 245)
		{
			document.ProfileForm.IndiaStates.disabled = true;
			document.ProfileForm.USAStates.disabled = true;
			document.ProfileForm.UKStates.disabled = false;
			document.ProfileForm.CanadaStates.disabled = true;
			document.ProfileForm.ZIP.disabled = true;
		}
		
	}
	else
	{
		document.ProfileForm.USAStates.disabled = true;
		document.ProfileForm.IndiaStates.disabled = true;
		document.ProfileForm.UKStates.disabled = true;
		document.ProfileForm.CanadaStates.disabled = true;
		document.ProfileForm.ZIP.disabled = true;	
	}	
}


// End hiding script from old browsers -->

function setBackground(el, image){
	if(el.value != '') 
		el.style.background = '#fff'; 
	else 
		el.style.backgroundImage = 'url('+image+')';
}

function changePhoto(reverse, dontChange)
{
	var img = document.getElementById('memberPhoto');
	
	if(!dontChange)
	{
		if(reverse)
		{
			if(window.currPhoto == 0)
				window.currPhoto = window.memberPhotos.length-1;
			else
				window.currPhoto--;
		}
		else
		{
			if(window.currPhoto == window.memberPhotos.length-1)
				window.currPhoto = 0;
			else
				window.currPhoto++;
		}
	}
	
		
	img.src = window.memberPhotos[window.currPhoto][0];
	
	img.style.width = window.memberPhotos[window.currPhoto][1]+'px';
	img.style.height = window.memberPhotos[window.currPhoto][2]+'px';
}

function changePhotoToID(id)
{
	window.currPhoto = id;
	changePhoto(false, true);
}

/*
function changeTab(id)
{
	if(id === false)
	{
		alert('You must first complete previous profile steps.');
		
		return false;
	}
	
	var el = null;
	var i = 0;
	
	while(el = document.getElementById('tabs['+i+']'))
	{
		if(i == id)
		{
			el.className = el.className+' selectedTab';
			
			document.getElementById('tabsContent['+i+']').style.display = 'block';
		}
		else
		{
			var tmp = el.className.split(' ');
			el.className = tmp[0];
			
			document.getElementById('tabsContent['+i+']').style.display = 'none';
		}
		
		i++;
	}
}
*/
function changeTab(id)
{
	if(id === false)
	{
		alert('You must first complete previous profile steps.');
		
		return false;
	}
	
	var el = null;
	var i = 0;
	
	while(el = document.getElementById('tabs['+i+']'))
	{
		if(i == id)
		{
			el.className = 'current';
			
			document.getElementById('tabsContent['+i+']').style.display = 'block';
		}
		else
		{
			el.className = "";
			
			document.getElementById('tabsContent['+i+']').style.display = 'none';
		}
		
		i++;
	}
}

function expandTopTabMenu(id)
{
	var menu = document.getElementById('topTabMenu['+id+']');
	
	menu.style.display = 'block';
}

var topMenuCollapser = [];
function colapseTopTabMenu(id)
{
	topMenuCollapser[id] = setTimeout("document.getElementById('topTabMenu["+id+"]').style.display = 'none';", 1000);
}

function cancelColapseTopTabMenu(id)
{
	clearTimeout(topMenuCollapser[id]);
}

function countCharacters(field, counterID)
{
	var counter = document.getElementById(counterID);
	
	var remaining = 4000-field.value.length;
	
	if(remaining < 1)
	{
		alert('You have exceeded the length limit for this field.');
		
		field.value = field.value.substr(0, 4000);
		
		counter.style.color = 'red';
		counter.innerHTML = 'no';
		
		return false;
	}
	
	var color = 'green';
	
	if(remaining <= 1000)
		color = 'red';
	else if(remaining > 1000 && remaining <= 2000)
		color = '#ff5e00';
	else if(remaining > 2000 && remaining <= 3000)
		color = '#ffa500';
		
	
	counter.style.color = color;
	counter.innerHTML = remaining;
}

function changeParentMenuClass(id, hover)
{
	var el = document.getElementById('topTabMenu['+id+']');
	
	if(el.className == 'selectedTabMenu')
		return;
	
	el.className = hover ? 'ddhover' : '';

}

function validateZIP(zip, qs, editProfile)
{
	if(document.getElementById('country'))
		var country = document.getElementById('country').value;
	else
		var country = document.getElementById('yourLocationCountry').value;
	
	if(country == 0)
	{
		if(document.getElementById('zipBox'))
		{
			document.getElementById('zipBox').style.display = 'none';
			document.getElementById('noZipBox').style.display = 'none';
		}
	}
	else if(country != 225 && country != 38)
	{
		if(document.getElementById('zipBox'))
		{
			document.getElementById('zipBox').style.display = 'none';
			document.getElementById('noZipBox').style.display = editProfile ? 'table-row' : 'block';
		}
	}
	else
	{
		if(document.getElementById('zipBox'))
		{
			document.getElementById('noZipBox').style.display = 'none';
			document.getElementById('zipBox').style.display = editProfile ? 'table-row' : 'block';
		}
				
		if(document.getElementById('ZIP'))
		{
			document.getElementById('ZIP').readOnly = false;
			
			if(document.getElementById('milesOfBox'))
			{
				document.getElementById('milesOfBox').style.display = 'block';
				document.getElementById('nearCityBox').style.display = 'none';
			}
		}
		
		var statusEl = document.getElementById('cityAndState');
		
		var reUS = /^\d{5}$/;
		var reCA = /^\w{6}$/;
		
		var status = '';
		var color = 'red';
		
		if(country != 0)
		{
			if(reUS.test(zip))
			{
				status = 'validating...';
				color = '#f82';
				
				isValidZIP(zip, qs);
			}
			else if(reCA.test(zip))
			{
				status = 'validating...';
				color = '#f82';
				
				isValidZIP(zip, qs);
			}
			else
			{
				status = 'Please enter valid zipcode.';
				color = '#a00';
				
				zipIsValid = false;
			}
		}
		else
		{
			if(!qs)
			{
				status = 'Please select country.';
				status = '';
				color = '#a00';
				
				zipIsValid = false;
			}
		}
		
		statusEl.style.color = color;
		statusEl.innerHTML = status;
	}	
}

function clearZIPSearch(el)
{
	zipIsValid = false;
	
	if(el.value != 225 && el.value != 38)
	{
		if(document.getElementById('miles'))
		{
			document.getElementById('miles').value = '';
			//document.getElementById('miles').readOnly = true;
		}
		
		if(document.getElementById('cityAndState'))
			document.getElementById('cityAndState').innerHTML = '';
		
		document.getElementById('ZIP').value = '';
		document.getElementById('ZIP').readOnly = true;
		
		if(document.getElementById('milesOfBox'))
		{
			document.getElementById('milesOfBox').style.display = 'none';
			document.getElementById('nearCityBox').style.display = el.value != 0 ? 'block' : 'none';
		}
	}
	else
	{
		//document.getElementById('miles').readOnly = false;
		//document.getElementById('ZIP').readOnly = '';
	}
}

function isValidZIP(zip, qs)
{
	window.zipIsValid = false;
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4)
		{
			if(httpHndl.status == 200)
			{
				var statusEl = document.getElementById('cityAndState');
				
				var status = qs ? 'That zipcode is not in our database, please use another valid zipcode' : 'Unknown zipcode!<br /><small>Please enter a valid zipcode of a city near you.</small>';
				
				if(document.getElementById('btnValidateZip'))
					document.getElementById('btnValidateZip').src = document.getElementById('btnValidateZip').src.replace('btn-zipcode-validated.gif', 'btn-validate.gif');
				
				var color = 'red';
				
				if(httpHndl.responseText.substr(0, 1) == '#')
				{
					status = httpHndl.responseText.substr(1, httpHndl.responseText.length-1);
					color = '#0a0';
					
					window.zipIsValid = true;
					
					if(document.getElementById('btnValidateZip'))
						document.getElementById('btnValidateZip').src = document.getElementById('btnValidateZip').src.replace('btn-validate.gif', 'btn-zipcode-validated.gif');
				}
				
				statusEl.style.color = color;
				statusEl.innerHTML = status;
			}
		}
	}
		
	if(document.getElementById('country'))
		var country = document.getElementById('country').value == 225 ? 1 : 2;
	else
		var country = document.getElementById('yourLocationCountry').value == 225 ? 1 : 2;
	
	httpHndl.open("GET", "/members/validatezip.php?dontcache="+Math.random()+"&zip="+zip+"&country="+country, true);
	httpHndl.send(null);
}

function httpGetObject()
{
	var req;
	
	if(window.XMLHttpRequest && !(window.ActiveXObject))
	{
		try 
		{
			req = new XMLHttpRequest();
		} 
		catch(e)
		{
			req = false;
		}
	} 
	else if(window.ActiveXObject)
	{
		try 
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch(e)
		{
			try 
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(e)
			{
				req = false;
			}
		}
	}
	
	return req;
}

function setAvailableCastes(religionEl, isSearchOption)
{
	var religion = religionEl.value;
	
	var el = document.getElementById('caste');
	
	var i = 0;
	for(i = el.options.length-1; i >= 0 ;i--)
	{
		el.remove(i);
	}
	
	if(!religion)
	{
		addOption(el, window.defaultOption, '');
	}
	else 
	{	
		if(isSearchOption)
			addOption(el, window.defaultOption, '-1');
		
		if(religionCastes[religion])
		{
			var castes = religionCastes[religion];
			for(i in castes)
			{
				addOption(el, castes[i], i);
			}
		}
		else
		{
			var text = religionEl.options[religionEl.selectedIndex].text;
			
			addOption(el, text, 0);
			addOption(el, 'Other', '');
		}
	}
}

function addOption(selectEl, text, value)
{
	var opt = document.createElement('option');
	opt.text = text;
	opt.value = value;
	selectEl.options.add(opt);
}

function minCountCharacters(el, field, minChars)
{
	var len = el.value.length;
	var status = document.getElementById(field+'Status');
	var counter = document.getElementById(field+'Count');
	
	if(len < minChars)
	{
		if(status.innerHTML.indexOf('You') == -1)
		{
			status.innerHTML = '(You must enter at least <span id="'+field+'Count" style="color: red"></span> more characters)';
			var counter = document.getElementById(field+'Count');
		}

		counter.style.color = 'red';
		counter.innerHTML = parseInt(minChars-len);
	}
	else
	{
		if(status.innerHTML.indexOf('You') != -1)
		{
			status.innerHTML = '(<span id="'+field+'Count"></span> characters remaining)';
			var counter = document.getElementById(field+'Count');
		}
		
		var remaining = 4000-len;
		
		if(remaining < 1)
		{
			alert('You have exceeded the length limit for this field.');
			
			el.value = el.value.substr(0, 4000);
			
			counter.style.color = 'red';
			counter.innerHTML = 'no';
			
			return false;
		}
		
		var color = 'green';
		
		if(remaining <= 1000)
			color = 'red';
		else if(remaining > 1000 && remaining <= 2000)
			color = '#ff5e00';
		else if(remaining > 2000 && remaining <= 3000)
			color = '#ffa500';
			
		
		counter.style.color = color;
		counter.innerHTML = remaining;
	}
}

/*
var lastExpanded = null;
function collapseExpandGroup(el)
{
	var parent = el.parentNode;
	
	parent.className = parent.className == 'open' ? '' : 'open';
	
	for(i in parent.childNodes)
	{
		var child = (parent.childNodes[i]);
		
		if(child.className == 'advancedTable')
		{
			child.style.display = child.style.display == 'none' ? 'block' : 'none';
		}
	}
}
*/

var lastExpanded = null;
function collapseExpandGroup(id)
{
	var el = document.getElementById('optionsContainer['+id+']');
	
	el.style.display = el.style.display == 'none' ? 'block' : 'none';
	
	if(lastExpanded != null && lastExpanded != id)
	{
		document.getElementById('optionsContainer['+lastExpanded+']').style.display = 'none';
	}
	
	lastExpanded = id;
}

function optionChanged(id)
{
	var opt, i = 0;
	var active = [];
	var enabledReligions = [];
	while(opt = document.getElementById(id+'['+i+']'))
	{
		if(opt.type == 'checkbox' && opt.checked == true)
		{
			if(id == 'religion')
			{
				enabledReligions[enabledReligions.length] = opt.value;				
			}
			
			var len = active.length;
			
			active[len] = [];
			active[len]['text'] = document.getElementById('label_'+opt.id).innerHTML;
			active[len]['id'] = opt.id;
		}
		
		i++;
	}
	
	if(id == 'religion')
	{
		showEnabledReligions(enabledReligions);
	}
	
	document.getElementById(id+'_any').checked = !active.length;
	
	if(id == 'religion')
		optionAnyChanged(id, !active.length);
	
	showSelectedOptions(id, active);
}


function showEnabledReligions(enabledReligions)
{
	var enabledCastes = [];
	for(i in enabledReligions)
	{
		if(castesByReligion[enabledReligions[i]])
		{
			for(j in castesByReligion[enabledReligions[i]])
			{
				enabledCastes[enabledCastes.length] = castesByReligion[enabledReligions[i]][j];
			}
		}
	}
	
	var opt, c = 0;
	var active = [];
	while(opt = document.getElementById('caste['+c+']'))
	{
		//alert(opt.type+" :: "+opt.value+" :: "+in_array(opt.value, enabledCastes)+" :: "+opt.checked);return;
		
		if(opt.type == 'checkbox')
		{
			if(in_array(opt.value, enabledCastes))
			{
				opt.parentNode.style.display = 'table-cell';
			}
			else
			{
				opt.parentNode.style.display = 'none';
				opt.checked = false;
			}
			
			if(opt.checked)
			{
				var len = active.length;
				
				active[len] = [];
				active[len]['text'] = document.getElementById('label_'+opt.id).innerHTML;
				active[len]['id'] = opt.id;
			}
		}
		
		c++;
	}
	
	
	showSelectedOptions('caste', active);
	
	
	var opt, i = 0;
	while(opt = document.getElementById('casteRow['+i+']'))
	{
		var c = 0;
		for(j in opt.childNodes)
		{
			if(opt.childNodes[j].width == '50%' && opt.childNodes[j].style.display == 'none')
			{
				c++;
			}
		}
		
		if(opt.style)
			opt.style.display = c == 2 ?  'none' : 'table-row';
		
		i++;
	}
}

function showSelectedOptions(group, active)
{
	var details = document.getElementById('details_'+group);
	
	if(!active.length)
	{
		details.style.display = 'none';
	}
	else
	{
		details.style.display = 'block';
		
		var list = document.getElementById('list_'+group);
		
		var toRemove = null;
		while(list.lastChild)
		{
			list.removeChild(list.lastChild);
		}
		
		for(i in active)
		{
			var li = document.createElement('li');
			li.innerHTML = active[i]['text'];
			li.id = 'list_'+active[i]['id'];
			li.onclick = removeOption;

			list.appendChild(li);
		}
	}
}

var removeOption = function()
{
	var id = this.id.substr(5, this.id.length-5);
	
	var el = document.getElementById(id);
	
	el.checked = false;
	
	var name = el.name.substr(0, el.name.length-2);
	
	optionChanged(name);
}

function optionAnyChanged(name, checked)
{
	if(!checked)
		return false;
	
	var opt, c = 0;
	while(opt = document.getElementById(name+'['+c+']'))
	{
		if(opt.type == 'checkbox')
			opt.checked = false;
		
		c++;
	}
	
	showSelectedOptions(name, []);
	
	if(name == 'religion')
	{
		var enabledReligions = [];
		for(i in castesByReligion)
		{
			enabledReligions[enabledReligions.length] = i;
		}
		
		showEnabledReligions(enabledReligions);
	}
}

function heightChanged()
{
	var from = document.getElementById('heightFrom');
	var to = document.getElementById('heightTo');
	
	if(!from || !to)
		return false;
	
	if(from.value != '' || to.value != '')
	{
		document.getElementById('details_height').style.display = 'block';
		
		var list = document.getElementById('list_height');
		list.innerHTML = '<li onclick="removeHeightCriteria()">'+
		'From '+from.options[from.selectedIndex].innerHTML+' to '+to.options[to.selectedIndex].innerHTML+
		'</li>';
	}
	else
	{
		document.getElementById('details_height').style.display = 'none';
	}
}

function removeHeightCriteria()
{
	document.getElementById('details_height').style.display = 'none';
	
	var from = document.getElementById('heightFrom');
	var to = document.getElementById('heightTo');
	
	from.selectedIndex = 0;
	to.selectedIndex = parseInt(to.options.length-1);
}

function optionalInputChanged(el, focus)
{
	if(!focus && el.value == '')
	{
		el.style.fontStyle = 'italic';
		el.value = 'optional  ';
	}
	else if(el.value == 'optional   ')
	{
		el.style.fontStyle = 'normal';
		el.value = '';
	}
	else
	{
		el.style.fontStyle = 'normal';
	}
}

function in_array(val, arr)
{
	for(i in arr)
	{
    	if(arr[i] == val)
    	{
    		return true;
        }
    }
    
    return false;
}


var lastCRExpanded = null;
function collapseExpandCustomizeResults(id)
{
	var el = document.getElementById('customizeResults['+id+']');
	
	el.style.display = el.style.display == 'none' ? 'block' : 'none';
	
	if(lastCRExpanded != null && lastCRExpanded != id)
	{
		document.getElementById('customizeResults['+lastCRExpanded+']').style.display = 'none';
	}
	
	lastCRExpanded = id;
}

function quickSearchFormSubmitted(form)
{
	var country = document.getElementById('yourLocationCountry').value;
	
	if(document.getElementById('yourLocationCountry').value != 225 && document.getElementById('yourLocationCountry').value != 38)
	{
		var selected = distanceRegionAndCitySelected();
		
		if(selected !== true && selected > 0 && selected < 8)
		{
			alert('Please select distance, region and city');
			
			return false;
		}
	}
	else
	{
		if(!zipIsValid)
		{
			alert('That zipcode not in our database, please use another valid zipcode');
			
			return false;
		}
	}
	
	return true;
}

var memberVerified = false;
function verifyMember(button, isPopup, checkGold)
{
	var checkGold = checkGold || null;
	
	var toMember = isPopup ? document.getElementById('cmpToMember') : document.getElementById('toMember');
	
	var re = /^\w*$/;
	if(!toMember.value)
	{
		alert("Please enter username.");
		
		return false;
	}
	else if(toMember.value.length < 4 || toMember.value.length > 14 || !re.test(toMember.value))
	{
		alert("Please enter valid username");
		
		return false;
	}
	
	if(isPopup)
		document.getElementById('cmpVerifiedMemberBox').innerHTML = 'verifying...';
	else
		document.getElementById('verifiedMemberBox').innerHTML = 'verifying...';
	
	memberVerified = false;
	
	
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4)
		{
			if(httpHndl.status == 200)
			{
				var msg = httpHndl.responseText;
				var isFiltered = httpHndl.responseText.indexOf('<script type="text/javascript"') == -1 ? false : true;
				
				if(httpHndl.responseText == 'There is no member with that username.' || isFiltered)
				{
					memberVerified = false;
					button.src = '../images/btn_verify_red.gif';
					
					if(isFiltered)
					{
						showFilteredMessageBox(true);
						setTimeout("showFilteredMessageBox(false)", 5000);
					}
				}
				else if(httpHndl.responseText == 'Already gold')
				{
					memberVerified = false;
					button.src = '../images/btn_verify_red.gif';
					
					msg = '<b>'+toMember.value+'</b> is already a gold member!';
				}
				else
				{
					if(document.getElementById('giftToMember'))
						document.getElementById('giftToMember').value = toMember.value;
					
					memberVerified = true;
					button.src = '../images/btn_verify_green.gif';
				}
				
				if(isPopup)
					document.getElementById('cmpVerifiedMemberBox').innerHTML = msg;
				else
					document.getElementById('verifiedMemberBox').innerHTML = msg;
			}
		}
	}
	
	httpHndl.open("GET", "verifymember.php?dontcache="+Math.random()+"&username="+toMember.value+(checkGold ? "&checkGold="+checkGold : ''), true);
	httpHndl.send(null);
	
	if(isPopup)
		showMembersConversation(toMember.value);
}

function memberNotVerified()
{
	memberVerified = false;
	
	document.getElementById('verifiedMemberBox').innerHTML = '';
	document.getElementById('btnVerify').src = '../images/btn_verify_red.gif';
	
	//if(document.getElementById('giftToMember'))
//		document.getElementById('giftToMember').value = '';
}


var uNameAvailable = false;
function checkUsernameAvailability(username, statusEl)
{
	var id = statusEl ? statusEl : 'unameAvailability';
	
	var status = document.getElementById(id);
	
	var re = /^[a-zA-Z0-9]*$/
	if(username.length < 5 || !re.test(username))
	{
		//alert(username+" :: "+(username.length < 5)+" || "+(!re.test(username)));
		status.style.color = '#d00';
		
		if(username.indexOf(' ') != -1)
			status.innerHTML = 'No spaces allowed';
		else
			status.innerHTML = 'Invalid username';
		
		if(statusEl == 'statusUsername')
			document.getElementById('boxUsername').className = 'validateField invalid';
		
		uNameAvailable = false;
		
		return false;
	}
	
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4)
		{
			if(httpHndl.status == 200)
			{
				if(httpHndl.responseText == 1)
				{
					uNameAvailable = true;
					
					status.style.color = '#029e4d';
					status.innerHTML = 'AVAILABLE';
				}
				else
				{
					uNameAvailable = false;
					
					status.style.color = '#d00';
					status.innerHTML = 'IN USE, pick again';
				}
				
				if(statusEl == 'statusUsername')
					document.getElementById('boxUsername').className = 'validateField '+(httpHndl.responseText == 1 ? '' : 'in')+'valid';
			}
		}
	}
	
	httpHndl.open("GET", "/members/checkusername.php?dontcache="+Math.random()+"&username="+username, true);
	httpHndl.send(null);
}

function checkUsernameValidity(username)
{
	var status = document.getElementById('unameAvailability');
	
	var re = /^\w*$/;
	if(username.length < 5 || !re.test(username))
	{
		status.style.color = '#d00';
		
		if(username.indexOf(' ') != -1)
			status.innerHTML = 'No spaces allowed';
		else
			status.innerHTML = 'Invalid username';
	}
	else
	{
		status.innerHTML = '';
	}
}
	

function sendToAFriend(mID)
{
	var frMail = document.getElementById('frMail');
	var result = document.getElementById('sendToAFriendResult');
	
	var regEx = /^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$/;
	
	if(!frMail || !regEx.test(frMail.value))
	{
		result.style.color = 'red';
		result.innerHTML = 'Enter valid e-mail';
		
		return false;
	}
	
	result.style.color = '#e95';
	result.innerHTML = 'sending...';
	
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4)
		{
			if(httpHndl.status == 200)
			{
				if(httpHndl.responseText == 'Sent')
				{
					result.style.color = 'green';
					result.innerHTML = httpHndl.responseText;
					frMail.value = 'Email';
				}
				else
				{
					result.style.color = 'red';
					result.innerHTML = 'Unable to send';
				}
			}
		}
	}
	
	httpHndl.open("GET", "sendtofriend.php?dontcache="+Math.random()+"&mID="+mID+"&recipient="+frMail.value, true);
	httpHndl.send(null);
}

function checkSubscriptionInput(isGift)
{
	if(isGift && !document.getElementById('giftToMember').value)
	{
		alert("Please choose a member to gift the membership to and verify his/her username.")
		
		return false;
	}
	
	if(document.getElementById('oneYear').checked == false && document.getElementById('sixMonths').checked == false && 
		document.getElementById('threeMonths').checked == false && document.getElementById('oneMonths').checked == false && 
		document.getElementById('sevenDays').checked == false)
	{
		alert("Please choose a subscription plan.");
		
		return false;
	}
	
	return true;
}

function wOpen(URL, w, h)
{
	var name = URL.substr(0, URL.indexOf('.'))+'_win';
	
	while(name.indexOf('-') != -1)
	{
		name = name.replace('-', '_');
	}
	
	window.open(URL, name, "width="+w+",height="+h+",left=100,top=100,scrollbars=no,status=yes,toolbar=no,location=no,directories=no,resizable=no");
}

function isValidEventPrice(el)
{
	var regEx = /^((\d+)|(\d+\.\d\d))$/;
	
	if(!regEx.test(el.value) && el.value.toLowerCase() != 'free')
	{
		alert('Please enter valid price.');
		el.focus();
		
		return false;
	}
	
	return true;
}

function validZipInput()
{
	var reUS = /^\d{5}$/;
	var reCA = /^\w{6}$/;

	if(!reUS.test(zip) && !reCA.test(zip))
	{
		alert('Please enter valid zipcode.');
	}
}

function monthChanged(value, yearID, dayID)
{
	var value = parseInt(value);
	var elDays = document.getElementById(dayID);
	var endDate = 0;
	
	if(!value || value == 1 || value == 3 || value == 5 || value == 7 || value == 8 || value == 10 || value == 12)
		endDate = 31;
	else if(value == 4 || value == 6 || value == 9 || value == 11)
		endDate = 30;
	else if(value == 2)
		endDate = (document.getElementById(yearID).value % 4) ? 28 : 29;
	
	elDays.length = 29;
	
	for(i = 29; i < endDate+1; i++)
	{
		var opt = document.createElement('option');
		opt.value = i;
		opt.text = i;
		opt.innerHTML = i;
		
		elDays.appendChild(opt);
	}
}

function yearChanged(year, monthID, dayID)
{
	var month = document.getElementById(monthID).value;
	var elDays = document.getElementById(dayID);
	
	if(month == 2)
	{
		monthChanged(2, year.id, dayID);
	}
}

function activateTextArea(el, defaultText, small)
{
	
	if(el.value == defaultText)
	{ 
		el.value = '';
		el.className = 'evFormTextarea'+(small ? 'Small' : '');
	}
}

function deActivateTextArea(el, defaultText, small)
{
	if(el.value == '') 
		el.value = defaultText;
	
	if(el.value == defaultText || el.value == '') 
		el.className = 'evFormTextarea'+(small ? 'Small' : '')+' defaultText';
	else
		el.className = 'evFormTextarea'+(small ? 'Small' : '');
}

function previewGoogleMap()
{
	var link = document.getElementById('eGoogleMap').value;
	
	if(!link)
	{
		alert("There's no link to preview.");
		
		return false;
	}
	else if(link.indexOf('http://') == -1 && link.indexOf('https://') == -1)
	{
		alert("Provided link is invalid.");
		
		return false;
	}
	
	window.open(link);
}

function previewBanner(path)
{
	var props = "width=500, height=500, left=100, top=100, scrollbars=no, status=yes, toolbar=no, location=no, directories=no, resizable=yes";
	window.open(path, '_blank', props);
}

function eventsValidateZIP(zip)
{
	zipIsValid = false;
	
	var statusEl = document.getElementById('zipValidation');
	
	var reUS = /^\d{5}$/;
	var reCA = /^\w{6}$/;
	
	var status = '';
	var color = 'red';
	
	if(reUS.test(zip))
	{
		status = 'validating...';
		color = '#f82';
		
		eventsIsValidZIP(zip, 1);
	}
	else if(reCA.test(zip))
	{
		status = 'validating...';
		color = '#f82';
		
		eventsIsValidZIP(zip, 2);
	}
	else
	{
		status = 'Please enter valid zipcode.';
		color = '#a00';
		
		zipIsValid = false;
	}
	
	statusEl.style.color = color;
	statusEl.innerHTML = status;
}

function eventsIsValidZIP(zip, country)
{
	window.zipIsValid = false;
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4)
		{
			if(httpHndl.status == 200)
			{
				var statusEl = document.getElementById('zipValidation');
				
				var status = 'That zipcode is not in our database, please use another valid zipcode';
				
				var color = 'red';
				
				if(httpHndl.responseText.substr(0, 1) == '#')
				{
					status = httpHndl.responseText.substr(1, httpHndl.responseText.length-1);
					color = '#0a0';
					
					window.zipIsValid = true;
				}
				
				statusEl.style.color = color;
				statusEl.innerHTML = status;
			}
		}
	}
	
	httpHndl.open("GET", window.validatorURL+"?dontcache="+Math.random()+"&zip="+zip+"&country="+country, true);
	httpHndl.send(null);
}

var carouselActive = false;

function moveCarousel(move, max)
{
	if(window.carouselActive)
		return false;
	
	var curr = parseInt(document.getElementById('eCarousel').style.left);
	
	if(!curr)
		curr = 0;
	
	if((move > 0 && curr == 0) || (move < 0 && curr*-1 == max-240) || max < 320)
		return;
	
	if(move > 0 && curr == -80)
		setArrowsStatus(true, false);
	else if((move < 0 && curr*-1 == max-320) || max < 320)
		setArrowsStatus(false, true);
	else
		setArrowsStatus(false, false);
	
	window.carouselActive = true;
	
	setOpacity(document.getElementById('eCarousel'), 50);
	
	for(i = 0; i < 11; i++)
	{
		setTimeout("document.getElementById('eCarousel').style.left = '"+(curr+(i*(move/10)))+"px';", i*50);
	}
	
	setTimeout("setOpacity(document.getElementById('eCarousel'), 100); carouselActive = false;", (i-1)*50);
}

function setArrowsStatus(left, right)
{
	setOpacity(document.getElementById('cArrowLeft'), (left ? 50 : 100));
	setOpacity(document.getElementById('cArrowRight'), (right ? 50 : 100));
}

function setOpacity(el, opacity) 
{
	if(typeof el === 'string')
	{
		el = document.getElementById(el);
	}
	
    el.style.opacity = (opacity / 100);
 	el.style.filter = "alpha(opacity="+opacity+")";
    el.style.MozOpacity = (opacity / 100);
    el.style.KhtmlOpacity = (opacity / 100);
}

function showEventPhoto(id, photo)
{
	document.getElementById('eventPhotoID').value = id;
	document.getElementById('eventPhotoBig').src = photo;
}

function eventMsgSubjectBlurred(el)
{
	if(el.value == '')
	{
		el.style.color = '#aaa';
		el.value = 'Subject';
	}
}

function eventMsgSubjectFocused(el)
{
	if(el.value == 'Subject')
	{
		el.style.color = '#000';
		el.value = '';
	}
}

function eventMsgMessageBlurred(el)
{
	if(el.value == '')
	{
		el.style.color = '#aaa';
		el.value = 'Message goes here...';
	}
}

function eventMsgMessageFocused(el)
{
	if(el.value == 'Message goes here...')
	{
		el.style.color = '#000';
		el.value = '';
	}
}


function showUserList(show)
{
	document.getElementById('confirmedMembersBox').style.display = show ? 'block' : 'none';
	
	if(!show)
		return false;
	
	window.scrollTo(0, 600);
	document.getElementById('sendTo').selectedIndex = 3;
}

function selectRecipients()
{
	var el = document.getElementsByName('selectedMembers[]');
	var ids = document.getElementById('recipientIDs');
	var names = document.getElementById('recipientNames');
	
	ids.value = '';
	names.value = '';
	
	for(i in el)
	{
		if(el[i].type == 'checkbox' && el[i].checked == true && el[i].value.indexOf('#') != -1)
		{
			var tmp = el[i].value.split('#');
			
			ids.value += tmp[0]+',';
			names.value += tmp[1]+',';
		}
	}
	
	ids.value = ids.value.substr(0, ids.value.length-1);
	names.value = names.value.substr(0, names.value.length-1);
	
	names.style.fontStyle = 'normal';
	
	showUserList(false);
}

function sendMessage()
{
	var subject = document.getElementById('eMsgSubject').value;
	var message = document.getElementById('eMsgMessage').value;
	
	if(document.getElementById('sendTo').value == 'Selected' && !document.getElementById('recipientIDs').value)
	{
		alert('Please select message recipients.');
		
		return false;
	}
	else if(subject == 'Subject')
	{
		alert('Please enter subject.');
		
		return false;
	}
	else if(message == 'Message goes here...')
	{
		alert('Please enter message.');
		
		return false;
	}
	
	if(document.getElementById('recipientIDs').value)
		var recipients = document.getElementById('recipientIDs').value;
	else
		var recipients = document.getElementById('recipientNames').value;
	
	var eventID = document.getElementById('eventID').value;
	var attachFlyer = document.getElementById('attachFlyer').checked ? 1 : 0;
	
	var testMail = document.getElementById('testEmail').value;
	
	var url = 'sendmessage.php?event='+eventID+'&recipients='+encodeURIComponent(recipients)+
	'&subject='+encodeURIComponent(subject)+'&message='+encodeURIComponent(message)+'&attachFlyer='+attachFlyer+
	'&testEmail='+encodeURIComponent(testMail)+'&noCache='+Math.random();
	
	var msgSender = getXMLHTTP();
	
	msgSender.onreadystatechange = function() 
   	{
    	if(msgSender.readyState == 4)
      	{
       		if(!msgSender.responseText)
       			messageSent();
       		else
       			alert("There was a problem sending your message.");
      	}
 	}
 	
 	msgSender.open('GET', url, true);
   	msgSender.send(null);	
}

function messageSent()
{
	alert('Your message has been sent.');
	
	document.getElementById('testMail').value = '';
	
	document.getElementById('sendTo').selectedIndex = 0;
	document.getElementById('recipientNames').style.fontStyle = 'italic';
	document.getElementById('recipientNames').value = 'Everyone';
	document.getElementById('recipientIDs').value = '';
	document.getElementById('eMsgSubject').value = 'Subject';
	document.getElementById('eMsgSubject').style.color = '#aaa';
	document.getElementById('eMsgMessage').value = 'Message goes here...';
	document.getElementById('eMsgMessage').style.color = '#aaa';
	document.getElementById('attachFlyer').checked = false;
}

function recipientsChanged(value)
{
	if(value == 'Selected')
	{
		document.getElementById('recipientNames').style.fontStyle = 'normal';
		document.getElementById('recipientNames').value = '';
		document.getElementById('recipientIDs').value = '';
		
		showUserList(true);
	}
	else
	{
		document.getElementById('recipientNames').style.fontStyle = 'italic';
		document.getElementById('recipientNames').value = value;
		document.getElementById('recipientIDs').value = '';
	}
}

function getXMLHTTP()
{
	var xmlHttp;
	
	try
   	{
    	xmlHttp = new XMLHttpRequest();
   	}
   	catch(e)
   	{
    	try
    	{
     		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    	}
    	catch(e)
    	{
     		try
      	 	{
	    	    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
       		}
     		catch(e)
      		{
       			return false;
       		}
  		}
   	} 
 	  
	return xmlHttp;
}

function showGuestlistChanged(publicStatus, hiddenStatus)
{
	var public = document.getElementById('publicGuestlist');
	var hidden = document.getElementById('hiddenGuestlist');
	
	if(publicStatus !== null)
		hidden.checked = !publicStatus;
	else
		public.checked = !hiddenStatus;
}

function checkRatioSettingsInput(form)
{
	if(!isInt(form.eMenLimit.value))
	{
		alert('Please enter valid integer.');
		form.eMenLimit.focus();
		
		return false;
	}
	else if(!isInt(form.eWomenLimit.value))
	{
		alert('Please enter valid integer.');
		form.eWomenLimit.focus();
		
		return false;
	}
	
	return true;
}

function isInt(value)
{
	return !(isNaN(value) || value.indexOf(',') != -1 || value.indexOf('.') != -1);
}

function isNumber(value)
{
	return !(isNaN(value) || value.indexOf(',') != -1);
}

function cancelEventForm(show)
{
	window.scrollTo(0, 600);
	
	document.getElementById('cancelEventForm').style.display = show === true ? 'block' : 'none';
}

function cancelEvent()
{
	var subject = document.getElementById('eCancelSubject').value;
	var message = document.getElementById('eCancelMessage').value;
	
	if(!subject)
	{
		alert('Please enter subject.');
		
		return false;
	}
	else if(!message)
	{
		alert('Please enter message.');
		
		return false;
	}
	
	var eventID = document.getElementById('eventID').value;
		
	var url = 'sendmessage.php?event='+eventID+'&recipients=Everyone'+
	'&subject='+encodeURIComponent(subject)+'&message='+encodeURIComponent(message)+'&noCache='+Math.random();
	
	var msgSender = getXMLHTTP();
	
	msgSender.onreadystatechange = function() 
   	{
    	if(msgSender.readyState == 4)
      	{
       		if(!msgSender.responseText)
       		{
       			alert("Your message was sent and the event will now be canceled.");
       			window.location = '?manage&details='+eventID+'&cancelEvent';
       		}
       		else
       			alert("There was a problem sending your message.");
      	}
 	}
 	
 	msgSender.open('GET', url, true);
   	msgSender.send(null);
}


var photosChanging = false;
var autoScroll = null;

function changeAutoScroll(stop)
{
	if(window.autoScroll !== null || stop)
	{
		clearInterval(window.autoScroll);
		
		window.autoScroll = null;
		
		document.getElementById('autoScrollBtn').className = 'evPGASOn';
	}
	else
	{
		window.autoScroll = setInterval("eventGallery(1)", 3000);
		
		document.getElementById('autoScrollBtn').className = 'evPGASOff';
	}
}

function eventGallery(move)
{
	if(photosChanging)
		return false;
	
	if(move < 0 && window.currPhoto == 0)
		window.currPhoto = window.eventPhotos.length-1;
	else if(move > 0 && window.currPhoto == window.eventPhotos.length-1)
		window.currPhoto = 0;
	else
		window.currPhoto += move;
	
	showNextPhoto();
}

function showNextPhoto()
{
	document.getElementById('currPhoto').innerHTML = window.currPhoto+1;
	
	window.photosChanging = true;
	
	document.getElementById('eventPhoto').src = window.eventPhotos[window.currPhoto];
	
	for(i = 0; i < 11; i++)
	{
		setTimeout("setOpacity('eventPhoto', "+(i*10)+");", i*100);
	}
	
	setTimeout("window.photosChanging = false;", i*100);
}

function eventsChangeSort(value)
{
	var currLoc = document.location.href;
	var pos = currLoc.indexOf('&sort');
	
	if(pos != -1)
		currLoc = currLoc.substr(0, pos);
	
	document.location = currLoc+'&sort='+value;
}

function eventsChangeAtendeesSort(value)
{
	var currLoc = document.location.href;
	var pos = currLoc.indexOf('&atsort');
	
	if(pos != -1)
		currLoc = currLoc.substr(0, pos);
	
	document.location = currLoc+'&atsort='+value;
}

function startSlideshow(eID, path)
{
	if(!path)
		path = '';
	
	var windowprops = "width=1000,height=700,left=10,top=10,scrollbars=no,status=yes,toolbar=no,location=no,directories=no,resizable=yes";
    window.open(path+'slideshow.php?eid='+eID, 'dcSlideshow', windowprops);
}

function setUnlimitedAttendees(checked)
{
	if(checked)
	{
		document.getElementById('eMenLimit').value = '';
		document.getElementById('eWomenLimit').value = '';
	}
}

function ratioChanged(value)
{
	if(value != '')
		document.getElementById('unlimitedAttendees').checked = false;
}

function inputFocused(el, defaultText)
{
	if(el.value == defaultText)
	{
		el.value = '';
		el.style.fontStyle = 'normal';
		el.style.color = '#000';
	}
	
	return true;
}

function inputBlurred(el, defaultText)
{
	if(el.value == '')
	{
		el.style.fontStyle = 'italic';
		el.style.color = '#999';
		el.value = defaultText;	
	}
	
	return true;
}

function showShareEventBox(show)
{
	var el = document.getElementById('shareEventBox');
	
	showHideEl(el, show);
}

function sendInvitations()
{
	var friendMail = document.getElementById('friendMail');
	
	if(friendMail.value && !validateEmail(friendMail.value))
	{
		alert('Please enter a valid email address.');
		friendMail.focus();
		
		return false;		
	}
	
	var el = document.getElementsByName('selectedMembers[]');
	var ids = '';
	
	for(i in el)
	{
		if(el[i].type == 'checkbox' && el[i].checked == true)
		{
			var tmp = el[i].value.split('#');
			
			ids += tmp[0]+',';
		}
	}
	
	ids = ids.substr(0, ids.length-1);
	
	
	var invSender = getXMLHTTP();
	
	invSender.onreadystatechange = function() 
   	{
    	if(invSender.readyState == 4)
      	{
       		if(!invSender.responseText)
       			alert("Your invitation has been sent.");
       		else
       			alert("There was a problem sending your invitation.");
       		
       		
       		document.getElementById('friendMail').value = '';
       		
       		var el = document.getElementsByName('selectedMembers[]');
			
			for(i in el)
			{
				if(el[i].type == 'checkbox')
					el[i].checked = false;
			}
      	}
 	}
 	
 	var eventID = document.getElementById('eventID').value;
 	
 	invSender.open('GET', 'sendinvitation.php?event='+eventID+'&mail='+encodeURIComponent(friendMail.value)+'&to='+ids, true);
   	invSender.send(null);
	
	showShareEventBox(false);
}

function addFriendForm(show)
{
	var el = document.getElementById('addFriendForm');
	
	if(show)
	{
		if(window.guestsLimit && window.currGuests == window.guestsLimit)
		{
			alert("You have reached the limit of guests that you can invite to this event.");
			
			return false;
		}
	}
	
	showHideEl(el, show);
}

function showHideEl(el, show)
{
	if(show)
	{
		var top = ((document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop)+20);
		
		if(top < 55)
			top = 55;
		
		el.style.display = 'block';
		el.style.top = top+'px';
	}
	else
		el.style.display = 'none';
}

function addFriend()
{
	var firstName = document.getElementById('gFirstName');
	var lastName = document.getElementById('gLastName');
	var email = document.getElementById('gEmail');
	
	if(!firstName.value)
	{
		alert("Please enter your friend's first name.");
		firstName.focus();
		
		return false;
	}
	
	if(!lastName.value)
	{
		alert("Please enter your friend's last name.");
		lastName.focus();
		
		return false;
	}
	
	if(!email.value)
	{
		alert("Please enter your friend's email address.");
		email.focus();
		
		return false;
	}
	
	if(email.value && !validateEmail(email.value))
	{
		alert('Please enter a valid email address.');
		email.focus();
		
		return false;
	}
	
	var gList = document.getElementById('guestList');
	
	
	var guest = document.createElement('div');
	
	var btn = document.createElement('input');
	btn.type = 'button';
	btn.value = '';
	btn.className = 'ueRemove';
	btn.onclick = removeFriend;
	btn.onmouseover = rmFriendMover;
	btn.onmouseout = rmFriendMout;
	
	guest.appendChild(btn);
	
	var nm = document.createElement('span');
	nm.innerHTML = firstName.value;
	
	guest.appendChild(nm);
	
	guest.appendChild(document.createTextNode(' '));
	
	nm = document.createElement('input');
	nm.type = 'hidden';
	nm.name = 'egFirstName[]';
	nm.value = firstName.value;
	
	guest.appendChild(nm);
	
	nm = document.createElement('span');
	nm.innerHTML = lastName.value;
	
	guest.appendChild(nm);
	
	nm = document.createElement('input');
	nm.type = 'hidden';
	nm.name = 'egLastName[]';
	nm.value = lastName.value;
	
	guest.appendChild(nm);
	
	
	var prc = document.createElement('span');
	prc.className = 'ueTicketPrice right';
	prc.innerHTML = '$'+window.gPrice;
	
	guest.appendChild(prc);
	
	var mail = document.createElement('input');
	mail.name = 'egEmail[]';
	mail.type = 'hidden';
	mail.value = email.value;
	
	guest.appendChild(mail);
	
	var msg = document.createElement('input');
	msg.name = 'egMessage[]';
	msg.type = 'hidden';
	msg.value = document.getElementById('gMessage').value;
	
	guest.appendChild(msg);
	
	gList.appendChild(guest);
	
	document.getElementById('gFirstName').value = '';
	document.getElementById('gLastName').value = '';
	document.getElementById('gEmail').value = '';
	document.getElementById('gMessage').value = '';
	
	window.currGuests++;
	
	var total = parseFloat(document.getElementById('totalPrice').innerHTML)+window.gPrice;
	document.getElementById('totalPrice').innerHTML = total.toFixed(2);
	
	addFriendForm(false);
}

var rmFriendMover = function(el)
{
	var el = (typeof el == 'object' && el.value) ? el : this;
	
	el.style.backgroundPosition = '0px -18px';
}

var rmFriendMout = function(el)
{
	var el = (typeof el == 'object' && el.value) ? el : this;
	
	el.style.backgroundPosition = '0px 0px';
}

var removeFriend = function(el)
{
	var el = (typeof el == 'object' && el.value) ? el : this;
	
	var answer = confirm('Are you sure you want to remove this friend?');
	
	if(answer === true)
	{
		el.parentNode.parentNode.removeChild(el.parentNode);
		
		window.currGuests--;
		
		var total = parseFloat(document.getElementById('totalPrice').innerHTML)-window.gPrice;
		document.getElementById('totalPrice').innerHTML = total.toFixed(2);
	}
}

function pickSubscriptionPlan()
{
	var picked = 0;
	
	picked += document.getElementById('oneYear').checked * 1;
	picked += document.getElementById('sixMonths').checked * 2;
	picked += document.getElementById('threeMonths').checked * 3;
	picked += document.getElementById('oneMonths').checked * 4;
	picked += document.getElementById('sevenDays').checked * 5;
	
	
	if(!picked)
	{
		alert("Please choose a subscription plan.");
		
		return false;
	}
	
	var periods = ['0', '1 year', '6 months', '3 months', '1 month', '7 days'];
	var prices = [0, 143.88, 89.94, 50.97, 17.99, 4.99];
	
	
	document.getElementById('subscriptionPlan').style.display = 'block';
	document.getElementById('upgradeArr').style.display = 'none';
	document.getElementById('upgradeOptions').style.display = 'none';
	
	document.getElementById('goldPeriod').innerHTML = periods[picked]+' gold membership';
	document.getElementById('goldPrice').innerHTML = prices[picked];
	
	document.getElementById('gmPeriod').value = periods[picked]+' gold membership';
	document.getElementById('gmPrice').value = prices[picked];
	
	var total = parseFloat(document.getElementById('totalPrice').innerHTML)+prices[picked];
	document.getElementById('totalPrice').innerHTML = total.toFixed(2);
	
	showHideEl(document.getElementById('membershipPlanBox'), false);
}

function cancelSubscriptionPlan()
{
	var total = parseFloat(document.getElementById('totalPrice').innerHTML)-parseFloat(document.getElementById('goldPrice').innerHTML);
	document.getElementById('totalPrice').innerHTML = total.toFixed(2);
	
	document.getElementById('subscriptionPlan').style.display = 'none';
	document.getElementById('upgradeArr').style.display = 'block';
	document.getElementById('upgradeOptions').style.display = 'block';
	
	document.getElementById('goldPeriod').innerHTML = '';
	document.getElementById('goldPrice').innerHTML = 0;
	
	document.getElementById('gmPeriod').innerHTML = '';
	document.getElementById('gmPrice').innerHTML = 0;
}

function addCastes(relID)
{
	var av = document.getElementById('avCastes['+relID+']');
	var sel = document.getElementById('selCastes['+relID+']');
	
	moveOptions(av, sel);
	
	removeDefaultOption(sel);
	
	setCastesStatus(relID, true);
}

function removeDefaultOption(sb)
{
	if(sb.options.length > 1)
	{
		for(i = 0; i < sb.options.length; i++)
		{
			if(sb.options[i] && sb.options[i].value == 0)
			{
				sb.removeChild(sb.options[i]);
			}
		}
	}
}

function remCastes(relID)
{
	var av = document.getElementById('avCastes['+relID+']');
	var sel = document.getElementById('selCastes['+relID+']');
	
	moveOptions(sel, av);
	
	addDefaultOption(sel);
	
	setCastesStatus(relID, false);
}

function addDefaultOption(sb)
{
	if(sb.options.length == 0)
	{
		var dm = document.createElement('option');
		dm.value = 0;
		dm.innerHTML = "Doesn't matter";
		
		sb.appendChild(dm);
	}
}

function moveOptions(from, to)
{
	var toMove = [];
	for(i = 0; i < from.options.length; i++)
	{
		if(from.options[i] && from.options[i].selected === true && from.options[i].value != 0)
		{
			toMove[toMove.length] = from.options[i];
		}
	}
	
	if(toMove.length)
	{
		for(i in toMove)
		{
			to.appendChild(toMove[i]);
		}
	}
}

function religionChanged(el)
{
	if(document.getElementById('casteHRow['+el.value+']'))
	{
		var display = el.checked ? 'block' : 'none';
		
		document.getElementById('casteHRow['+el.value+']').style.display = display;
		document.getElementById('casteSRow['+el.value+']').style.display = display;
	}
}

function showGreenBox(show) 
{
	document.getElementById("upWindow").style.display = show ? 'block' : 'none';
	
	if(!show && document.getElementById('photoNo'))
		document.getElementById('photoNo').checked = true;
}

function multiSelectChanged(el)
{
	var from = el;
	
	var isAvailable = el.name.substr(0, 2) == 'av';
	
	var tmpName = (isAvailable ? 'sel' : 'av')+el.name.substr((isAvailable ? 2 : 3), el.name.length-2);
	
	var to = document.getElementById(tmpName);
	
	moveOptions(from, to);
	
	//
	setLanguagesSpokenStatus();
	
	if(isAvailable)
		removeDefaultOption(to);
	else
		addDefaultOption(from);
}

function getSelectedAsStr(id)
{
	var el = document.getElementById(id);
	var selStr = '';
	
	for(i = 0; i < el.options.length; i++)
	{
		if(el.options[i].selected !== undefined && el.options[i].value != 0)
		{
			selStr += el.options[i].value+',';
		}
	}
	
	return selStr.substr(0, selStr.length-1);
}

function showHidePPSection(id, display)
{
	var rows = document.getElementsByName(id+'_row');
	
	var display = display || null;
	for(i = 0; i < rows.length; i++)
	{
		if(display === null)
			display = rows[i].style.display == 'none' ? 'table-row' : 'none';
		
		rows[i].style.display = display;
	}
	
	var arr = document.getElementById(id+'_arr');
	
	if(arr)
	{
		var tmp = arr.src;
		arr.src = tmp.indexOf('fl-arrow-up.png') != -1 ? tmp.replace('fl-arrow-up.png', 'fl-arrow.png') : tmp.replace('fl-arrow.png', 'fl-arrow-up.png');
	}
}

function uncheckPPSection(name)
{
	if(document.getElementById(name+'_active').checked == false)
	{
		 var res = confirm('Are you sure you want to uncheck this? Doing so will not apply the choices you selected and leave them at the default settings.');
		 
		 if(res)
		 	showHidePPSection(name, 'none');
		 
		 return !res;
	}
	
	showHidePPSection(name, '');
	
	return true;
}

function pptShow(show)
{
	document.getElementById('partnerPreferencesTable').style.display = show ? 'block' : 'none';
}

var activeFilterCategory = null;
function activateFilterCategory(name, activate)
{
	if(window.activeFilterCategory)
	{
		var nm = window.activeFilterCategory;
		window.activeFilterCategory = null;
		
		activateFilterCategory(nm, false);
	}
	
	if(activate == undefined)
		activate = true;
	
	var row = document.getElementById(name+'_row');
	var edit = document.getElementById(name+'_edit');
	
	row.className = activate ? 'mainRow' : 'topRow';
	edit.style.display = activate ? 'none' : 'inline';
	
	if(activate)
		window.activeFilterCategory = name;
}

function uncheckAll(Item,Name)
{
	if(Item.checked == true)
	{
		var len = document.ProfileForm.elements.length;
		
		for (var i=0;i<len;i++)
    		if (document.ProfileForm.elements[i].name == Name)
    		{ 
				document.ProfileForm.elements[i].checked = false;
			}
	}
}

function uncheckAny(Item)
{
	Item.checked = false;
}

function setDefaultText(focused, el, text)
{
	if(typeof el == 'string')
		el = document.getElementById(el);
	
	if(!el)
		return false;
	
	if(focused)
	{
		if(el.value == text)
		{
			el.style.color = '#000';
			el.value = '';
		}
	}
	else
	{
		if(!el.value || el.value == text)
		{
			el.value = text;
			el.style.color = '#999';
		}
	}
}

function setStatus(el, optionsName)
{
	var el = document.getElementById(el+'_status');
	
	if(!el)
		return false;
	
	if(!optionsName)
	{
		el.innerHTML = "Doesn't matter";
		
		return false;
	}
	
	var opt = document.getElementsByName(optionsName);
	
	var optID = label = null;
	var status = [];
	for(i = 0; i < opt.length; i++)
	{
		if(opt[i].checked)
		{
			optID = opt[i].id;
			
			label = getNextSibling(opt[i]);
			
			status[status.length] = label.innerHTML;
		}
	}
	
	if(status.length)
	{
		var st = '';
		for(i = 0; i < status.length; i++)
		{
			if(i)
				st += (i == status.length-1 ? ' or ' : ', ');
			
			st += status[i];
		}
		
		el.innerHTML = st;
		
		return true;
	}
	else
	{
		el.innerHTML = "Doesn't matter";
		
		return false;
	}
}

function getNextSibling(el) 
{
    do
    {
        el = el.nextSibling;
    }
    while(el && el.nodeType != 1);
    
    return el;
}

function setAgeStatus(value, from)
{
	var el = from ? document.getElementById('age_status_from') : document.getElementById('age_status_to');
	
	if(!el)
		return false;
	
	el.innerHTML = value;
}

function setDistanceStatus(el, value)
{
	var el = document.getElementById(el+'_status');
	
	if(!el)
		return false;
	
	el.innerHTML = value+' miles';
	
	document.getElementById('distance').checked = true;
	document.getElementById('anyDistance').checked = false;
}

function setHeightStatus(el)
{
	var el = document.getElementById(el+'_status');
	
	if(!el)
		return false;
	
	var hff = document.getElementById('HeightFeetFrom').value;
	var hif = document.getElementById('HeightInchesFrom').value;
	var hft = document.getElementById('HeightFeetTo').value;
	var hit = document.getElementById('HeightInchesTo').value;
	
	if(hff == 0 || hft == 0)
		var status = "Doesn't matter";
	else
		var status = document.getElementById('HeightFeetFrom').value+' feet '+document.getElementById('HeightInchesFrom').value+' inches to '+
				 	 document.getElementById('HeightFeetTo').value+' feet '+document.getElementById('HeightInchesTo').value+' inches';
				
	el.innerHTML = status;
}

var currentRels = [];
function setCastesStatus(relID, add)
{
	var statusEl = document.getElementById('Caste_status');
	
	if(!statusEl)
		return false;
	
	var found = false;
	for(i = 0; i < window.currentRels.length; i++)
	{
		if(window.currentRels[i] == relID)
		{
			if(!add)
				window.currentRels[i] = null;
			
			found = true;
		}
	}
	
	if(!found)
		window.currentRels[window.currentRels.length] = relID;
	
	var el = null;
	var status = [];
	for(i in window.currentRels)
	{
		if(!window.currentRels[i])
			continue;
		
		el = document.getElementById('selCastes['+window.currentRels[i]+']');
		
		if(!el)
			continue;
		
		for(j = 0; j < el.options.length; j++)
		{
			if(el.options[j].value)
				status[status.length] = el.options[j].innerHTML;
		}
	}
	
	statusEl.innerHTML = getStatusStr(status);
}

function getStatusStr(status)
{
	if(!status.length)
		var st = "Doesn't matter";
	else
	{
		var st = '';
		for(i = 0; i < status.length; i++)
		{
			if(i)
				st += (i == status.length-1 ? ' or ' : ', ');
			
			st += status[i];
		}
	}
	
	return st;
}

function setLanguagesSpokenStatus()
{
	var el = document.getElementById('selLanguages');
	var statusEl = document.getElementById('Languagesspoken_status');
	
	if(!el || !statusEl)
		return false;
	
	var status = [];
	for(j = 0; j < el.options.length; j++)
	{
		if(el.options[j].value != 0)
			status[status.length] = el.options[j].innerHTML;
	}
	
	statusEl.innerHTML = getStatusStr(status);
}

function startUpload()
{
  document.getElementById('uploadResult').innerHTML = '<span>Uploading .....</span>';
  
  return true;
}

function stopUpload(success, message, npID)
{
	if(success == 1)
	{
		document.getElementById('uploadResult').innerHTML = '<span>Uploading ..... done!<\/span> (now choose an option below)';
		
		document.getElementById('uploadedPhoto').src = message;
		document.getElementById('uploadedPhoto').style.width = 'auto';
		document.getElementById('uploadedPhoto').style.height = 'auto';
		
		if(document.getElementById('photoPrimary'))
		{
			var pos = message.lastIndexOf('/');
			var filename = message.substr(pos);
			filename = message.substr(0, pos)+filename.replace('/70_', '/130_');
			
			document.getElementById('photoPrimary').src = filename;
			
			document.getElementById('pendingApprovalText').style.display = 'block';
			document.getElementById('btnDeletePhoto').style.display = 'block';
			document.getElementById('btnReplacePhoto').style.display = 'block';
			document.getElementById('btnAddPhoto').style.display = 'none';
			
			document.getElementById('newPhoto').value = '';
			document.getElementById('uploadedPhoto').src = '';
			
			showGreenBox(false);
		}
		
		document.getElementById('npID').value = npID;
	}
	else 
	{
		document.getElementById('uploadResult').innerHTML = '<span>The photo cannot be uploaded!<\/span>';
		
		alert(message);
	}
	
	return true;
}

function stopUploadAtt(success, message, npID)
{
	pleaseWait.deactivate();
	
	if(success == 1)
		composeMessageSend(message);		
	else
		alertMessage(message, true);
	
	return true;
}

function uploadPhotoValid()
{
	var value = document.getElementById('newPhoto').value;
	
	if(!value)
	{
		alert('Please choose the photo you want to upload.');
		
		return false;
	}
	
	return true;
}

function makePrimary(value)
{
	if(confirm('Are you sure you want to make this primary photo?')) 
		document.location = 'pictures.php?makeprimary='+value;
	
	return false;
}

function makePrivate(value)
{
	if(confirm('Are you sure youwant to make this photo backstage?')) 
		document.location = 'pictures.php?makebks='+value;
	
	return false;
}

function makePublic(value)
{
	if(confirm('Are you sure you want to make this photo public')) 
		document.location = 'pictures.php?makepublic='+value;
	
	return false;
}

function redoUpload()
{
	document.getElementById('uploadResult').innerHTML = '<span>Choose file and click "Upload Photo"</span>';
	document.getElementById('uploadedPhoto').src = '';
	document.getElementById('uploadedPhoto').style.width = '0';
	document.getElementById('uploadedPhoto').style.height = '0';
	document.getElementById('newPhoto').value = '';
	
	document.getElementById('newPhoto').focus();
}

function showErr(field, error)
{
	var row = document.getElementById(field+'_row');
	var err = document.getElementById(field+'_err');
	
	if(row)
		row.style.background = error ? '#fb4945' : '';
	
	if(err)
	{
		err.innerHTML = error;
		err.style.color = '#fff';
	}
}

function changeBSSort(value)
{
	var loc = window.location+'';
	var pos = loc.indexOf('?');
	
	if(pos != -1)
	{
		loc = loc.substr(0, pos);
	}
	
	loc += '?sort='+value;
	
	window.location = loc;
}

function showAllPhotos(el, numPix)
{
	document.getElementById('publicPhotosBox').style.height = (numPix*127)+'px';
	document.getElementById('publicPhotosBox').style.overflow = 'visible';	
	
	document.getElementById('privatePhotosBox').style.height = (numPix*127)+'px';
	document.getElementById('privatePhotosBox').style.overflow = 'visible';
	
	document.getElementById('pixVisible').innerHTML = document.getElementById('pixTotal').innerHTML;
	
	if(el)
		el.style.display = 'none';
}

function msgPreviewForm(show)
{
	document.getElementById('previewMessageBox').style.display = show ? 'block' : 'none';
}

function sendToTestMail()
{
	if(!validateEmail(document.getElementById('testMail').value))
	{
		alert('Please enter valid e-mail address.');
		
		return false;
	}
	
	document.getElementById('recipientIDs').value = 'test';
	
	document.getElementById('testEmail').value = document.getElementById('testMail').value;
	
	sendMessage();
	
	msgPreviewForm(false);
}

function adjustPos(photo, w, h)
{
	photo.style.marginLeft = (parseInt(w/2-75)*-1)+'px';
	photo.style.marginTop = (parseInt(h/2)*-1)+'px';
}

function showBiggerPhoto(el)
{
	var bigger = getNextSibling(el);
	
	if(bigger)
		bigger.style.display = 'block';
}

function checkDefault(el)
{
	if(el.checked == false)
		return false;
	
	var other = null;
	var id = el.id;
	var c = 1;
	
	while(other = document.getElementById(id+c))
	{
		other.checked = false;
		c++;
	}
}

function uncheckDefault(id)
{
	var elements = document.getElementsByName(id+'[]');
	
	var c = 0;
	for(i = 0; i < elements.length; i++)
	{
		if(elements[i].checked == true)
			c++;
	}
	
	document.getElementById(id).checked = c ? false : true;
}

function uploadPhotoStartOver(profileCreation)
{
	var pc = profileCreation;
	var httpHndl = httpGetObject();
	
	if(pc)
		showGreenBox(false);
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4)
		{
			if(httpHndl.status == 200)
			{
				if(httpHndl.responseText == 'success')
				{
					document.getElementById('newPhoto').value = '';
					document.getElementById('uploadedPhoto').src = '';
					
					document.getElementById('newPhoto').focus();
					
					if(pc)
						showGreenBox(false);
				}
			}
		}
	}
	
	httpHndl.open("GET", "cancelupload.php?dontcache="+Math.random());
	httpHndl.send(null);
}

function showFilteredMessageBox(show)
{
	document.getElementById('filteredMessageBox').style.display = show ? 'block' : 'none';
	document.getElementById('filteredMessageBox').style.zIndex = show ? '500000' : '0';
}

function showRecentActivities(id, el)
{
	var everyone = id == 1 ? 'block' : 'none';
	var favourites = id == 2 ? 'block' : 'none';
	var nearMe = id == 3 ? 'block' : 'none';
	
	document.getElementById('recentActivitiesEveryone').style.display = everyone;
	document.getElementById('recentActivitiesFavourites').style.display = favourites;
	document.getElementById('recentActivitiesNearMe').style.display = nearMe;
	
	document.getElementById('tabEveryone').className = "";
	document.getElementById('tabFavorites').className = "";
	document.getElementById('tabNearMe').className = "";
	
	el.className = "current";
}

function startChat(member)
{
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			if(httpHndl.responseText == 1)
			{
				alertMessage('This member has blocked you', true);
			}
			else if(httpHndl.responseText == 2 || httpHndl.responseText == 3)
			{
				var himher = httpHndl.responseText == 2 ? 'him' : 'her';
				var message = 'This user is in your block list. To chat with '+himher+', please un-block '+himher+' first - <a href="javascript: void(0)" onclick="unblockMember('+member+')">click here</a> to un-block';
				
				alertMessage(message, true, false)
			}
			else
			{
				ccStartChat(member);
			}
		}
	}
	
	httpHndl.open("GET", "mutualblock.php?partner="+member, true);
	httpHndl.send(null);
}

function unblockMember(memberID)
{
	hidePopup('alertbox');
	
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			if(httpHndl.responseText == 1)
			{
				alertMessage('The member has been successfully removed from your block list! Would you like to add that member to your buddy list as well - <a href="javascript: void(0)" onclick="addToBuddyList('+memberID+')">click here to add to buddy list?</a>', false, false);
			}
			else
			{
				alertMessage('The member cannot be removed from your block list!');
			}
		}
	}
	
	httpHndl.open("GET", "blockmember.php?memberID="+memberID, true);
	httpHndl.send(null);
}

function addToBuddyList(memberID, member, el)
{
	hidePopup('alertbox');
	
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			if(httpHndl.responseText == 1)
			{
				if(member)
					alertMessage('You have successfully added '+member+' to your chat buddy list');
				else
					alertMessage('The member has been added to your buddy list');
				
				if(el)
					swapSiblingsVisibility(el);
				
				if(memberID)
					setTimeout("ccStartChat("+memberID+");", 2500);
			}
			else
			{
				if(member)
					alertMessage(member+' cannot be added to your buddy list', true);
				else
					alertMessage('The member cannot be added to your buddy list', true);
			}
		}
	}
	
	var url = memberID ? "addbuddy.php?memberID="+memberID : "addbuddy.php?member="+member;
	
	httpHndl.open("GET", url, true);
	httpHndl.send(null);
}

function removeFromBuddyList(member, el)
{
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			if(httpHndl.responseText == 1)
			{
				alertMessage('You have successfully removed '+member+' from your chat buddy list');
				
				if(el)
					swapSiblingsVisibility(el);
			}			
			else
				alertMessage(member+' cannot be removed from your buddy list', true);
		}
	}
	
	httpHndl.open("GET", "removebuddy.php?member="+member, true);
	httpHndl.send(null);
}

function ccStartChat(member)
{
	jqcc("#cometchat").show();
	jqcc("#cometchat_base").show();
	jqcc("#cometchat_userstab").show();
	jqcc("#cometchat_chatboxes").show();
	jqcc("#cometchat_chatbox_left").show();
	jqcc("#cometchat_chatbox_right").show();
	
	jqcc.cometchat.chatWith(member);
}

function ccHide()
{
	jqcc.cometchat.hideBar();
}

function showPopup(what)
{
	if(what == 'compose')
	{
		document.getElementById("popupCompose").style.display = "block";
		document.getElementById('cmpSubject').focus();
		
		if(window.IS_CANVAS && fbPageInfo)
			FB.Canvas.scrollTo(0, parseInt(fbPageInfo.offsetTop)+88);
		else
			window.scrollTo(0, 88);
	}
	else if(what == 'alertbox')
	{
		document.getElementById("alertBox").style.display = "block";
	}
	else if(what)
	{
		if(document.getElementById(what))
			document.getElementById(what).style.display = 'block';
	}
	else
	{
		if(document.getElementById('captchaNormal') && document.getElementById('captchaPopup'))
		{
			document.getElementById('captchaPopup').appendChild(document.getElementById('captchaCode'));
		}
		
		if(window.IS_CANVAS && fbPageInfo)
			FB.Canvas.scrollTo(0, parseInt(fbPageInfo.offsetTop)+88);
		else
			window.scrollTo(0, 88);
		
		document.getElementById("popup").style.display = "block";
	}
}

function hidePopup(what)
{
	if(what == 'compose')
	{
		if(document.getElementById('cmpSubject').value || document.getElementById('cmpMessage').value)
		{
			var answer = confirm('Are you sure you want to discard your message and close this compose message window?');
			
			if(!answer)
				return false;
		}
		
		document.getElementById("popupCompose").style.display = "none";
	}
	else if(what == 'alertbox')
	{
		document.getElementById("alertBox").style.display = "none";
		
		clearTimeout(alertBoxTimeout);
	}
	else if(what)
	{
		if(document.getElementById(what))
			document.getElementById(what).style.display = 'none';
	}
	else
	{
		if(document.getElementById('captchaNormal') && document.getElementById('captchaPopup'))
		{
			document.getElementById('captchaNormal').appendChild(document.getElementById('captchaCode'));
		}
		
		document.getElementById("popup").style.display = "none";
	}
	
	window.scrollBy(0, 1);
	window.scrollBy(0, -1);
}

var moreActivitiesGroup = 0;
var mag = [];
mag['everyone'] = 0;
mag['favorites'] = 0;
mag['near'] = 0;
function showMoreActivities(link, type)
{
	if(type)
	{
		mag[type]++;
		
		var num = mag[type];
	}
	else
	{
		moreActivitiesGroup++;
		
		var num = moreActivitiesGroup;
	}
	
	type = type ? type+'_' : '';
	
	document.getElementById(type+'activitiesGroup['+num+']').style.display = 'block';
	
	if(num == document.getElementById(type+'totalActivitiesGroups').value)
		link.style.display = 'none';
	
	if(IS_CANVAS)
		FB.Canvas.setSize({ width: 640, height: document.body.clientHeight });
}

function checkChangeMailForm(form)
{
	if(!form.mail.value)
	{
		alert('Enter e-mail addres');
		form.mail.focus();
		
		return false;
	}
	
	if(!validateEmail(form.mail.value))
	{
		alert('Invalid e-mail addres');
		form.mail.focus();
		
		return false;
	}
	
	return true;
}

function composeMessagePopup(toMember)
{
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			if(httpHndl.responseText == 1)
				alertMessage('Sorry, this member has blocked you!', true);
			else if(httpHndl.responseText == 2)
				alertMessage("Sorry but you have been filtered as you don't meet "+toMember+"'s partner preferences. Don't worry there's plenty of more fish in the sea!", true, 8);
			else
				composeMessagePopupOpen(toMember);
		}
	}
	
	httpHndl.open("GET", "isblockedby.php?member="+toMember, true);
	httpHndl.send(null);
}

function composeMessagePopupOpen(toMember)
{
	document.getElementById('cmpSubject').value = '';
	document.getElementById('cmpMessage').value = '';
	document.getElementById('membersConversation').innerHTML = '';
	
	showPopup('compose');
	
	if(toMember)
	{
		document.getElementById('cmpToMember').value = toMember;
		verifyMember(document.getElementById('cmpBtnVerify'), true);
		memberVerified = true;
	}
}

composeMessageForm = null
function composeMessageValidate(form)
{
	window.composeMessageForm = form;
	
	if(form.cmpToMember.value == "")
	{
		alert("Please, enter username of the receiver.");
		form.cmpToMember.focus();
		return false;
	}
	
	if(!memberVerified)
	{
		alert("Please verify the username first, by clicking the button Verify next to the recipient's username");
		form.cmpToMember.focus();
		return false;
	}
	
	if(form.Subject.value == "")
	{
		alert("Please, enter subject.");
		form.Subject.focus();
		return false;
	}	
	
	if(form.message.value == "")
	{
		alert("Please, enter message.");
		form.message.focus();
		return false;	
	}
	
	if(form.attachment.value)
	{
		startUpload();
		pleaseWait.activate();
		
		return true;
	}
	else
	{
		composeMessageSend();
		return false;
	}
}

function composeMessageSend(attachment)
{
	var form = window.composeMessageForm;
	
	var httpHndl = httpGetObject();	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			var toMember = form.cmpToMember.value;
			
			memberVerified = false;
			
			form.cmpToMember.value = '';
			form.Subject.value = '';
			form.message.value = '';
			form.attachment.value = '';
			
			hidePopup('compose');
			
			if(httpHndl.responseText == 2)
			{
				alertMessage('Sorry, this member has blocked you!', true);
			}
			else
			{
				if(httpHndl.responseText == 1)
					alertMessage('Your message to '+toMember+' has been sent!');
				else
					alertMessage('Message cannot be sent!', true);
			}
		}
	}
	
	var url = "sendmessage.php?dontcache="+Math.random()+"&username="+form.cmpToMember.value+"&subject="+form.Subject.value+"&message="+form.message.value;
	
	if(attachment)
		url += "&attachment="+attachment;
	
	httpHndl.open("GET", url, true);
	httpHndl.send(null);
}

var alertBoxTimeout = false;
function alertMessage(message, isError, seconds)
{
	document.getElementById('alertMessage').className = isError ? 'error' : '';
	
	document.getElementById('alertMessage').innerHTML = message;
	
	showPopup('alertbox');
	
	if(window.IS_CANVAS && fbPageInfo)
	{
		var pos = FB.Canvas.getPageInfo();
		
		var el = document.getElementsByClassName('alertBox');
		
		el[0].style.top = parseInt(pos.scrollTop)+'px';
	}		
	
	timeout = seconds ? seconds * 1000 : 3000;
	
	if(seconds !== false)
		alertBoxTimeout = setTimeout("hidePopup('alertbox')", timeout);
}

function showMembersConversation(partner)
{
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			document.getElementById('membersConversation').innerHTML = httpHndl.responseText;
		}
	}
	
	httpHndl.open("GET", "getconversation.php?partner="+partner, true);
	httpHndl.send(null);
}

function sendWinkPopup(el, toMember, toRemove)
{
	if(!confirm('Are you sure you want to wink at '+toMember+'?'))
		return false;
	
	sendWinkRequest(el, "winkat.php?toMember="+toMember, toMember, 1, toRemove);
}

function winkNoThanksPopup(el, wID, toMember, toRemove)
{
	if(!confirm('Are you sure you want to respond "No thanks!" to '+toMember+"'s wink?"))
		return false;
	
	sendWinkRequest(el, "winkat.php?noThanks="+wID, toMember, 2, toRemove);
}

function sendWinkRequest(el, url, toMember, type, toRemove)
{
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			var success = httpHndl.responseText == 1;
			
			if(type == 1) 
			{
				if(httpHndl.responseText == 2)
				{
					alertMessage("Sorry but you have been filtered as you don't meet "+toMember+"'s partner preferences. Don't worry there's plenty of more fish in the sea!", true);
					
					return;
				}
				else
					var message = success ? 'You have winked at '+toMember : "You've already winked at "+toMember+" within the last 30 days";
			}
			else if(type == 2)
				var message = success ? 'You said "No thanks!" to '+toMember+'\'s wink' : "Your response cannot be sent";
			
			if(document.getElementById(toRemove))
				document.getElementById(toRemove).style.display = 'none';
			
			if(httpHndl.responseText == 1)
			{
				swapSiblingsVisibility(el);
				
				changeDuplicateButtons(el);
			}
			
			alertMessage(message, !success);
		}
	}
	
	httpHndl.open("GET", url, true);
	httpHndl.send(null);
}

function addFavouritePopup(el, member)
{
	if(!confirm('Are you sure you want to add '+member+' to your favorites?'))
		return false;
	
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			var success = httpHndl.responseText == 1 || httpHndl.responseText == 2;
			
			if(success)
			{
				var message = 'You have added '+member+' to your favorites!';
				
				if(httpHndl.responseText == 2)
					message += ' Do you want to add '+member+' to your buddy list as well - <a href="javascript: void(0)" onclick="addToBuddyList(0, \''+member+'\')">click here</a>?';
			}
			else
				var message = member+' cannot be added to your favorites!';
			
			if(success)
			{
				swapSiblingsVisibility(el);
				
				changeDuplicateButtons(el);
				
				var timeout = httpHndl.responseText == 2 ? false : 3;
			}
			else
				var timeout = 3;
			
			alertMessage(message, !success, timeout);
		}
	}
	
	httpHndl.open("GET", "addfavourite.php?member="+member, true);
	httpHndl.send(null);
}

function removeFavouritePopup(el, member)
{
	if(!confirm('Are you sure you want to remove '+member+' from your favorites?'))
		return false;
	
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			var success = httpHndl.responseText == 1;
			var message = success ? member+' has been successfully removed from your favorites!' : member+' cannot be removed from your favorites!';
			
			if(success)
			{
				swapSiblingsVisibility(el);
				
				changeDuplicateButtons(el);
			}
			
			alertMessage(message, !success);
		}
	}
	
	httpHndl.open("GET", "removefavourite.php?member="+member, true);
	httpHndl.send(null);
}

function swapSiblingsVisibility(toHide)
{
	if(!toHide)
		return false;
	
	var toShow = toHide.nextSibling;
	
	while(toShow && toShow.nodeType == 3)
	{
		toShow = toShow.nextSibling;
	}
	
	if(!toShow)
	{
		toShow = toHide.previousSibling;
		
		while(toShow && toShow.nodeType == 3)
		{
			toShow = toShow.previousSibling;
		}
	}
	
	if(toShow)
	{
		toShow.style.display = 'block';
		toHide.style.display = 'none';
	}
}

function blockMemberPopup(el, member, block)
{
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			var success = httpHndl.responseText == 1;
			
			if(block)
				var message = success ? member+' has been successfully added to your block list!' : member+' cannot be added to your block list!';
			else
				var message = success ? member+' has been successfully removed from your block list!' : member+' cannot be removed from your block list!';
			
			if(success)
				swapSiblingsVisibility(el);
			
			alertMessage(message, !success);
		}
	}
	
	httpHndl.open("GET", "blockmember.php?member="+member+(block ? '&block' : ''), true);
	httpHndl.send(null);
}

function changeDuplicateButtons(el)
{
	var divs = document.getElementsByTagName('div');
	
	for(var i = 0; i < divs.length; i++)
	{
		if(divs[i].title == el.title)
		{
			swapSiblingsVisibility(divs[i]);
		}
	}
}

function associateAccountsVerify(form)
{
	if(!form.email.value)
	{
		alert('Please enter e-mail');
		form.email.focus();
		
		return false;
	}
	
	var regEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i;
	if(!regEx.test(form.email.value))
	{
		alert('Please enter valid e-mail');
		form.email.focus();
		
		return false;
	}
	
	if(!form.pass.value)
	{
		alert('Please enter password');
		form.pass.focus();
		
		return false;
	}
	
	return true;
}

function enableFbLogin()
{
	var httpHndl = httpGetObject();
	httpHndl.open("GET", "/members/enablefblogin.php", true);
	httpHndl.send(null);
	
	//setTimeout(fbIsLoggedIn, 500);
}

function fbIsLoggedIn()
{
	FB.getLoginStatus(function(response) 
	{
		if(response.session) 
		{
			window.location.reload();
		}
	});
}

function popupLoginInit()
{
	showPopup('popupLogin');
	
	document.getElementById('loginInit').style.display = 'block';
	document.getElementById('loginCodeSent').style.display = 'none';
	document.getElementById('loginNotActivated').style.display = 'none';
}

function popupLoginCodeSent()
{
	showPopup('popupLogin');
	
	document.getElementById('loginInit').style.display = 'none';
	document.getElementById('loginCodeSent').style.display = 'block';
	document.getElementById('loginNotActivated').style.display = 'none';
}

function popupLoginNotActivated()
{
	showPopup('popupLogin');
	
	document.getElementById('loginInit').style.display = 'none';
	document.getElementById('loginCodeSent').style.display = 'none';
	document.getElementById('loginNotActivated').style.display = 'block';
}

function popupFpInit()
{
	showPopup('popupForgottenPass');
	
	document.getElementById('fpInit').style.display = 'block';
	document.getElementById('fpSent').style.display = 'none';
	document.getElementById('fpError').style.display = 'none';
	
	document.getElementById('fpRecoveryErrors').style.display = 'none';
	document.getElementById('fpRecoveryForm').style.display = 'block';
}

function popupFpSent()
{
	showPopup('popupForgottenPass');
	
	document.getElementById('fpInit').style.display = 'none';
	document.getElementById('fpSent').style.display = 'block';
	document.getElementById('fpError').style.display = 'none';
}

function popupFpError()
{
	showPopup('popupForgottenPass');
	
	document.getElementById('fpInit').style.display = 'none';
	document.getElementById('fpSent').style.display = 'none';
	document.getElementById('fpError').style.display = 'block';
}

function popupAccActivated()
{
	showPopup('popupSignUpActivated');
	
	document.getElementById('accActivated').style.display = 'block';
	document.getElementById('accCodeSent').style.display = 'none';
}

function popupAccCodeSent()
{
	showPopup('popupSignUpActivated');
	
	document.getElementById('accActivated').style.display = 'none';
	document.getElementById('accCodeSent').style.display = 'block';
}

function validEmail(value)
{
	var regEx = /^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$/;
	
	return (!value || !regEx.test(value)) ? false : true;
}

function submitLoginForm(form)
{
	document.getElementById('loginErrorMessage').style.display = 'none';
	
	if(!form.email.value)
	{
		loginShowError('Please enter e-mail address');
		form.email.focus();
		
		return false;
	}
	else if(!validEmail(form.email.value))
	{
		loginShowError('Please enter valid e-mail address');
		form.email.focus();
		
		return false;
	}
	
	if(!form.pass.value)
	{
		loginShowError('Please enter password');
		form.pass.focus();
		
		return false;
	}
	else if(form.pass.value.length < 5)
	{
		loginShowError('Please enter valid password');
		form.pass.focus();
		
		return false;
	}
	
	aLogin(form.email.value, form.pass.value);
	
	return false;
}

function aLogin(email, pass, dontHash)
{
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			var loc = window.location.toString();
			
			var prefix = (loc.indexOf('/members/') == -1) ? 'members/' : '';
			
			switch(parseInt(httpHndl.responseText))
			{
				case 1:
					window.location = prefix+'memberhome.php';
				break;
				case 2:
					loginShowError('<b>Incorrect e-mail/password</b>');
				break;
				case 3:
					window.location = prefix+'messagecenter.php';
				break;
				case 4:
					window.location = prefix+'winks.php';
				break;
				case 5:
					document.getElementById('activationSentTo').innerHTML = email;
					document.getElementById('resendEmail').value = email;
					
					popupLoginNotActivated();
				break;
				case 6:
					loginShowError('<strong>Sorry</strong>, but your account has been disabled by customer service. Please <a href="javascript: void(0)" onclick="hidePopup(\'popupLogin\'); showPopup()">Contact Us</a>.');
				break;
				default:
					if(httpHndl.responseText > 10 && httpHndl.responseText < 15)
						window.location = prefix+'profile.php?step='+(10-httpHndl.responseText);
				break;
			}
		}
	}
	
	httpHndl.open("GET", "/members/alogin.php?email="+email+"&pass="+pass+(dontHash ? '&donthash' : ''));
	httpHndl.send(null);
}

function loginShowError(error)
{
	document.getElementById('loginErrorMessage').style.display = 'inline';
	document.getElementById('loginErrorMessage').innerHTML = error;
}

function submitRecoverPassForm(form)
{
	document.getElementById('fpRecoveryErrors').style.display = 'none';
	document.getElementById('fpRecoveryForm').style.display = 'block';
	
	if(!form.email.value || form.email.value == 'Email address')
	{
		fpShowError('Please enter e-mail address');
		form.email.focus();
		
		return false;
	}
	else if(!validEmail(form.email.value))
	{
		fpShowError('Please enter valid e-mail address');
		form.email.focus();
		
		return false;
	}
	
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			switch(parseInt(httpHndl.responseText))
			{
				case 1:
					hidePopup('popupForgottenPass');
					popupFpSent();
				break;
				case 2:
					document.getElementById('fpRecoveryForm').style.display = 'none';
					fpShowError('You are currently using your Facebook account to login.<br /><br />To login using your email address, <a href="javascript: void(0)" onclick="requestSitePass(\''+form.email.value+'\')">click here</a> to request a password');
				break;
				case 3:
					document.getElementById('fpRecoveryForm').style.display = 'block';
					fpShowError('There is no account associated with this e-mail address');
				break;
			}
		}
	}
	
	httpHndl.open("GET", "/members/aforgottenpass.php?email="+form.email.value);
	httpHndl.send(null);
	
	return false;
}

function fpShowError(error)
{
	document.getElementById('fpRecoveryErrors').style.display = 'block';
	
	document.getElementById('fpRecoveryErrors').innerHTML = error;
}

function requestSitePass(email)
{
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			if(httpHndl.responseText == 1)
			{
				hidePopup('popupForgottenPass');
				popupFpSent();
			}
		}
	}
	
	httpHndl.open("GET", "/members/aforgottenpass.php?site&email="+email);
	httpHndl.send(null);
}

function submitResendActivationForm(form)
{
	raShowError('');
	
	if(!form.email.value)
	{
		raShowError('Please enter e-mail address');
		form.email.focus();
		
		return false;
	}
	else if(!validEmail(form.email.value))
	{
		raShowError('Please enter valid e-mail address');
		form.email.focus();
		
		return false;
	}
	
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			if(httpHndl.responseText == 1)
			{
				hidePopup('popupLogin');
				
				document.getElementById('codeSentTo').innerHTML = form.email.value;				
				popupLoginCodeSent();
			}
			else if(httpHndl.responseText == 2)
			{
				raShowError('There is another account associated with the new e-mail address that you requested the activation code to be sent to');
			}
		}
	}
	
	httpHndl.open("GET", "/members/aresendactivation.php?email="+form.email.value+"&oldmail="+document.getElementById('activationSentTo').innerHTML);
	httpHndl.send(null);
	
	return false;
}

function raShowError(error)
{
	document.getElementById('ResendActivationError').style.display = 'block';
	
	document.getElementById('ResendActivationError').innerHTML = error;
}

function submitChangeMailForm(form)
{
	cmShowError('');
	
	if(!form.email.value || form.email.value == 'Email address')
	{
		cmShowError('Please enter e-mail address');
		form.email.focus();
		
		return false;
	}
	else if(!validEmail(form.email.value))
	{
		cmShowError('Please enter valid e-mail address');
		form.email.focus();
		
		return false;
	}
	
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			if(httpHndl.responseText == 1)
			{
				hidePopup('popupSignUpActivated');
				
				document.getElementById('codeSentTo').innerHTML = form.email.value;				
				popupLoginCodeSent();
			}
			else if(httpHndl.responseText == 2)
			{
				cmShowError('There is another account associated with the new e-mail address that you requested the activation code to be sent to');
			}
		}
	}
	
	httpHndl.open("GET", "/members/aresendactivation.php?email="+form.email.value+"&oldmail="+document.getElementById('mailSentTo').innerHTML);
	httpHndl.send(null);
	
	return false;
}

function cmShowError(error)
{
	document.getElementById('changeMailError').style.display = 'block';
	
	document.getElementById('changeMailError').innerHTML = error;
}

function submitSignUpForm(form)
{
	suShowError('');
	
	if(!form.username.value)
	{
		suShowError('Please enter username');
		form.username.focus();
		
		return false;
	}
	
	if(!form.email.value)
	{
		suShowError('Please enter e-mail address');
		form.email.focus();
		
		return false;
	}
	else if(!validEmail(form.email.value))
	{
		suShowError('Please enter valid e-mail address');
		form.email.focus();
		
		return false;
	}
	
	if(!form.pass.value)
	{
		suShowError('Please enter password');
		form.pass.focus();
		
		return false;
	}
	else if(form.pass.value.length < 5)
	{
		suShowError('Your passsword must be at least 5 symbols long');
		form.pass.focus();
		
		return false;
	}
	
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			if(httpHndl.responseText == 1)
			{
				hidePopup('popupSignUp');
				showPopup('popupSignUpActivated');
				popupAccCodeSent();
				
				document.getElementById('mailSentTo').innerHTML = form.email.value;
				document.getElementById('mailSentTo2').innerHTML = form.email.value;
			}
			else if(httpHndl.responseText == 2)
			{
				suShowError('There is another account associated with this e-mail address');
			}
			else if(httpHndl.responseText == 3)
			{
				suShowError('This username is already in use. Pick again.');
			}
		}
	}
	
	httpHndl.open("GET", "/members/asignup.php?email="+form.email.value+"&username="+form.username.value+"&pass="+form.pass.value);
	httpHndl.send(null);
	
	return false;
}

function suShowError(error)
{
	document.getElementById('signUpErrorMessage').style.display = 'block';
	
	document.getElementById('signUpErrorMessage').innerHTML = error;
}

function signupValidateUsername(el)
{
	var username = el.value;
	var status = document.getElementById('statusUsername');
	
	checkUsernameAvailability(el.value, 'statusUsername');
}

function signupValidateSelection(el, what, baseClass, onlyValid)
{
	baseClass = baseClass || 'validateField';
	
	if(what == 'Location')
	{
		var valid = true;
		var errMessage = 'ERROR: Please make a selection';
		
		if(!el.value)
			valid = false;
		else if(el.value == 225 || el.value == 38)
		{
			if(!zipIsValid)
			{
				errMessage = 'ERROR: Please enter your zipcode';
				
				valid = false;
			}
		}
		else
		{
			if(document.getElementById('yourLocationRegion') && document.getElementById('yourLocationRegion').value == '')
				valid = false;
			
			if(document.getElementById('yourLocationCity') && document.getElementById('yourLocationCity').value == '')
				valid = false;
		}
		
		if(!valid && onlyValid)
		{
			document.getElementById('box'+what).className = baseClass;
			document.getElementById('status'+what).innerHTML = '';
			
			return false;
		}
		
		document.getElementById('box'+what).className = valid ? baseClass+' valid' : baseClass+' invalid';
		
		if(document.getElementById('status'+what))
			document.getElementById('status'+what).innerHTML = valid ? '' : errMessage;
	}
	else
	{
		var valid = true;
		
		if(!el.value)
			valid = false;
		
		document.getElementById('box'+what).className = valid ? baseClass+' valid' : baseClass+' invalid';
		
		if(document.getElementById('status'+what))
			document.getElementById('status'+what).innerHTML = valid ? '' : 'ERROR: Please make a selection';
		
		var valid = el.value ? true : false;
	}
	
	return valid ? true : false;
}

function signupChangeBirthDays()
{
	var year = document.getElementById('birthdayYear').value;
	
	if(!year)
		return false;
	
	var month = document.getElementById('birthdayMonth').value;
	var daysInMonth = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	
	var days = daysInMonth[month];
	
	if(month == 2 && !(year % 4) && (year % 100 || !(year % 400)))
		days += 1;
	
	var old = document.getElementById('birthdayDay').value;
	
	document.getElementById('birthdayDay').options.length = 1;
	
	for(var i = 1; i < days+1; i++)
	{
		var opt = document.createElement('option');
		opt.value = i;
		opt.text = i;
		
		document.getElementById('birthdayDay').appendChild(opt);
		
		if(i == old)
			document.getElementById('birthdayDay').selectedIndex = i;
	}
}

function signupValidateBirthday(onlyValid)
{
	var valid = document.getElementById('birthdayYear').value && document.getElementById('birthdayMonth').value && document.getElementById('birthdayDay').value;
	
	if(!valid && onlyValid)
	{
		document.getElementById('boxBirthday').className = 'validateField';
		document.getElementById('statusBirthday').innerHTML = '';
		return false;
	}
	
	document.getElementById('boxBirthday').className = valid ? 'validateField valid' : 'validateField invalid';
	document.getElementById('statusBirthday').innerHTML = valid ? '' : 'ERROR: Please make a selection';
	
	return valid;
}

function signupInterestedChanged(isAny)
{
	var any = document.getElementById('any');
	var dating = document.getElementById('dating');
	var friendship = document.getElementById('friendship');
	var networking = document.getElementById('networking');
	var marriage = document.getElementById('marriage');
	
	if(isAny && any.checked)
	{
		dating.checked = false;
		friendship.checked = false;
		networking.checked = false;
		marriage.checked = false;
	}
	else if(!dating.checked && !friendship.checked && !networking.checked && !marriage.checked)
		any.checked = true;
	else
		any.checked = false;
}

function signupValidateStep1(form)
{
	var valid = true;
	
	signupValidateUsername(document.getElementById('suusername'));
	
	if(!uNameAvailable)
	{
		valid = false;
		
		if(!form.username.value)
		{
			document.getElementById('boxUsername').className = 'validateField invalid';
			document.getElementById('statusUsername').innerHTML = 'Please choose username';
		}
	}
	
	if(!signupValidateSelection(form.gender, 'Gender'))
		valid = false;
	
	if(!signupValidateSelection(form.seeking, 'Seeking'))
		valid = false;
	
	if(!signupValidateSelection(form.relationshipStatus, 'Relationship'))
		valid = false;
	
	if(!signupValidateSelection(form.yourLocationCountry, 'Location'))
		valid = false;
	
	if(!signupValidateBirthday())
		valid = false;
	
	return valid;
}

function signupCountryChanged(country)
{
	if(country == 225 || country == 38)
	{
		document.getElementById('usaOrCanada').style.display = 'inline';
		document.getElementById('otherCountry').style.display = 'none';
		
		signupValidateZip(document.getElementById('zip'));
	}
	else
	{
		document.getElementById('usaOrCanada').style.display = 'none';
		document.getElementById('otherCountry').style.display = 'inline';
		
		document.getElementById('yourLocationRegion').selectedIndex = 0;
		document.getElementById('yourLocationCity').selectedIndex = 0;
		document.getElementById('yourLocationCity').options.length = 1;
		
		signupChangeRegions();
	}
}

function signupChangeRegions()
{
	if(document.getElementById('yourLocationCountry').value == 0)
	{
		if(document.getElementById('milesof'))
			document.getElementById('milesof').style.display = 'none';
		
		return false;
	}
	else if(document.getElementById('milesof'))
		document.getElementById('milesof').style.display = 'block';
	
	document.getElementById('yourLocationCity').selectedIndex = 0;
	
	pleaseWait.activate();
	
	locationSelector.getRegions(document.getElementById('yourLocationCountry').value);	
	//setTimeout("locationSelector.changeRegions(locationSelector.getRegions(document.getElementById('yourLocationCountry').value));", 100);
}

function signupRegionChanged()
{
	if(!document.getElementById('yourLocationCountry').value || !document.getElementById('yourLocationRegion').value)
		return false;
	
	pleaseWait.activate();
	
	locationSelector.getCities(document.getElementById('yourLocationCountry').value, document.getElementById('yourLocationRegion').value);
}

var locationSelector = 
{
	regions: [],
	cities: [],
	
	getRegions: function(cID)
	{
		if(!this.regions[cID])
		{
			var httpHndl = httpGetObject();
			
			httpHndl.onreadystatechange = function()
			{
				if(httpHndl.readyState == 4 && httpHndl.status == 200)
				{
					locationSelector.regions[cID] = httpHndl.responseText;
					
					locationSelector.changeRegions(locationSelector.regions[cID]);
				}
			}
			
			httpHndl.open("GET", "/members/getregions.php?cid="+cID);
			httpHndl.send(null);
		}
		else
			locationSelector.changeRegions(locationSelector.regions[cID]);
	},
	
	getCities: function(cID, rID)
	{
		if(!this.cities[cID])
			this.cities[cID] = [];
		
		if(!this.cities[cID][rID])
		{
			var httpHndl = httpGetObject();
			
			httpHndl.onreadystatechange = function()
			{
				if(httpHndl.readyState == 4 && httpHndl.status == 200)
				{
					locationSelector.cities[cID][rID] = httpHndl.responseText;
					
					locationSelector.changeCities(locationSelector.cities[cID][rID]);
				}
			}
			
			httpHndl.open("GET", "/members/getcities.php?cid="+cID+"&rid="+rID);
			httpHndl.send(null);
		}
		else
			locationSelector.changeCities(locationSelector.cities[cID][rID]);
	},
	
	changeRegions: function(regions)
	{
		var el = document.getElementById('yourLocationRegion');
		
		el.options.length = 1;
		
		var tmp = regions ? regions.split('#') : [];
		tmp[tmp.length] = '0,Other';
		
		for(var i = 0; i < tmp.length; i++)
		{
			if(!tmp[i])
				continue;
			
			var values = tmp[i].split(',');
			
			var opt = document.createElement('option');
			opt.value = values[0];
			opt.innerHTML = values[1];
			
			el.appendChild(opt);
		}
		
		pleaseWait.deactivate();
	}, 
	
	changeCities: function(cities)
	{
		var el = document.getElementById('yourLocationCity');
		
		el.options.length = 1;
		
		var tmp = cities.split('#');
		tmp[tmp.length] = '0,Other';
		
		for(var i = 0; i < tmp.length; i++)
		{
			if(!tmp[i])
				continue;
			
			var values = tmp[i].split(',');
			
			var opt = document.createElement('option');
			opt.value = values[0];
			opt.innerHTML = values[1];
			
			el.appendChild(opt);
		}
		
		pleaseWait.deactivate();
	}
}

var pleaseWait = 
{
	el: null,
	
	activate: function()
	{
		if(!this.el)
		{
			this.el = document.createElement('div');
			
			var blackScreen = document.createElement('div');
			blackScreen.className = 'blackScreen';
			
			this.el.appendChild(blackScreen);
			
			var loader = document.createElement('div');
			loader.className = 'loader';
			
			var img = document.createElement('img');
			img.src = '/images/loader.gif';
			
			loader.appendChild(img);
			
			this.el.appendChild(loader);
			
			document.body.appendChild(this.el);
		}
		
		this.el.style.display = 'block';
	}, 
	
	deactivate: function()
	{
		this.el.style.display = 'none';	
	}
}

var zipIsValid = false;
function signupValidateZip(el)
{
	var zip = el.value;
	
	if(el.value.length < 5)
	{
		document.getElementById('boxLocation').className = 'validateField invalid';
		document.getElementById('statusLocation').innerHTML = 'ERROR: Please enter valid zipcode';
		
		return false;
	}
	
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4)
		{
			if(httpHndl.status == 200)
			{
				if(httpHndl.responseText.substr(0, 1) == '#')
				{
					zipIsValid = true;
					
					signupValidateSelection(document.getElementById('yourLocationCountry'), 'Location');
				}
				else
				{
					zipIsValid = false;
					
					document.getElementById('boxLocation').className = 'validateField invalid';
					document.getElementById('statusLocation').innerHTML = 'ERROR: That zipcode is not in our database, please use another valid zipcode';
				}
			}
		}
	}
	
	var country = document.getElementById('yourLocationCountry').value == 225 ? 1 : 2;
	
	httpHndl.open("GET", "validatezip.php?dontcache="+Math.random()+"&zip="+zip+"&country="+country, true);
	httpHndl.send(null);
}

function signupValidateStep2(form)
{
	var valid = true;
	
	if(!signupValidateSelection(form.profileHeadline, 'Headline'))
		valid = false;
	
	if(!signupValidateSelection(form.haveChildren, 'Children', 'validateRow'))
		valid = false;
	
	if(!signupValidateHeight())
		valid = false;
	
	if(!signupValidateSelection(form.bodyType, 'BodyType', 'validateRow'))
		valid = false;
	
	if(!IS_LUNCHMIX && !signupValidateSelection(form.religion, 'Religion', 'validateRow'))
		valid = false;
	
	if(!signupValidateSelection(form.education, 'Education', 'validateRow'))
		valid = false;
	
	if(!signupValidateSelection(form.occupation, 'Occupation', 'validateRow'))
		valid = false;
	
	return valid;
}

function signupValidateHeight(onlyValid)
{
	var valid = document.getElementById('heightFeet').value != '' && document.getElementById('heightInches').value != '';
	
	if(!valid && onlyValid)
	{
		document.getElementById('boxHeight').className = 'validateRow';
		return false;
	}
	
	document.getElementById('boxHeight').className = 'validateRow '+(valid ? 'valid' : 'invalid');
	
	return valid;
}

function signupChangeCastes(religion)
{
	pleaseWait.activate();
	
	casteSelector.getCastes(religion);
}

var casteSelector = 
{
	castes: [], 
	
	getCastes: function(el)
	{
		var religion = el.value;
		var religionName = el.options[el.selectedIndex].innerHTML;
		
		if(!this.castes[religion])
		{
			var httpHndl = httpGetObject();
			
			httpHndl.onreadystatechange = function() 
			{
				if(httpHndl.readyState == 4 && httpHndl.status == 200)
				{
					casteSelector.castes[religion] = httpHndl.responseText ? httpHndl.responseText : '0,'+religionName+'#0,Other';
					casteSelector.changeCastes(casteSelector.castes[religion]);
				}
			}
			
			httpHndl.open("GET", "/members/getcastes.php?rid="+religion, true);
			httpHndl.send(null);
		}
		else
			casteSelector.changeCastes(casteSelector.castes[religion]);
	}, 
	
	changeCastes: function(castes)
	{
		if(!castes || castes.indexOf('#') == -1)
		{
			pleaseWait.deactivate();
			return false;
		}
		
		var el = document.getElementById('community');
		
		el.options.length = 0;
		
		var tmp = castes.split('#');
		
		for(var i = 0; i < tmp.length; i++)
		{
			if(!tmp[i])
				continue;
			
			var values = tmp[i].split(',');
			
			var opt = document.createElement('option');
			opt.value = values[0];
			opt.innerHTML = values[1];
			
			el.appendChild(opt);
			
			if(values[1].toLowerCase() == 'please select')
			{
				document.getElementById('rowCaste').className = 'validateRow';
				pleaseWait.deactivate();
				
				return false;
			}
		}
		
		document.getElementById('rowCaste').className = 'validateRow valid';
		
		pleaseWait.deactivate();
	}
}

function distanceRegionAndCitySelected()
{
	if(document.getElementById('yourLocationCountry').value == 0)
		return false;
	
	var distance = document.getElementById('miles');
	var region = document.getElementById('yourLocationRegion');
	var city = document.getElementById('yourLocationCity');
	
	if(region.options.length == 2 && city.options.length == 2)
		return true;
	
	if(distance.value != 0 && region.value && (city.value != "" || city.options.length == 2))
		return true;
	
	var selected = ((distance.value != 0) * 1) + ((region.value > 0) * 2) + ((city.value != "") * 4);
	
	if(selected)
		return selected;
	
	return false;
}

function validateSearchForm()
{
	var country = document.getElementById('yourLocationCountry').value;
	
	if(country == 225 || country == 38)
	{
		if(!zipIsValid && document.getElementById('miles').value)
		{
			alert('Please enter valid zipcode');
			
			return false;
		}
	}
	else
	{
		var selected = distanceRegionAndCitySelected();
		
		if(selected !== true && selected > 0 && selected < 8)
		{
			alert('Please select distance, region and city');
			
			return false;
		}		
	}
	
	return true;
}

function deletePhoto(id, type)
{
	if(!confirm('Are you sure you want to delete this photo?'))
		return false;
	
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			if(httpHndl.responseText == 1)
			{
				//alertMessage('Photo deleted', false, 2);
				
				if(type == 'primary')
				{	
					document.getElementById('mainPhoto').innerHTML = '<img src="/images/nophotobig.gif" alt="no photo" id="photoPrimary">';
				}
				else
				{
					var box = document.getElementById('photoBox'+id);
					
					if(box && box.parentNode)
						box.parentNode.removeChild(box);
					
					if(type == 'private')
						changePhotoCount(-1, 0);
					else
						changePhotoCount(0, -1);
				}
				
				if(document.getElementById('pendingApprovalText'))
				{
					document.getElementById('pendingApprovalText').style.display = 'none';					
					document.getElementById('btnDeletePhoto').style.display = 'none';
					document.getElementById('btnReplacePhoto').style.display = 'none';
					document.getElementById('btnAddPhoto').style.display = 'block';
				}
			}
			else
				alertMessage('Photo cannot be deleted', true);
		}
	}
	
	httpHndl.open("GET", "adeletephoto.php?id="+id, true);
	httpHndl.send(null);
}

function changePhotoType(id, from, to, el)
{
	if(from == 'new' && (document.getElementById('uploadedPhoto').src == '' || document.getElementById('uploadedPhoto').src == window.location))
	{
		alert('Please upload a photo first');
		
		return false;
	}
		
	if(id == -1)
		id = document.getElementById('npID').value;
	
	var question = '';
	
	if(to == 'primary')
		question = 'Are you sure you wish to make this your primary photo?';
	else if(to == 'public')
		question = 'Are you sure you wish to make this photo public?';
	else
		question = 'Are you sure you wish to make this photo private?';
	
	//if(!confirm(question))
	//	return false;
	
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			if(httpHndl.responseText == 1)
			{
				if(from == 'new')
				{
					if(to == 'primary')
					{
						changePrimaryPhoto();
						
						var newSrc = document.getElementById('uploadedPhoto').src;
						document.getElementById('mainPhoto').innerHTML =  '<a target="_blank" href="'+newSrc+'"><img src="'+newSrc+'" alt=""></a>';
						document.getElementById('mainPhotoID').value = id;
					}
					else
					{				
						var src = document.getElementById('uploadedPhoto').src;
						
						addNewPhoto(id, to, src);
						
						var prv = to == 'private' ? 1 : 0;
						var pub = to == 'public' ? 1 : 0;
						changePhotoCount(prv, pub);
					}
					
					document.getElementById('newPhoto').value = '';
					document.getElementById('uploadedPhoto').src = '';
					
					document.getElementById('newPhoto').focus();
				}
				else
				{
					if(to == 'primary')
					{
						var box = document.getElementById('photoBox'+id);
						
						var newSrc = document.getElementById('mPhoto'+id).src;
						
						if(box && box.parentNode)
							box.parentNode.removeChild(box);
						
						changePrimaryPhoto();
						
						document.getElementById('mainPhoto').innerHTML =  '<a target="_blank" href="'+newSrc+'"><img src="'+newSrc+'" alt=""></a>';
						document.getElementById('mainPhotoID').value = id;
						
						if(from == 'private')
							changePhotoCount(-1, 0);
						else
							changePhotoCount(0, -1);
					}
					else
					{
						var box = document.getElementById('photoBox'+id);
						
						var placeholder = to == 'private' ? 'privatePhotosBox' : 'publicPhotosBox';
						
						document.getElementById(placeholder).appendChild(box);
						
						if(to == 'private')
							changePhotoCount(1, -1);
						else
							changePhotoCount(-1, 1);
						
						swapSiblingsVisibility(el);
						
						swapSiblingsVisibility(document.getElementById('deletePhoto'+id));
					}
				}
			}
			else
				alertMessage('Photo type cannot be changed', true);
		}
	}
	
	httpHndl.open("GET", "achangephototype.php?id="+id+"&type="+to, true);
	httpHndl.send(null);
}

function changePhotoCount(priv, pub)
{
	var pr = document.getElementById('privatePhotosCnt');
	var pb = document.getElementById('publicPhotosCnt');
	
	var prvCnt = pr.innerHTML = parseInt(pr.innerHTML)+priv;
	var pubCnt = pb.innerHTML = parseInt(pb.innerHTML)+pub;
	
	document.getElementById('noPhotosPrivate').style.display = prvCnt ? 'none' : 'inline';
	document.getElementById('noPhotosPublic').style.display = pubCnt ? 'none' : 'inline';
	
	var num = prvCnt;
	
	if(pubCnt > num)
		num = pubCnt;
	
	showAllPhotos(null, num);
	
	document.getElementById('pixVisible').innerHTML = document.getElementById('pixTotal').innerHTML = prvCnt+pubCnt;
	
	if(document.getElementById('pixViewAll'))
		document.getElementById('pixViewAll').style.display = 'none';
	
	document.getElementById('availableSlots').innerHTML = parseInt(document.getElementById('availableSlots').innerHTML)-(priv+pub);
	document.getElementById('availableSlots2').innerHTML = parseInt(document.getElementById('availableSlots2').innerHTML)-(priv+pub);
}

function addNewPhoto(id, type, src)
{
	var newPic = document.createElement('div');					
	var bigSrc = src.replace('70_', '400_');
	var fullSizeSrc = src.replace('70_', '');
	
	newPic.id = 'photoBox'+id;
	
	var html = '';
	
	html += '<div class="blackBoxTop">&nbsp;</div>';
	html += '<div class="blackBox">';
	html += '<table border="0" cellpadding="0" cellspacing="0" width="100%">';
	html += '<tr>';
	html += '<td width="50%" rowspan="2" align="center" valign="middle" style="height: 80px;">';
	html += '<a href="'+fullSizeSrc+'" target="_blank" align="left">';
	html += '<img id="mPhoto'+id+'" src="'+src+'"  style="max-width: 70px; max-height: 70px;" onmouseover="showBiggerPhoto(this)" />';
	html += '<img src="'+bigSrc+'" style="position: absolute; z-index: 2; display: none" onload="adjustPos(this, 600, 600)" onmouseout="this.style.display = \'none\'" />';
	html += '</a>';
	html += '</td>';
	html += '<td width="50%" align="right" valign="middle">';
	html += '<input type="image" name="makePrimary" value="Primary" onclick="changePhotoType('+id+', \''+type+'\', \'primary\')" src="../images/bb-make-primary.png" />';
	html += '</td>';
	html += '</tr>';
	html += '<tr>';
	html += '<td align="right" valign="middle">';
	
	if(type == 'public')
	{
		html += '<input type="image" name="MakeBackstage" value="Backstage" onclick="changePhotoType('+id+', \'public\', \'private\', this)" src="../images/bb-make-private.png" />';
		html += '<input style="display: none" type="image" name="MakePublic" value="Public" onclick="changePhotoType('+id+', \'private\', \'public\', this)" src="../images/bb-make-public.png" />';
	}
	else if(type == 'private')
	{
		html += '<input type="image" name="MakePublic" value="Public" onclick="changePhotoType('+id+', \'private\', \'public\', this)" src="../images/bb-make-public.png" />';
		html += '<input style="display: none" type="image" name="MakeBackstage" value="Backstage" onclick="changePhotoType('+id+', \'public\', \'private\', this)" src="../images/bb-make-private.png" />';
	}					
	
	html += '</td>';
	html += '</tr>';
	html += '<tr>';
	html += '<td align="left" valign="middle">';
	html += '<img src="../images/approved-pending.png" />';
	html += '</td>';
	html += '<td align="right" valign="middle">';
	
	if(type == 'public')
	{
		html += '<a id="deletePhoto'+id+'" href="javascript: void(0)" onclick="deletePhoto('+id+', \'public\')"><img src="../images/bb-delete.png" /></a>';
		html += '<a style="display: none" href="javascript: void(0)" onclick="deletePhoto('+id+', \'private\')"><img src="../images/bb-delete.png" /></a>';
	}
	else if(type == 'private')
	{
		html += '<a id="deletePhoto'+id+'" href="javascript: void(0)" onclick="deletePhoto('+id+', \'private\')" class="editRedLink" ><img src="../images/bb-delete.png" /></a>';
		html += '<a style="display: none" href="javascript: void(0)" onclick="deletePhoto('+id+', \'public\')" class="editRedLink" ><img src="../images/bb-delete.png" /></a>';
	}
	
	html += '</td>';
	html += '</tr>';
	html += '</table>';
	html += '</div>';
	html += '<div class="blackBoxBottom">&nbsp;</div>';
	
	newPic.innerHTML = html;
	
	document.getElementById(type == 'private' ? 'privatePhotosBox' : 'publicPhotosBox').appendChild(newPic);
}

function changePrimaryPhoto()
{
	var oldSrc = document.getElementById('mainPhoto').innerHTML;
	
	if(oldSrc.trim().substr(0, 2) == '<a')
	{
		var start = oldSrc.indexOf('src="');
		
		var imgSrc = '';
		for(var i = start+5; i < oldSrc.length; i++)
		{
			if(oldSrc[i] == '"')
				break;
			
			imgSrc += oldSrc[i];
		}
	}
	
	var oldID = document.getElementById('mainPhotoID').value;
	
	if(imgSrc && oldID != null)
	{
		addNewPhoto(oldID, 'public', imgSrc);
		changePhotoCount(0, 1);
	}
}

var ccFloat = 
{
	target: null, 
	interval: null, 
	
	init: function()
	{
		this.interval = setInterval("ccFloat.loop()", 250);
	},
	
	redrawBase: function()
	{
		if(document.getElementById('cometchat_base'))
			ccFloat.move(parseInt(document.getElementById('cometchat_base').style.top));
	},
	
	loop: function()
	{
		if(!document.getElementById('cometchat_base'))
			return false;
		
		var fbInfo = FB.Canvas.getPageInfo();
		
		this.target = parseInt(fbInfo.scrollTop)+parseInt(fbInfo.clientHeight)-parseInt(fbInfo.offsetTop)-25;
						
		if(this.target === null)
			return;
		
		var current = parseInt(document.getElementById('cometchat_base').style.top);
		
		if(!current)
			current = 1000;
		
		if(this.target > parseInt(document.body.clientHeight)-25)
			this.target = parseInt(document.body.clientHeight)-25;
		
		var diff = this.target - current;
		
		if(diff)
		{
			var step = parseInt(diff/5);
			
			setTimeout("ccFloat.move("+(this.target-step*4)+")", 10);
			setTimeout("ccFloat.move("+(this.target-step*3)+")", 20);
			setTimeout("ccFloat.move("+(this.target-step*2)+")", 30);
			setTimeout("ccFloat.move("+(this.target-step)+")", 40);
			setTimeout("ccFloat.move("+(this.target)+")", 50);
		}
		else
			ccFloat.move(current);
	},
	
	setTarget: function(h)
	{
		this.target = h;
	},
	
	move: function(h)
	{
		document.getElementById('cometchat_base').style.top = h+'px';
		document.getElementById('cometchat_hidden').style.top = h+'px';
		
		var el = getElementsByClassName('cometchat_tabpopup');
		
		for(var i = 0; i < el.length; i++)
		{
			if(el[i].id)
			{
				var elHeight = el[i].id.indexOf('cometchat_user_') == 0 ? 304 : 233;
				
				if(el[i].id == 'cometchat_optionsbutton_popup')
					elHeight = 279;
				
				document.getElementById(el[i].id).style.bottom = null;						
				document.getElementById(el[i].id).style.top = (h-elHeight)+'px';
			}
		}
		
		document.getElementById('cometchat_trayicon_chatrooms_popup').style.bottom = null;
		document.getElementById('cometchat_trayicon_chatrooms_popup').style.top = (h-325)+'px';
		
		document.getElementById('cometchat_trayicon_announcements_popup').style.bottom = null;
		document.getElementById('cometchat_trayicon_announcements_popup').style.top = (h-325)+'px';
		
		document.getElementById('cometchat_trayicon_games_popup').style.bottom = null;
		document.getElementById('cometchat_trayicon_games_popup').style.top = (h-325)+'px';
		
		document.getElementById('cometchat_trayicon_translate_popup').style.bottom = null;
		document.getElementById('cometchat_trayicon_translate_popup').style.top = (h-325)+'px';
		
		document.getElementById('cometchat_trayicon_share_popup').style.bottom = null;
		document.getElementById('cometchat_trayicon_share_popup').style.top = (h-75)+'px';
		
		document.getElementById('cometchat_tooltip').style.bottom = null;
		document.getElementById('cometchat_tooltip').style.top = (h-30)+'px';
		document.getElementById('cometchat_tooltip').style.height = '20px';
		
		document.getElementById('cometchat_userstab_popup').style.bottom = null;
		document.getElementById('cometchat_userstab_popup').style.top = (h-233)+'px';
		
		document.getElementById('cometchat_optionsbutton_popup').style.bottom = null;
		document.getElementById('cometchat_optionsbutton_popup').style.top = (h-279)+'px';
	}
}

function getElementsByClassName(className)
{
	if(document.getElementsByClassName)
		return document.getElementsByClassName(className);
	else
	{
		var response = [];
		
		var el = document.getElementsByTagName('div');				
		for(var i = 0; i < el.length; i++)
		{
			if(el[i].className == className)
				response[response.length] = el[i];
		}
		
		return response;
	}
}

function fbSilentLogin(fbID)
{
	var httpHndl = httpGetObject();
	
	httpHndl.onreadystatechange = function()
	{
		if(httpHndl.readyState == 4 && httpHndl.status == 200)
		{
			if(!httpHndl.responseText.indexOf('#'))
				return false;
			
			var tmp = httpHndl.responseText.split('#');
			
			if(tmp[0])
				aLogin(tmp[0], tmp[1], true);
		}
	}
	
	httpHndl.open("GET", "/members/getloginbyfbid.php?fbid="+fbID);
	httpHndl.send(null);
}
