jQuery.cookie = function(name, value, options) {
	if (typeof value != 'undefined') { // name and value given, set cookie
		options = options || {};
		if (value === null) {
			value = '';
			options.expires = -1;
		}
		var expires = '';
		if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
			var date;
			if (typeof options.expires == 'number') {
				date = new Date();
				date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
			} else {
				date = options.expires;
			}
			expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
		}
		var path = options.path ? '; path=' + (options.path) : '';
		var domain = options.domain ? '; domain=' + (options.domain) : '';
		var secure = options.secure ? '; secure' : '';
		document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
	} else { // only name given, get cookie
		var cookieValue = null;
		if (document.cookie && document.cookie != '') {
			var cookies = document.cookie.split(';');
			for (var i = 0; i < cookies.length; i++) {
				var cookie = jQuery.trim(cookies[i]);
				// Does this cookie string begin with the name we want?
				if (cookie.substring(0, name.length + 1) == (name + '=')) {
					cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
					break;
				}
			}
		}
		return cookieValue;
	}
};

jQuery.fn.corner = function(o) {
	function hex2(s) {
		var s = parseInt(s).toString(16);
		return ( s.length < 2 ) ? '0'+s : s;
	};
	function gpc(node) {
		for ( ; node && node.nodeName.toLowerCase() != 'html'; node = node.parentNode  ) {
			var v = jQuery.css(node,'backgroundColor');
			if ( v.indexOf('rgb') >= 0 ) {
				rgb = v.match(/\d+/g);
				return '#'+ hex2(rgb[0]) + hex2(rgb[1]) + hex2(rgb[2]);
			}
			if ( v && v != 'transparent' )
				return v;
		}
		return '#ffffff';
	};
	function getW(i) {
		switch(fx) {
		case 'round':  return Math.round(width*(1-Math.cos(Math.asin(i/width))));
		case 'notch':  return width;
		case 'bevel':  return i+1;
		case 'bite':   return Math.round(width*(Math.cos(Math.asin((width-i-1)/width))));
		}
	};
	o = (o||"").toLowerCase();
	var keep = /keep/.test(o);                       // keep borders?
	var cc = ((o.match(/cc:(#[0-9a-f]+)/)||[])[1]);  // corner color
	var sc = ((o.match(/sc:(#[0-9a-f]+)/)||[])[1]);  // strip color
	var width = parseInt((o.match(/(\d+)px/)||[])[1]) || 10; // corner width
	var re = /round|bevel|notch|bite/;
	var fx = ((o.match(re)||['round'])[0]);
	var edges = { T:0, B:1 };
	var opts = {
		TL:  /top|tl/.test(o),       TR:  /top|tr/.test(o),
		BL:  /bottom|bl/.test(o),    BR:  /bottom|br/.test(o)
	};
	if ( !opts.TL && !opts.TR && !opts.BL && !opts.BR )
		opts = { TL:1, TR:1, BL:1, BR:1 };
	var strip = document.createElement('div');
	strip.style.overflow = 'hidden';
	strip.style.height = '1px';
	strip.style.backgroundColor = sc || 'transparent';
	strip.style.borderStyle = 'solid';
	return this.each(function(index){
		var pad = {
			T: parseInt(jQuery.css(this,'paddingTop'))||0,     R: parseInt(jQuery.css(this,'paddingRight'))||0,
			B: parseInt(jQuery.css(this,'paddingBottom'))||0,  L: parseInt(jQuery.css(this,'paddingLeft'))||0
		};

		if (jQuery.browser.msie) this.style.zoom = 1; // force 'hasLayout' in IE
		if (!keep) this.style.border = 'none';
		strip.style.borderColor = cc || gpc(this.parentNode);
		var cssHeight = jQuery.curCSS(this, 'height');

		for (var j in edges) {
			var bot = edges[j];
			strip.style.borderStyle = 'none '+(opts[j+'R']?'solid':'none')+' none '+(opts[j+'L']?'solid':'none');
			var d = document.createElement('div');
			var ds = d.style;

			bot ? this.appendChild(d) : this.insertBefore(d, this.firstChild);

			if (bot && cssHeight != 'auto') {
				if (jQuery.css(this,'position') == 'static')
					this.style.position = 'relative';
				ds.position = 'absolute';
				ds.bottom = ds.left = ds.padding = ds.margin = '0';
				if (jQuery.browser.msie)
					ds.setExpression('width', 'this.parentNode.offsetWidth');
				else
					ds.width = '100%';
			}
			else {
				ds.margin = !bot ? '-'+pad.T+'px -'+pad.R+'px '+(pad.T-width)+'px -'+pad.L+'px' :
									(pad.B-width)+'px -'+pad.R+'px -'+pad.B+'px -'+pad.L+'px';
			}

			for (var i=0; i < width; i++) {
				var w = Math.max(0,getW(i));
				var e = strip.cloneNode(false);
				e.style.borderWidth = '0 '+(opts[j+'R']?w:0)+'px 0 '+(opts[j+'L']?w:0)+'px';
				bot ? d.appendChild(e) : d.insertBefore(e, d.firstChild);
			}
		}
	});
};


	function setGender(){
		var i_like_m = $('#radio-male').attr('className');
		var i_like_f = $('#radio-female').attr('className');
		if($('#i-am-female').css('display') == 'block')
			$("#filter_sess_gender").val('F');
		else
			$("#filter_sess_gender").val('M');

		if(i_like_m == 'gender_radio-on' && i_like_f == 'gender_radio-on') {
			$("#filter_i_like").val('B');
		}
		else if(i_like_m == 'gender_radio-on') {
			$("#filter_i_like").val('M');
		}
		else if(i_like_f == 'gender_radio-on') {
			$("#filter_i_like").val('F');
		}
		else {
			$("#filter_i_like").val('B');
		}
		$("#filter_form").submit();
	}

$(document).ready(function () {
	var COOKIE_NAME = 'cookie_warning';
	var headerFooterSize = 300;     // header + footer + paddings + margins + borders
	var minContentSize = 100;
	$("#logo").click( function() {
		window.location = "http://www.xtube.com/index.php";
	});

	var filter_i_like = $("#filter_i_like").val();
	var filter_sess_gender = $("#filter_sess_gender").val();

		$("#radio-male,#like-male").click(function() {
		var className=$('#radio-male').attr('className');
		if(className == 'gender_radio-on') {
			$('#radio-male').attr({className:'gender_radio-off'});
			$('#like-male').css('color','#7b7b7b');
		}
		else {
			$('#radio-male').attr({className:'gender_radio-on'});
			$('#like-male').css('color','#f7f7f7');
		}
		setGender();
		return false;
		});
		$("#radio-female,#like-female").click(function() {
		var className=$('#radio-female').attr('className');
		if(className == 'gender_radio-on') {
			$('#radio-female').attr('className','gender_radio-off');
			$('#like-female').css('color','#7b7b7b');
		}
		else {
			$('#radio-female').attr('className','gender_radio-on');
			$('#like-female').css('color','#f7f7f7');
		}
		setGender();
				return false;
		});
	$("#gender-male-m,#gender-male-f,#switch-female").click(function() {
		$('#i-am-male').css('display','block');
		$('#i-am-female').css('display','none');
		setGender();
		return false;
	});
	$("#gender-female-m,#gender-female-m,#switch-male").click(function() {
		$('#i-am-male').css('display','none');
		$('#i-am-female').css('display','block');
		setGender();
		return false;
	});
	$("#share_off").click(function() {
		if($("#share_on_box").position().left <= -1000){
			var p = $(this).position();
			var X = p.left + 73 + 'px';
			var Y = p.top + 'px';
		}
		else{
			X = '-10000px';
			Y = '-10000px';
		}

		$("#share_on_box").css('left',X).css('top',Y);
		return false;
	});
		$(".share_code_btn, .share_code_btn_photo").click(function() {
		var new_Y = $(this).position().top + 30;
				if($("#share_on_box").position().left <= -1000 || $("#share_on_box").position().top != new_Y){
						var p = $(this).position();
						var X = p.left + 134 + 'px';
						var Y = p.top + 30 + 'px';
				}
				else{
						X = '-10000px';
						Y = '-10000px';
				}

		$("#embed_on_box").css('left','-10000px');
				$("#share_on_box").css('left',X).css('top',Y);
				return false;
		});
		$(".embed_code_btn").click(function() {
		var new_Y = $(this).position().top + 30;
				if($("#embed_on_box").position().left <= -1000 || $("#embed_on_box").position().top != new_Y){
						var p = $(this).position();
						var X = p.left + 134 + 'px';
						var Y = p.top + 30 + 'px';
				}
				else{
						X = '-10000px';
						Y = '-10000px';
				}

		$("#share_on_box").css('left','-10000px');
				$("#embed_on_box").css('left',X).css('top',Y);
				return false;
		});
	$("#share_box_submit").click(function() {
		$('#share_on').submit();
	});
	$("#embed_on_box_big,#embed_on_box_small").click(function() {
		$(this).select();
	});

	$("#mar_summary").click(function() {
		document.location.href='/my_account.php';
	});
	$("#mar_transactions").click(function() {
		document.location.href='/my_transactions.php';
	});
	$("#mar_points").click(function() {
		document.location.href='/my_point.php';
	});
	$("#mar_linking").click(function() {
		document.location.href='/linking_codes.php';
	});
	$("#mar_cancel").click(function() {
		document.location.href='/cancelmembership.php';
	});
	$("#mar_remove").click(function() {
		document.location.href='/remove_my_account.php';
	});
	$("#mar_subscenter").click(function() {
		document.location.href='/subscription.php';
	});
	$("#mar_subsvideo").click(function() {
		document.location.href='/my_subscribed_videos.php';
	});
	$("#mar_subsphoto").click(function() {
		document.location.href='/my_subscribed_photos.php';
	});
	$("#mar_subsamateur").click(function() {
		document.location.href='/my_subscribed_amateurs.php';
	});
	$("#mar_subschannel").click(function() {
		document.location.href='/my_subscribed_paidchannels.php';
	});
	$("#mar_mysubscripe").click(function() {
		document.location.href='/my_subscribers.php';
	});
	$("#mar_freevideos").click(function() {
		document.location.href='/my_favorite_videos.php';
	});
	$("#mar_freephotos").click(function() {
		document.location.href='/my_favorite_sets.php';
	});
	$("#mar_amavideos").click(function() {
		document.location.href='/my_favorite_amateur_videos.php';
	});
	$("#mar_amaphotos").click(function() {
		document.location.href='/my_favorite_amateur_photos.php';
	});
	$("#mar_amateurs").click(function() {
		document.location.href='/my_favorite_amateurs.php';
	});
	$("#mar_favdvds").click(function() {
		document.location.href='/my_favorite_paidchannels.php';
	});
});

function setCid(sex_type){
	$("#filter_sex_type").val(sex_type);
	$("#filter_form").submit();
}

function thumb_info_desc_over(m,o) {
	var X= o.left -46 + 'px';
	var Y= o.top - 130 + 'px';

	if(m.length >220) {
		m = m.substring(0,220) + ' ...';
	}
	$("#thumb_info_desc_box_cont").html(m);
	$("#thumb_info_desc_box").css('left',X).css('top',Y).css('display','block');
	return false;
}
function thumb_info_desc_out() {
	$("#thumb_info_desc_box").css('left','-10000px');
	return false;
}

function set_share_box(id,type) {
	if(type == 'video') {
		var url = 'http://www.xtube.com/watch.php?v=' + id;
	}
	else if(type == 'set') {
		var url = 'http://www.xtube.com/set.php?s=' + id;
	}

	$("#share_on_box_msg").html(url);
	$("#share_on_box_code").val(id)
	return false;
}

function set_embed_box(s, b) {
	var s_text = $(s).text();
	var b_text = $(b).text();
//alert("xxxxx s_test="+s_text+"xxxxxxxx b="+b_text);
	$("#embed_on_box_small").val(s_text);
	$("#embed_on_box_big").val(b_text);
	return false;
}

function toggleVisibility(whichForm, setVisible)
{
	var newstate="none"
	if(setVisible == true)
		newstate = ""

	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichForm).style;
		style2.display = newstate;
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichForm].style;
		style2.display = newstate;
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichForm].style;
		style2.display = newstate;
	}
}


function setInnerHTML(div_id, value)
{
	var dstDiv = document.getElementById(div_id);
	dstDiv.innerHTML = value;
}

function redirectURL(goURL) {
	document.location.href=goURL;
}

function createXMLHttpRequest() {
	  if (window.XMLHttpRequest) { // Mozilla, Safari,...
		  xmlHttp = new XMLHttpRequest();

		  if (xmlHttp.overrideMimeType)
			  xmlHttp.overrideMimeType('text/xml');

	  } else if (window.ActiveXObject) { // IE
		  try {
			  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		  } catch (e) {
			  try {
				  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			  } catch (e) {}
		  }
	  }
}

function handleStateChange () {
	if(xmlHttp.readyState==4) {
		if(xmlHttp.status==200) {
			var innerHTMLContent=xmlHttp.responseText;
			if (typeof( div_main_qlist )!= 'undefined'){
				document.getElementById('div_main_qlist').innerHTML=innerHTMLContent;
				if (innerHTMLContent.replace(/^\s+|\s+$/g,"")==""){
					document.getElementById('div_main_qlist').style.display="none";
				}
				else{
					document.getElementById('div_main_qlist').style.display="";
				}
			}
			onAddQLClick(qListId,'videoId','getvid','begin','end');
		}
	}
}

function getVideoId () {
	if(xmlHttp.readyState==4) {
		if(xmlHttp.status==200) {
			var playlist=xmlHttp.responseText.split(",");
			for (var i=0; i < playlist.length; i++){
				if (myact=='clear'){
					 if (document.getElementById('v_id_'+playlist[i])!= null ) document.getElementById('v_id_'+playlist[i]).className="IconImg";
					 if (document.getElementById('div_main_qlist')!= null ){
							document.getElementById('div_main_qlist').style.display="none";
							document.getElementById('div_main_qlist').innerHTML='';
					 }
				}
				else if (document.getElementById('v_id_'+playlist[i])!= null ) document.getElementById('v_id_'+playlist[i]).className="IconImgDone";
			}
		}
	}
}

function hasClass(element,myClassName){
	if(!element){
	return;
	}
	var upperClass=myClassName.toUpperCase();
	if(element.className){
		var classes=element.className.split(' ');
		for(var i=0;i<classes.length;i++){
			if(classes[i].toUpperCase()==upperClass){
				return true;
			}
		}
	}
	return false;
}
function addClass(element,myClass){
	if(!hasClass(element,myClass)){
		element.className+=element.className?(" "+myClass):myClass;
	}
}
function rmClass(element,myClass){
	var upperClass=myClass.toUpperCase();
	var remainClasses=[];
	if(element.className){
		var classes=element.className.split(' ');
		for(var i=0;i<classes.length;i++){
			if(classes[i].toUpperCase()!=upperClass){
				remainClasses[remainClasses.length]=classes[i];
			}
		}
		element.className=remainClasses.join(' ');
	}
}


function mouseOverQuickListAdd(img){
	if(!img.className.match('Done')){
		rmClass(img,'IconImg');
		rmClass(img,'IconImgDone');
		addClass(img,'IconImgOver');
	}
}
function mouseOutQuickListAdd(img){
	if(!img.className.match('Done')){
		rmClass(img,'IconImgOver');
		rmClass(img,'IconImgDone');
		addClass(img,'IconImg');
	}
}

function clickedQuickListAdd(img){
	rmClass(img,'IconImg');
	rmClass(img,'IconImgOver');
	addClass(img,'IconImgDone');
}

function disp_advancedsearch(flag){
	var adshtml;
	var data;
	var COOKIE_NAME = 'cookie_warning';
	if(flag) {
		adshtml = document.getElementById('advanced-search-pop').innerHTML;
		if (adshtml=='' || adshtml=='\n') {
			data = "";
			sendData_ads(data);
		}
		else {
			$('#advanced-search-pop').toggle();
		}
		$('#sex_type_'+$.cookie(COOKIE_NAME)).attr('checked','checked');
	}
	else {
		$('#advanced-search-pop').css('display','none');
	}
}



var FlashObject = function(swf, id, w, h, ver, c) {
	this.swf = swf;
	this.id = id;
	this.width = w;
	this.height = h;
	this.version = ver;
	this.align = "middle";

	this.params = new Object();
	this.variables = new Object();

	this.redirect = "";
	this.sq = document.location.search.split("?")[1] || "";
	this.bypassTxt = "<p>Already have Macromedia Flash Player? <a href='?detectflash=false&"+ this.sq +"'>Click here if you have Flash Player "+ this.version +" installed</a>.</p>";

	if (c) this.color = this.addParam('bgcolor', c);
	this.addParam('quality', 'high'); // default to high
	this.addParam('allowFullScreen', 'true');
	this.doDetect = getQueryParamValue('detectflash');
}




// get value of query string param
function getQueryParamValue(param) {
	var q = document.location.search || document.location.href.split("#")[1];
	if (q) {
		var detectIndex = q.indexOf(param +"=");
		var endIndex = (q.indexOf("&", detectIndex) > -1) ? q.indexOf("&", detectIndex) : q.length;
		if (q.length > 1 && detectIndex > -1) {
			return q.substring(q.indexOf("=", detectIndex)+1, endIndex);
		} else {
			return "";
		}
	}
}

/* add Array.push if needed */
if(Array.prototype.push == null){
	Array.prototype.push = function(item) { this[this.length] = item; return this.length; }
}


/***** End FlashObject embed ****************/



/******************* fvalidate ****************************/

		var whitespace = " \t\n\r";
		var validChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
		var pEntryPrompt = "Please enter the following information: "

		var mPrefix = "You did not enter a valid value into the following field: "
		var mSuffix = "This is a required field. Please enter it now."

		// s is an abbreviation for "string"
		var sEmail = "Email Address"
		var sUsername = "Username"
		var sPassword = "Password"

		// i is an abbreviation for "invalid"
		var iEmail = "The Email Address field must be a valid email address (e.g. foo@somedomain.com). Please re-enter it now."
		var iUserPassword = "Your Username and Password selections cannot be the same. Please choose a different Username or Password."
		var iUsrPw = "Username and Password must be at least 4 characters long. Please re-enter it now."
		var iIncludSpace = "Username, Password and email can not include Space. Please re-enter it now."
		var iConfirmPassword = "Confirm Password is not correct. Please re-enter it now."
		var iInvalidChar = "Username. \n (only [0-9],[a-z],[A-Z],[_],[-] is valid for username!"
		var iCertifyAge = "You have to verify you are over 18 years old.";
		var iAgreeTerm = "You have to agree to the terms of use and privacy policy.";


		// Check whether string s is empty.
		function isEmpty(s) {
			return ((s == null) || (s.length == 0));
		}

		function promptEntry (s){
			window.status = pEntryPrompt + s
		}

	   function warnEmpty (theField, s){
			theField.focus()
			alert(mPrefix + "\n\n\t" + s + "\n\n" + mSuffix)
			return false
		}

		function warnInvalid (theField, s){
			theField.focus()
			theField.select()
			alert(s)
			return false
		}

		function isAllWhitespace (s) {
			var i;
			if (isEmpty(s)) return true;

			for (i = 0; i < s.length; i++){
					var c = s.charAt(i);

					if (c != ' ') return false
			}

			return true;
		}

	   function isValidChar (theField) {
			var s = theField.value;

			for (i = 0; i < s.length; i++){
				var c = s.charAt(i);

			if(validChar.indexOf(c)>=0)
				continue;
			else
				return warnEmpty (theField, iInvalidChar);

			}

			return true;
		}

		function charInString (c, s){
			for (i = 0; i < s.length; i++) {
				if (s.charAt(i) == c) return true;
			}
			return false
		}

		function striplWhitespace (s){
			var i = 0;
			var j = 0;

			while ((i < s.length) && charInString (s.charAt(i), ' '))
				i++;

			s1 = s.substring (i, s.length);

			while ((j < s1.length) && charInString (s1.charAt(s1.length - j - 1), ' '))
				j++;

			s2 = s1.substring (0, s1.length - j);
			return s2;
		}

		function checkString (theField, s){
			if (isAllWhitespace(theField.value))
				return warnEmpty (theField, s);
			else
				return true;
		}

		function isEmail (s) {
			var i = 1;
			var sLength = s.length;

			// look for @
			while ((i < sLength) && (s.charAt(i) != "@"))
				i++

			if ((i >= sLength) || (s.charAt(i) != "@")) return false;
			else i += 2;

			// look for .
			while ((i < sLength) && (s.charAt(i) != "."))
				i++

			// there must be at least one character after the .
			if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
			else return true;
		}

		function checkEmail (theField){
			var str = '';

			str = striplWhitespace(theField.value);
			if(str.indexOf(' ')>=0)
				return warnInvalid (theField, iIncludSpace);

			if (!isEmail(theField.value))
				return warnInvalid (theField, iEmail);
			else return true;
		}

		function validateUsrPw(theField) {
			var s = theField.value;
			var str = '';

			if(!isAllWhitespace(s)){
				str = striplWhitespace(theField.value);
				if(str.indexOf(' ')>=0)
					return warnInvalid (theField, iIncludSpace);
				else if(str.length<4)
					return warnInvalid(theField, iUsrPw);
				else
					return true;
			} else {
				return warnInvalid(theField, iUsrPw);
			}
		}

		function ckeckUsrPw(theField1, theField2) {
			if (theField1.value == theField2.value)
				return warnInvalid(theField2, iUserPassword);
			else
				return true;
		}

		function ckeckAgeTerm(theField1, theField2) {
			if (!theField1.checked)
				return warnInvalid(theField1, iCertifyAge);
			else if(!theField2.checked)
				return warnInvalid(theField2, iAgreeTerm);
			else
				return true;

		}

		function checkConfirmPW(theField1, theField2) {

			if (theField1.value != theField2.value)
				return warnInvalid(theField2, iConfirmPassword);
			else
				return true;
		}

		function validateFormInfo(form) {

			return (
				checkEmail(form.elements["email"]) &&
				checkString(form.elements["user_id"],sUsername) &&
				validateUsrPw(form.elements["user_id"]) &&
				isValidChar(form.elements["user_id"]) &&
				checkString(form.elements["password1"],sPassword) &&
				validateUsrPw(form.elements["password1"]) &&
				ckeckUsrPw(form.elements["user_id"],form.elements["password1"]) &&
				checkConfirmPW(form.elements["password1"],form.elements["password2"]) &&
				ckeckAgeTerm(form.elements["certify_age"], form.elements["agree_to_terms"])

				);

		}

		function validateFormInfo1(form) {

			return (
				checkString(form.elements["user_id"],sUsername) &&
				validateUsrPw(form.elements["user_id"]) &&
				isValidChar(form.elements["user_id"]) &&
				checkString(form.elements["password"],sPassword) &&
				validateUsrPw(form.elements["password"])
			)
		}

		function validateFormInfo2(form) {

			return (
				checkEmail(form.elements["email"])
			)
		}

	   function validateFormInfo3(form) {

			return (
				validateUsrPw(form.elements["uid"]) &&
				isValidChar(form.elements["usid"])

			)
		}

/******************* End fvalidate ****************************/



	function addGroupVideo(form_id) {
		var addGroupVideo_form = document.forms[form_id];
		makeHttpRequest(addGroupVideo_form.name,addGroupVideoResXML);

	}

	function deleteGroupVideo(form_id) {
		var deleteGroupVideo_form = document.forms[form_id];
		makeHttpRequest(deleteGroupVideo_form.name,deleteGroupVideoResXML);

	}

	function approveGroupVideo(form_id) {
		var approveGroupVideo_form = document.forms[form_id];
		makeHttpRequest(approveGroupVideo_form.name,approveGroupVideoResXML);

	}


	function addGroupSet(form_id) {
		var addGroupSet_form = document.forms[form_id];
		makeHttpRequest(form_id,addGroupSetResXML);

	}

	function approveGroupSet(form_id) {
		var approveGroupSet_form = document.forms[form_id];
		makeHttpRequest(approveGroupSet_form,approveGroupSetResXML);

	}

	function deleteGroupSet(form_id) {
		var deleteGroupSet_form = document.forms[form_id];
		makeHttpRequest(deleteGroupSet_form.name,deleteGroupSetResXML);

	}

	function addGroupVideoResXML() {
		if (http_request.readyState == 4 && http_request.status == 200) {
			var res_code = http_request.responseXML.getElementsByTagName('res_code')[0].firstChild.data;
			var form_id  = http_request.responseXML.getElementsByTagName('form_id')[0].firstChild.data;
			var form = document.forms[form_id];
			var this_button = form.add_button;

			if(res_code == 'SUCCESS') {
				this_button.value = "Video Added!";
				this_button.disabled = true;

			} else if(res_code == 'EXIST') {
				this_button.value = "Video exists in this group!";
				this_button.disabled = true;

			} else {
				alert("An error occured while adding video.");
				this_button.disabled = false;
				this_button.value = "Add Video to this group";
			}
		}
	}

	function deleteGroupVideoResXML() {
		if (http_request.readyState == 4 && http_request.status == 200) {
			var res_code = http_request.responseXML.getElementsByTagName('res_code')[0].firstChild.data;
			var form_id  = http_request.responseXML.getElementsByTagName('form_id')[0].firstChild.data;
			var form = document.forms[form_id];
			var this_button = form.delete_button;

			if(res_code == 'SUCCESS') {
				this_button.value = "Video Removed!";
				this_button.disabled = true;

			} else {
				alert("An error occured while removing video.");
				this_button.disabled = false;
				this_button.value = "Remove Video from this group";
			}
		}
	}

	function addGroupSetResXML() {
		if (http_request.readyState == 4 && http_request.status == 200) {
			var res_code = http_request.responseXML.getElementsByTagName('res_code')[0].firstChild.data;
			var form_id  = http_request.responseXML.getElementsByTagName('form_id')[0].firstChild.data;
			var form = document.forms[form_id];
			var this_button = form.add_button;

			if(res_code == 'SUCCESS') {
				this_button.value = "Photo Set Added!";
				this_button.disabled = true;

			} else if(res_code == 'EXIST') {
				this_button.value = "Photo Set exists in this group!";
				this_button.disabled = true;

			} else {
				alert("An error occured while adding Photo Set.");
				this_button.disabled = false;
				this_button.value = "Add Photo Set to this group";
			}
		}
	}

	function deleteGroupSetResXML() {
		if (http_request.readyState == 4 && http_request.status == 200) {
			var res_code = http_request.responseXML.getElementsByTagName('res_code')[0].firstChild.data;
			var form_id  = http_request.responseXML.getElementsByTagName('form_id')[0].firstChild.data;
			var form = document.forms[form_id];
			var this_button = form.delete_button;

			if(res_code == 'SUCCESS') {
				this_button.value = "Photo Set Removed!";
				this_button.disabled = true;

			} else {
				alert("An error occured while removing Photo Set.");
				this_button.disabled = false;
				this_button.value = "Remove Photo Set from this group";
			}
		}
	}

	function approveGroupSetResXML() {
		if (http_request.readyState == 4 && http_request.status == 200) {
			var res_code = http_request.responseXML.getElementsByTagName('res_code')[0].firstChild.data;
			var form_id  = http_request.responseXML.getElementsByTagName('form_id')[0].firstChild.data;
			var form = document.forms[form_id];
			var this_button = form.approve_button;

			if(res_code == 'SUCCESS') {
				this_button.value = "Photo Set Approved!";
				this_button.disabled = true;

			} else {
				alert("An error occured while approving Photo Set.");
				this_button.disabled = false;
				this_button.value = "Approve Photo Set";
			}
		}
	}

	function approveGroupVideoResXML() {
		if (http_request.readyState == 4 && http_request.status == 200) {
			var res_code = http_request.responseXML.getElementsByTagName('res_code')[0].firstChild.data;
			var form_id  = http_request.responseXML.getElementsByTagName('form_id')[0].firstChild.data;
			var form = document.forms[form_id];
			var this_button = form.approve_button;

			if(res_code == 'SUCCESS') {
				this_button.value = "Video Approved!";
				this_button.disabled = true;

			} else {
				alert("An error occured while approving Video.");
				this_button.disabled = false;
				this_button.value = "Approve Video";
			}
		}
	}

	function doGroupMemberRequest(act,group_id) {
		var url="/groups/?g="+group_id+"&act="+act;
		window.location.href=url;
	}

	function doProtectedGroupMemberRequest(act,group_id,request_user_id) {
		var url="/groups/?g="+group_id+"&act="+act+"&r_user_id="+request_user_id;
		window.location.href=url;
	}





	function commentResXML() {

		if (http_request.readyState == 4 && http_request.status == 200) {
			var res_code = http_request.responseXML.getElementsByTagName('res_code')[0].firstChild.data;
			var form_id  = http_request.responseXML.getElementsByTagName('form_id')[0].firstChild.data;
			var form = document.forms[form_id];
			var comment_button = form.add_comment_button;
			var discard_button = form.discard_comment_button;

			if(res_code == 'SUCCESS') {
				comment_button.value = "Thanks for the comment!";
				comment_button.className = "btn-xl2";
				comment_button.disabled = true;
				discard_button.disabled = true;
				discard_button.style.display  = "none";
			} else {
				alert("An error occured while posting the comment.");
				comment_button.disabled = false;
				comment_button.value = "Post Comment";
			}
		}
	}

	function ratingResXML() {
		if (http_request.readyState == 4 && http_request.status == 200) {
			var res_code = http_request.responseXML.getElementsByTagName('res_code')[0].firstChild.data;
			var res_msg = http_request.responseXML.getElementsByTagName('res_msg')[0].firstChild.data;
			var rating = http_request.responseXML.getElementsByTagName('rating')[0].firstChild.data;

			if(res_code == 'SUCCESS') {

				document.getElementById('rate_id').style.display='none';
				document.getElementById('mark_id').style.width=rating*100/5+'%';
				alert(res_msg);

			} else {

				alert(res_msg);
				ratingComponent.starCount = 0;
				ratingComponent.resetStars();
			}
		}
	}

	function userBlockResXML() {
		if (http_request.readyState == 4 && http_request.status == 200) {
			var res_code = http_request.responseXML.getElementsByTagName('res_code')[0].firstChild.data;
			var res_msg = http_request.responseXML.getElementsByTagName('res_msg')[0].firstChild.data;

			if(res_code == 'SUCCESS') {
				document.getElementById('div_userBlock').style.display='none';
				document.getElementById('div_userBlockResult').innerHTML = res_msg;
				document.getElementById('div_userBlockResult').style.display='block';
			} else {
				alert("An error occured while blocking user, please try again !");
			}
		}
	}

	function userUnblockResXML() {
		if (http_request.readyState == 4 && http_request.status == 200) {
			var res_code = http_request.responseXML.getElementsByTagName('res_code')[0].firstChild.data;
			var res_msg = http_request.responseXML.getElementsByTagName('res_msg')[0].firstChild.data;

			if(res_code == 'SUCCESS') {
				document.getElementById('div_userUnblock').style.display='none';
				document.getElementById('div_userUnblockResult').innerHTML = res_msg;
				document.getElementById('div_userUnblockResult').style.display='block';
			} else {
				alert("An error occured while unblocking user, please try again !");
			}
		}
	}


	function addFriendResXML() {
		if (http_request.readyState == 4 && http_request.status == 200) {
			var res_code = http_request.responseXML.getElementsByTagName('res_code')[0].firstChild.data;
			var res_msg = http_request.responseXML.getElementsByTagName('res_msg')[0].firstChild.data;

			if(res_code == 'SUCCESS') {
				document.getElementById('div_addFriend').style.display='none';
				document.getElementById('div_addFriendResult').innerHTML = res_msg;
				document.getElementById('div_addFriendResult').style.display='block';
			} else {
				alert("An error occured while adding friend, please try again !");
			}
		}
	}

	function addFriendResXML_dating() {
		if (http_request.readyState == 4 && http_request.status == 200) {
			var res_code = http_request.responseXML.getElementsByTagName('res_code')[0].firstChild.data;
			var res_msg = http_request.responseXML.getElementsByTagName('res_msg')[0].firstChild.data;
			var uid = http_request.responseXML.getElementsByTagName('uid')[0].firstChild.data;

			if(res_code == 'SUCCESS') {
/*				document.getElementById('div_addFriend').style.display='none';
				document.getElementById('div_addFriendResult').innerHTML = res_msg;
				document.getElementById('div_addFriendResult').style.display='block';
*/
				alert("Add Friend Request has been sent to "+uid+" !");
			} else {
				alert("An error occured while adding friend, please try again !");
			}
			document.location.href= document.location.href;
		}
	}

	function addVideo2FavoriteResXML() {
		if (http_request.readyState == 4 && http_request.status == 200) {
			var res_code = http_request.responseXML.getElementsByTagName('res_code')[0].firstChild.data;
			var res_msg = http_request.responseXML.getElementsByTagName('res_msg')[0].firstChild.data;

			if(res_code == 'SUCCESS') {
				alert(res_msg);
				document.getElementById('div_addVideo2Fav').style.display='none';
				document.getElementById('div_addVideo2FavResult').innerHTML = res_msg;
				document.getElementById('div_addVideo2FavResult').style.display='block';
			} else {
				alert("An error occured while adding video to favorite, please try again !");
			}
		}
	}

	function addSet2FavoriteResXML() {
		if (http_request.readyState == 4 && http_request.status == 200) {
			var res_code = http_request.responseXML.getElementsByTagName('res_code')[0].firstChild.data;
			var res_msg = http_request.responseXML.getElementsByTagName('res_msg')[0].firstChild.data;

			if(res_code == 'SUCCESS') {
				document.getElementById('div_addSet2Fav').style.display='none';
				document.getElementById('div_addSet2FavResult').innerHTML = res_msg;
				document.getElementById('div_addSet2FavResult').style.display='block';
			} else {
				alert("An error occured while adding Set to favorite, please try again !");
			}
		}
	}

	function addGallery2FavoriteResXML() {
		if (http_request.readyState == 4 && http_request.status == 200) {
			var res_code = http_request.responseXML.getElementsByTagName('res_code')[0].firstChild.data;
			var res_msg = http_request.responseXML.getElementsByTagName('res_msg')[0].firstChild.data;

			if(res_code == 'SUCCESS') {
				document.getElementById('div_addGallery2Fav').style.display='none';
				document.getElementById('div_addGallery2FavResult').innerHTML = res_msg;
				document.getElementById('div_addGallery2FavResult').style.display='block';
			} else {
				alert("An error occured while adding Gallery to favorite, please try again !");
			}
		}
	}

	function addAmateur2FavoriteResXML() {
		if (http_request.readyState == 4 && http_request.status == 200) {
			var res_code = http_request.responseXML.getElementsByTagName('res_code')[0].firstChild.data;
			var res_msg = http_request.responseXML.getElementsByTagName('res_msg')[0].firstChild.data;

			if(res_code == 'SUCCESS') {
				document.getElementById('div_addAmateur2Fav').style.display='none';
				document.getElementById('div_addAmateur2FavResult').innerHTML = res_msg;
				document.getElementById('div_addAmateur2FavResult').style.display='block';
			} else {
				alert("An error occured while adding Amateur to favorite, please try again !");
			}
		}
	}





var XT_RATING_IMG = '/img/interface/icons/icn-rate-on.gif';
var XT_RATING_IMG_HALF = '/img/interface/icons/icn-rate-half.gif';
var XT_RATING_IMG_BG = '/img/interface/icons/icn-rate-off.gif';
messages = new Array("Rate This!", "Poor", "Nothing special", "Worth watching", "Pretty cool", "Awesome!");

function XTRating(ratingElementId, maxStars, objectName, formName) {
	this.ratingElementId = ratingElementId;
	this.maxStars = maxStars;
	this.objectName = objectName;
	this.formName = formName;

	this.starTimer = null;
	this.starCount = 0;

	function showRatingResult(starNum, message) {
		document.getElementById(this.ratingElementId).style.display='none';

		for (var i=1; i <= starNum; i++)
			document.getElementById('result_star_' + i).src = XT_RATING_IMG;

		document.getElementById('ratingResultMessage').innerHTML = message;

		document.getElementById('ratingResultDiv').style.display='block';

	}

	function showStars(starNum) {
		this.clearStarTimer();
		for (var i=1; i < this.maxStars + 1; i++)
			document.getElementById('star_' + i).src = XT_RATING_IMG_BG;

		for (var i=1; i <= starNum; i++)
			document.getElementById('star_' + i).src = XT_RATING_IMG;

		document.getElementById('ratingMessage').innerHTML = messages[starNum];
	}

	function setStars(starNum) {
		this.starCount = starNum;
		this.clearStarTimer();
		this.showStars(starNum);
		document.forms[this.formName]['rating'].value = this.starCount;
		var ratingElementId = this.ratingElementId;
		makeHttpRequest(this.formName, ratingResXML);
	}

	function clearStars() {
		this.starTimer = setTimeout(this.objectName + ".resetStars()", 100);
	}

	function resetStars() {
		this.clearStarTimer();
		if (this.starCount) {
			this.clearStarTimer();
			this.showStars(this.starCount);
		} else {
			for (var i=1; i < this.maxStars + 1; i++)
				document.getElementById('star_' + i).src = XT_RATING_IMG_BG;

		}

		document.getElementById('ratingMessage').innerHTML = messages[0];
	}

	function clearStarTimer() {
		if (this.starTimer) {
			clearTimeout(this.starTimer);
			this.starTimer = null;
		}
	}

	this.showRatingResult = showRatingResult;
	this.clearStars = clearStars;
	this.clearStarTimer = clearStarTimer;
	this.resetStars = resetStars;
	this.setStars = setStars;
	this.showStars = showStars;

}




function toggleVisibility(whichForm, setVisible)
{
	var newstate="none"
	if(setVisible == true)
		newstate = ""

	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichForm).style;
		style2.display = newstate;
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichForm].style;
		style2.display = newstate;
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichForm].style;
		style2.display = newstate;
	}
}


function setInnerHTML(div_id, value)
{
	var dstDiv = document.getElementById(div_id);
	dstDiv.innerHTML = value;
}

function redirectURL(goURL) {
	document.location.href=goURL;
}



	function addFriend(form_id) {
		if (confirm("Are you sure you want to add this user as your friend?")) {
			var addFriend_form = document.forms[form_id];
			makeHttpRequest(addFriend_form.name,addFriendResXML);
		}
	}

	function addFriend_dating(form_id) {
		if (confirm("Are you sure you want to add this user as your friend?")) {
			var addFriend_form = document.forms[form_id];
			makeHttpRequest(addFriend_form.name,addFriendResXML_dating);
		}
	}
	function ajax_addFriend_dating(form_id,user_id) {
		if (confirm("Are you sure you want to add this user as your friend?")) {
			var addFriend_form = document.forms[form_id];
			document.forms[form_id].user_id.value = user_id;
			makeHttpRequest(addFriend_form.name,addFriendResXML_dating);
		}
	}


	function blockUser(form_id) {
		if (confirm("Are you sure you want to block this user?")) {
			var block_form = document.forms[form_id];
			makeHttpRequest(block_form.name,userBlockResXML);
		}
	}

	function unblockUser(form_id) {
		if (confirm("Are you sure you want to unblock this user?")) {
			var unblock_form = document.forms[form_id];
			makeHttpRequest(unblock_form.name,userUnblockResXML);
		}
	}

	function addVideo2Favorite(form_id) {
		if (confirm("Are you sure you want to add this video to your favorites?")) {
			var fav_form = document.forms[form_id];
			makeHttpRequest(fav_form.name,addVideo2FavoriteResXML);
		}
	}

	function addSet2Favorite(form_id) {
		if (confirm("Are you sure you want to add this photo set to your favorites?")) {
			var fav_form = document.forms[form_id];
			makeHttpRequest(fav_form.name,addSet2FavoriteResXML);
		}
	}

	function addGallery2Favorite(form_id) {
		if (confirm("Are you sure you want to add this Gallery to your favorites?")) {
			var fav_form = document.forms[form_id];
			makeHttpRequest(fav_form.name,addGallery2FavoriteResXML);
		}
	}

	function addAmateur2Favorite(form_id) {
		if (confirm("Are you sure you want to add this Amateur to your favorites?")) {
			var fav_form = document.forms[form_id];
			makeHttpRequest(fav_form.name,addAmateur2FavoriteResXML);
		}
	}

	function go(URL) {
		document.location.href=URL;
	}


	function submit_search() {
		var search_text = document.search_form_top.search.value;

		if (search_text.length<2)
			alert('Please enter keywords into the search box.');
		else
			location.href='http://www.xtube.com/video_search.php?search='+search_text;
	}

	function get_value(rval) {
		for(i=0;i<rval.length;i++)
		{
			if (rval[i].checked == true)
				return rval[i].value;
		}
	}

	function get_value_rating(rval) {
		var rtnval=0;

		if (rval=='20%')
			rtnval=1;
		else if (rval=='40%')
			rtnval=2;
		else if (rval=='60%')
			rtnval=3;
		else if (rval=='80%')
			rtnval=4;
		else if (rval=='100%')
			rtnval=5;

		return rtnval;
	}

	function submit_rating(rate_num) {
	var acton=document.getElementById('rate_mark');
	var widthval="0%";

	if (rate_num==1)
		widthval="20%";
	else if (rate_num==2)
		widthval="40%";
	else if (rate_num==3)
		widthval="60%";
	else if (rate_num==4)
		widthval="80%";
		else if (rate_num==5)
		widthval="100%";

	if (acton.style.width==widthval)
		acton.style.width="0%";
	else
		acton.style.width=widthval;
	}

	var advanced_search_selected='video';

	function showCatInfo(srh_cat_type) {

		var act_vs=document.getElementById('cat_video_set');
		var act_pw=document.getElementById('cat_pw');

		var act_dvd=document.getElementById('cat_dvd');
		var act_dvdpass=document.getElementById('cat_dvdpass');
		var act_amateur=document.getElementById('cat_amateur');

		var act_ads_bt=document.getElementById('advanced_search_bt_div');
		var act_close_bt=document.getElementById('close_ads_bt');

		var act_ads_lable_video=document.getElementById('ads_lable_video');
		var act_ads_lable_set=document.getElementById('ads_lable_set');
		var act_ads_lable_people=document.getElementById('ads_lable_people');
		var act_ads_lable_webcam=document.getElementById('ads_lable_webcam');
		var act_ads_lable_amateur=document.getElementById('ads_lable_amateur');
		var act_ads_lable_dvd=document.getElementById('ads_lable_dvd');
		var act_ads_lable_dvdpass=document.getElementById('ads_lable_dvdpass');
       var advancedSearchPop=document.getElementById('advanced-search-pop');

	advanced_search_selected = srh_cat_type;

	act_ads_lable_video.style.color='#7f7f7f';
	act_ads_lable_set.style.color='#7f7f7f';
	act_ads_lable_people.style.color='#7f7f7f';
	act_ads_lable_webcam.style.color='#7f7f7f';
	act_ads_lable_amateur.style.color='#7f7f7f';
	act_ads_lable_dvd.style.color='#7f7f7f';
	act_ads_lable_dvdpass.style.color='#7f7f7f';

	if (srh_cat_type=='video'){
		act_ads_lable_video.style.color='#2a2a2a';
		advancedSearchPop.style.height=("204px");
	}else if (srh_cat_type=='set'){
		act_ads_lable_set.style.color='#2a2a2a';
		advancedSearchPop.style.height=("204px");
	}else if (srh_cat_type=='people') {
		act_ads_lable_people.style.color='#2a2a2a';
		advancedSearchPop.style.height=("204px");
	}else if (srh_cat_type=='webcam') {
		act_ads_lable_webcam.style.color='#2a2a2a';
		advancedSearchPop.style.height=("204px");
	}else if (srh_cat_type=='amateur') {
		act_ads_lable_amateur.style.color='#2a2a2a';
		advancedSearchPop.style.height=("345px");
	}else if (srh_cat_type=='dvd') {
		act_ads_lable_dvd.style.color='#2a2a2a';
		advancedSearchPop.style.height=("345px");
	} else if (srh_cat_type=='dvdpass') {
		act_ads_lable_dvdpass.style.color='#2a2a2a';
		advancedSearchPop.style.height=("345px");
	}
		act_dvd.style.display='none';
		act_dvdpass.style.display='none';
		act_amateur.style.display='none';

		if ((srh_cat_type=='dvd')||(srh_cat_type=='dvdpass')||(srh_cat_type=='amateur')) {

			$('#advanced-search-pop').attr('className','advanced-search_bg_l');

		act_vs.style.display='none';
		act_pw.style.display='none';

			if (srh_cat_type=='dvd') {
			act_dvd.style.display='';
			} else if (srh_cat_type=='dvdpass') {
			act_dvdpass.style.display='';
			} else if (srh_cat_type=='amateur') {
			act_amateur.style.display='';
			}

			act_ads_bt.style.display='none';

			act_close_bt.style.left='-40px';

			act_close_bt.style.bottom='-142px';

		return;
		} else if (srh_cat_type=='people') {

		act_vs.style.display='none';
		act_pw.style.display='';

		var acton=document.getElementById('cat_p_srh');
	  var actoff1=document.getElementById('cat_w_srh');

			var actoff12=document.getElementById('cat_w_srh_2');
			var actoff13=document.getElementById('cat_w_srh_3');
			actoff12.style.display='none';
			actoff13.style.display='none';

		acton.style.display='';
	} else if (srh_cat_type=='webcam') {

		act_vs.style.display='none';
		act_pw.style.display='';

		var acton=document.getElementById('cat_w_srh');
	  var actoff1=document.getElementById('cat_p_srh');

			var actoff12=document.getElementById('cat_w_srh_2');
			var actoff13=document.getElementById('cat_w_srh_3');
			actoff12.style.display='';
			actoff13.style.display='';

	  acton.style.display='';
	} else {

			var acton=document.getElementById('cat_v_srh');
			if (srh_cat_type=='set')
				acton.style.display='none';
			else
				acton.style.display='';

		var acton=document.getElementById('cat_w_srh');
	  var actoff1=document.getElementById('cat_p_srh');
	  acton.style.display='none';

		act_vs.style.display='';
		act_pw.style.display='none';
	}

		actoff1.style.display='none';

		$('#advanced-search-pop').attr('className','advanced-search_bg_s');

		act_close_bt.style.bottom='0px';
		act_ads_bt.style.display='';

	}

	function ads_submit_chk(e)
	{
		var keynum;

		if(window.event) {
		  keynum = e.keyCode;
		}
		else if(e.which) {
		keynum = e.which;
		}

		if (keynum=='13')
			submit_acvanced_search();

	}

	function submit_acvanced_search() {

		var srh_type = advanced_search_selected;
		var keywords_vs = document.advanced_search_form.keywords_vs.value;
		var rating_vs = get_value_rating(document.getElementById('rate_mark').style.width);
		var duration = document.advanced_search_form.duration.value;
		var uploaded = document.advanced_search_form.uploaded.value;
		var sex_type_vs = get_value(document.advanced_search_form.sex_type_vs);

		var keywords_pw = document.advanced_search_form.keywords_pw.value;
		var category_p = document.advanced_search_form.category_p.value;
		var category_w = document.advanced_search_form.category_w.value;
		var gender_pw = document.advanced_search_form.gender_pw.value;
		var status_pw = get_value(document.advanced_search_form.status_pw);
		var age_pw_s = document.advanced_search_form.age_pw_s.value;
		var age_pw_e = document.advanced_search_form.age_pw_e.value;
		var location_pw = document.advanced_search_form.location_pw.value;

		var urlval = "type="+srh_type+"&keywords_vs="+keywords_vs+"&rating_vs="+rating_vs+"&duration="+duration+"&uploaded="+uploaded+"&sex_type_vs="+sex_type_vs;
		urlval += "&keywords_pw="+keywords_pw+"&category_p="+category_p+"&category_w="+category_w+"&gender_pw="+gender_pw+"&status_pw="+status_pw+"&age_pw_s="+age_pw_s+"&age_pw_e="+age_pw_e+"&location_pw="+location_pw;

		if (((keywords_vs.length<2)&&((srh_type=='video') || (srh_type=='set')))||((keywords_pw.length<2)&&((srh_type=='people') || (srh_type=='webcam'))))
			alert('Please enter keywords into the advanced search box.');
		else
			location.href='http://www.xtube.com/results_as.php?'+urlval;
	}

	var SubmitMark_dvdpass = 0;

	function CheckSelectedOptions_dvdpass()
	{
			var msgstr="";
			var rtnstr;

			if(SubmitMark_dvdpass==1) {
						msgstr = "Please wait ...\n";
			}
			else {
				rtnstr = checklistbox_dvdpass('p_studio_id');
				if (rtnstr != "")
					msgstr += rtnstr;

				rtnstr = checklistbox_dvdpass('p_director_id');
				if (rtnstr != "")
					msgstr += rtnstr;

				rtnstr = checklistbox_dvdpass('p_selectedchannel_id');
				if (rtnstr != "")
					msgstr += rtnstr;

			}
			if(msgstr!="") {
					alert(msgstr);
					return false;
			} else {
					if(SubmitMark_dvdpass==0) {
						SubmitMark_dvdpass = 1;
						return true;
					}
			}
	}

	function checklistbox_dvdpass(lstid) {
			var numsel;
			var rtndata;
			var current;
			var chkListBox;
			var i;


			chkListBox = document.getElementById(lstid);

			numsel = 0;
			rtndata = "";
			for (i=0;i<chkListBox.options.length;i++)
			{
				current = chkListBox.options[i];
				if (current.value == "-1")
					continue;

				if (current.selected){
					numsel ++;
				}
			}
			if(numsel > 5) {
				if (lstid == 'p_studio_id')
					rtndata='You have selected '+numsel.toString()+' options in Studios.'+' You can not select more than 5 options!\n';
				else if (lstid == 'p_director_id')
					rtndata='You have selected '+numsel.toString()+' options in Directors.'+' You can not select more than 5 options!\n';
				else if (lstid == 'p_selectedchannel_id')
					rtndata='You have selected '+numsel.toString()+' options in Select Channels.'+' You can not select more than 5 options!\n';

			}

			return rtndata;
	}

	function AddRemoveChannels_dvdpass(from,to)
	{
			var current;
			var selmark;
			var allselemark;

			fromListBox = document.getElementById(from);
			toListBox = document.getElementById(to);

			current = fromListBox.options[0];

			selmark = false;
			allselemark=false;

			for (i=0;i<fromListBox.options.length;i++)
			{
				current = fromListBox.options[i];
				if ((current.selected) || (allselemark)){
					if (current.value == '-1') {
						if (i==0) {
							allselemark=true;
							continue;
						}
					}

					selmark = true;
				  toListBox.options[toListBox.length] = new Option(current.text,current.value);
				  fromListBox.options[i] = null;
				  i--;
				}
			}
			if (!selmark)
				alert ('You should select one or more options!');
	}

	function NarrowDirectors_dvdpass()
	{
			var current;
			var numsel;
			var data;

			fromListBox = document.getElementById('p_studio_id');

			numsel = 0;
			data = "";
			for (i=0;i<fromListBox.options.length;i++)
			{
				current = fromListBox.options[i];
				if (current.value == "-1")
					continue;

				if (current.selected){
					numsel ++;

					if (data=="")
						data = 'studio_id' + "='" + escape(current.value)+"'";
					else
						data = data + ",'" + escape(current.value)+"'";

				}
			}

			if (numsel == 0)
				alert ('You have not selectd one or more options!');
			else if(numsel > 5)
				alert ('You have selected '+numsel.toString()+' options.'+' Please select 1 to 5 options!');
			else {
				sendData_dvdpass(data,'p_director_id');
			}
	}

	function getHTTPObject_dvdpass() {
		var xhr = false;
		if (window.XMLHttpRequest) {
			xhr = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
		try {
		xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
		try {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e) {
			xhr = false;
		}
		}
	}
	return xhr;
	}

	function sendData_dvdpass(data,selid) {
	var request = getHTTPObject_dvdpass();
	if (request) {
		request.onreadystatechange = function() {
		  parseResponse_dvdpass(request,selid);
		};
		request.open( "POST", "/paid_channels/advancedsearch_1.php", true );
		request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		request.send(data);
		return true;
	} else {
		return false;
	}
	}

	function parseResponse_dvdpass(request,selid)
	{
		var toListBox;
		var tmpstr = new Array();
		var i;

	if (request.readyState == 4) {
		if (request.status == 200 || request.status == 304) {

			tmpstr = request.responseText.split(',');

			toListBox = document.getElementById(selid);

			for (i=1;i<toListBox.options.length;i++)
				{
				  toListBox.options[i] = null;
				  i--;
				}

			for (i=0;i<tmpstr.length;i++) {
					toListBox.options[toListBox.length] = new Option(tmpstr[i],tmpstr[i]);
				}
		}
	}
	}


	var SubmitMark_amateur = 0;

	function CheckSelectedOptions_amateur()
	{
			var msgstr="";
			var rtnstr;

			if(SubmitMark_amateur==1) {
						msgstr = "Please wait ...\n";
			}
			else {
				rtnstr = checklistbox_amateur('a_selectedamateur_id');
				if (rtnstr != "")
					msgstr += rtnstr;

				rtnstr = checklistbox_amateur('a_selectedchannel_id');
				if (rtnstr != "")
					msgstr += rtnstr;

			}
			if(msgstr!="") {
					alert(msgstr);
					return false;
			} else {
					if(SubmitMark_amateur==0) {
						SubmitMark_amateur = 1;
						return true;
					}
			}
	}

	function checklistbox_amateur(lstid)
	{
			var numsel;
			var rtndata;
			var current;
			var chkListBox;
			var i;

			chkListBox = document.getElementById(lstid);

			numsel = 0;
			rtndata = "";
			for (i=0;i<chkListBox.options.length;i++)
			{
				current = chkListBox.options[i];
				if (current.value == "-1")
					continue;

				if (current.selected){
					numsel ++;
				}
			}
			if(numsel > 5) {
				if (lstid == 'a_selectedamateur_id')
					rtndata='You have selected '+numsel.toString()+' options in Select Amateurs.'+' You can not select more than 5 options!\n';
				else if (lstid == 'a_selectedchannel_id')
					rtndata='You have selected '+numsel.toString()+' options in Select Channels.'+' You can not select more than 5 options!\n';

			}

			return rtndata;
	}

	function AddRemoveAmateursChannels(from,to)
	{
			var current;
			var selmark;
			var allselemark;

			fromListBox = document.getElementById(from);
			toListBox = document.getElementById(to);

			current = fromListBox.options[0];

			selmark = false;
			allselemark=false;

			for (i=0;i<fromListBox.options.length;i++)
			{
				current = fromListBox.options[i];
				if ((current.selected) || (allselemark)){
					if (current.value == '-1') {
						if (i==0) {
							allselemark=true;
							continue;
						}
					}

					selmark = true;
				  toListBox.options[toListBox.length] = new Option(current.text,current.value);
				  fromListBox.options[i] = null;
				  i--;
				}
			}
			if (!selmark)
				alert ('You should select one or more options!');
	}


	var SubmitMark_dvd = 0;

	function CheckSelectedOptions_dvd()
	{
			var msgstr="";
			var rtnstr;

			if(SubmitMark_dvd==1) {
						msgstr = "Please wait ...\n";
			}
			else {
				rtnstr = checklistbox_dvd('d_studio_id');
				if (rtnstr != "")
					msgstr += rtnstr;

				rtnstr = checklistbox_dvd('d_director_id');
				if (rtnstr != "")
					msgstr += rtnstr;

				rtnstr = checklistbox_dvd('d_selectedchannel_id');
				if (rtnstr != "")
					msgstr += rtnstr;

			}
			if(msgstr!="") {
					alert(msgstr);
					return false;
			} else {
					if(SubmitMark_dvd==0) {
						SubmitMark_dvd = 1;
						return true;
					}
			}
	}

	function checklistbox_dvd(lstid)
	{
			var numsel;
			var rtndata;
			var current;
			var chkListBox;
			var i;


			chkListBox = document.getElementById(lstid);

			numsel = 0;
			rtndata = "";
			for (i=0;i<chkListBox.options.length;i++)
			{
				current = chkListBox.options[i];
				if (current.value == "-1")
					continue;

				if (current.selected){
					numsel ++;
				}
			}
			if(numsel > 5) {
				if (lstid == 'd_studio_id')
					rtndata='You have selected '+numsel.toString()+' options in Studios.'+' You can not select more than 5 options!\n';
				else if (lstid == 'd_director_id')
					rtndata='You have selected '+numsel.toString()+' options in Directors.'+' You can not select more than 5 options!\n';
				else if (lstid == 'd_selectedchannel_id')
					rtndata='You have selected '+numsel.toString()+' options in Select Channels.'+' You can not select more than 5 options!\n';

			}

			return rtndata;
	}

	function AddRemoveChannels_dvd(from,to)
	{
			var current;
			var selmark;
			var allselemark;

			fromListBox = document.getElementById(from);
			toListBox = document.getElementById(to);

			current = fromListBox.options[0];

			selmark = false;
			allselemark=false;

			for (i=0;i<fromListBox.options.length;i++)
			{
				current = fromListBox.options[i];
				if ((current.selected) || (allselemark)){
					if (current.value == '-1') {
						if (i==0) {
							allselemark=true;
							continue;
						}
					}

					selmark = true;
				  toListBox.options[toListBox.length] = new Option(current.text,current.value);
				  fromListBox.options[i] = null;
				  i--;
				}
			}
			if (!selmark)
				alert ('You should select one or more options!');
	}

	function NarrowDirectors_dvd()
	{
			var current;
			var numsel;
			var data;

			fromListBox = document.getElementById('d_studio_id');

			numsel = 0;
			data = "";
			for (i=0;i<fromListBox.options.length;i++)
			{
				current = fromListBox.options[i];
				if (current.value == "-1")
					continue;

				if (current.selected){
					numsel ++;

					if (data=="")
						data = 'studio_id' + "='" + escape(current.value)+"'";
					else
						data = data + ",'" + escape(current.value)+"'";

				}
			}

			if (numsel == 0)
				alert ('You have not selectd one or more options!');
			else if(numsel > 5)
				alert ('You have selected '+numsel.toString()+' options.'+' Please select 1 to 5 options!');
			else {
				sendData_dvd(data,'d_director_id');
			}
	}

	function getHTTPObject_dvd()
	{
		var xhr = false;
		if (window.XMLHttpRequest) {
			xhr = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
		try {
		xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
		try {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e) {
			xhr = false;
		}
		}
	}
	return xhr;
	}

	function sendData_dvd(data,selid)
	{
	var request = getHTTPObject_dvd();
	if (request) {
		request.onreadystatechange = function() {
		  parseResponse_dvd(request,selid);
		};
		request.open( "POST", "/paid_channels/advancedsearch_1.php", true );
		request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		request.send(data);
		return true;
	} else {
		return false;
	}
	}

	function parseResponse_dvd(request,selid)
	{
		var toListBox;
		var tmpstr = new Array();
		var i;

	if (request.readyState == 4) {
		if (request.status == 200 || request.status == 304) {

			tmpstr = request.responseText.split(',');

			toListBox = document.getElementById(selid);

			for (i=1;i<toListBox.options.length;i++)
				{
				  toListBox.options[i] = null;
				  i--;
				}

			for (i=0;i<tmpstr.length;i++) {
					toListBox.options[toListBox.length] = new Option(tmpstr[i],tmpstr[i]);
				}
		}
	}
	}

	function checkLogin() {
		return true;
	}

