﻿// Login Script
function logIn()
{    
    $("#login").jqm({modal: true}).jqmShow();        
}

function closeLogIn()
{
    $("#login").jqmHide();  
}

function ViewRichTextBox(el)
{
    $("tr", $("table", $("#richTextBox")))[0].hide();
}

function ShowPasswordRecovery(el)
{
    $("#recovery_password").show();
    $("input[type='password']","#recovery_password").each(function(){
       $(this).val("");
    })
    $el.hide();
}

function ValidateForm(el)
{
    $("form").validate();
}

function CommentCheckChanged(el)
{
    //find the mail txt input
    $parrent = $(el).parents("div:first");
    if( $("input[type='text']",$parrent) != null)
    {
        $divMail = $("#divMail",$parrent)
        $txtMail = $("input[type='text']",$parrent);
        //if the checkbox is checked
        if($(el).is(":checked"))
        {        
            $divMail.show();
            $txtMail.addClass("required"); 
        }
        else
        {
            $divMail.hide();
            $txtMail.removeClass("required");
        }
    }
    //if not null show it and make it required
}

function LoadMessageTooltip(el)
{
    $(el).tooltip();
}

function ShowSendMessage(userId)
{
    $("#hdnUserMessageId").val(userId);
    $("#message_to_author").jqm({modal: true}).jqmShow();
}
function HideSendMessage(el)
{
    $("#message_to_author").jqmHide();
}

function SlideIcons(el)
{
    $divIcons = $(el).parents("div:first");
    $("#inner_icons", $divIcons).slideToggle("slow");
    $("body" ).onclick(function(el){
            $("#inner_icons").slideUp("slow");
        });
    $("textarea", $divEditor).focus()
    //inner_icons
}
function SetIconText(el)
{
    $divEditor = $(el).parents("div.editor:first");
    var title = $(el).attr("title");
    var curText= $("textarea", $divEditor).val(); 
    $("textarea", $divEditor).val(curText + title);//.val()
    $("#inner_icons", $divEditor).slideToggle("fast");
    $("textarea", $divEditor).focus()
}

/***********************************************
* Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetxpoint=-60 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else if (curX<leftedge)
tipobj.style.left="5px"
else
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+"px"

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
else
tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip



/*
        Quiz Javascript
*/
function Add_NewAnswer(el)
{
    $row = $(el).parents("tr:first");
    $tbody = $(el).parents("tbody:first");
    //clonning the row
    $templ_clone = $row.clone();
    $templ_clone.find("input")
            .each(function(){
                $(this).val('');
            })
    $templ_clone.appendTo($tbody);
}

function Remove_NewAnswer(el)
{
    $row = $(el).parents("tr:first");
    $row.remove();
}

function btnQuizEdit_Click(el)
{
    $td = $(el).parents("td:first");
    $td.find("input").each(function(){
             $(this).show();
             });
    $table = $td.parents("table:first");
    $table.find("input").each(function(){
                $(this).show();
                if ($(this).attr("name"))
		            $(this).attr("name", $(this).attr("name").replace(/_template.*/, ""));
		        if ($(this).attr("id"))
		            $(this).attr("id", $(this).attr("id").replace(/_template.*/, ""));
             });
    $table.find("label").each(function(){
                $(this).hide();
                });
    $("#txtActiveFrom").datepicker();
    $("#txtActiveTo").datepicker();
    
    $("#quiz_button",$td).show();
    $("#quiz_edit_button", $td).hide();
    $(el).hide();
}
function btnQuizCancel_Click(el)
{
    $td = $(el).parents("td:first");

    $table = $td.parents("table:first");
    $table.find("label").each(function(){
            $(this).show();
            });  
                   
    $table.find("input").each(function(){
            $(this).hide();
            if ($(this).attr("name"))
	            $(this).attr("name", $(this).attr("name") + "_template");
         });
//    $td.find("input").each(function(){
//         $(this).show();
//         });
    $("#quiz_button", $td).hide();
    $("#quiz_edit_button", $td).show();
    $(el).hide();
}
/*
    Quiz Javascript End
*/
/*
    START LUCK control
*/

function ShowLuck(el)
{
    $("#luck_container").jqm({     
    //onHide: function(h) {
      //h.w.fadeOut('3000',function(){ h.o.remove();  });
    //},
    modal: true}).jqmShow(); 
}

function ShowLuckyMessage(el)
{
    //$td = "td:first");
    $parent_container = $(el).parents(".inner_container");
    $parent_span = $(el).parents("span:first");
    var msg = $("#luck", $parent_span).val();
    $(el).parents(".clovers").hide();
    
    $lbl = $("<center><label><big>Your luck today:</big></label></center>");
    $lbl.appendTo( $parent_container);
    $luck_msg = $("<p><center><div class='luck_message'>" + msg + "</div></center></p>");
    $luck_msg.appendTo( $parent_container);
    
    $luck_msg.clone().appendTo($("#luck_message"));
}

function CloseCurrentModal(el)
{
    $("#luck_container").jqmHide();
    $(el).parents(".jqmWindow").jqm().jqmHide();
    top.$('#luck_container').jqmHide(); 
    $("#luck_container").hide();
}
/*  END LUCK control*/