﻿/// <reference path="jquery-1.4.2.min.js" />
function MainLoad() {

    LoadFlash();
    InitDropDownList();
      
	$(".tanitimfilmi").click(function(e) {
		e.preventDefault ? e.preventDefault() : e.returnValue = false;
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 640,
			'height'		: 385,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			'wmode'				: 'transparent',
			'allowfullscreen'	: 'true'
			}
		});
	});

	$(".focusempty").each(function(){$(this).focusEmpty()});
    
    $(".detailsright td:last-child").css("border-right","none");
    $(".detailsright td:first-child").css("font-weight", "bold");
    $(".productlist .item").hover(function() { $(this).find(".title a").css("border-bottom", "1px solid #6b3500").css("font-weight", "bold"); }, function() { $(this).find(".title a").css("border-bottom", "none").css("font-weight", "normal"); });
    
    $("*[rel=jsabox_img]").click(function() {
        $("#jsaboxcontent").html("<div class='lightboxcontent'><img src='Images/close.jpg' class='close' /><img src='" + $(this).attr("href") + "' /></div>");
        $(".lightboxcontent").click(function(){return false;});
        $(".lightboxcontent .close").click(function(){CloseItem();});

        $("#jsabox").show();
        return false;
    });
    
    $("*[rel=jsabox_swf]").click(function() {
        $("#jsaboxcontent").html("<div type='Flash' src='" + $(this).attr("href") + "' width='" + $(this).attr("width") + "' height='" + $(this).attr("height") + "'></div>");
        $("#jsabox").show();
        LoadFlash();
        return false;
    });

    $("*[rel=jsabox_html]").click(function() {
        $("#jsaboxcontent").html("<div type='Flash' src='" + $(this).attr("href") + "' width='" + $(this).attr("width") + "' height='" + $(this).attr("height") + "'></div>");        
        $("#jsabox").show();
        LoadFlash();
        return false;
    });
    
    $("*[rel=jsaBox_html]").click(function() {
        var item = $("#" + $(this).attr("href")).clone().show();
        $("#jsaboxcontent").html("<div class='lightboxcontent'>" + item.html() + "</div>");
        $("#jsabox").show();
        return false;
    });
    
    $("*[rel=jsaBox_map]").click(function() {
        var item = $("#" + $(this).attr("href")).clone().show();
        $("#jsaboxcontent").html("<div class='mapcontent'>" + item.html() + "</div>");
        $("#jsabox").show();
        return false;
    });
    
    $("*[rel=jsaBox_flash]").click(function() {
        var item = $("#" + $(this).attr("href")).clone().show();
        $("#jsaboxcontent").html("<div class='lightboxcontent' style='width:600px;height:180px;'><img src='Images/close.jpg' class='close' />" + item.html() + "</div>");
        $("#jsabox").show();
        return false;
    });

    $("#jsabox").click(function() {CloseItem();});

    $("*[rel=jsabox_video]").click(function () {
        $("#jsaboxcontent").html("<div type='Flash' class='lightboxcontents' src='Flash/VideoPlayer.swf?pvideo=" + BasePath + $(this).attr("href") + "' width='303px' height='235px'></div>");
        LoadFlash();
        $("#jsabox").show();
        return false;
    });

    $("*[rel=jsaBox_ad]").click(function () {
        $("#jsaboxcontent").html("<div id='showflash'></div>");
        $("#showflash").click(function () { return false; }).GenerateFlash({ src: "Flash/player.swf?pimage=Flash/video-thumbnail.jpg&pskin=Flash/skins/classic.swf&pvideo=" + $(this).attr("href"), width: "550px", height: "445px" }).append("<div class='closebutton'><a onclick='javascript:CloseItem();'><img src='Images/close.png' class='close' /></a></div>");
        $("#jsabox").show();
        return false;
    });

    $(".Phone").each(function () {
        if ($(this).attr("ismask") != "1") {
            $(this).attr("ismask", "1");
            $(this).mask("9(999) 999-9999");
        }
    });

    $(".Date").each(function () {
        if ($(this).attr("ismask") != "1") {
            $(this).attr("ismask", "1");
            $(this).mask("99/99/9999");
        }
    }).blur(function () {
        if (!DateControl($(this).val())) {
            $(this).val("");
        }
    });

    $(".BidDate").each(function () {
        if ($(this).attr("ismask") != "1") {
            $(this).attr("ismask", "1");
            $(this).mask("9999/99/99");
        }
    }).blur(function () {
        if (!BidDateControl($(this).val())) {
            $(this).val("");
        }
    });
    
    $(".Year").mask("9999");
    $(".TC").mask("99999999999");
    $(".TaxNumber").mask("9999999999");
    $(".Hour").mask("99:99").blur(function(){
        if ( parseInt($(this).val().replace(":","")) > 2359 ) {
            $(this).val("");
        }
    });
    
    $(".Number").keyup(function(){
        if (! IsNumeric($(this).val()) ) {
            $(this).val(ConvertNumeric($(this).val()));
        }
    });

    $(".inputtext").focus(function () { $(this).css("background-position", "left bottom"); }).blur(function () { $(this).css("background-position", ""); });
    $(".inputtextarea").focus(function () { $(this).css("background-position", "left bottom"); }).blur(function () { $(this).css("background-position", ""); });
    $(".inputdrp").focus(function () { $(this).parent().css("background-position", "left bottom"); }).blur(function () { $(this).parent().css("background-position", ""); });

    $(".FakeUpload").change(function () {
        $(this).parent().find(".fakeupload").val($(this).val());
    });

    $(".menu ul ul").hide();
    $(".menu .select").each(function () {
        var top = false;
        var parent = $(this).parent();
        while (!top) {
            parent.show();
            parent = parent.parent();
            if (parent.attr("class") == "menu") { top = true; }
        }
    });
    $(".menu .select").parent().parent().find("ul:eq(0)").show();

    var leftmenuh = $(".mainleft .leftmenu").height();
    $(".mainright .pagecontent").css('min-height', '' + (leftmenuh + 100) + 'px').css('height', '' + (leftmenuh + 100) + 'px');

    doResize();

}

function doResize() {
    var allo = $(window).height();
    var verro = $(document).height();
    if (verro > allo) { $('body').css('height', '' + verro + 'px'); }    
} 


function InitDropDownList() {
    var Browser = $.browser;
    if (!(Browser.msie && Browser.version == "6.0")) {
        $(".inputdrp").each(function () {
            if ($(this).attr("isdrp") != "true") {
                $(this).attr("isdrp", true);
                $(this).parent().addClass("inputdrpParent").each(function () { $(this).html("<span class='inputdrpText'>" + $(this).find("option[selected=true]").text() + "</span>" + $(this).html()); });
            }
        })
        $(".inputdrp").change(function () { $(this).parent().find(".inputdrpText").html($(this).find("option[selected=true]").text()); });
    }
}

function IsNumeric(Text) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var Char;
    for (i = 0; i < Text.length && IsNumber == true; i++) {
        Char = Text.charAt(i);
        if (ValidChars.indexOf(Char) == -1) { IsNumber = false; };
    }
    return IsNumber;
}

function ConvertNumeric(Text) {
    var ValidChars = "0123456789.";
    var Char = "";

    for (i = 0; i < Text.length; i++) {
        if (ValidChars.indexOf(Text.charAt(i)) != -1) {
            Char = Char + Text.charAt(i);
        }
    }
    return Char;
}

function focusText(field) {
    if (field.defaultValue == field.value) field.value = '';
}

function blurText(field) {
    if (field.value == '') { field.value = field.defaultValue; }
}

function CloseItem() {
    $("#jsaboxcontent").html("").hide();
    setTimeout(function () { $("#jsabox").hide(); $("#jsaboxcontent").show(); }, 50);
}

function openImage(fileUrl) {
    $("#jsaboxcontent").hide().html("<div class='qualtycontent' id='showflash'></div>")
    $("#jsabox").show();
    $("#showflash").GenerateFlash({ src: "Flash/LightBox.swf?urlPic=" + fileUrl, width: "420px", height: "573px" });
    setTimeout(function () {
        $("#jsaboxcontent").slideDown(300);
    }, 200);
}

function ShowParent($this, StopItem) {
    $this.parent().find("li").show();
    if ($(StopItem).attr("id") != $this.attr("id")) {
        ShowParent($this.parent(), StopItem);
    }
}

function InitPhotoGallery() {


    var gallerysize = $(".imagegallery .imageitems .imageitem").size();
    var galleryNumber = 0;

    $(".gallerynext").click(gallerynext);
    $(".galleryprevious").click(galleryprevious);
    $(".imagenext").click(imagenext);
    $(".imageprevious").click(imageprevious);


    $(".imagegallery .imageitems .imageitem a").each(function () {
        $(this).attr("number", galleryNumber);
        galleryNumber++;
    });

    $(".imagegallery .imageitems .imageitem a").click(function () {
        showgalleryimage($(this).attr("number"));
        return false;
    });

    $("#imgNow").load(function () {
        $(".imageloading").animate({ height: $("#imgNow").height() }, 300, function () {
            $(".imagenavigation").css("height", $("#imgNow").height());
            $(".imageloading").fadeOut(100, function () {
                $("#imgNow").show();
                if ($("#imgDesc").html().toString().length > 0) {
                    $("#imgDesc").show();
                }
                else {
                    $("#imgDesc").hide();
                }
            });
        });
    }).hover(function () {
        $(".imagegallery .imagenavigation").show();
    });
    $(".imagegallery .imagenavigation").hover(function () {
    }, function () {
        $(".imagegallery .imagenavigation").hide();
    });

    function showgalleryimage(Number) {
        var $this = $(".imagegallery .imageitems .imageitem a:eq(" + Number + ")");
        $(".imageloading").show();

        $("#imgNow").hide().attr("src", $this.attr("binaryUrl")).attr("number", Number);

        $("#imgDesc").html($this.attr("desc"));

        $("#imgdesc").hide();

        $(".galleryinfo").html("Resim " + (parseInt(Number) + 1) + "/" + (gallerysize));
        $(".imagegallery .imageitems .imageitem a").find("img").removeClass("select");
        $this.find("img").addClass("select");
        $(".imagegallery .imageitems").animate({ top: "-" + ((Math.floor(Number / 4) * 76) + "px") }, 500);
    }

    function imagenext() {
        var Number = parseInt($("#imgNow").attr("number"));
        if (Number < gallerysize - 1) { Number++; }
        else { Number = 0; }
        showgalleryimage(Number);
    }

    function imageprevious() {
        var Number = parseInt($("#imgNow").attr("number"));
        if (Number > 0) { Number--; }
        else { Number = gallerysize - 1; }
        showgalleryimage(Number);
    }

    function gallerynext() {
        var top = parseInt($(".imagegallery .imageitems").css("top").replace("px", ""));

        if (top > (((gallerysize / 4) * 76) - 76) * -1) {
            $(".imagegallery .images .imageitems").animate({ top: "-=76px" }, 500);
        }
    }
    function galleryprevious() {
        if (parseInt($(".imagegallery .imageitems").css("top").replace("px", "")) < 0) {
            $(".imagegallery .images .imageitems").animate({ top: "+=76px" }, 500);
        }
    }

    showgalleryimage(0);

}


function DateControl(fld) {
    var RegExPattern = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
    if ((fld.match(RegExPattern)) && (fld != '')) { return true; }
    else { return false; }
}


function BidDateControl(fld) {
    var RegExPattern = /^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$/;
    if ((fld.match(RegExPattern)) && (fld != '')) { return true; }
    else { return false; }
}


