// JavaScript Document

function submitLogin () {

}

function stop_slider () {
	stop_slide = true;
	speed = start_speed;
}

var index = 0;
function slide_images (rr) {
	if(stop_slide == true) {
		return false;
	}
	
	if(rr == 'reset') {
		if(y<0) {
			speed += speed * .02;
			y += speed;
			doc('video_mask').style.left = y+'px';
			setTimeout('slide_images(\"reset\")', rate);
		} else {	
			y = 0;
			speed = start_speed;
			stop_slide = false;	
		}	
		return false;
	}
	
	if(y > (-1*max_width)) {
		speed += speed * .02;
		y -= speed;
		doc('video_mask').style.left = (y)+'px';
		setTimeout('slide_images(' + (y) + ')', rate);
	} else {
		y = (-1*max_width);
		speed = start_speed;
		stop_slide = false;
	}
}

function post_video () {
	document.getElementById('new_videos').innerHTML = "<form><input type='hidden' name='video' id='video' value='true'/>"
		+ "Video Title <br /><input style='width:100%' name='video_title' id='video_title'/><br />"
		+ "Video Location <br /><input style='width:100%' name='video_src' id='video_src'/><br />"
		+ "<input type='button' onClick='add_video()' value='Add'/>"
		+ "<input type=\"button\" onClick=\"window.location.reload()\" value=\"Cancel\"/></form>";
}
	
function video_station() {
	width =  ((videos.length) * 94);
	max_width = ((videos.length-4) * 94);
	var html = "<div id='active_video'>" + video_html(0) + "</div>";

	if(videos.length>1) { 
		html += "<div style='float: left; color: #333'>Now showing: " + videos.length + "/" + videos.length + " videos</div><br />";
		html += "<div>" + video_scanner() + "</div>";
	}
	
	if(owner) {
		html += "<div class='basic_scroll_arrow' style='border: 1px solid #CCC; width: 240px; padding: 14px; margin: 18px;' id='new_videos'><span onClick='post_video()'>+ Add Video</span></div>";
	}

	var video_link = "./videos.php?vi=" + videos[index]['entry_id'];	
	var link = " onClick='window.location=\"" + video_link + "\"'";
	if(block_reload_video) { link = " onClick='run_video("+index+")'" }

	var video_title = "<span style='cursor: pointer'"+link+">" + videos[index]['title'];
	video_title += "</span> [<a href='http://www.facebook.com/sharer.php?u=" + video_link + "' target='_blank'>share</a>]";

	if(owner) {
	    video_title += " <span onClick='delete_video(" + videos[index]['entry_id'] + ")'>[remove]</span>";
	}

	document.getElementById('video_frame').innerHTML = html;
	document.getElementById('video_frame_title').innerHTML = video_title;	
}

var mainvideo;
function tv_station() {
	width =  ((videos.length) * 94);
	max_width = ((videos.length-4) * 94);
	var html = "<div id='active_video'>" + video_player_html(0) + "</div>";

	if(videos.length>1) { 
		//html += "<div style='float: left; color: #333'>Now showing: " + videos.length + "/" + videos.length + " videos</div><br />";
		//html += "<div>" + video_scanner() + "</div>";
	}
	
	if(owner) {
		html += "<div class='basic_scroll_arrow' style='border: 1px solid #CCC; width: 240px; padding: 14px; margin: 18px;' id='new_videos'><span onClick='post_video()'>+ Add Video</span></div>";
	}


	var video_link = "./videos.php?vi=" + videos[index]['entry_id'];
	var link = " onClick='window.location=\"" + video_link + "\"'";
	if(block_reload_video) { link = " onClick='load_video("+index+")'" }

	onYouTubePlayerReady = function (playerId) {			
   		ytplayer = document.getElementById("player2");
  		//ytplayer.addEventListener('onStateChange', 'next');		
		ytplayer.cueVideoById(mainvideo['src']);
		ytplayer.playVideo();
  	}


	document.getElementById('video_frame').innerHTML = html;
	//document.getElementById('video_frame_title').innerHTML = video_title;
	document.getElementById('video_scanner').innerHTML = "<div style='width: 356px; padding-right: 4px '>" + video_images_vert() + "</div>";

}

video_scanner = function() {
	var html = "<table callpadding='0px' cellspacing='0px' border='0px'><tr><td width='24px' class='basic_scroll_arrow' onMouseOver='stop_slide = false; slide_images(\"reset\")' onMouseOut='stop_slider()'> < </td><td>";
	html += "<div id='video_scanner' style='border: 1px solid #CCC; background-color: #111; width: 450px; overflow: hidden'>" + video_images() + "</div>";
	html += "<td width='24px' class='basic_scroll_arrow' onMouseOver='stop_slide = false; slide_images()' onMouseOut='stop_slider()'> > </td></tr></table>";	
	return html;
}

video_images = function (index) {
	if(!index) {
		index = 0;
	}

	var div_html = "<div id='video_mask' style='position: relative;";	
	var row_html = "";
	for(var x = 0; x < videos.length; x++) {
		var thumb = "<img title='" + videos[x]['title']  + "' onclick='run_video(" + x + ")' style='cursor: pointer' height='60px' src='http://i.ytimg.com/vi/" + videos[x]['src'] + "/default.jpg' alt='----'/>";
		if(videos[x]['origin'] == 'vimeo') { thumb = "<img title='" + videos[x]['title']  + "' onclick='run_video(" + x + ")' style='cursor: pointer' height='60px' src='" + videos[x]['thumb'] + "' alt='----'/>"; }

                row_html += "<td ";
                if(index == x) {
                        row_html += "style='margin: 6px; border: 1px solid #999' ";
                }
                row_html += ">";
                row_html += thumb;
                row_html += "</td>";
	}
	var offset = (((index) * 54)*-1) + 155;
	if(index < 3) {
		offset = 0;
	}
	
	if(index > (videos.length-4)) {
		offset = (((videos.length-4) * 54)*-1);
	
	}
	
	y = offset;
	stop_slide = false;
	speed = start_speed;
	div_html += "left:" + offset + "px";
	div_html += "'>";
	
	var html = div_html + "<table><tr>" + row_html + "</tr></table></div></td>";
	return html;
}

function randOrd(){
	return (Math.round(Math.random())-0.5);
} 

video_images_vert = function (index) {
	if(!index) {
		index = 0;
	}

	mainvideo = videos[0];
	
	var x = 0;
		var thumb = "<img title='" + videos[x]['title']  + "' onclick='window.location.reload()' style='cursor: pointer; border: 1px solid #FF6600' height='60px' src='http://i.ytimg.com/vi/" + videos[x]['src'] + "/default.jpg'/>";
		if(videos[x]['origin'] == 'vimeo') { thumb = "<img title='" + videos[x]['title']  + "' onclick='window.location.reload()' style='cursor: pointer' height='60px' src='" + videos[x]['thumb'] + "' alt='thumb'/>"; }
		row_html += thumb;

 	var forum_url = videos[x]['forum_url'];
 	var forum_title = (videos[x]['forum_title']) ? videos[x]['forum_title'] : forum_url;
 	if (forum_url) { var video_link = "http://"+forum_url+"/videos.php?vi="+videos[x]['entry_id']; var forum_link = "<a href='"+video_link+"'>"+forum_title+"</a>" } else { var video_link = "http://bigupsforum.com/tv.php?vi="+videos[x]['entry_id']; var forum_link = "BigUpsForum.com"; forum_url = "";}

	var full_title = escape(truncateStr(videos[x]['title'], 100));
	var main_title = truncateStr(videos[x]['title'], 28);

	var video_share = "<div class='glass' style='border: 1px solid #111; float: left; padding: 4px 6px 2px 6px; width:116px'><a onClick='if(auth){auto_video(\"" + full_title + "\",\"" + videos[x]['src'] + "\",\"youtube\",\"1\"); this.innerHTML=\"<div>Saved!</div>\"}' target='_blank' class='or_link'><img src='http://bigupsforum.com/go/images/bigups_logo.png' alt='Bigups' valign='middle' height='18px' style='float:left; margin-right: 6px;'/></a><a href='http://twitter.com/intent/tweet?text=" + full_title + "&url=" + video_link + "&via=bigupsforum' target='_blank' class='or_link'><img style='float:left; margin: 0px 2px 0px 6px' src='http://geoliphicmedia.com/images/social_buttons/twitter_follow.png' width='10px'/></a> <a href='http://apps.facebook.com/bigupsforum/?share=1&u=" + video_link + "' target='_blank' class='or_link'><img style='float:left' src='http://geoliphicmedia.com/images/social_buttons/facebook_friends.png' width='10px'/></a> <div style='float: left'><small style='color: #666'> share video</small></div></div>";

	var div_html = "<div style='color: #EEE'><div style='float: left; margin: 0px 3px 3px 0px'>NOW PLAYING: <br />" + thumb + "</div>";
	div_html += "<a href='"+video_link+"'>" + main_title + "</a><br />";
	div_html += "posted on " + forum_link + "<br /><small style='color: #666'>" + truncateStr(video_link, 26) + "</small>" + video_share;
	div_html += "<div style='clear: both'></div>";


	var count = 20; //videos.length;
	var tmp_videos = videos;

	if(video_network) { div_html += "<br /><br /><br />VIDEOS posted on <a href='http://" + video_network_link + "'>" + video_network + "</a>:<div style='clear: both; width: 280px;'></div>";
	tmp_videos.sort( randOrd );
	var row_html = "";
	if(count>videos.length) { count = videos.length; }
	for(var x = 1; x < count; x++) {
		var thumb = "<img title='" + tmp_videos[x]['title']  + "' onclick='load_video(" + x + ")' style='border: 1px solid #FFF; margin-left: 2px; cursor: pointer' height='60px' src='http://i.ytimg.com/vi/" + tmp_videos[x]['src'] + "/default.jpg'/>";
		if(tmp_videos[x]['origin'] == 'vimeo') { thumb = "<img title='" + tmp_videos[x]['title']  + "' onclick='load_video(" + x + ")' style='cursor: pointer' height='60px' src='" + tmp_videos[x]['thumb'] + "' alt=''/>"; }
		//row_html += thumb;

 	var forum_url = videos[x]['forum_url'];
 	var forum_title = (videos[x]['forum_title']) ? videos[x]['forum_title'] : forum_url;
 	if (forum_url) { var video_link = "http://"+forum_url+"/videos.php?vi="+videos[x]['entry_id']; var forum_link = "<a href='"+video_link+"'>"+forum_title+"</a>" } else { var video_link = "http://bigupsforum.com/tv.php?vi="+videos[x]['entry_id']; var forum_link = "BigUpsForum.com"; forum_url = "";}

	var full_title = escape(truncateStr(videos[x]['title'], 100));
	var main_title = truncateStr(videos[x]['title'], 28);

	var video_share = "<div style='float: left; padding: 2px; text-align: center;'><a onClick='if(auth){auto_video(\"" + full_title + "\",\"" + videos[x]['src'] + "\",\"youtube\",\"1\"); this.innerHTML=\"<div>Saved!</div>\"}' target='_blank' class='or_link'><img src='http://bigupsforum.com/go/images/bigups_logo.png' alt='Bigups' valign='middle' height='14px' style='float:left; margin-right: 2px;'/></a><a href='http://twitter.com/intent/tweet?text=" + full_title + "&url=" + video_link + "&via=bigupsforum' target='_blank' class='or_link'><img style='float:left; margin: 2px 2px 0px 2px' src='http://geoliphicmedia.com/images/social_buttons/twitter_follow.png' width='10px'/></a> <a href='http://apps.facebook.com/bigupsforum/?share=1&u=" + video_link + "' target='_blank' class='or_link'><img style='float:left; margin: 2px' src='http://geoliphicmedia.com/images/social_buttons/facebook_friends.png' width='10px'/></a> <div style='float: left'><small style='color: #666'></small></div></div>";

			var thumb = "<img title='" + tmp_videos[x]['title']  + "' onclick='load_video(" + x + ")' style='cursor: pointer; border: 1px solid #FFF; float: left' height='40px' src='http://i.ytimg.com/vi/" + tmp_videos[x]['src'] + "/default.jpg'/>";
			if(tmp_videos[x]['origin'] == 'vimeo') { thumb = "<img title='" + tmp_videos[x]['title']  + "' onclick='load_video(" + x + ")' style='cursor: pointer; border: 1px solid #FFF; float: left' height='40px' src='" + tmp_videos[x]['thumb'] + "' alt=''/>"; }

			thumb += "<div style='float:left; width: 280px; padding-left: 2px'><div style='float: left'><a class='grey_link' href='tv.php?vi=" + tmp_videos[x]['entry_id']  + "'>" + tmp_videos[x]['title'] + "</a></div>" + video_share + "</div>";
			

			thumb += "<div style='clear: both; height: 6px;'></div>";
			thumb += "<div style='clear: both; height: 4px; border-top: 1px dotted #222;'></div>";
			row_html += thumb;
	}
	
	} else { 
		div_html += "<br /><br /><br />NEW VIDEO POSTS:<div style='clear: both; width: 310px;'></div>";
		var row_html = "";
		for(var x = 1; x < count; x++) {

 	var forum_url = videos[x]['forum_url'];
 	var forum_title = (videos[x]['forum_title']) ? videos[x]['forum_title'] : forum_url;
 	if (forum_url) { var video_link = "http://"+forum_url+"/videos.php?vi="+videos[x]['entry_id']; var forum_link = "<a href='"+video_link+"'>"+forum_title+"</a>" } else { var video_link = "http://bigupsforum.com/tv.php?vi="+videos[x]['entry_id']; var forum_link = "BigUpsForum.com"; forum_url = "";}

	var full_title = escape(truncateStr(videos[x]['title'], 100));
	var main_title = truncateStr(videos[x]['title'], 28);

	var video_share = "<div style='float: left; padding: 2px; text-align: center;'><a onClick='if(auth){auto_video(\"" + full_title + "\",\"" + videos[x]['src'] + "\",\"youtube\",\"1\"); this.innerHTML=\"<div>Saved!</div>\"}' target='_blank' class='or_link'><img src='http://bigupsforum.com/go/images/bigups_logo.png' alt='Bigups' valign='middle' height='14px' style='float:left; margin-right: 2px;'/></a><a href='http://twitter.com/intent/tweet?text=" + full_title + "&url=" + video_link + "&via=bigupsforum' target='_blank' class='or_link'><img style='float:left; margin: 2px 2px 0px 2px' src='http://geoliphicmedia.com/images/social_buttons/twitter_follow.png' width='10px'/></a> <a href='http://apps.facebook.com/bigupsforum/?share=1&u=" + video_link + "' target='_blank' class='or_link'><img style='float:left; margin: 2px' src='http://geoliphicmedia.com/images/social_buttons/facebook_friends.png' width='10px'/></a> <div style='float: left'><small style='color: #666'></small></div></div>";

			var thumb = "<img title='" + tmp_videos[x]['title']  + "' onclick='load_video(" + x + ")' style='cursor: pointer; border: 1px solid #FFF; float: left' height='40px' src='http://i.ytimg.com/vi/" + tmp_videos[x]['src'] + "/default.jpg'/>";
			if(tmp_videos[x]['origin'] == 'vimeo') { thumb = "<img title='" + tmp_videos[x]['title']  + "' onclick='load_video(" + x + ")' style='cursor: pointer; border: 1px solid #FFF; float: left' height='40px' src='" + tmp_videos[x]['thumb'] + "' alt=''/>"; }

			thumb += "<div style='float: left; width: 280px; padding-left: 2px'><div style='float: left'><a class='grey_link' href='tv.php?vi=" + tmp_videos[x]['entry_id']  + "'>" + tmp_videos[x]['title'] + "</a></div>" + video_share + "</div>";
			

			thumb += "<div style='clear: both; height: 6px;'></div>";
			thumb += "<div style='clear: both; height: 4px; border-top: 1px dotted #222;'></div>";
			row_html += thumb;
		}
	}	


	

	div_html += "<div id='video_mask' style='position: relative;";		
	var offset = (((index) * 54)*-1) + 155;
	if(index < 3) {
		offset = 0;
	}
	
	if(index > (tmp_videos.length-4)) {
		offset = (((tmp_videos.length-4) * 54)*-1);
	
	}
	
	y = offset;
	stop_slide = false;
	speed = start_speed;
	div_html += "'></div>";
	
	var html = div_html;
	if(!video_network) { html += "<table width='100%'><tr>" + row_html + "</tr></table></div></td>"; }
	if(video_network) { html += "<table width='100%'><tr>" + row_html + "</tr></table></div></td>"; }
	return html;
}


video_html = function (index) {
	switch(videos[index]['origin']) {
		case 'vimeo': return vimeo_html(index); break;
		default: return bio_video_html(index);
	}
}

var vimeo_html = function (index) {
    	var video = videos[index];
    	embed  = '<embed src="http://vimeo.com/moogaloop.swf?clip_id=';
    	embed += video['src'];
    	embed += '&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=f06800&amp;fullscreen=1&amp;autoplay=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="100%" height="480"></embed>';
    return embed;
}

var bio_video_html = function (index) {
	
	var video_url = "http://youtube.com/v/" + videos[index]['src'];
	var video_html = '<div style="padding-bottom: 8px;">';
	
	if(auth && videos[index]['bio_id']) {
		video_html += "Band/Artist: ";
		video_html += '<b>' + videos[index]['bio_name'] + '</b><br />';
	} else if (owner){
		var album_title = "<select><option>No artists</option></select>"; 
		try {
			if(artists) {
				album_title = "<select onChange='add_video_band(" + index + ", this.value)'>";
				album_title += "<option value='none'>No band/artist</option>";
				for(var x = 0; x < artists.length; x++) {
					album_title += "<option value='" + artists[x]['entry_id'] + "'>" + artists[x]['bio_name'] + "</option>";	
				}
				album_title += "</select>";
				video_html += "Band/Artist: ";
				video_html += album_title + '<br />';
			} 
		} catch(err) { }
	}
	video_html += '</div><div style="padding-bottom: 8px"><object width="100%" height="480"><param name="movie" value="';
	video_html += video_url;
	video_html += '&fs=1&autoplay=' + videoAutoPlay + '&loop=1;enablejsapi=1&version=3"></param><param name="wmode" value="transparent"></param><param name="allowscriptaccess" claue="alwats"></param><embed src="';
	video_html += video_url;
	video_html += '&fs=1&autoplay=' + videoAutoPlay + '&loop=1;enablejsapi=1&version=3" type="application/x-shockwave-flash" wmode="transparent" width="100%" height="480"></embed></object></div>';		
	return video_html;
}

var video_player_html = function (index) {

	if(videos[index]['origin']=='vimeo') { return vimeo_html(index); }
	
	var video_url = "http://youtube.com/v/" + videos[index]['src'];
	var video_html = '<div style="padding-bottom: 8px;">';
	
	if(auth && videos[index]['bio_id']) {
		video_html += "Band/Artist: ";
		video_html += '<b>' + videos[index]['bio_name'] + '</b><br />';
	} else if (owner){
		var album_title = "<select><option>No artists</option></select>"; 
		try {
			if(artists) {
				album_title = "<select onChange='add_video_band(" + index + ", this.value)'>";
				album_title += "<option value='none'>No band/artist</option>";
				for(var x = 0; x < artists.length; x++) {
					album_title += "<option value='" + artists[x]['entry_id'] + "'>" + artists[x]['bio_name'] + "</option>";	
				}
				album_title += "</select>";
				video_html += "Band/Artist: ";
				video_html += album_title + '<br />';
			} 
		} catch(err) { }
	}

    var params = { allowScriptAccess: "always", movie: "http://www.youtube.com/apiplayer?enablejsapi=1&version=3&playerapiid=ytplayer", wmode: "transparent" };
    var atts = { id: "player2" };
    swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&version=3&playerapiid=ytplayer","active_video", "640", "480", "8", null, null, params, atts, runVideo);

}

var block_reload_video = false;

load_video = function (index) {
	//document.title = "Spotlight TV | " + videos[index]['title'];
	var video_link = "./tv.php?vi=" + videos[index]['entry_id'];
	document.location = video_link;
	return false;
}

run_video = function (index) {	
	document.title = videos[index]['title'];
	var video_link = "./tv.php?vi=" + videos[index]['entry_id'];

	var link = " onClick='window.location=\"" + video_link + "\"'";
	if(block_reload_video) { link = " onClick='run_video("+index+")'" }

	var video_title = "<span style='cursor: pointer'" + link + ">" + videos[index]['title'];
	video_title += "</span> [<a href='http://www.facebook.com/sharer.php?u=" + video_link + "' target='_blank'>share</a>]";

	if(owner) {
		video_title += " <span onClick='delete_video(" + videos[index]['entry_id'] + ")'>[remove]</span>";
	}
	doc('video_frame_title').innerHTML = video_title;
	doc('active_video').innerHTML = video_html(index); 
	doc('video_scanner').innerHTML = video_images(index);
}

function add_video_band (index, bio_id) {
	
	var video_id = videos[index]['entry_id'];
	var bio_id = bio_id;
	
	var callback = function () {
		window.location.reload();		
	}
	
	var XObj;
	try { XObj = new XMLHttpRequest(); }
	catch(e) { XObj = new ActiveXObject(Microsoft.XMLHTTP); }
	
	XObj.onreadystatechange = function () {
		if(XObj.readyState == 4) {
			if(callback) {
				callback();
			}
		}		
	}		
	
	XObj.open('POST','php/update_video.php?update_video_band=true&bio_id=' + bio_id + '&entry_id=' + video_id, true);
	XObj.send(null);
}

function delete_video(id) { 
	
	var callback = function () {
		window.location.reload();		
	}
	
	var XObj;
	try { XObj = new XMLHttpRequest(); }
	catch(e) { XObj = new ActiveXObject(Microsoft.XMLHTTP); }
	
	XObj.onreadystatechange = function () {
		if(XObj.readyState == 4) {
			if(callback) {
				callback();
			}
		}		
	}		
			
	XObj.open('POST','php/add_videos.php?delete=true&id='+id,true);
	XObj.send(null);
}

function add_video() { 
	
	var title = document.getElementById('video_title').value;
	var src = document.getElementById('video_src').value;
	var origin = "youtube";
	
	var youtube = src.indexOf('youtube.com');
	var vimeo = src.indexOf('vimeo.com');
	if(youtube <0 && vimeo <0) {
		alert('You can only add youtube and vimeo videos, sorry.');
		return false;
	}	
	
	document.getElementById('video_title').value = '';
	document.getElementById('video_src').value = '';
	

	var youtube_link = src.indexOf('?v=');
	if(youtube_link > 0) {
		var start = (youtube_link+3);
		var youtube_code = src.substr(start, 11);
		src=youtube_code;
	}
	
	var youtube_inline = src.indexOf('v/');
	if(youtube_inline > 0) {
		var start = (youtube_inline+2);
		var youtube_code = src.substr(start, 11);
		src=youtube_code;
	}

	var vimeo_inline = src.indexOf('moogaloop.swf?clip_id=');
	if(vimeo_inline > 0) {
		var start = (vimeo_inline+22);
		var vimeo_code = src.substr(start, 8);
		src=vimeo_code;
		var origin = "vimeo";
	}

	var vimeo_link = src.indexOf('vimeo.com/');
	if(vimeo_link >= 0 && vimeo_inline <=0) {
		var start = (vimeo_link+10);
		var vimeo_code = src.substr(start, 8);
		src=vimeo_code;
		var origin = "vimeo";
	}

	var callback = function () {
		window.location.reload();		
	}
	
	var XObj;
	try { XObj = new XMLHttpRequest(); }
	catch(e) { XObj = new ActiveXObject(Microsoft.XMLHTTP); }
	
	XObj.onreadystatechange = function () {
		if(XObj.readyState == 4) {
			if(callback) {
				callback();
			}
		}		
	}		
			
	XObj.open('POST','php/add_videos.php?add=true&title=' + title + '&src=' + src + '&user_serial=' + serial + '&origin=' + origin, true);
	XObj.send(null);
}

function remove_event(id) { 
	
	var callback = function () {
		window.location.reload();		
	}
	
	var XObj;
	try { XObj = new XMLHttpRequest(); }
	catch(e) { XObj = new ActiveXObject(Microsoft.XMLHTTP); }
	
	XObj.onreadystatechange = function () {
		if(XObj.readyState == 4) {
			if(callback) {
				callback();
			}
		}		
	}		
			
	XObj.open('POST','php/add_event.php?remove=true&id='+id,true);
	XObj.send(null);
}


function auto_video (title, src, origin, reload) {
	if(reload) {
		var callback = function () {
			window.location="http://bigupsforum.com/tv.php";		
		}
	}
	
	var XObj;
	try { XObj = new XMLHttpRequest(); }
	catch(e) { XObj = new ActiveXObject(Microsoft.XMLHTTP); }
	
	XObj.onreadystatechange = function () {
		if(XObj.readyState == 4) {
			if(callback) {
				callback();
			}
		}		
	}		
			
	XObj.open('POST','php/add_videos.php?add=true&title=' + title + '&src=' + src + '&user_serial=' + serial + '&origin=' + origin, true);
	XObj.send(null);
}

function remove_event(id) { 
	
	var callback = function () {
		window.location.reload();		
	}
	
	var XObj;
	try { XObj = new XMLHttpRequest(); }
	catch(e) { XObj = new ActiveXObject(Microsoft.XMLHTTP); }
	
	XObj.onreadystatechange = function () {
		if(XObj.readyState == 4) {
			if(callback) {
				callback();
			}
		}		
	}		
			
	XObj.open('POST','php/add_event.php?remove=true&id='+id,true);
	XObj.send(null);
}

function add_event() { 
	
	var name = escape(document.getElementById('event_name').value);
	var date = document.getElementById('event_date').value;
	var img = document.getElementById('event_img').value;
	var info = escape(document.getElementById('event_info').value);
	var door = document.getElementById('event_door').value;
	var start = document.getElementById('event_start').value;
	var sales = document.getElementById('event_sales').value;
	
	var callback = function () {
		window.location.reload();		
	}
	
	var XObj;
	try { XObj = new XMLHttpRequest(); }
	catch(e) { XObj = new ActiveXObject(Microsoft.XMLHTTP); }
	
	XObj.onreadystatechange = function () {
		if(XObj.readyState == 4) {
			if(callback) {
				callback();
			}
		}		
	}		
			
	XObj.open('POST','php/add_event.php?add=true&name=' + name + '&date=' + date + '&img=' + img + '&info=' + info + '&door=' + door + '&start=' + start + '&sales=' + sales, true);
	XObj.send(null);
}

