var playerPath = 'http://images.stupidvideos.com/2.0.2/swf/video.swf';
//var playerPath = 'http://dev.stupidvideos.com/player/video.swf';
function write_chart_tabs() {
	if (arguments.length > 0)
		mode = arguments[0];
    
	var modes = new Array('new','popular','related','user');
    
	var sOut = '';
	for (i=0;i<modes.length;i++) {
		sOut += '<div style="background:url(/images/vid/tab_' + modes[i] + '_o';
		if (modes[i] == mode)
			sOut += 'n';
		else
			sOut += 'ff';
		sOut += '.gif) no-repeat;float:left;" onMouseover="roll(this,true,\'\');" onMouseout="roll(this,false,\'\');"><div class="hidden"><a href="#" onClick="change_chart(\'' + modes[i] + '\');return false;"><img src="/images/vid/tab_' + modes[i] + '_on.gif" border="0"/></a></div></div>';
	}
	document.getElementById('chart_tabs').innerHTML = sOut;
	var more_link = '/videos/';
	if (mode == 'new')
		more_link += 'all/new/';
	else if (mode == 'popular')
		more_link += 'all/popular/';
	if (more_link != '')
		document.getElementById('chart_ftr_text').innerHTML = '<a href="' + more_link + '">View All Videos</a> &gt;';
}
function change_chart(m) {
	if (m != mode || arguments.length > 1) {
		write_chart_tabs(m);
		var oXML = new XMLHttpRequest();
        
        var url = '/charts/video.php?m=' + m + '&c=' + categoryID + '&i=';
        if(default_mode != "new" && m == "new")
        {
            var url = '/charts/video.php?m=new_in_category&c=' + categoryID + '&i=';
        }
		
        if (m == 'user')
			url += userID;
		else
			url += videoID;
		oXML.open('GET',url,true);
		oXML.onreadystatechange = function() {
			if (oXML.readyState == 4) {
				document.getElementById('chart').innerHTML = oXML.responseText;
				update_chart();
			}
		}
		oXML.send(null);
	}
}
var ss_timer;
var lyr_id = '';
function ss_overlay(lyr,on,name,lnk) {
	if (on)
		ss_clear();
	lyr_id = String(lyr.id);
	lyr_id = lyr_id.substr(8);
	if (on)
		document.getElementById('ss_lower' + lyr_id).innerHTML = '<div class="ss_view_overlay" onMouseover="clearTimeout(ss_timer);"><a href="' + lnk + '"><img src="/images/vid/ss_mouseover.gif" border="0"/></a></div><div class="ss_black_overlay" onMouseover="clearTimeout(ss_timer);" onClick="document.location = \'' + lnk + '\'">' + name + '</a></div>';
	else
		ss_timer = setTimeout('ss_clear()',100);
}
function ss_clear() {
	clearTimeout(ss_timer);
	if (lyr_id != '')
		document.getElementById('ss_lower' + lyr_id).innerHTML = '';
}		
function review_focus(on) {
	if (on)
		get_flash_movie().fl_pause();
	else
		get_flash_movie().fl_play();
}
function add_review(frm) {
	var text = encodeURIComponent(frm.comment.value);
	var oXML = new XMLHttpRequest();
	var url = '/vid/reviews.php?u=' + viewerID + '&n=' + viewerName + '&v=' + currentVideoID + '&p=1';
	if (frm.reviewID)
		url += '&c=' + frm.reviewID.value;
	url += '&t=' + text;
	oXML.open('GET',url,true);
	oXML.onreadystatechange = function() {
		if (oXML.readyState == 4) {
			if (oXML.responseText == '<LOGOUT/>') {
				hide_box('popup');
				signout();
			} else {
				document.getElementById('reviews').innerHTML = oXML.responseText;
				close_popup('popup');
			}
		}
	}
	oXML.send(null);
}
function adjust_review(box,total) {
	var len = box.value.length;
	if (len > total)
		box.value = box.value.substr(0,total);
	document.getElementById(box.name + '_count').innerHTML = (total - len) + ' characters left.  ' + total + ' total.  No HTML please.';
}
function video_init() {
	var so = new SWFObject(playerPath,'myFlash', 448, 336, 9,"#000000");
	so.addParam("wmode","transparent");
    so.addParam("AllowScriptAccess","always");
    so.addParam("AllowFullScreen","true");
	var cook = String(document.cookie);
	if (cook.indexOf('ui=') > -1) {
		var ck = cook.substr(cook.indexOf('ui='));
		if (ck.indexOf(';') > -1) {
			ck = ck.substr(0,ck.indexOf(';'));
        }
		ck = unescape(ck).split('~');
		if (ck.length > 3) {
			so.addVariable('pr',ck[3]);  
        }
	}                          
	so.addVariable("i",currentVideoID);
	so.addVariable("p",escape(playlist));
	so.addVariable('sk',7);
	so.addVariable('si',2);
	so.addVariable('sct',section);
	so.addVariable('m',mute);
	so.addVariable('imm',imm);
    so.addVariable('uid',viewerID);
    so.addVariable('usn',viewerName);
	so.write('video_player');
}
function update_chart() {
	if (document.getElementById('playlist'))
		var wrp = document.getElementById('playlist')
	else
		var wrp = document.getElementById('chart');
	var boxes = wrp.getElementsByTagName('div');
	var is_on = false;
	for(i=0;i<boxes.length;i++) {
		id = boxes[i].id;
		id = id.substr(0,5);
		if (id == 'chrt_') {
			if (boxes[i].id == 'chrt_' + currentVideoID) {
				boxes[i].className = 'chart_box_on';
				is_on = true;
			} else {
				boxes[i].className = 'chart_box';
				is_on = false;
			}
		}
		if (boxes[i].className == 'chart_image_off' && is_on)
			boxes[i].innerHTML = '<div style="padding:43px 0px 0px 56px;"><img src="/images/vid/btn_playing.gif"/></div>';
		else if (boxes[i].className == 'chart_image_off' && !is_on)
			boxes[i].innerHTML = '';
	}		
}
var ad_timer;
function refresh_ads() {
	clearTimeout(ad_timer);
    ord=Math.random()*10000000000000000;
	document.getElementById('bannertop').innerHTML = '';
	document.getElementById('instream_lrec').style.display = 'none';
	document.getElementById('banner_lrec').style.display = 'block';
	//document.getElementById('banner_lrec').innerHTML = '<iframe name="lrec" id="lrec" src="http://www.purevideo.com/ads/banner.php?s=2&pos=LREC&cat=' + section + '&r=' + Math.random() + '" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" scrolling="no" width="300" height="250" frameborder="0"></iframe>';
    //document.getElementById('banner_lrec').innerHTML = '<iframe name="lrec" id="lrec" src="http://optimized-by.rubiconproject.com/a/6251/8217/14012-15.html?" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" scrolling="no" width="300" height="250" frameborder="0"></iframe>';
    document.getElementById('banner_lrec').innerHTML = '<iframe name="lrec" id="lrec" src="/ads/doubleclick.php?dart_zone=' + dart_zone + '&ord_value=' + ord + '" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" scrolling="no" width="300" height="250" frameborder="0"></iframe>';
    
    urchinTracker('/ajax/ad/LREC/' + section);
	document.getElementById('half_lrec').innerHTML = '<iframe name="hlrec" id="hlrec" src="http://www.purevideo.com/ads/banner.php?s=2&pos=HLREC&cat=' + section + '&r=' + Math.random() + '" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" scrolling="no" width="300" height="100" frameborder="0"></iframe>';    
    document.getElementById('sky').innerHTML = '<iframe name="skyscraper" id="skyscraper" src="/ads/doubleclick.php?dart_zone=' + dart_zone + '&ord_value=' + ord + '&ad_type=sky" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" scrolling="no" width="160" height="600" frameborder="0"></iframe>';
    urchinTracker('/ajax/ad/SKY/' + section);
	ad_timer = setTimeout("refresh_ads();",60000);
}
function ad_banner(str) {
    if (str.indexOf("<") == 0) {
        document.getElementById('bannertop').innerHTML = '<div style="float:left;text-align:right;width:40px;"><img src="http://images.stupidvideos.com/images/misc/broughtToYouBy.gif"></div>'+str;
    } else { 
        //document.getElementById('bannertop').innerHTML = '<div style="float:left;text-align:right;width:40px;"><img src="http://images.stupidvideos.com/images/misc/broughtToYouBy.gif"></div><IFRAME SRC="http://www.purevideo.com/ads/banner.php?s=2&pos=Banner&cat=' + str + '" scrolling="no" width="728" height="90" frameborder="0" marginheight="0" marginwidth="0"></IFRAME>';
        document.getElementById('bannertop').innerHTML = '<div style="float:left;text-align:right;width:40px;"><img src="http://images.stupidvideos.com/images/misc/broughtToYouBy.gif"></div><iframe src="http://optimized-by.rubiconproject.com/a/6251/8217/14012-2.html?" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="728" height="90"></iframe>';
    }
}
function ad_lrec(new_lrec) {
	ad_showing = true;
	new_lrec = unescape(new_lrec);
    document.getElementById("video_title_holder").style.display = "none"; 
	document.getElementById('instream_lrec').style.display = 'block';
	document.getElementById('banner_lrec').style.display = 'none';
	document.getElementById('video_info').style.display = 'none';
	clearTimeout(ad_timer);
	document.getElementById('instream_lrec').innerHTML = new_lrec;
	urchinTracker('/ajax/ad/PRL/' + section);
}
function send_video(id) {
	ad_showing = false;
	currentVideoID = id;
	var loc = String(document.location);
	if (loc.indexOf('#') > -1)
		loc = loc.substr(0,loc.indexOf('#'));
	document.location = loc + '#' + id;
	document.getElementById('video_info').style.display = 'block';
	update_chart()
	refresh_ads();
	urchinTracker('/ajax/video/' + id);
}
function send_xml(xml) {
	xml = xml.replace(/& /g,'&amp; ');
	var oXML = Sarissa.getDomDocument();
	oXML = (new DOMParser()).parseFromString(xml, "text/xml");
	display_metadata(oXML);
}
function show_desc(show) {
	if (!show)
		document.getElementById('md_desc').innerHTML = short_desc + ' <a href="#" onClick="show_desc(true); return false;">Show more &gt;</a>';
	else
		document.getElementById('md_desc').innerHTML = long_desc + ' <a href="#" onClick="show_desc(false); return false;">Show less &gt;</a>';
}		
var long_desc;
var short_desc;
function display_metadata(oXML) {
    if (!ad_showing) {
        document.getElementById("video_title_holder").style.display = "block";
    }
	currentVideoName = val(oXML,'urlname','video');
	currentVideoTitle = val(oXML,'name','video');
    document.getElementById('video_title').innerHTML = currentVideoTitle;
	document.title = currentVideoTitle + title_end;
	var submitter = val(oXML,'submitter_name','video');
	if (userID != submitter) {
		userID = submitter;
		if (mode == 'user')
			change_chart('user',true);
	}
	userID = submitter;
	if (currentPlaylist != 'similar' && videoID != currentVideoID) {
		videoID = currentVideoID;
		if (mode == 'similar')
			change_chart('similar',true);
	}	
	var imageID = val(oXML,'submitter_image','video');
//	if (imageID != '' && imageID > 0) {
		document.getElementById('md_top').innerHTML = '<div id="mg_img" class="left"><a href="/profile/' + submitter + '/"><img src="' + imagePathFromID(imageID,'80_80') + '" width="80" height="80" style="border:1px solid #000; margin-right:8px;"/></a></div><div style="float:left;width:180px;margin-right:10px;overflow:hidden;"><div class="md_row"><b>From:</b> <span id="md_from"></span></a></div><div class="md_row"><b>Total Views:</b> <span id="md_views"></span></div><div class="md_row"><span id="fav"></span></div></div><div style="float:left;width:150px;"><div class="md_row">My Rating: <span id="rating_widget"></span></div><div class="md_row">Average: <span id="rating_hardcoded"></span><p style="margin-top:6px;"><span id="download"></span></p></div></div>';
//	} else {
//		document.getElementById('md_top').innerHTML = '<div class="metabox"><div class="md_row"><b>From:</b> <span id="md_from"></span></a></div><div class="md_row"><b>Total Views:</b> <span id="md_views"></span></div></div><div class="left"><div class="md_row">My Rating: <span id="rating_widget"></span></div><div class="md_row">Average: <span id="rating_hardcoded"></span></div></div><div id="fav" class="favorites"></div><div id="download" class="download"></div>';
//	}
	if (submitter == '')
		document.getElementById('md_from').innerHTML = 'Anonymous';
	else
		document.getElementById('md_from').innerHTML = '<a href="/profile/' + submitter + '/" title="' + submitter + '">' + truncate(submitter,40) + '</a>';
	document.getElementById('md_views').innerHTML = addCommas(val(oXML,'total_views','video'));
	long_desc = val(oXML,'description','video');
	if (long_desc.length > 180) {
		short_desc = long_desc.substr(0,178) + '...';
		show_desc(false);
	} else {
		document.getElementById('md_desc').innerHTML = long_desc;
	}
	if (isIE)
		document.getElementById('md_desc').style.display = 'inline-block';
	else
		document.getElementById('md_desc').style.display = 'block';
	var avg_rating = Math.round(val(oXML,'avg_rating','video'));
	var avg = '';
	for(i=1;i<11;i++) {
		if (i < avg_rating) {
			if (i % 2 == 0) {
				avg += '<img src="/images/vid/grwidget_even_on.gif" class="star">';
			} else {
				avg += '<img src="/images/vid/grwidget_odd_on.gif" class="star">';
			}
		} else {
			if (i % 2 == 0) {
				avg += '<img src="/images/vid/grwidget_even_off.gif" class="star">';
			} else {
				avg += '<img src="/images/vid/grwidget_odd_off.gif" class="star">';
			}
		}
	}
	document.getElementById('rating_hardcoded').innerHTML = avg;
	var my = write_widget(-1);
	document.getElementById('rating_widget').innerHTML = my;
	var path = val(oXML,'category_path','video') + currentVideoName + '/';
	
	var cat_path = (val(oXML,'category_path','video'));
	var buzzlink = encodeURIComponent('http://www.stupidvideos.com' + path);
	document.getElementById('yahooBuzzLink').innerHTML = '<iframe src="/yahoo_buzzlink.php?name='+ currentVideoName +'&cat_path='+ cat_path +'" frameborder="0" width="75px" height="38px" scrolling="no" marginwidth="0" marginheight="0"></iframe>';
	
	document.getElementById('video_url').value = 'http://www.stupidvideos.com' + path;
	document.getElementById('embed_url').value = '<object width="448" height="336"><param name="movie" value="'+playerPath+'?sa=1&sk=7&si=2&i=' + currentVideoID + '"></param><embed src="'+playerPath+'?sa=1&sk=7&si=2&i=' + currentVideoID + '" type="application/x-shockwave-flash" width="448" height="336"></embed></object>';
	document.getElementById('fav').innerHTML = '<a href="#" onClick="bookmark(); return false;">Add to Favorites</a>';
	document.getElementById('download').innerHTML = '<a href="#" onClick="javascript:download_box(currentVideoID,currentVideoName); return false;">Download</a>';
	//document.getElementById('digg').innerHTML = '<iframe src="/vid/digg.php?t=' + escape(currentVideoTitle) + '&u=' + escape(document.getElementById('video_url').value) + '&d=' + escape(long_desc) + '" width="110" height="17" marginwidth="0" marginheight="0" leftmargin="0" topmargin="0" frameborder="0" scrolling="no" align="absmiddle"></iframe>';
	load_reviews(1);
}

var review_text = '';
function load_reviews(page) {
	var oXML = new XMLHttpRequest();
	var url = '/vid/reviews.php?v=' + currentVideoID + '&p=' + page + '&r=' + Math.random();
	oXML.open('GET',url,true);
	oXML.onreadystatechange = function() {
		if (oXML.readyState == 4) {
			document.getElementById('reviews').innerHTML = oXML.responseText;
		}
	}
	oXML.send(null);
}	
function write_widget(rating) {
	var w = '';
	for(i=1;i<11;i++) {
		w += '<a href="#" onClick="adjust_widget(' + i + '); return false;">';
		if (i > rating) {
			if (i % 2 == 0) {
				w += '<img src="/images/vid/widget_even_off.gif"';
			} else {
				w += '<img src="/images/vid/widget_odd_off.gif"';
			}
		} else {
			if (i % 2 == 0) {
				w += '<img src="/images/vid/widget_even_on.gif"';
			} else {
				w += '<img src="/images/vid/widget_odd_on.gif"';
			}
		}
		w += ' class="star" border="0"/></a>';
	}
	return w;
}
function adjust_widget(pos) {
	send_rating(currentVideoID, pos);
}
function send_rating(vid,pos) {
	var url = '/process/processRating.php?v=' + vid + '&r=' + pos;

	var oHTTP =  new XMLHttpRequest();
	oHTTP.open('GET', url, true);

	oHTTP.onreadystatechange = function() {
		if (oHTTP.readyState == 4)
			document.getElementById('rating_widget').innerHTML = write_widget(pos);
	}
	oHTTP.send(null);
}
function pad_image(imageID) {
	imageID = String(imageID);
	while(imageID.length < 8) {
		imageID = '0' + imageID;
	}
	return imageID;
}
function imagePathFromID(imageID,size) {
	var base_imageID = imageID;
	imageID = pad_image(imageID);
	var path = 'http://images.stupidvideos.com/images/2/' + imageID.substr(0,2) + '/' + imageID.substr(2,2) + '/' + imageID.substr(4,2) + '/' + imageID.substr(6,2) + '/' + base_imageID + '_' + size + '.jpg';
	return path;
}
function truncate(str,len) {
	if (str.length > len)
		str = str.substr(0,len-2) + '...';
	return str;
}
function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
function bookmark() {
	var url = '/process/processFavorite.php?v=' + currentVideoID;
	var oHTTP =  new XMLHttpRequest();
	oHTTP.open('GET', url, true);

	oHTTP.onreadystatechange = function() {
		if (oHTTP.readyState == 4) {
			if(oHTTP.responseText=="<OK/>")
				document.getElementById('fav').innerHTML = '<b>Added to Favorites</b>';
			else {
				dim_page(true);
				guestwall();
			}
//		   	document.location = '/registration/?ec=2&dest=' + encodeURIComponent(document.location);
		}
	}
	oHTTP.send(null);
}
function ext_share(partner) {
	var current_vidPath = document.getElementById('video_url').value;
	if (current_vidPath != '') {
		if (partner == 'facebook') {
			window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(current_vidPath) + '&t=' + encodeURIComponent(currentVideoTitle),'sharer','toolbar=0,status=0,width=626,height=436');
		} else if (partner == 'digg') {
			var url = 'http://digg.com/submit?phase=2&url=' + encodeURIComponent(current_vidPath) + '&title=' + encodeURIComponent(currentVideoTitle) + '&topic=videos_comedy&bodytext=' + encodeURIComponent(document.getElementById('md_desc').innerHTML);
			window.open(url);
		} else if (partner == 'delicious') {
			var url = 'http://del.icio.us/post?v=4&noui&jump=close&url=' + encodeURIComponent(current_vidPath) + '&title=' + encodeURIComponent(currentVideoTitle);
			window.open(url,'delicious','toolbar=no,width=700,height=400');
		} else if (partner == 'stumble') {
			var url = 'http://www.stumbleupon.com/submit?url=' + encodeURIComponent(current_vidPath) + '&title=' + encodeURIComponent(currentVideoTitle);
			window.open(url);
		} else if (partner == 'myspace') {
			var url = 'http://www.myspace.com/Modules/PostTo/Pages/?t=' + encodeURIComponent(currentVideoTitle) + '&c=' + encodeURIComponent(document.getElementById('embed_url').value + '<br/>' + document.getElementById('md_desc').innerHTML) + '&u=' + encodeURIComponent(current_vidPath) + '&l=';
			window.open(url);
		}
	}
}
function reload_flash() {
	if (arguments.length == 0)
		var newID = currentVideoID;
	else
		var newID = arguments[0];
	if (mode == 'playlist')
		var newrss = playlist;
	else if (mode == 'user')
		var newrss = '/rss/user.php?u=' + userID;
	else if (mode == 'related')
		var newrss = '/rss/rss.php?chart=similar&v=' + videoID;
	else {
		var newrss = '/rss/rss.php?chart=' + mode;
		if (section != '')
			newrss += '&cat=' + section;
	}
	currentPlaylist = mode;
    get_flash_movie().fl_playlist(playlist, newID);
    //get_flash_movie().fl_playlist('http://www.stupidvideos.com'+newrss, newID);
    //get_flash_movie().fl_load(newID);
	//get_flash_movie().fl_init(newrss,newID,true);
}
var isIE = navigator.appName.indexOf("Microsoft") != -1;
function get_flash_movie() {
	if (isIE) {
		return window['myFlash'];
	} else {
		return document['myFlash'];
	}
}
function delete_review(reviewID) {
	var oXML = new XMLHttpRequest();
	var url = '/vid/reviews.php?d=' + reviewID + '&v=' + currentVideoID;
	oXML.open('GET',url,true);
	oXML.onreadystatechange = function() {
		if (oXML.readyState == 4) {
			if (oXML.responseText == '<LOGOUT/>') {
				signout();
			} else {
				document.getElementById('reviews').innerHTML = oXML.responseText;
			}
		}
	}
	oXML.send(null);
}
function delete_reply(replyID) {
	var oXML = new XMLHttpRequest();
	var url = '/vid/reviews.php?dr=' + replyID + '&v=' + currentVideoID;
	oXML.open('GET',url,true);
	oXML.onreadystatechange = function() {
		if (oXML.readyState == 4) {
			if (oXML.responseText == '<LOGOUT/>') {
				signout();
			} else {
				document.getElementById('reviews').innerHTML = oXML.responseText;
			}
		}
	}
	oXML.send(null);
}
function add_reply(frm) {
	var oXML = new XMLHttpRequest();
	var url = '/vid/reviews.php?u=' + viewerID + '&v=' + currentVideoID;
	if (frm.reviewID)
		url += '&r=' + frm.reviewID.value;
	if (frm.replyID)
		url += '&c=' + frm.replyID.value;
	url +='&p=1&t=' + encodeURIComponent(frm.comment.value);
	oXML.open('GET',url,true);
	oXML.onreadystatechange = function() {
		if (oXML.readyState == 4) {
			if (oXML.responseText == '<LOGOUT/>') {
				hide_box('popup');
				signout();
			} else {
				document.getElementById('reviews').innerHTML = oXML.responseText;
				close_popup('popup');
			}
		}
	}
	oXML.send(null);
}
function post_reply(reviewID) {
	get_flash_movie().fl_pause();
	var sOut = '<div class="popup_contents"><div class="popup_close"><a href="#" onClick="hide_box(\'popup\');return false;">X</a></div><div class="popup_hdr">Post a Reply</div><form id="comment_form"><input type="hidden" name="reviewID" value="' + reviewID + '"/><textarea name="comment" id="comment_field" onKeyUp="adjust_review(this,750);"></textarea><div id="comment_count">750 characters left. 750 total. No HTML please.</div><div class="generic_btn generic_btn_right"><a href="#" onClick="close_popup(\'popup\');return false;">Cancel</a></div><div class="generic_btn generic_btn_right"><a href="#" onClick="add_reply(document.getElementById(\'comment_form\'));return false;">Reply</a></div><div class="clear"></div></form></div></div>';
	display_box(sOut,true);
	if (document.getElementById('comment_field'))
		document.getElementById('comment_field').focus();
}
function edit_reply(replyID) {
	get_flash_movie().fl_pause();
	var sOut = '<div class="popup_contents"><div class="popup_close"><a href="#" onClick="hide_box(\'popup\');return false;">X</a></div><div class="popup_hdr">Post a Reply</div><form id="comment_form"><input type="hidden" name="replyID" value="' + replyID + '"/><textarea name="comment" id="comment_field" onKeyUp="adjust_review(this,750);">' + document.getElementById('reply_' + replyID).innerHTML + '</textarea><div id="comment_count">' + (750 - document.getElementById('reply_' + replyID).innerHTML.length) + ' characters left. 750 total. No HTML please.</div><div class="generic_btn generic_btn_right"><a href="#" onClick="close_popup(\'popup\');return false;">Cancel</a></div><div class="generic_btn generic_btn_right"><a href="#" onClick="add_reply(document.getElementById(\'comment_form\'));return false;">Reply</a></div><div class="clear"></div></form></div></div>';
	display_box(sOut,true);
	if (document.getElementById('comment_field'))
		document.getElementById('comment_field').focus();
}
function post_comment() {
	get_flash_movie().fl_pause();
	var sOut = '<div class="popup_contents"><div class="popup_close"><a href="#" onClick="hide_box(\'popup\');return false;">X</a></div><div class="popup_hdr">Post a Comment</div><form id="comment_form"><textarea name="comment" id="comment_field" onKeyUp="adjust_review(this,2000);"></textarea><div id="comment_count">2000 characters left. 2000 total. No HTML please.</div><div class="generic_btn generic_btn_right"><a href="#" onClick="close_popup(\'popup\');return false;">Cancel</a></div><div class="generic_btn generic_btn_right"><a href="#" onClick="add_review(document.getElementById(\'comment_form\'));return false;">Post a Comment</a></div><div class="clear"></div></form></div></div>';
	
    display_box(sOut,true);
	if (document.getElementById('comment_field'))
		document.getElementById('comment_field').focus();
}	
function edit_comment(reviewID) {
	get_flash_movie().fl_pause();
	var sOut = '<div class="popup_contents"><div class="popup_close"><a href="#" onClick="hide_box(\'popup\');return false;">X</a></div><div class="popup_hdr">Post a Comment</div><form id="comment_form"><input type="hidden" name="reviewID" value="' + reviewID + '"/><textarea name="comment" id="comment_field" onKeyUp="adjust_review(this,2000);">' + document.getElementById('review_' + reviewID).innerHTML + '</textarea><div id="comment_count">' + (2000 - document.getElementById('review_' + reviewID).innerHTML.length) + ' characters left. 2000 total. No HTML please.</div><div class="generic_btn generic_btn_right"><a href="#" onClick="close_popup(\'popup\');return false;">Cancel</a></div><div class="generic_btn generic_btn_right"><a href="#" onClick="add_review(document.getElementById(\'comment_form\'));return false;">Post a Comment</a></div><div class="clear"></div></form></div></div>';
	display_box(sOut,true);
	if (document.getElementById('comment_field'))
		document.getElementById('comment_field').focus();
}	
function download_box(currentVideoID, currentVideoName) {
    var wmvURL = 'http://download.stupidvideos.com/process/download/processDownload.php?s=www.stupidvideos.com&v=' + currentVideoID + '&t=1&n=' + currentVideoName;
    var mp4URL = 'http://download.stupidvideos.com/process/download/processDownload.php?s=www.stupidvideos.com&v=' + currentVideoID + '&t=2&n=' + currentVideoName;
	var pspURL = 'http://download.stupidvideos.com/process/download/processDownload.php?s=www.stupidvideos.com&v=' + currentVideoID + '&t=3&n=' + currentVideoName;
	var phoneURL = 'http://download.stupidvideos.com/process/download/processDownload.php?s=www.stupidvideos.com&v=' + currentVideoID + '&t=4&n=' + currentVideoName;
	
	get_flash_movie().fl_pause();
	var sOut = '<div class="popup_contents"><div class="popup_close"><a href="#" onClick="hide_box(\'popupdownload\');hide_box(\'popup\');return false;">X</a></div><div style="margin:0;"><div class="popup_hdr">Download</div><br /><br /><div style="float:left;background-color:#252525;color:#fff;border:1px solid #000;padding:10px;width:410px;_width:425px;height:60px;">Please select your download format below.<br /><br /><a href="' + wmvURL + '"><img src="/images/vid/dl_mediaplayer_icon.gif" width="16" height="17" border="0" alt="Windows Media" style="margin:0 0 5px 0px;vertical-align:middle;" /> Windows Media</a> <a href="' + mp4URL + '"><img src="/images/vid/dl_apple_icon.gif" width="12" height="16" border="0" alt="iPod" style="margin:0 0 3px 30px;vertical-align:middle;" /> iPod</a> <a href="' + phoneURL + '"><img src="/images/vid/dl_smartphone_icon.gif" width="9" height="16" border="0" alt="SmartPhone" style="margin:0 0 3px 30px;vertical-align:middle;" /> SmartPhone</a><a href="' + pspURL + '"><img src="/images/vid/dl_psp_icon.gif" width="16" height="15" border="0" alt="PSP" style="margin:0 0 2px 30px;vertical-align:middle;" /> PSP</a></div></div></div>';
	display_download_box(sOut);
}
function close_popup(id) {
	hide_box(id);
	get_flash_movie().fl_play();
}

