﻿jQuery(document).ready(function(){
    startImagesRollOvers();
    startLogInControls();
    startValidationControls();   
    preventEnterKey(); 
    expandibleMenus();
});

function preventEnterKey()
{
   jQuery("input[type=text],input[type=password]").live("keypress",function (e){
        if(e.keyCode == 13)
        {
            //showMessage("Enter prevented")
            return false;
        }
   });
}

function startValidationControls()
{
    //when key is pressed in the textbox
    jQuery(".txtPrice").live("keypress", function (e)
    {
      
      if(e.which==46)
      {
        if(this.value.indexOf(".") != -1)
            return false;
      }
      else if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))//if the letter is not digit then display error and don't type anything
      {
//        if(jQuery("#errmsg").length == 0)
//            jQuery(".txtPrice").after("<span id='errmsg'></span>");
//        //display error message
//        jQuery("#errmsg").html("Digits Only").show().fadeOut("slow");
        return false;
      }
    });
}

function startImagesRollOvers()
{
    jQuery(".pfile-image > img,.pfile-image > input").live("mouseover",function(e){
        
        if(jQuery("#divShowImage").size() == 0)
        {
            var y = jQuery(this).parent().offset().top;
            var x = jQuery(this).parent().offset().left + 60;
            jQuery("body").append("<div id='divShowImage' style='display:none;position:absolute;top:" + y + "px;left:" + x + "px'><img src='" + jQuery(this).attr("src").replace("Thumb", "")+ "' alt='Loading . . .' /></div>")
        }
        jQuery("#divShowImage").slideDown(300);
    });    
    jQuery(".pfile-image > img,.pfile-image > input").live("mouseout",function(){
        
        if(jQuery("#divShowImage").size() > 0)
        {
            jQuery("#divShowImage:first").slideUp(50, function(){
                jQuery("body").find("#divShowImage").remove();
            });
            
        }
    });
    jQuery(".pfile-image > img,.pfile-image > input").live("click",function(){
        
        if(jQuery("#divShowImage").size() > 0)
        {
            jQuery("#divShowImage:first").slideUp(50, function(){
                jQuery("body").find("#divShowImage").remove();
            });
            
        }
    });
}


function startLogInControls()
{
    jQuery("#ctl00_Header1_UcLogin1_LoginView1_ASPMessageBox_pnlMessage").hide();

    populateElement("#ctl00_Header1_UcLogin1_LoginView1_txtUserName","e-mail");
    populateElement("#ctl00_Header1_UcLogin1_LoginView1_txtPassword","password");
    
    jQuery("#ctl00_Header1_UcLogin1_LoginView1_txtPassword").keypress(function (e) {
        if(e.which == 13){
            jQuery("#ctl00_Header1_UcLogin1_LoginView1_ImageButton1").trigger("click");
        } 
    });
    
//    if(jQuery(".hSignUp").val() == "off")
//    {
        jQuery(".login-info").hide();
//    }
}



function populateElement(selector, defvalue) 
{
    jQuery(selector).each(function() {
	    if(jQuery.trim(this.value) == "") {
	    this.value = defvalue;
	    }
	    jQuery(this).attr("defvalue", defvalue);
	    
    });

    jQuery(selector).focus(function() {
	    if(this.value == jQuery(this).attr("defvalue")) {
	    this.value = "";
	    }
    });

    jQuery(selector).blur(function() {
	    if(jQuery.trim(this.value) == "") {
	    this.value = jQuery(this).attr("defvalue");
	    }
    });

}


function corners()
{
//    jQuery("input[type='submit']").corners("5px transparent");
//    jQuery("input[type='button']").corners("5px transparent");
//    jQuery("input[type='file']").corners("5px transparent");
}

function showMessage(message)
{
    if(jQuery("#alertBox").length == 0)
        jQuery("<div id='alertBox' style='display:none'>" + message + "</div>").appendTo(document.body);

    jQuery("#alertBox").css("background-color","#F1F2F2");
    jQuery("#alertBox").css("width","200px");
    jQuery("#alertBox").css("height","100px");
    jQuery("#alertBox").css("line-height","100px");
    jQuery("#alertBox").css("font-size","10pt");
    jQuery("#alertBox").css("-moz-border-radius","5px");
    jQuery("#alertBox").css("-webkit-border-radius","5px");
    jQuery("#alertBox").css("border","1px solid #BCBEC0");
    jQuery("#alertBox").css("text-align","center");
    jQuery("#alertBox").css("vertical-align","middle");
    jQuery("#alertBox").css("z-index","90010");

    jQuery("#alertBox").css("position","absolute");
    jQuery("#alertBox").css("top", ( jQuery(window).height() - jQuery("#alertBox").height() ) / 2 + jQuery(window).scrollTop() + "px");
    jQuery("#alertBox").css("left", ( jQuery(window).width() - jQuery("#alertBox").width() ) / 2 + jQuery(window).scrollLeft() + "px");
    
    jQuery("#alertBox").html(message).fadeIn("fast").delay(2000, function() { jQuery("#alertBox").fadeOut(3000) });
}

function showAlert(message, width, height, callback)
{
    if(width == undefined || width == null)
        width = '300';
    if(height == undefined || height == null)
        height = '100';
    
    if(jQuery("#alertBox").length == 0)
        jQuery("<div id='alertBox' style='display:none'>" + message + "</div>").appendTo(document.body);

    jQuery("#alertBox").css("background-color","#F1F2F2");
    jQuery("#alertBox").css("width", width + "px");
    jQuery("#alertBox").css("height", height + "px");
    jQuery("#alertBox").css("line-height", "30px");
    jQuery("#alertBox").css("font-size","10pt");
    jQuery("#alertBox").css("-moz-border-radius","5px");
    jQuery("#alertBox").css("-webkit-border-radius","5px");
    jQuery("#alertBox").css("border","1px solid #BCBEC0");
    jQuery("#alertBox").css("text-align","center");
    jQuery("#alertBox").css("vertical-align","middle");
    jQuery("#alertBox").css("z-index","90010");
    jQuery("#alertBox").css("padding","10px");


    jQuery("#alertBox").css("position","absolute");
    jQuery("#alertBox").css("top", ( jQuery(window).height() - jQuery("#alertBox").height() ) / 2 + jQuery(window).scrollTop() + "px");
    jQuery("#alertBox").css("left", ( jQuery(window).width() - jQuery("#alertBox").width() ) / 2 + jQuery(window).scrollLeft() + "px");
    
    jQuery("#alertBox").html(message).fadeIn("fast");
    
    jQuery("<input id='bOk' type='button' value='Ok'></input>").appendTo(jQuery("#alertBox"));
    jQuery("#bOk").css("position","absolute");
    jQuery('#bOk').css("display","block");
    jQuery("#bOk").css("bottom", "25px");
    jQuery("#bOk").css("width", "50px");
    jQuery("#bOk").css("left", (jQuery('#alertBox').width() - jQuery("#bOk").width() ) / 2 - jQuery(window).scrollLeft() + "px");
    
    if(callback != undefined && callback != null)
        jQuery("#bOk").click(callback);
}

jQuery.fn.delay = function(time,func){
    return this.each(function(){
        setTimeout(func,time);
    });
};


function showOverlay()
{
if(jQuery("#overlay").length == 0)
    jQuery("<div id='overlay'></div>").appendTo(document.body); 

jQuery("#overlay").show();
jQuery("#overlay").animate({ 
    opacity: 0.4,
    height: getMaxHeight()
  }, "slow"); 
}
function hideOverlay()
{
jQuery("#overlay").animate({ 
    opacity: 0.0,
    height: "0px"
  }, "slow");
jQuery("#overlay").hide(); 
}

function expandibleMenus()
{
    jQuery(".expandible > ul").hide();
    jQuery(".expandible").css("padding-left","0px");
    jQuery(".expandible > a").prepend("+ ");
    jQuery(".expandible > a").click(function(){
        if(jQuery(this).text().substring(0,1) == "+")
        {
            jQuery(this).parent().find("ul").slideDown();
            jQuery(this).text(jQuery(this).text().replace("+","-"));
        }
        else
        {
            jQuery(this).parent().find("ul").slideUp();
            jQuery(this).text(jQuery(this).text().replace("-","+"));
        }
        
    });
    jQuery(".expandible > a[visible=true]").click();    
}
