
// JavaScript Document

d = document;

function uploadPhoto(feedback, dayValue, monthValue, yearValue) {
		
		
//		backgroundBlack();
		
		popup();
		
		disableDateDropDowns();
		
		tableCell = d.getElementById('middle_middle');
		
		a = d.createElement('a');
		a.href = 'javascript:closePopUp()';
		a.innerHTML = '[x] close';
		a.className = 'smallRed';
		
		tableCell.appendChild(a);
		
		h1 = d.createElement('h1');
		h1.innerHTML = 'Send Us Your Photo';

		tableCell.appendChild(h1);
		
		if (feedback != '') {

			p = d.createElement('p');
			p.innerHTML = feedback;
			p.style.color = 'red';
			p.style.fontWeight = 'bold';
			tableCell.appendChild(p);
			
		}
		
		form = d.createElement('form');
		form.name = 'upload';
		form.action = '/cgi-bin/upload.pl';
		form.method = 'POST';
		form.enctype = 'multipart/form-data';
		form.setAttribute('onSubmit', 'submitUploadPhoto()');
		form.setAttribute('enctype', 'multipart/form-data');
		
		p = d.createElement('p');
		p.innerHTML = 'You can send us any image in jpg, jpeg or gif file formats.  You can send us any size file.  Your image will automatically be resized for our calendar and for possible use on the air. ';
		form.appendChild(p);
		
		p = d.createElement('p');
		p.innerHTML = '<b>Upload your photo:</b> <br />';
		
		input = d.createElement('input');
		input.type = 'file';
		input.name = '1';
		
		p.appendChild(input);
		form.appendChild(p);
		
		p = d.createElement('p');
		p.innerHTML = '<b>Pick a date (mm/dd/yyyy):</b> <i>Optional</i> ';
		
		input = d.createElement('input');
		input.type = 'text';
		input.name = 'month';
		input.size = '2';
		
		p.appendChild(input);
		p.innerHTML += '/';
		
		input = d.createElement('input');
		input.type = 'text';
		input.name = 'day';
		input.size = '2';
		
		p.appendChild(input);
		p.innerHTML += '/';
		
		input = d.createElement('input');
		input.type = 'text';
		input.name = 'year';
		input.size = '4';
		
		p.appendChild(input);
		form.appendChild(p);
		
		p = d.createElement('p');
		p.innerHTML = '<b>Your Name:</b> ';
		
		input = d.createElement('input');
		input.type = 'text';
		input.name = 'name';
//		input.value = '';
		
		p.appendChild(input);
		form.appendChild(p);
		
		p = d.createElement('p');
		p.innerHTML = '<b>Your Email:</b> ';
		
		input = d.createElement('input');
		input.type = 'text';
		input.name = 'email';
		input.id = 'email_id';
		input.setAttribute('onblur', "javascript:validateEmail(this.value, '')"); 
//		input.value = '';
		
		p.appendChild(input);
		form.appendChild(p);
		
		p = d.createElement('p');
		p.innerHTML = '<b>Your Caption:</b> <i>Optional</i> ';
		
		input = d.createElement('input');
		input.type = 'text';
		input.name = 'caption';
		
		p.appendChild(input);
		form.appendChild(p);
		
		p = d.createElement('p');
		p.innerHTML = '<b>Photo Location:</b> <i>Optional</i> ';
		
		input = d.createElement('input');
		input.type = 'text';
		input.name = 'location';
		
		p.appendChild(input);
		form.appendChild(p);
		
/*		p = d.createElement('p');
		
		input = d.createElement('input');
		input.type = 'checkbox';
		input.name = 'remember';
		input.value = 'yes';
		
		label = d.createElement('label');
		label.appendChild(input);
		label.innerHTML += ' Remember My Information';
		
		p.appendChild(label);
		form.appendChild(p);
*/	
		p = d.createElement('p');
		
		input = d.createElement('input');
		input.type = 'submit';
		input.value = 'Submit your photo';
				
		p.appendChild(input);
		
		input = d.createElement('input');
		input.type = 'button';
		input.value = 'Cancel';
		input.setAttribute('onclick',"closePopUp()");
		
		p.appendChild(input);
		form.appendChild(p);
		
		input = d.createElement('input');
		input.type = 'hidden';
		input.name = 'ip';
		input.value = '38.103.63.61';
		form.appendChild(input);
		
		input = d.createElement('input');
		input.type = 'hidden';
		input.name = 'sesID';
		input.value = '9890ce89d9644351455db8f473b074fd';
		form.appendChild(input);
		
		input = d.createElement('input');
		input.type = 'hidden';
		input.name = 'date';
		input.value = '08-09-08_00-52-55';
		form.appendChild(input);
		
		tableCell.appendChild(form);
		
		d.forms['upload'].elements['day'].value = dayValue;
		d.forms['upload'].elements['month'].value = monthValue;
		d.forms['upload'].elements['year'].value = yearValue;
		
		
		
}

function validateEmail(i, response) {
	if(response!='') {
		//response mode
		if(response == 'false') {
			alert('Please enter a valid email address.'); 	
			d.getElementById('email_id').focus();
		}
	} else { 
		// input mode
		var url = '/xml/validate_email.php?email=' + i;
		loadXMLDoc(url);
	}
}

function thankyou() {
			
//		backgroundBlack();
		
		popup();
		
		tableCell = d.getElementById('middle_middle');
		
		a = d.createElement('a');
		a.href = 'javascript:closePopUp()';
		a.innerHTML = '[x] close';
		a.className = 'smallRed';
		
		tableCell.appendChild(a);
		
		h1 = d.createElement('h1');
		h1.innerHTML = 'Thank You!';

		tableCell.appendChild(h1);

		p = d.createElement('p');
		p.innerHTML = "Thank you for sending us your photo.  We will contact you by email when your image has been reviewed.<br /><br /><a href=\"javascript:closePopUp()\">Click here to close this window</a>";
		tableCell.appendChild(p);
		
		
		
	}

function closePopUp() {

	
	div = d.getElementById('popup');
	div.parentNode.removeChild(div);
	
//	div = d.getElementById('backgroundBlack');
//	div.parentNode.removeChild(div);
	
	if (f = d.forms['monthYear'])
	{
	e = f.elements['month'];
	e.disabled = false;
	
	e = f.elements['year'];
	e.disabled = false;
	
	enableObjects();
	}
	
}



function submitUploadPhoto() {
	
	tableCell = d.getElementById('middle_middle');
	
	f = d.forms['upload'];
//	f.style.display = 'none';
	
//	tableCell.innerHTML += "Sending your photo now...";
	
}

function disableDateDropDowns() {

	if (d.forms['monthYear']) {
		
		f = d.forms['monthYear'];
		
		if (f.elements['month']) {
			e = f.elements['month'];
			e.disabled = true;
		}
		
		if (f.elements['year']) {
			e = f.elements['year'];
			e.disabled = true;
		}
	}
	
}

function createBorderTable() {

	table = d.createElement('table');
	table.id = 'pop_up_table';
	table.cellPadding = '0';
	table.cellSpacing = '0';
	table.width = '645px';
	
	tr = d.createElement('tr');
	
	td = d.createElement('td');
//	td.id = 'top_left';
	tr.appendChild(td);
	
	td = d.createElement('td');
//	td.id = 'top_middle';
	tr.appendChild(td);
	
	td = d.createElement('td');
//	td.id = 'top_right';
	tr.appendChild(td);
	
	table.appendChild(tr);
	
	tr = d.createElement('tr');
	
	td = d.createElement('td');
//	td.id = 'middle_left';
	tr.appendChild(td);
	
	td = d.createElement('td');
	td.id = 'middle_middle';
	tr.appendChild(td);
	
	td = d.createElement('td');
//	td.id = 'middle_right';
	tr.appendChild(td);
	
	table.appendChild(tr);
	
	tr = d.createElement('tr');
	
	td = d.createElement('td');
//	td.id = 'bot_left';
	tr.appendChild(td);
	
	td = d.createElement('td');
//	td.id = 'bot_middle';
	tr.appendChild(td);
	
	td = d.createElement('td');
//	td.id = 'bot_right';
	tr.appendChild(td);
	
	table.appendChild(tr);
	
	return table;
	
}

function disableObjects() {
	
	if (d.getElementById('300by250')) {
		obj = d.getElementById('300by250');
		
		obj.style.display = 'none';
	}
	
	if (d.getElementById('300by100')) {
		obj = d.getElementById('300by100');
		
		obj.style.display = 'none';
	}
	
}

function enableObjects() {
	
	if (d.getElementById('300by250')) {
		obj = d.getElementById('300by250');
		
		obj.style.display = '';
	}
	
	if (d.getElementById('300by100')) {
		obj = d.getElementById('300by100');
		
		obj.style.display = '';
	}
}

function popup() {
	
	disableObjects();
	
	div = d.createElement('div');
	html = d.getElementById('kacl');
	div.id = 'popup';
	table = createBorderTable();
	div.appendChild(table);
	
	var top = 20;
	var left = 0;
	
	div.style.top = top+'px';
	div.style.left = left+'px';
	
	d.body.appendChild(div);
	
}

function backgroundBlack() {
		
		html = d.getElementById('kacl');
				
		div = d.createElement('div');
		
		height = ( html.offsetHeight > d.body.scrollHeight) ?  html.offsetHeight : d.body.scrollHeight + 50;
		//width = ( html.offsetWidth > d.body.scrollWidth ) ? html.offsetWidth : d.body.scrollWidth;
		width = 645;
		
		div.id = 'backgroundBlack';
		
		div.style.height = height+"px";
		div.style.width = width+"px";
		
		
		d.body.appendChild(div);
		
}

function openPosting(i) {

		
//		backgroundBlack();
	
		popup();
		
		disableDateDropDowns();
		
		tableCell = d.getElementById('middle_middle');
		
		a = d.createElement('a');
		a.href = 'javascript:closePopUp()';
		a.innerHTML = '[x] close';
		a.className = 'smallRed';
		
		tableCell.appendChild(a);
		a.charset="ISO-8859-1";
		a = d.createElement('a');
		a.href = '/printer_friendly/flier.php?id='+i+'&type=flier';
		a.innerHTML = ' | printer friendly flier';
		a.className = 'smallRed';
		
		tableCell.appendChild(a);
		
		a = d.createElement('a');
		a.href = '/Calendar/event_ics.php?id='+i;
		a.innerHTML = ' | download for Outlook';
		a.className = 'smallRed';
		
		tableCell.appendChild(a);
				a = d.createElement('a');
		a.href = '/user/contact_event_lister.php?id='+i;
		a.innerHTML = ' | Contact Event Lister';
		a.className = 'smallRed';
		
		tableCell.appendChild(a);
				
						a = d.createElement('a');
		a.href = '/user/add_to_personal_calendar.php?id='+i;
		a.innerHTML = ' | Add to Personal Calendar';
		a.className = 'smallRed';
		
		tableCell.appendChild(a);
				
		
		h1 = d.createElement('h1');
		h1.innerHTML = 'View Event';
		h1.id = 'event_popup_header'

		tableCell.appendChild(h1);
		
		p = d.createElement('p');
		
		img = d.createElement('img');
		img.src = '/images/progress.gif';
		
		p.appendChild(img);
		p.innerHTML += ' Loading...';
		p.style.fontSize = '110%';
		p.id = 'loading';
		
		tableCell.appendChild(p);
		
		getImage(i, img, '');
		
}
function adminOpenPosting(i) {

		
//		backgroundBlack();
	
		popup();
		
		disableDateDropDowns();
		
		tableCell = d.getElementById('middle_middle');
		
		a = d.createElement('a');
		a.href = 'javascript:closePopUp()';
		a.innerHTML = '[x] close';
		a.className = 'smallRed';
		
		tableCell.appendChild(a);

		h1 = d.createElement('h1');
		h1.innerHTML = 'View Event';
		h1.id = 'event_popup_header'

		tableCell.appendChild(h1);
		
		p = d.createElement('p');
		
		img = d.createElement('img');
		img.src = '/images/progress.gif';
		
		p.appendChild(img);
		p.innerHTML += ' Loading...';
		p.style.fontSize = '110%';
		p.id = 'loading';
		
		tableCell.appendChild(p);
		
		getImage(i, img, '');
		
}
function getImage(i, img, input) {
	
	if (input != '') {
		
		p = d.getElementById('loading');
		p.parentNode.removeChild(p);
		
		tableCell = d.getElementById('middle_middle');
		
		p = d.createElement('p');
		p.style.textAlign = 'center';
		
		img = d.createElement('img');
		img.src = '/images/get_image.php?id='+i+'&type=popUp';
		img.style.float = 'center';
		
		p.appendChild(img);
		tableCell.appendChild(p);
		
		str = input.split(/\.\|\./);
		
		img = d.createElement('img');
		img.src = '/images/logo.jpg';
		img.style.float = 'right';
		img.align = 'right';
		p.appendChild(img);
		
		
		if (str[2] != ' ') {
			p = d.createElement('p');
			p.innerHTML = '<b>Event Name</b>: '+str[2];
			tableCell.appendChild(p);
		}
		
		if (str[0] != ' ') {
			p = d.createElement('p');
			p.innerHTML = '<b>Event Organization</b>: '+str[0];
			tableCell.appendChild(p);
		}
		
		if (str[1] != ' ') {
			p = d.createElement('p');
			p.innerHTML = '<b>Event Location</b>: '+str[1];
			tableCell.appendChild(p);
		}
		
		if (str[3] != ' ') {
			p = d.createElement('p');
			p.innerHTML = '<b>Event Description</b>: '+str[3];
			tableCell.appendChild(p);
		}
			if (str[5] != 'http://') {
			p = d.createElement('p');
			p.innerHTML = '<b>URL</b>: <a target=\'_blank\' href=\''+str[5]  + '\' >' +str[5] +'</a>';
			tableCell.appendChild(p);
		}

		h1 = d.getElementById('event_popup_header');
		h1.innerHTML += ' on ' + str[4];
		if (str[6] != ' ' && str[7] != ' ')
			h1.innerHTML += '&nbsp;&nbsp;' + str[6] + ' - ' +str[7];
		else
		{
		if (str[6] != ' ') {
			h1.innerHTML += '  Start Time: ' + str[6];
		}
		if (str[7] != ' ') {
			h1.innerHTML +=  '  End Time: ' +str[7];
		}
		}
	}
	else {
		
		url = '/xml/getPhoto.php?id='+i;
		loadXMLDoc(url);
		
	}
	
}

function start_slideshow(i, imgs) {

		if(imgs != '') {
			backgroundBlack();
		
			popup();
			
			disableDateDropDowns();
			
			tableCell = d.getElementById('middle_middle');
			
			a = d.createElement('a');
			a.href = 'javascript:closePopUp()';
			a.innerHTML = '[x] close';
			a.className = 'smallRed';
			
			tableCell.appendChild(a);
			
			a = d.createElement('a');
			a.href = 'javascript:window.print()';
			a.innerHTML = ' | print';
			a.className = 'smallRed';
			
			tableCell.appendChild(a);
			
			h1 = d.createElement('h1');
			h1.innerHTML = 'View Photo';
	
			tableCell.appendChild(h1);
			
			p = d.createElement('p');
			p.style.textAlign = 'center';
			
			s = d.createElement('strong');
			s.className = 'slide_links';
			s.innerHTML = '<A HREF="javascript:SLIDES.previous()">&lt;Previous</A>&nbsp;';
			p.appendChild(s);
			
			s = d.createElement('strong');
			s.className = 'slide_links';
			s.innerHTML = '<A HREF="javascript:SLIDES.next()">Next&gt;</A>&nbsp;';
			p.appendChild(s);
			
			s = d.createElement('strong');
			s.className = 'slide_links';
			s.innerHTML = '<A HREF="javascript:SLIDES.play()">Play</A>&nbsp;';
			p.appendChild(s);
			
			s = d.createElement('strong');
			s.className = 'slide_links';
			s.innerHTML = '<A HREF="javascript:SLIDES.pause()">Stop</A>';
			p.appendChild(s);
			
			b = d.createElement('br');
			p.appendChild(b);
			b = d.createElement('br');
			b.style.lineHeight = '3px';
			p.appendChild(b);
			
			img = d.createElement('img');
			img.name = 'SLIDESIMG';
			img.src = '/images/progress.gif';
			img.style.filter = 'progid:DXImageTransform.Microsoft.Fade()';
			p.appendChild(img);
			
			b = d.createElement('br');
			p.appendChild(b);
			
			div = d.createElement('div');
			div.id = 'SLIDESTEXT';
			p.appendChild(div);
			
			tableCell.appendChild(p);
			
			SLIDES = new slideshow("SLIDES");
			SLIDES.timeout = 5000;
			SLIDES.prefetch = 1;
			SLIDES.repeat = true;
			SLIDES.image = document.images.SLIDESIMG;
			
			newStr = imgs.split(/\.\|\./);
			j = 1;
			for(i = 0; i < newStr[0]; i++) {
				s = new slide();
				s.src =  "/images/get_image.php?id="+newStr[j]+"&type=popUp";
				s.text = "<img style=\"float:right; padding: 3px;\" align=\"right\" src=\"/images/logo.jpg\" width=\"211\" height=\"80\" /><div style=\"text-align:left; padding: 3px;\"><b>Name</b>: "+newStr[j+1]+"<br /><b>Location</b>: "+newStr[j+2]+"<br /><b>Caption</b>: "+newStr[j+3]+"<br /><b>Date</b>: "+newStr[j+4]+"</span>";
				s.link = "javascript:preview('"+newStr[j]+"', '10', '10');";
				s.target = "";
				s.attr = "";
				s.filter = "";
				SLIDES.add_slide(s);
				j+=5;
				
				if (false) SLIDES.shuffle();
			}
			
			if (document.images) {
				SLIDES.textid = "SLIDESTEXT";
				SLIDES.update();
				SLIDES.play();
			}
			
			// For browsers that cannot change the HTML on the page,
			// display all of the text from the slideshow.
			// I place this within the DIV, so browers won't see it
			// if they can change the DIV.
			
			//nodivtext = SLIDES.get_all_text("<li>", "<p>\n");
			//nodivtext = SLIDES.get_text();
			//if (nodivtext) {
			  //document.write("\n" + nodivtext + "\n");
			//}
		} // end if
		else {
			url = '/xml/getPhotos.php?id='+i;
			loadXMLDoc(url);
		}
		
}

function preview(id, h, w) {
		
		string = "page" + id + " = window.open('/Calendar/photo_preview.php?id=" + id + "', 'mssgDisplay', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+h+",height="+w+"');";
		eval(string);
}	

var req;
function loadXMLDoc(url) {	
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) 
	{
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send(null);
	// branch for IE/Window ActiveX version
	} 
	
	else if (window.ActiveXObject)
	 {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) 
		{
			req.onreadystatechange = processReqChange;
			req.open("GET", url, true);
			req.send();
		}
	}
}
function processReqChange() {
	// only if req shows "complete"
	if (req.readyState == 4) {
		// only if "OK"
		if(req.status == 200) {
			// ...processing statements go here...
			response = req.responseXML.documentElement;
			method = response.getElementsByTagName('method')[0].firstChild.data;
			result = response.getElementsByTagName('result')[0].firstChild.data;
			eval (method + ' result)');
		}
	}
}