// JavaScript Document
/* <![CDATA[ */
var http = getHTTPObject();
var default_url = "/callback/";
var xmlDoc;

var right_now=new Date();
var the_year=right_now.getFullYear();;
var the_month=(right_now.getMonth() + 1);


function getHTTPObject() {
	var xmlhttp;
	try {
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
		} catch (E) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}
	return xmlhttp;
}

function replyQuery(direction){
	if(direction=='forward') 
		the_month++;
	if(direction == 'backward')
		the_month--;
		
	if(the_month > 12){
		the_month = 1;
		the_year++;
	}
	
	if(the_month < 1){
		the_month = 12;
		the_year--;
	}	
	
	var url = default_url + "calendar/?month=" + the_month + "&year=" + the_year;
	url = url + "&sid=" + Math.random();	
	
	if((http.readyState == 0) || (http.readyState == 4)){			
		http.open("GET", url, true); 
		http.onreadystatechange = handleHttpCalendarResponse;
		http.send(null);
	}
}

function invite(fName, fEmail, eventID){
	var url = default_url + "invite/";
	var params = "fName=" + fName + "&fEmail=" + fEmail + "&eventID=" + eventID;
	
	if((http.readyState == 0) || (http.readyState == 4)){	
		document.body.style.cursor = 'wait';
		http.open("POST", url, true); 
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");		
		http.onreadystatechange = function() {//Call a function when the state changes.									
			if(http.readyState == 4 && http.status == 200) {	
				 document.body.style.cursor = 'default';
				var response = eval ('(' + http.responseText + ')');
				
				if(response[0].sent){
					document.getElementById('inviteForm').innerHTML = "<h3>Your invitation has been sent. Thank you</h3>";
				}
				
			}
		}
		http.send(params);
	}
}

function contestInvite(fName, fEmail, contestID){
	var url = default_url + "contest/";
	var params = "fName=" + fName + "&fEmail=" + fEmail + "&contestID=" + contestID;
	
	if((http.readyState == 0) || (http.readyState == 4)){	
		document.body.style.cursor = 'wait';
		http.open("POST", url, true); 
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");		
		http.onreadystatechange = function() {//Call a function when the state changes.									
			if(http.readyState == 4 && http.status == 200) {	
				 document.body.style.cursor = 'default';
				var response = eval ('(' + http.responseText + ')');
				
				if(response[0].sent){
					document.getElementById('inviteForm').innerHTML = "<h3>Your invitation has been sent. Thank you</h3>";
				}
				
			}
		}
		http.send(params);
	}
}


function logon(username, password){
	var url = default_url + "login/";
	var params = "username=" + username + "&password=" + password;
		
	if((http.readyState == 0) || (http.readyState == 4)){			
		http.open("POST", url, true); 
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");		
		http.onreadystatechange = function() {//Call a function when the state changes.									
			if(http.readyState == 4 && http.status == 200) {				
				var response = eval ('(' + http.responseText + ')');			
				if(typeof(response.username)!='undefined'){
					document.getElementById('errors').innerHTML="<p>" + response.username[0] + "</p>";
				}
				else if(response.length > 0){
					if(response[0].valid > 0){
						displayPop(globElement);
						document.getElementById('intoHolder').innerHTML="<p>Welcome, " + response[0].fName + ". <a href=\"/accounts/logout/\">Logout</a>";
						document.getElementById('login').style.display="none";
						
						document.getElementById('popbody').innerHTML = '';
														
						if(globEvent > 0)
							eventLookup(globEvent);					
					}
				}
			}
		}
		http.send(params);
	}
}

function addEvent(eventID, element){
	globElement = element;
	globEvent = parseInt(eventID);
	var url = default_url + "addList/?eventID=" + eventID;
	url = url + "&sid=" + Math.random();		
	if((http.readyState == 0) || (http.readyState == 4)){			
		http.open("GET", url, true); 
		http.onreadystatechange = handleHttpAddEvent;
		http.send(null);
	}
}

function eventLookup(eventID){
	globEvent = parseInt(eventID);
	var url = default_url + "eventLookup/?action=Lookup&eventID=" + eventID;
	url = url + "&sid=" + Math.random();	
	if((http.readyState == 0) || (http.readyState == 4)){		
		http.open("GET", url, true); 
		http.onreadystatechange = handleHttpEventLookup;
		http.send(null);
	}
}

function contestLookup(contestID){
	globEvent = parseInt(contestID);
	var url = default_url + "contestLookup/?action=Lookup&contestID=" + contestID;
	url = url + "&sid=" + Math.random();	
	if((http.readyState == 0) || (http.readyState == 4)){		
		http.open("GET", url, true); 
		http.onreadystatechange = handleHttpContestLookup;
		http.send(null);
	}
}

function handleHttpEventLookup(){	
	if (http.readyState == 4) {			
		if ((http.status == 200)||(http.status == 0)) { 	
			var response = eval ('(' + http.responseText + ')');
			if(response[0].pk > 0){
				globEvent = 0;
				var curdate = response[0].fields.show_date.split('-');
				var year = parseInt(curdate[0]);
				var month = parseInt(curdate[1]);
				var day = curdate[2].substr(0,2);
				var showDate = new Date();
				showDate.setYear(year);
				showDate.setMonth(month);
				showDate.setDate(day);			
				remoteHTML = "<div class=\"popData\"><div class=\"popLeft\" id=\"inviteForm\"><label>Your Friend's Name</label><input type=\"text\" id=\"fName\" class=\"popInput\"/><label>Your Friend's Email Address</label><input type=\"text\" id=\"fEmail\" class=\"popInput\" /><input type=\"submit\" class=\"submit\" value=\"Submit\"onclick=\"invite(document.getElementById('fName').value, document.getElementById('fEmail').value, " + response[0].fields.AC_ID + "); return false;\" /></div></div>";	
		
				remoteHTML += "<div class=\"popData eventInfo\"><div class=\"popLeft\"><p>Invite your friends to</p><h4 class=\"title\">" + response[0].fields.billing + "</h4><h4 class=\"date\">" + month + "/" + day + "/" + year + "</h4>";
				var eventImage = response[0].fields.event_image;
				if (eventImage.length > 0){
						remoteHTML += "<img src=\"/media/images/events/thumbs/" + response[0].fields.AC_ID + "_featurette.jpg\" alt=\"" + response[0].fields.billing + "\"/>";
				}
				
			} else {
				globEvent = response[0].eventID;
				globContest = null;
				remoteHTML = "<div class=\"popData\"><div class=\"popLeft\"><div id=\"errors\"></div><p>Please sign in or <a href=\"/accounts/register/\">register</a> if you are not already a ConcertWire Community member</p><label>Your Username</label><input type=\"text\" id=\"uName\" class=\"popInput\"/><label>Your Password</label><input type=\"password\" id=\"pass\" class=\"popInput\" /><input type=\"submit\" class=\"submit\" value=\"Submit\" onclick=\"logon(document.getElementById('uName').value, document.getElementById('pass').value); return false\"/></div></div>";	
		
				remoteHTML += "<div class=\"popData eventInfo\"><div class=\"popLeft\"><h4 class=\"title\">Join ConcertWire Community</h4><p>Be the music. Join ConcertWire Free and connect with the world:</p><ul><li>Sound off in our fan forum</li><li>Invite friends to concerts</li><li>Rate and review recent shows</li><li>Win prizes for attending multiple shows</li><li>Integrate Flickr, MySpace and Facebook accounts</li><li>Download widgets for your blog</li></ul>";
			}
			remoteHTML += "</div></div><div class=\"anchor\"></div>";	
			document.getElementById('popbody').innerHTML=remoteHTML;
			displayPop(globElement);		
			return;
		}
	}
}
function handleHttpContestLookup(){	
	if (http.readyState == 4) {			
		if ((http.status == 200)||(http.status == 0)) { 	
			var response = eval ('(' + http.responseText + ')');
			if(response[0].pk > 0){
				globContest = null;
				var enddate = response[0].fields.end.split('-');
				var year = parseInt(enddate[0]);
				var month = parseInt(enddate[1]);
				var day = enddate[2].substr(0,2);
				var showDate = new Date();
				showDate.setYear(year);
				showDate.setMonth(month);
				showDate.setDate(day);			
				remoteHTML = "<div class=\"popData\"><div class=\"popLeft\" id=\"inviteForm\"><label>Your Friend's Name</label><input type=\"text\" id=\"fName\" class=\"popInput\"/><label>Your Friend's Email Address</label><input type=\"text\" id=\"fEmail\" class=\"popInput\" /><input type=\"submit\" class=\"submit\" value=\"Submit\"onclick=\"contestInvite(document.getElementById('fName').value, document.getElementById('fEmail').value, " + response[0].pk + "); return false;\" /></div></div>";	
		
				remoteHTML += "<div class=\"popData eventInfo\"><div class=\"popLeft\"><p>Invite your friends to</p><h4 class=\"title\">" + response[0].fields.title + "</h4><h4 class=\"date\">" + month + "/" + day + "/" + year + "</h4>";
				/*
				var contestImage = response[0].fields.image;
				if (contestImage.length > 0){
						remoteHTML += "<img src=\"/media/postimgs/" + contestImage + "\" alt=\"" + response[0].fields.title + "\"/>";
				}
				*/
				
			} else {
				globContest = response[0].pk;
				globEvent = null;
				remoteHTML = "<div class=\"popData\"><div class=\"popLeft\"><div id=\"errors\"></div><p>Please sign in or <a href=\"/accounts/register/\">register</a> if you are not already a ConcertWire Community member</p><label>Your Username</label><input type=\"text\" id=\"uName\" class=\"popInput\"/><label>Your Password</label><input type=\"password\" id=\"pass\" class=\"popInput\" /><input type=\"submit\" class=\"submit\" value=\"Submit\" onclick=\"logon(document.getElementById('uName').value, document.getElementById('pass').value); return false\"/></div></div>";	
		
				remoteHTML += "<div class=\"popData eventInfo\"><div class=\"popLeft\"><h4 class=\"title\">Join ConcertWire Community</h4><p>Be the music. Join ConcertWire Free and connect with the world:</p><ul><li>Sound off in our fan forum</li><li>Invite friends to concerts</li><li>Rate and review recent shows</li><li>Win prizes for attending multiple shows</li><li>Integrate Flickr, MySpace and Facebook accounts</li><li>Download widgets for your blog</li></ul>";
			}
			remoteHTML += "</div></div><div class=\"anchor\"></div>";	
			document.getElementById('popbody').innerHTML=remoteHTML;
			displayPop(globElement);		
			return;
		}
	}
}

function handleHttpAddEvent(){
	if (http.readyState == 4) {		
		if ((http.status == 200)||(http.status == 0)) { 	
			var response = eval ('(' + http.responseText + ')');
			if(response[0].pk > 0){
				globEvent = 0;
				var curdate = 0;
				var year = 0;
				var month = 0;
				var day = 0;
				
				var eventCount = response.length;
				remoteHTML = "<div class=\"popData\"><div class=\"popLeft\"><p>Your list has been saved</p></div></div>";	
				remoteHTML += "<div class=\"popData eventInfo\"><div class=\"popLeft\"><p>Your current saved list</p>";	
				for(var i=0; i<eventCount; i++){
					curdate = response[0].fields.show_date.split('-');
					year = parseInt(curdate[0]);
					month = parseInt(curdate[1]);
					day = curdate[2].substr(0,2);
					remoteHTML += "<h4 class=\"title\"><a href=\"/event/" + response[i].fields.AC_ID + "/" + response[i].fields.slug +"/\">" + response[i].fields.billing + "</a></h4><h4 class=\"date\">" + month + "/" + day + "/" + year + "</h4>";				
				}
				
			} else {
				globEvent = response[0].eventID;
				remoteHTML = "<div class=\"popData\"><div class=\"popLeft\"><div id=\"errors\"></div><p>Please sign in or <a href=\"/accounts/register/\">register</a> if you are not already a ConcertWire Community member</p><label>Your Username</label><input type=\"text\" id=\"uName\" class=\"popInput\"/><label>Your Password</label><input type=\"password\" id=\"pass\" class=\"popInput\" /><input type=\"submit\" class=\"submit\" value=\"Submit\" onclick=\"logon(document.getElementById('uName').value, document.getElementById('pass').value); return false\"/></div></div>";	
		
				remoteHTML += "<div class=\"popData eventInfo\"><div class=\"popLeft\"><h4 class=\"title\">Join ConcertWire Community</h4><p>Be the music. Join ConcertWire Free and connect with the world:</p><ul><li>Sound off in our fan forum</li><li>Invite friends to concerts</li><li>Rate and review recent shows</li><li>Win prizes for attending multiple shows</li><li>Integrate Flickr, MySpace and Facebook accounts</li><li>Download widgets for your blog</li></ul>";
			}
			remoteHTML += "</div></div><div class=\"anchor\"></div>";	
			document.getElementById('popbody').innerHTML=remoteHTML;
			displayPop(globElement);		
			return;
		}
	}
}

function switchView(sectionID){
	var switchSection = document.getElementById(sectionID);
	var switchLinks = switchSection.getElementsByTagName('A');
	var switchList = switchSection.getElementsByTagName('OL');
	
	var linksCount = switchLinks.length;
	var listCount = switchList.length;
	
	for(var i=0; i < linksCount; i++){			
		if (switchLinks[i].className.indexOf('doMoreNav') >= 0){			
			if(switchLinks[i].className.indexOf('selected') < 0){
				switchLinks[i].className += ' selected';
			} else if (switchLinks[i].className.indexOf('selected') >= 0){
				switchLinks[i].className = switchLinks[i].className.replace(new RegExp(" selected\\b"), "");
			}			
		}
	}
	for(var i=0; i < listCount; i++){
		if(switchList[i].className.indexOf('hidden') < 0){
			switchList[i].className += 'hidden';
		} else if (switchList[i].className.indexOf('hidden') >= 0){
			switchList[i].className = switchList[i].className.replace(new RegExp("hidden\\b"), "");
		}					
	}
	
}

function handleHttpCalendarResponse() {
	if (http.readyState == 4) {		
		if ((http.status == 200)||(http.status == 0)) { 					
			document.getElementById("concertCalendar").innerHTML = http.responseText;
		}
	}
}


/* ]]> */// JavaScript Document