
function getpass(){
    
    var display = document.getElementById('getpass_form').style.display;

    if (display == 'block') {
        //document.getElementById('auth').style.overflow = "hidden";
        display = 'none';
    }
    else {
        //document.getElementById('auth').style.overflow = "visible";
        document.getElementById('login_form').style.display = 'none';
        display = 'block';
    }
    document.getElementById('getpass_form').style.display = display;
    return false;
}

function send_click(){

    var prefix = document.getElementById('pre').value;
    var phone = document.getElementById('passnumber').value;

    var msisdn = prefix + phone;

    if(msisdn != null && msisdn.toString().match('(99893|99894)[\\d]{7}')){
        paassword(prefix + phone);
        document.getElementById('getpass_form').style.display = 'none';
        document.getElementById('sent_form').style.display = 'block'
    }else{
        document.getElementById('pre').style.border = 'red';
        document.getElementById('number').style.border = 'red';
    }
}

function checkEnter(e){ //e is event object passed from function invocation

    var characterCode //literal character code will be stored in this variable

    if(e && e.which){ //if which property of event object is supported (NN4)
        e = e
        characterCode = e.which //character code is contained in NN4's which property
    }
    else{
        e = event
        characterCode = e.keyCode //character code is contained in IE's keyCode property
    }

    if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
        send_click();

        return false;
    }

    return true;
}

function hideSentForm(){
    document.getElementById('getpass_form').style.display = 'none';
    document.getElementById('sent_form').style.display = 'none';
    document.getElementById('login_form').style.display = 'block';
    return false;
}

jQuery(document).ready(function () {
    /*jQuery("#auth .auth a").toggle(
        function () {
            jQuery("#auth .wrapper").animate({
                marginLeft: "0"
            }, 1000 )
        },
        function () {
            jQuery("#getpass_form").css("display","none")
            jQuery("#auth").css("overflow", "hidden");
            jQuery("#auth .wrapper").animate({
                marginLeft: "-251px"
            }, 1000 );
        }
    );*/
    //jQuery(".iepngfix").ifixpng();

    jQuery("#authpopup").hide();
    jQuery("#login_box").toggle(
        function () {
            jQuery("#authpopup").show();
            return false;
        },
        function () {
             jQuery("#authpopup").hide();
             return false;
        }
    );

    jQuery("#artistlist div:first").removeClass("close").addClass("open");
    jQuery("#artistlist div.open p").slideDown();

    jQuery("#artistlist h4 a").click(function () {
        if (jQuery(this).parent().next().css("display") == "none") {
            jQuery("#artistlist div p").slideUp("slow");
            jQuery(this).parent().next().slideDown("slow");
        }
        jQuery("#artistlist div").removeClass("open").addClass("close");
        jQuery(this).parent().parent().addClass("open").removeClass("close");

        return false;
    });
});

// execute your scripts when DOM is ready. this is a good habit
$(function() {

    // initialize scrollable
    $("div.scrollable").scrollable({
        vertical:true,
        size: 3

    // use mousewheel plugin
    });

    //----- Lang -----//
	$("#lang li.current a").click(function() {$("#lang li").css("display", "block");return false});
	$("#langselect").toggle(function() {
		$("#lang li").css("display", "block");
	}, function() {
		$("#lang li:not('.current')").css("display", "none");
	})

	//----- Search -----//
	$('#search input[type="text"]').focus(function() {this.value = ''});

	//----- Tabs -----//
	$(".tabs .tab").append('<span class="rounds tr"></span><span class="rounds tl"></span><span class="rounds br"></span><span class="rounds bl"></span>').css('display', 'none');
	$(".tabs .tab:eq(" + $(".tabs li.current").index() + ")").css('display', 'block');
	$(".tabs li a").click(function() {
		if ($(this).parent().hasClass('current')) {
			return false;
		} else {
			$(".tabs li").removeClass('current');
			$(this).parent().addClass('current');
			$(".tabs .tab").css('display', 'none');
			$(".tabs .tab:eq(" + $(this).parent().index() + ")").css('display', 'block');
			return false;
		}
	})

	//----- Forms -----//
	checkRadioAndCheckboxes()
	checkSelect();
	$(".inputradio").click(function() {chekedInput($(this).find('input'))});
	$(".inputcheckbox").click(function() {chekedInput($(this).find('input'))});
	$(".select .items span").click(function() {selectItem($(this))});
	$(".select .label").live('click', function() {
		var elem = $(this).parent().find('.items');
		if (elem.css('display') == 'none') elem.css('display', 'block');
		else elem.css('display', 'none');
	});

        
})

function checkRadioAndCheckboxes() {
	$(".inputradio input").parents(".inputradio").css('backgroundPosition', 'bottom left');
	$(".inputcheckbox input").parents(".inputcheckbox").css('backgroundPosition', 'bottom left');
	$(".inputradio input:checked").parents(".inputradio").css('backgroundPosition', 'top left');
	$(".inputcheckbox input:checked").parents(".inputcheckbox").css('backgroundPosition', 'top left');
}
function chekedInput(elem) {
	if (elem.attr('checked') && elem.attr('type') != 'radio') {elem.removeAttr('checked');}
	else {elem.attr('checked', 'checked')};
	checkRadioAndCheckboxes();
}
function checkSelect() {
	$(".select").each(function() {
		var elem = $(this);
		var selectWidth = elem.find('select').width();
		elem.find('select').css('display', 'none');
		var text = elem.find("option:selected").text();
		elem.append("<span class='label' style='width:" + selectWidth + "px'>" + text + "</span>");

		var itemsWidth = selectWidth + 29;
		var items = "<span class='items' style='width:" + itemsWidth + "px'>";
		elem.find("option").each(function() {items += "<span>" + $(this).text() + "</span>"});
		items += "</span>";

		elem.append(items);

                $('#auth .select .label').css('width', '58px');
                $('#auth .select .items').css('width', '87px');
	})
}
function selectItem(elem) {
	var index = elem.index()
	elem.parents(".select").find("option:eq(" + index + ")").attr("selected", "selected");
	elem.parents(".select").find(".label").text(elem.text());
	elem.parents(".select").find(".items").css('display', 'none');
}
