// png fix
$(document).ready(function()
{

//----------------------------------------------------

	$('#png-fix').pngFix();
	//$('img').pngFix();
	
//----------------------------------------------------
// menu bar	

    $("#menu li a").wrapInner( '<span class="out"></span>' ).append( '<span class="bg"></span>' ).pngFix();
	$("#menu li a").each(function() {
		$( '<span class="over">' +  $(this).text() + '</span>' ).appendTo( this );
	});

	$("#menu li a").hover(function() {
		
		$(".out",	this).stop().animate({'top':	'45px'},	250); // move down - hide
		$(".over",	this).stop().animate({'top':	'0px'},		250); // move down - show
		$(".bg",	this).stop().animate({'top':	'0px'},		120); // move down - show

	}, function() {
	
		$(".out",	this).stop().animate({'top':	'0px'},		250); // move up - show
		$(".over",	this).stop().animate({'top':	'-45px'},	250); // move up - hide
		$(".bg",	this).stop().animate({'top':	'-45px'},	120); // move up - hide
	});	

//----------------------------------------------------
// tabs	


	$(".tab_content").hide(); 
	$("ul.tabs li:first").addClass("active").show(); 
	$(".tab_content:first").show(); 
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active");
		$(this).addClass("active"); 
		$(".tab_content").hide();
		var activeTab = $(this).attr("id");
		$(activeTab).fadeIn("slow");
	});

});

//----------------------------------------------------

function ShowMessage(nID)
{
    $.fancybox({
        'href'              : 'show_message.asp?id='+nID,
		'titlePosition'		: 'inside',
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'modal'             : 'true'
		
	});
}

//----------------------------------------------------

function ModalDialog(_target)
{

$.fancybox({
	            'href'              : _target,
				'titlePosition'		: 'inside',
				'transitionIn'		: 'fade',
				'transitionOut'		: 'fade',
				'modal'             : 'true'
				
			});
}

//----------------------------------------------------

function ShowScreenShot(_target)
{
$.fancybox({
	            'href' : _target,
				'titlePosition'		: 'inside',
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'type'              : 'image'
				
			});
}

//----------------------------------------------------
function LoadContent(_target)
{

$('.ajx-content-container').fadeOut("slow",function()
   {
		$(this).html('<center><div class="loading-center"></div></center><br />').fadeIn('slow');
		$.ajax({
				type:	'GET',
				url:	_target,
				data:	"",
				dataType:	'html',
				timeout:	5000,
				success:function(d,s){
				$('.ajx-content-container').fadeOut('slow',function(){
				$('.ajx-content-container').html(d).fadeIn('slow');
				});
				}
			});		
			
	});
			
}

//----------------------------------------------------

function MakeLogin(user,pass,remember)
{	
		$.ajax({
				type:	'POST',
				url:	"users_login.asp?kadi="+user+"&sifre="+pass+"&hatirla="+remember,
				data:	"",
				dataType:	'html',
				timeout:	5000,
				success:function(d,s){
				if (d == "hata"){
				
				 ShowMessage(2);
				
				}	
                else if (d == "banned"){
				 
				 ShowMessage(3);
				}				
				else{
						location.reload(true);
					}
				}
			});				
}

//----------------------------------------------------

function login_validator(theForm)
{
	var isremember = "";
	if (theForm.hatirla.checked)
	{
	 isremember = "yes";
	}	
	if(theForm.kadi.value == "" || theForm.sifre.value == "") {

	     ShowMessage(1);
		 return false;
	}
    else
	{
	MakeLogin(theForm.kadi.value,theForm.sifre.value,isremember);
	return false;
	}
	return false;
}

//----------------------------------------------------

function redirect_target(target){
    window.location = target;
}

//----------------------------------------------------

function redirect(target){
    setTimeout("redirect_target('"+target+"')", 3000)
}

//----------------------------------------------------

function form_validator_search(theForm)
{

	if(theForm.keyword.value == "" || theForm.keyword.value.length < 2 ) {
		 ShowMessage(11);
		 theForm.keyword.focus();
		 return(false);
	}
	LoadContent('search_ajax.asp?key='+theForm.keyword.value+'&cid='+theForm.category.value);
	return (false);
}

//----------------------------------------------------

function form_validator_contact(theForm)
{


	
if(theForm.name.value == "") {
		 ShowMessage(22);
		 theForm.name.focus();
		 return(false);
	}

	
	if((theForm.email.value == "") || (theForm.email.value.indexOf ("@",0) == -1 ||  theForm.email.value.indexOf (".",0) == -1)) {
		 ShowMessage(23);
		 theForm.email.focus();
		 return(false);
	}
	
		if(theForm.subject.value == "") {
		 ShowMessage(24);
		 theForm.subject.focus();
		 return(false);
	}
	
	
	if(theForm.message.value == "") {
		 ShowMessage(25);
		 theForm.message.focus();
		 return(false);
	}
		if (theForm.message.value.length < 5)
	{
		 ShowMessage(26);
		 theForm.message.focus();
		 return(false);
	}
	
	if(theForm.captchacode.value == "") {
		 ShowMessage(41);
		 theForm.captchacode.focus();
		 return(false);
	}
	
	return (true);
}

//----------------------------------------------------

function form_validator_signup(theForm)
{

	if(theForm.kadi.value == "" || theForm.sifre.value == "" || theForm.sifre2.value == "" || theForm.email.value == "" || theForm.captchacode.value == "") {
		 
		  ShowMessage(29);
		 return(false);
	}

	if (theForm.captchacode.value.length < 6)
	{
		 ShowMessage(41);
		 theForm.captchacode.focus();
		 return(false);
	}
	
    if((theForm.email.value == "") || (theForm.email.value.indexOf ("@",0) == -1 ||  theForm.email.value.indexOf (".",0) == -1)) {
		 ShowMessage(30);
		 theForm.email.focus();
		 return(false);
	}

	if (theForm.kadi.value.length < 4 || theForm.kadi.value.length > 14)
	{
		 ShowMessage(31);
		 theForm.kadi.focus();
		 return(false);
	}

	if ( theForm.sifre.value.length < 4 || theForm.sifre.value.length > 14)
	{
		 ShowMessage(32);
		 theForm.sifre.focus();
		 return(false);
	}
	
	if (theForm.sifre.value != theForm.sifre2.value)
	{
		 ShowMessage(33);
		 theForm.sifre.focus();
		 return(false);
	}
	
	return (true);
}

//----------------------------------------------------

function UpdateCaptcha(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

//----------------------------------------------------

function form_validator_forgot(theForm)
{

if((theForm.email.value == "") || (theForm.email.value.indexOf ("@",0) == -1 ||  theForm.email.value.indexOf (".",0) == -1)) {
		 ShowMessage(45);
		 theForm.email.focus();
		 return(false);
	}
}

//----------------------------------------------------

function ExpandBlock(target)
{

  var el = document.getElementById(target);
	if ( el.style.display != "none" ) {
	$(el).fadeOut('fast');
		
	}else
	{
	$(el).fadeIn('slow');
	}	
	
				
}

//----------------------------------------------------

function form_validator_editaccount(theForm)
{

	
    if((theForm.email.value == "") || (theForm.email.value.indexOf ("@",0) == -1 ||  theForm.email.value.indexOf (".",0) == -1)) {
		 ShowMessage(52);
		 theForm.email.focus();
		 return(false);
	}

	if (theForm.sifre.value.length != 0)
	{
		 if ( theForm.sifre.value.length < 4 || theForm.sifre.value.length > 14)
	    {
		 ShowMessage(53);
		 theForm.sifre.focus();
		 return(false);
	   }
	
	 if ( theForm.sifre2.value.length < 4 || theForm.sifre2.value.length > 14)
	    {
		 ShowMessage(54);
		 theForm.sifre.focus();
		 return(false);
	   }
	}
	
	url = "usercp_editaccount2.asp?sifre="+theForm.sifre.value+"&sifre2="+theForm.sifre2.value+"&email="+theForm.email.value+"&ad="+theForm.ad.value+"&url="+theForm.url.value+"&update_mail="+theForm.update_mail.value+"&newitem_mail="+theForm.newitem_mail.value;
    ModalDialog(url);
	
	return (false);
}

//----------------------------------------------------

function form_validator_suggest(theForm)
{

	if(theForm.title.value == "") {
		 ShowMessage(58);
		 theForm.title.focus();
		 return(false);
	}
	
	if (theForm.title.value.length < 8 || theForm.title.value.length > 50)
	{
		 ShowMessage(61);
		 theForm.title.focus();
		 return(false);
	}
	if(theForm.msg.value == "") {
		 ShowMessage(59);
		 theForm.msg.focus();
		 return(false);
	}
		if (theForm.msg.value.length < 15 || theForm.msg.value.length > 500)
	{
		 ShowMessage(60);
		 theForm.msg.focus();
		 return(false);
	}
	return (true);
}
