﻿function viewPhoto(strPath)	{
	window.open('assets/viewphoto.aspx?strPath=' + strPath, 'Viewver', 'width=780, height=500, scrollbars=yes, status=yes, resizable=yes')
}

function ResizePhotoViewer(window) {
	var img = document.getElementById('imgPhoto')
	var x = img.width + 50;
	var y = img.height + 155;
	
	if (screen.availWidth<x) { 
		x = screen.availWidth - 28; 
	}
	
	window.resizeTo(x,y);
}

function showEmail(strName, strDomain, strLinkText) {
	var strEmail = strName + '@' + strDomain;
	if (!strLinkText) {strLinkText = strEmail;}
	
	document.write('<a class="email" href="mailto:' + strEmail + '">' + strLinkText + '</a>');
}

function PlayFlash(src, cssclass)	{
	document.write("<object class=\"" + cssclass + "\" type=\"application/x-shockwave-flash\" data=\"" + src + "\">")
	document.write("<param name=\"movie\" value=\"" + src + "\" />")
	document.write("</object>") 
}

function HidePhoto()	{
	document.getElementById('largeimage').style.display='none';
}

function Enlarge(photoId)	{
	if (document.getElementById('largeimage').style.display=='block')	{
		document.getElementById('largeimage').style.display='none';
	}
	else	{
		document.getElementById('imglarge').src='assets/dbphoto.aspx?tablename=CE_News&ColNameData=FileData&ColNameSize=FileSize&ColNameId=cntNewsId&id=' + photoId + '&width=500';
		document.getElementById('largeimage').style.display='block';
	}
}

function Toggle(obj)	{
	if (document.getElementById(obj).style.display=='block')	{
		document.getElementById(obj).style.display='none';
	}
	else	{
		document.getElementById(obj).style.display='none';
		document.getElementById(obj).style.display='block';
	}
}

//CLIENT SPECIFIC
function VisaBild(picture){
	NewWin = window.open('clientfiles/assets/visabild.aspx?picture=' + picture, 'Nyhetsbild', 'width=150,height=150,resizable');
	NewWin.focus();
}

function CheckaBild(strBild)	{
	var imgBild = document.images(strBild);
	if (imgBild.width > 500)	{
		imgBild.width = 500;
	}
}

function VisaExt(namn)	{
	var img1 = new Image().src = "clientfiles/gfx/i.gif"
	var img2 = new Image().src = "clientfiles/gfx/i_on.gif"
	
	if (document.getElementById(namn).style.display == 'block')	{
		document.getElementById(namn).style.display='none';
		//document.images['i' + namn].src=img1;
	}
	else	{
		document.getElementById(namn).style.display='block';
		//document.images['i' + namn].src=img2;
	}
}

tooltip = {
	name : "tooltip",
	tip : null
};
tooltip.init = function () {
	if (!document.getElementById) return;
		
	this.tip = document.getElementById (this.name);
		
	var area;
	var anchors = document.getElementsByTagName ("area");
	for (var i = 0; i < anchors.length; i ++) {
		area = anchors[i];
		if (area.className == "tooltip") {
			area.onmouseover = function () {tooltip.show (this.alt)};
			area.onmouseout = function () {tooltip.hide ()};
		}
	}
};
tooltip.show = function (text) {
	if (!this.tip) return;
	this.tip.innerHTML = text;
	// Without the next line, Explorer5/Mac has a redraw problem.
	this.tip.style.visibility = "visible";
	this.tip.style.display = "block";
};
tooltip.hide = function () {
	if (!this.tip) return;
	// Without the next line, Explorer5/Mac has a redraw problem.
	this.tip.style.visibility = "hidden";
	this.tip.style.display = "none";
	this.tip.innerHTML = "";
};


//----------------------------------------------------------------------------------------------
// Overlabel

function initOverLabels() {
    if (!document.getElementById) return;

    var labels, id, field;

    labels = document.getElementsByTagName('label');
    for (var i = 0; i < labels.length; i++) {

        if (labels[i].className == 'overlabel') {

            // Skip labels that do not have a named association
            // with another field.
            id = labels[i].htmlFor || labels[i].getAttribute('for');
            if (!id || !(field = document.getElementById(id))) {
                continue;
            }

            // Change the applied class to hover the label 
            // over the form field.
            labels[i].className = 'overlabel-apply';

            // Hide any fields having an initial value.
            if (field.value !== '') {
                hideLabel(field.getAttribute('id'), true);
            }

            // Set handlers to show and hide labels.
            field.onfocus = function() {
                hideLabel(this.getAttribute('id'), true);
            };
            field.onblur = function() {
                if (this.value === '') {
                    hideLabel(this.getAttribute('id'), false);
                }
            };

            // Handle clicks to label elements (for Safari).
            labels[i].onclick = function() {
                var id, field;
                id = this.getAttribute('for');
                if (id && (field = document.getElementById(id))) {
                    field.focus();
                }
            };

        }
    }
};

function hideLabel(field_id, hide) {
    var field_for;
    var labels = document.getElementsByTagName('label');
    for (var i = 0; i < labels.length; i++) {
        field_for = labels[i].htmlFor || labels[i].getAttribute('for');
        if (field_for == field_id) {
            labels[i].style.display = (hide) ? 'none' : 'block';
            return true;
        }
    }
};

//----------------------------------------------------------------------------------------------

window.onload = function() {
    setTimeout(initOverLabels, 50);
    tooltip.init();
}