<!-- Hide script from old browsers
// Make sure file is not hosted in a different frameset
if ( top.location.href != window.location.href )
  { top.location.href=window.location.href }

    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 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)
{
	var statusEl = document.getElementById('cityAndState');
	
	var reUS = /^\d{5}$/;
	var reCA = /^\w{6}$/;
	
	var status = '';
	var color = 'red';
	
	if(document.getElementById('country').value != 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)
{
	if(el.value == 0)
	{
		if(document.getElementById('miles'))
		{
			document.getElementById('miles').value = '';
			document.getElementById('miles').readOnly = true;
		}
		
		document.getElementById('ZIP').value = '';
		document.getElementById('ZIP').readOnly = true;
		
		zipIsValid = true;
	}
	else
	{
		//document.getElementById('miles').readOnly = false;
		document.getElementById('ZIP').readOnly = false;
	}
}

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;
			}
		}
	}
	
	var country = document.getElementById('country').value == 225 ? 1 : 2;
	
	httpHndl.open("GET", "validatezip.php?dontcache="+Math.random()+"&zip="+zip+"&country="+country, true);
	httpHndl.send();
}

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)
{
	var len = el.value.length;
	var status = document.getElementById(field+'Status');
	var counter = document.getElementById(field+'Count');
	
	if(len < 100)
	{
		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(100-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.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)
{
	if(!zipIsValid)
	{
		alert('That zipcode not in our database, please use another valid zipcode');
		
		return false;
	}
	
	return true;
}

var memberVerified = false;
function verifyMember(button, checkGold)
{
	var checkGold = checkGold || null;
	
	var button = button;
	var toMember = 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;
	}
	
	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('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';
				}
				
				document.getElementById('verifiedMemberBox').innerHTML = msg;
			}
		}
	}
	
	httpHndl.open("GET", "verifymember.php?dontcache="+Math.random()+"&username="+toMember.value+(checkGold ? "&checkGold="+checkGold : ''), true);
	httpHndl.send();
}

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)
{
	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';
		
		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';
				}
			}
		}
	}
	
	httpHndl.open("GET", "checkusername.php?dontcache="+Math.random()+"&username="+username, true);
	httpHndl.send();
}

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();
}

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)
{
	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();
}

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 chose an option below)';
		
		document.getElementById('uploadedPhoto').src = message;
		document.getElementById('uploadedPhoto').style.width = 'auto';
		document.getElementById('uploadedPhoto').style.height = 'auto';
		
		document.getElementById('npID').value = npID;
	}
	else 
	{
		document.getElementById('uploadResult').innerHTML = '<span>The photo cannot be uploaded!<\/span>';
		
		alert(message);
	}
	
	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;
	
	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();
	
	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();
}

function showFilteredMessageBox(show)
{
	document.getElementById('filteredMessageBox').style.display = show ? 'block' : 'none';
}