$(function(){
	var actBodyOpen = false;
	$('body').addClass('body');
	function zindex10(zindex){		
		$(zindex).addClass('zindex');		
		if(!$(zindex).parent().hasClass('body')){
			zindex = $(zindex).parent()
			zindex10(zindex)
		}
	}
	
	$("body").click(function(){			
		if(actBodyOpen){
			actBodyOpen.children('ul').css('display','none');
			actBodyOpen.removeClass('OpenSelect');
			
		};
	});
	$(".select_form ul li").click(function(){
		$(this).parent().prev().html('<span>'+$(this).text()+'</span>')
		$(this).parent().prev().css('color','#575757')
		if (window.location.href.indexOf('/video.php')>-1) {
			Set_Cookie( 'vidsort', $(this).text(), 1 )
			window.location.reload(true)
		}
	}).mouseover(function(){
		$(this).css({'backgroundColor':'#316ac5', 'color':'#ffffff'})
	}).mouseout(function(){
		$(this).css({'backgroundColor':'#ffffff', 'color':'#575757'})		
	});
	
	$(".select_form").click(function(){
		if($(this).hasClass('select_form_top')){
			$(this).children('ul').css({'top':'auto', 'bottom':'17px'})
		};
		$(this).children('ul').css('width',$(this).innerWidth());
		$(this).children('div').css('width',$(this).children('div').innerWidth());
		if(!$(this).hasClass('OpenSelect')){			
			$('.zindex').removeClass('zindex');
			actBodyOpen = $('.OpenSelect');
			$(this).addClass('OpenSelect');
			$(this).css('backgroundPosition','100% 1px');
			zindex10(this);
			$(this).children('ul').css('display','block');
			$(this).addClass('lastopen');			
		}else{
			$(this).removeClass('OpenSelect');
			$(this).children('ul').css('display','none');			
		};		
	}).mouseover(function(){
		if(!$(this).hasClass('OpenSelect')){
			$(this).css('backgroundPosition','100% -16px')
		};
	}).mouseout(function(){
		if(!$(this).hasClass('OpenSelect')){
			$(this).css('backgroundPosition','100% 1px')			
		};
		actBodyOpen = $(this);
	});
	
	$(".F_checkbox").click(function(){
		if($(this).children().children('span').hasClass('act')){
			$(this).children().children('span').removeClass('act');
		}else{
			$(this).children().children('span').addClass('act');
		}
	});
	
	$(".F_radio").click(function(){		
		$(this).parent().find(".F_radio_pl span").removeClass('act');
		$(this).find(".F_radio_pl span").addClass('act');
		if (document.location.href.indexOf('signup.php')>-1)  filcat();
	});
	
});

function Set_Cookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
		";expires=" + expires_date.toGMTString() + 
		";path=/;domain=.primecams.com";
}

function bodyopacity() {
	//c=document.getElementById("container");
	//c.style.opacity=0.4;
	//c.style.filter="alpha(opacity=40)";
	$(document.getElementById("container")).fadeTo("slow", 0.4);
}
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };

function pclogform() {
	f=document.getElementById("pcloginform");
	if (f.pclogun.value.length<6 || f.pclogun.value=='Username') {
		alert('UserName must have 6 characters at least.');	return;
	}
	if (f.pclogpas.value.length<6 || f.pclogpas.value=='Username') {
		alert('Password must have 6 characters at least.');	return;
	}
	f.submit();
}

function headapply() {
	if (document.getElementById("headim").className=="act") {
		Set_Cookie("pciam",1,30);
	} else {
		Set_Cookie("pciam",0,30);
	}
	var pm=0;
	if (document.getElementById("headpm").className=="act") {
		pm=2;
		Set_Cookie("pcpref",2,30);
	}
	if (document.getElementById("headpf").className=="act") {
		Set_Cookie("pcpref",1+pm,30);
	}
	if (document.getElementById("headpm").className=="" && document.getElementById("headpf").className=="")
	{
		Set_Cookie("pcpref",1,30);
	}
	//document.location.reload(true);
	document.location.href='http://www.primecams.com/';
}

function forgotjs() {
	alert(this);
	return false;
}
