var ber="&rand="+new Date().getTime();

function LoadTrack(files,swf,a,id,ti,ar,usr){
	new Ajax.Updater("dummy", '/process/musicplayed.asp?id='+id+ber, { method: 'get' });
	$(a).innerHTML= "Playing";
	thisMovie(swf).loadFile({file:files,title:ti,author:ar,link:"/profile.asp?id="+usr}); 
	thisMovie(swf).sendEvent('playitem', 0);
	setTimeout('$("'+a+'").innerHTML= "Play"',2000);
	
}

/*-------------------------------------------------------------------
Player javascript API
-------------------------------------------------------------------*/
function sendEvent(swf,typ,prm) { 
	thisMovie(swf).sendEvent(typ,prm); 
};
function getUpdate(typ,pr1,pr2,swf) {
	if(typ == "state" && swf == "jstest") {
		gid('stateshow').innerHTML = pr1;
	}
};
function getLength(swf) { 
	var len = thisMovie(swf).getLength(); 
	alert('the length of the playlist is: '+len);
};
function addItem(swf,obj,idx) {
	thisMovie(swf).addItem(obj,idx);
};
function removeItem(swf,idx) {
	thisMovie(swf).removeItem(idx);
};
function itemData(swf,idx) { 
	var obj = thisMovie(swf).itemData(idx);
	var txt = "";
	for(var i in obj) { 
		txt += i+": "+obj[i]+"\n";
	}
	alert(txt);
};
function thisMovie(movieName) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
};

function SEtLoad(){
	$('inv1').style.display='none';
	$('inv1a').style.display='';
	$('inv2').style.display='none';
	$('inv2a').style.display='';
}
function checkall(way){
	$$("input.chll").each(function(element){
		if(way=="on"){
			element.checked=true;
		}else{
			element.checked=false;
		}
	});
	return false;
}

function mrate(star){
	var temp = star.id.split("-");
	for (i=1;i<=10;i++){
		if(i<=temp[1]){
			document.getElementById("r-"+i).src='/img/star.jpg';
		}else{
			document.getElementById("r-"+i).src='/img/star_off.jpg';
		}
	}
	$('rate').value=temp[1];
}

function loadbar(div,limit,PID){
	var updater = $(div);
	updater.style.display="";
	updater.innerHTML="Uploading, Please Wait";
	setTimeout("barupdater('"+div+"',10,'"+PID+"');",500);
}
function barupdater(div,limit,pid){
	limit = limit -1;
	new Ajax.Updater(div, '/includes/uploadbar.asp?PID='+pid+"&to="+limit+ber, { method: 'get' });
	setTimeout("barupdater('"+div+"',"+limit+",'"+pid+"');",2000);
}
function PluginPost(){
	var url = "process/plugins.asp?"
	url = url+Sortable.serialize('firstlist');
	url = url+"&"+Sortable.serialize('secondlist');
	url = url+"&"+Sortable.serialize('thirdlist');
	window.location=url;
}
function ClubPost(AID){
	var url = "process/clubgal.asp?"
	url = url+Sortable.serialize('firstlist');
	url = url+"&id="+AID;
	window.location=url;
}

function ReorderPost(AID){
	var url = "process/reorder.asp?"
	url = url+Sortable.serialize('firstlist');
	url = url+"&id="+AID;
	window.location=url;
}
function DeleteShopImage(ID,div){
	new Ajax.Updater(div, 'process/delimg.asp?ID='+ID+ber, { method: 'get' });
	setTimeout("$('"+div+"').style.display='none';",3000);
}
function ShopExtend(ID,div){
	new Ajax.Updater(div, 'process/extend.asp?ID='+ID+ber, { method: 'get' });
}
function ShopWithdraw(ID,div){
	new Ajax.Updater(div, '/shop/process/withdraw.asp?ID='+ID+ber, { method: 'get' });
}
function ChangeImg(img,pimg){
	$(img).src = pimg.src;
}
var mapobj = "";

function loadamap(lon,lat,height,div){
	var map = new GMap2($(div));
	map.setCenter(new GLatLng(lat, lon), height);
	var point = new GLatLng(lat,lon);
	map.addOverlay(new GMarker(point));
}
var MapLoaded = false;
function mapload() {
	if(!$("map") || $("map") == null || $("map") == "undefined"){
	}else{
		if (GBrowserIsCompatible()) {
			var map = new GMap2($("map"));
			mapobj = map;
			mapobj.setCenter(new GLatLng(53.4967, -2.0015), 6);
			mapobj.addControl(new GSmallMapControl());
			var firstpoints =mapobj.fromDivPixelToLatLng(new GPoint(0,0));
			var secondpoints =mapobj.fromDivPixelToLatLng(new GPoint(mapobj.getSize().width,mapobj.getSize().height));
			GetPoints(firstpoints,secondpoints,SearchType);		
		}
	}
}
var adstatus="";
function GetPoints(Fp,Sp,Wh){
	var lists="";
	$("map").style.display = "none";
	$("loader").style.display = "";
	if (Wh=="club" || Wh=="event"){
		$('nas').style.display="none";
	}
	mapobj.addControl(new GSmallMapControl());
	new Ajax.Request('/process/services.asp?type='+Wh+'&x1='+Fp.x+'&x2='+Sp.x+'&y1='+Fp.y+'&y2='+Sp.y+ber, {
		method:'get',
		onSuccess: function(transport){
			var json = transport.responseText.evalJSON();
			switch (Wh){
				case "hire": {
					for (var i = 0; i < json.hire.length; i++) {
						var point = new GLatLng(json.hire[i].latitude,json.hire[i].longitude);
						var infoTabs = [
							new GInfoWindowTab("Info", json.hire[i].t1),
							new GInfoWindowTab("Contact", json.hire[i].t2),
							new GInfoWindowTab("Hire", json.hire[i].t3)
						];
						mapobj.addOverlay(createMarker(point,infoTabs,json.hire[i].ad_status));
					}
					$("map").style.display = "";
					$("loader").style.display = "none";
					MapLoaded = true;
					break;
				}
				case "repair": {
					for (var i = 0; i < json.repair.length; i++) {
						var point = new GLatLng(json.repair[i].latitude,json.repair[i].longitude);
						var infoTabs = [
							new GInfoWindowTab("Info", json.repair[i].t1),
							new GInfoWindowTab("Contact", json.repair[i].t2)
						];
						mapobj.addOverlay(createMarker(point,infoTabs,json.repair[i].ad_status));
					}
					$("map").style.display = "";
					$("loader").style.display = "none";
					MapLoaded = true;
					break;
				}
				case "record": {
					for (var i = 0; i < json.record.length; i++) {
						var point = new GLatLng(json.record[i].latitude,json.record[i].longitude);
						var infoTabs = [
							new GInfoWindowTab("Info", json.record[i].t1),
							new GInfoWindowTab("Contact", json.record[i].t2)
						];
						mapobj.addOverlay(createMarker(point,infoTabs,json.record[i].ad_status));
					}
					$("map").style.display = "";
					$("loader").style.display = "none";
					MapLoaded = true;
					break;
				}
				case "event": {
					for (var i = 0; i < json.club.length; i++) {
						var point = new GLatLng(json.club[i].latitude,json.club[i].longitude);
						var infoTabs = [
							new GInfoWindowTab("Event", json.club[i].t1),
							new GInfoWindowTab("Location", json.club[i].t2),
							new GInfoWindowTab("Upcoming", json.club[i].t3)
						];
						mapobj.addOverlay(createMarker(point,infoTabs,json.club[i].ad_status));
					}
					$("map").style.display = "";
					$("loader").style.display = "none";
					MapLoaded = true;
					adstatus =json.AD;
					ADS();
					break;
				}
				case "club": {
					for (var i = 0; i < json.club.length; i++) {
						var point = new GLatLng(json.club[i].latitude,json.club[i].longitude);
						var infoTabs = [new GInfoWindowTab("Info", json.club[i].t1),new GInfoWindowTab("Address", json.club[i].t2),new GInfoWindowTab("Events", json.club[i].t3)];
						mapobj.addOverlay(createMarker(point,infoTabs,json.club[i].ad_status));
					}
					$("map").style.display = "";
					$("loader").style.display = "none";
					MapLoaded = true;
					adstatus =json.AD;
					ADS();
					break;
				}
			}
		}
	});
}
var prev=-1;
function ADS(){	
	var div = "lrg";
	var ranNum= Math.floor(Math.random()*adstatus.length);
	prev=0;
	if (adstatus.length>1){
		while(ranNum==prev){
			var ranNum= Math.floor(Math.random()*adstatus.length);
		}
	}
	prev=ranNum;
	image2 = new Image();
	image2.src = "/img/services/"+adstatus[ranNum].banner;
	if(adstatus[ranNum].banner.length>0){
		$('nas').style.display="";
		$(div).innerHTML = "<center><a href=\"/event.asp?id="+adstatus[ranNum].eid+"\"><img border=\"0\" alt=\"advertising\" src=\"/img/services/"+adstatus[ranNum].banner+"\"><br>Click Here to View Event</a></center>";
		new Effect.SlideDown($(div));
		if (adstatus.length>1){
			setTimeout('ADS();',10000);
		}
	}
}


function PostcodeSearch(pc){
	if (MapLoaded==true){
		new Ajax.Request('/process/geocode.asp?s='+$(pc).value+ber, {
			method:'get',
			onSuccess: function(transport){
				var json = transport.responseText.evalJSON();
				mapobj.setCenter(new GLatLng(json.result_set[0].point.lat,json.result_set[0].point.lon), 11);
			}
		});
	}else{
		alert("Please Wait for the Map to load");
	}
}

function createMarker(point, number,add_status) {
  var marker = new GMarker(point);
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowTabsHtml(number);
  });
  return marker;
}
function InputClear(id){
	if($(id).value=="username..." || $(id).value=="password..."){
		$(id).value="";
	}
}
var showorhide = 0;
var origTxt = "";
function ShowHide(Aid,Did,text){
	if(showorhide==0){
		new Effect.Grow($(Did));
		origTxt = $(Aid).innerHTML;
		$(Aid).innerHTML = text;
		showorhide = 1;
	}else{
		new Effect.Shrink($(Did)); 
		$(Aid).innerHTML = origTxt;
		showorhide = 0;
	}
}

function docustom(id,div,selected){
	$(div).innerHTML = "<input name='c_manu' id='c_manu' type='text' class='clean lrg'> <BR><a href=\"javascript:UpdateManu('"+id+"','"+div+"','"+selected+"');\">Show List</a>";
}
	
function UpdateManu(id,div,selected){
	new Ajax.Request('process/json.asp?id='+$(id).value+ber, {
		method:'get',
		onSuccess: function(transport){
			var json = transport.responseText.evalJSON();
			if(json.total=="0"){
				$(div).innerHTML = "<input class='clean lrg' name='c_manu' id='c_manu' type='text'>";
			}else{
				var list = "<select name='manu' id='manu' class='clean lrg'>";
				for (var i = 0; i < json.list.length; i++) {
					if (selected==json.list[i].id){
						list = list + "<option value='"+json.list[i].id+"' selected>"+json.list[i].name+"</option>";
					}else{
						list = list + "<option value='"+json.list[i].id+"'>"+json.list[i].name+"</option>";
					}
				}
				list = list + "</select> <a href=\"javascript:docustom('"+id+"','"+div+"','"+selected+"');\">Not Listed?</a>";
				$(div).innerHTML = list;
			}
		}
	});
}
function loadad(id){
	new Ajax.Request('/process/advert.asp?id='+id+ber, {
		method:'get',
		onSuccess: function(transport){
			if(transport.responseText.length > 4){
				window.location = transport.responseText;
			}
		}
	});
}
var rateloaded = false;
var comloaded = false;
function CommTog(what){
	if(what=="rate"){
		if(rateloaded==true){
			new Effect.BlindUp($('dorate'));
			rateloaded = false;
		}else{
			if(comloaded==true){
				new Effect.BlindUp($('profile_comments'));
			}
			new Effect.BlindDown($('dorate'));
			rateloaded = true;
		}
	}
	if(what=="comment"){			
		if(comloaded==true){
			new Effect.BlindUp($('profile_comments'));
			comloaded = false;
		}else{
			if(rateloaded==true){
				new Effect.BlindUp($('rate-it'));
			}
			new Effect.BlindDown($('profile_comments'));
			comloaded = true;
		}
	}
}
function ChoSear(itm){
	$('avid').style.fontWeight = "normal";
	$('amus').style.fontWeight = "normal";
	$('apro').style.fontWeight = "normal";
	$('aimg').style.fontWeight = "normal";
	$('aclubs').style.fontWeight = "normal";
	switch (itm){
    case "video": {
		$('avid').style.fontWeight = "bold";
		$('type2').value='video';
		$('users2').style.display ='none';
		$('rest2').style.display ='';
		break;
	}
	case "images":{
		$('aimg').style.fontWeight = "bold";
		$('type2').value='images';
		$('users2').style.display ='none';
		$('rest2').style.display ='';
		break;
	}
	case "profile":{
		$('apro').style.fontWeight = "bold";
		$('type2').value='profile';
		$('users2').style.display ='';
		$('rest2').style.display ='none';
		break;
	}
	case "music":{
		$('amus').style.fontWeight = "bold";
		$('type2').value='music';
		$('users2').style.display ='none';
		$('rest2').style.display ='';
		break;
	}
	case "web":{
		$('aweb').style.fontWeight = "bold";
		$('type2').value='web';
		$('users2').style.display ='none';
		$('rest2').style.display ='';
		break;
	}
	case "clubs": {
		$('aclubs').style.fontWeight = "bold";
		$('type2').value='club';
		$('users2').style.display ='none';
		$('rest2').style.display ='';
		break;
	}
	}
}

function ChoSear2(itm){
	$('aname').style.fontWeight = "normal";
	$('astyle').style.fontWeight = "normal";
	$('apost').style.fontWeight = "normal";
	$('adesc').style.fontWeight = "normal";
	$('aaddr').style.fontWeight = "normal";
	switch (itm){
    case "name": {
		$('aname').style.fontWeight = "bold";
		$('type2').value='name';
		break;
	}
	case "style": {
		$('astyle').style.fontWeight = "bold";
		$('type2').value='style';
		break;
	}
	case "post": {
		$('apost').style.fontWeight = "bold";
		$('type2').value='post';
		break;
	}
	case "desc": {
		$('adesc').style.fontWeight = "bold";
		$('type2').value='desc';
		break;
	}
	case "addr": {
		$('aaddr').style.fontWeight = "bold";
		$('type2').value='addr';
		break;
	}
	}
}


function ChoSear3(itm){
	$('aname').style.fontWeight = "normal";
	$('apost').style.fontWeight = "normal";
	$('adesc').style.fontWeight = "normal";
	$('aaddr').style.fontWeight = "normal";
	switch (itm){
    case "name": {
		$('aname').style.fontWeight = "bold";
		$('type2').value='name';
		break;
	}
	case "post": {
		$('apost').style.fontWeight = "bold";
		$('type2').value='post';
		break;
	}
	case "desc": {
		$('adesc').style.fontWeight = "bold";
		$('type2').value='desc';
		break;
	}
	case "addr": {
		$('aaddr').style.fontWeight = "bold";
		$('type2').value='addr';
		break;
	}
	}
}

var allids=Array();
var allemails=Array();
function GrabContacts(typ,user,pass){
	$('form').style.display="none";
	$('loader').innerHTML="<center><img src=\"/img/loader.gif\"><br>Gathering your Contact list<br><b>Please Wait</centeR>";
	switch (typ){
		case "msn": {
			var url ='/php/MSN/index.php';
			break;
		}
		case "gmail": {
			var url ='/php/Gmail/index.php';
			break;
		}
		case "aim": {
			var url ='/php/aim/index.php';
			break;
		}
		case "yahoo": {
			var url ='/php/Yahoo/index.php';
			break;
		}
		case "myspace": {
			var url ='/php/myspace/index.php';
			break;
		}
	}
	
	new Ajax.Request(url+'?username='+user+'&password='+pass,{
    method:'get',
    onSuccess: function(transport){
		var json = transport.responseText.evalJSON();
		if(json.error=="1"){
			$('form').style.display="";
			$('loader').innerHTML="<center><font color=\"red\">Could not Load List. Maybe your username or password is incorrect</font></centeR>";
		}else{
			$('loader').innerHTML="<center><font color=\"green\"><img src=\"/img/loader.gif\"><br>Successfully Got List<br><b>Please Wait</font></centeR>";
			if(json.contacts.length<1){
				$('loader').innerHTML="<center><font color=\"red\">Could not find anyone in your list why not manually add them <a href=\"tellmyfriends.asp\">here</a></font></centeR>";
			}else{
				var output=""
				for (var i = 0; i < json.contacts.length; i++) {
					allids[i]="F-"+i;
					allemails[i]=json.contacts[i].email;
					output+="<div title=\"Send an invite to "+json.contacts[i].email+"\"  onclick=\"SendRequest('"+json.contacts[i].email+"',this)\" id=\"F-"+i+"\" class=\"Simple friends\">";
					output+="<img src=\""+json.contacts[i].img+"\" align=\"left\" style=\"width:50px;height:50px;\">";
					output+="<b>"+json.contacts[i].name+"</b><br>";
					output+="<i>"+json.contacts[i].email+"</i><br>";
					output+="<br style=\"clear:both;\"></div>";
				}
				out1 = "<Center><img src=\"/img/buttons/selectall.png\" onclick=\"SelectAll();\" style=\"cursor:pointer;\" hspace=\"10\"><input onclick=\"Invite()\" name=\"\" class=\"button\" type=\"image\" src=\"/img/buttons/invite.png\" hspace=\"10\" /></center>";
				$('loader').innerHTML="<BR><p>Click on the friends you want to send an invite to. If they are already on JustMixin we will send a friend invite for you. <br></p>"+out1+output+"<center><img hspace=\"10\" src=\"/img/buttons/selectall.png\" onclick=\"SelectAll();\" style=\"cursor:pointer;\"><input onclick=\"Invite()\" name=\"\" hspace=\"10\" class=\"button\" type=\"image\" src=\"/img/buttons/invite.png\" /></center>";
			}
		}
    },
    onFailure: function(){ 
		$('form').style.display="";
		$('loader').innerHTML="<center><font color=\"red\">Internal Error Occured.</font></centeR>";
	}
  });
	return false;
}
var clicked=Array();
var emailarray=Array();
function SendRequest(email,div){
	var got=false
	for (var i = 0; i < clicked.length; i++) {
		if (div.id==clicked[i]){got=true;}
	}
	if (got==true){
		for (var i = 0; i < emailarray.length; i++) {
			if(emailarray[i]==email){
				clicked[i]="";
				emailarray[i]="";
				div.style.backgroundColor="#F2F2F2";
				div.title="Send an invite to "+email;
			}
		}	
	}else{
		clicked[clicked.length]=div.id;
		emailarray[emailarray.length]=email;
		div.style.backgroundColor="#AFB5F5";
		div.title="Remove invite to "+email;
	}
}
function SelectAll(){
	clicked=allids;
	emailarray=allemails;
	for (var ii = 0; ii < clicked.length; ii++){
		if(clicked[ii].length>0 && typeof $(clicked[ii]) != 'undefined'){
			div = $(clicked[ii]);
			div.style.backgroundColor="#AFB5F5";
			div.title="Remove invite to "+emailarray[ii];
		}
	}
}

function Invite(){
	if(confirm('Are you sure you want to send invites to your selected friends?')){
		if ( emailarray.length<1){
			alert("You need to select some friends");
		}else{
			var sendto=0;
			for (var i = 0; i < emailarray.length; i++) {
				if(typeof emailarray[i] != 'undefined'){
					if(emailarray[i].length>0){
						sendto++;
						var d = new Date()
						new Ajax.Updater('loader', "/process/tellmyfriends2.asp?email="+emailarray[i]+"&ts="+d.toUTCString(), { method: 'get' });
					}
				}
			}
			if (sendto<1){
				alert("You need to select some friends");
			}
		}
	}
}
function checkAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}
function EnterGo(itm){
	if (window.event.keyCode == 13 && itm.value!="") {
		PostcodeSearch('pcss');
	}
}