var checkflag = "false";

//limit textarea
function limitTextArea(textArea,maxLength)
{
    if(textArea.value.length > maxLength)
    {
        textArea.value = textArea.value.substr(0,maxLength-3);
        alert("Maximum " + maxLength + " Zeichen");
    }
}

function sf ()
{
	document.sform ['searchvalue'].focus ();
}
function check (field)
{
	if(field)
	{
	    if (checkflag == "false")
	    {
		    for (i = 0; i < field.length; i ++)
		    {
			    field [i].checked = true;
		    }
		    checkflag = "true";
	    } 
	    else
	    {
		    for (i = 0; i < field.length; i ++)
		    {
			    field [i].checked = false;
		    }
		    checkflag = "false";
	    }
	}
}
function SetColAndSubmit (i)
{
	document.aspnetForm ['cid'].value = i;
	document.aspnetForm.submit ();
}
function SetSortAndSubmit (i)
{
	document.aspnetForm ['srt'].value = i;
	document.aspnetForm.submit ();
}

function SetAndGoto(queries,setquries,sm)
{
    //adddebug(queries);
    var qpairs = queries.split("&");       
    var spairs = setquries.split("&") ;
    
    var outQuery = ""
            
    for(x=0;x<spairs.length;x++)
    {
        var spair = spairs[x].split("=")
        var foundpair = false;
        for(y=0;y<qpairs.length;y++)
        {
           var qpair = qpairs[y].split("=")
           
           adddebug("compare: " + qpair[0] + " " + spair[0]);
           
           if(qpair[0] == spair[0])
           {
                foundpair = true;
                qpairs[y] = spairs[x]; 
                adddebug("set: " + spairs[x])                             
           }
        }
        if(foundpair == false)
        {
           adddebug("push: " + spairs[x])
           qpairs.push(spairs[x]);
        }
    }
    adddebug("------------------");
    
    for(i=0;i<qpairs.length;i++)
    {
        if(qpairs[i] != "")
        {
        outQuery += qpairs[i] +"&";        
        }
    }
    
    adddebug(outQuery);
    location.href = sm + "?" + outQuery;
    
}

function SetChargedAndSubmit (i)
{
	document.aspnetForm ['crd'].value = i;
	document.aspnetForm.submit ();
}

function SetFreeAndSubmit (i)
{
	document.aspnetForm ['fre'].value = i;
	document.aspnetForm.submit ();
}

function SetPagesizeAndSubmit (i)
{
		if (document.searchform) 
	{
	    get_form().action = "/search/";
	}
	get_form() ['ps'].value = i;
	get_form() ['cp'].value = 1;
	get_form().submit ();
}

function SetPageAndSubmit (i)
{
	if (document.searchform) 
	{
	    get_form().action = "/search/";
	}
	get_form() ['cp'].value = i;
	get_form().submit ();
}
function SetValueAndSubmit (i,val)
{

	get_form() [val].value = i;
	get_form().submit ();
}

function SetDetailAndSubmit (i)
{
	get_form()  ['mid'].value = i;
	get_form().action = "/detail/";
	get_form().submit ();
}

function AddToLightBoxAndSubmit (i)
{
	get_form ()['addlightb'].value = i;
	get_form ().submit ();
}
function RemFromLightBoxAndSubmit (i)
{
	get_form () ['remlightb'].value = i;
	get_form ().submit ();
}
function settop (i, cid, CurrentPage)
{
	document.aspnetForm ['settop'].value = i;
	document.aspnetForm ['cid'].value = cid;
	document.aspnetForm ['cp'].value = CurrentPage;
	document.aspnetForm.submit ();
}
document.onkeydown = checkKeycode;
function checkKeycode (e)
{
//	var keycode;
//	if (window.event) keycode = window.event.keyCode;
//	else if (e)
//	keycode = e.which;
//	if (keycode == 39 && ae(e) == null)
//	{
//		if (get_form() ['cp'].value == "")
//		{
//			get_form() ['cp'].value = "1"
//		}
//		SetPageAndSubmit (Number (get_form() ['cp'].value) + 1)
//	}
//	if (keycode == 37 && Number (get_form() ['cp'].value) > 1 && ae(e) == null)
//	{
//		SetPageAndSubmit (Number (get_form() ['cp'].value) - 1)
//	}
}
function ae(e) 
{
	var target;
	if ("activeElement" in document)
	{ 
		target = document.activeElement; //Si IE
	} 
	else  
	{ 
		target = e ? e.explicitOriginalTarget : null;  // Si Firefox
	}
	return target.type
}




// adm add fields
var counterobj = new Object ();
function add_element (no)
{
	var elm = document.getElementById ('key_add_tr' + no)
	counterobj [no] ++
	newelm = elm.cloneNode (true);
	newelm.id = 'IPTC' + no + '_' + counterobj [no]
	newelm.childNodes [0].childNodes [0].name = 'IPTC' + no + '_' + counterobj [no]
	//newelm.childNodes[0].childNodes[0].value = 'IPTC' + no + '_' + counterobj[no]
	newelm.childNodes [1].childNodes [0].value = '-'
	newelm.childNodes [1].childNodes [0].onclick = remove_element
	elm.parentNode.insertBefore (newelm, elm)
	elm.childNodes [0].childNodes [0].value = ''
}
function remove_element ()
{
	var elm = this.parentNode.parentNode
	elm.parentNode.removeChild (elm);
}
function remove_elementbyid (id)
{
	var elm = document.getElementById (id)
	elm.parentNode.removeChild (elm);
}
function get_form ()
{

	if (document.searchform) 
	{
	return document.searchform;
	}
	else
	{
	return document.aspnetForm; 
	}
	
}





function handleKeySubmit(e,mform){
	var key=e.keyCode || e.which;
	if (key==13){
	//mform.submit();
	}
}



function cnc(ref,over,selected)
{
    if ( ! selected)
    {
        if(over == true)
        {
            ref.className = ref.className + "Hover";
        }
        if(over == false)
        {
            ref.className = ref.className.replace("Hover","");
        }    
    }
}


var dateField = null;
var datePicker = null;
function openDatePicker(df)
{   
    dateField = df;
    datePicker = window.open('DatePicker.aspx','calendarPopup','width=200,height=200');
    datePicker.focus();
}

function openDatePicker2(df)
{   
    dateField = document.getElementById (df);
    datePicker = window.open('DatePicker.aspx','calendarPopup','width=200,height=200');
    datePicker.focus();
}

var DialogWin = {};
DialogWin.overlay = null;
DialogWin.container = null;
DialogWin.winTitle = null;
DialogWin.ContText = "";
DialogWin.ContText2 = "empty";

DialogWin.OkUrl = "";

window.onload = function() 
{
DialogWin.build()
}

DialogWin.build = function()
{
DialogWin.overlay = document.createElement("DIV");
DialogWin.overlay.className = "DialogWinOverlay";
DialogWin.overlay.id = "DialogWinOverlay"
DialogWin.overlay.style.visibility = "hidden"

document.body.appendChild(DialogWin.overlay);

Helpers.changeOpac(0,"DialogWinOverlay")


DialogWin.container = document.createElement("DIV");
DialogWin.container.className = "DialogWinContainer";
DialogWin.container.id = "DialogWinContainer"
DialogWin.container.style.visibility = "hidden"

document.body.appendChild(DialogWin.container);

Helpers.changeOpac(0,"DialogWinContainer")


//table to center window
var ContainerTable = document.createElement("table");
ContainerTable.className = "DialogWinContainerTable";
ContainerTable.cellPadding = "0"
ContainerTable.cellSpacing = "0"
DialogWin.container.appendChild(ContainerTable);

var tbody = document.createElement("tbody");
ContainerTable.appendChild(tbody);

var rowTop = document.createElement("tr");
tbody.appendChild(rowTop);

var TableCell = document.createElement("td");
TableCell.align = "center"
TableCell.valign = "middle"
rowTop.appendChild(TableCell);

var winFrame = document.createElement("DIV");
winFrame.className = "DialogWinFrame";
TableCell.appendChild(winFrame)

DialogWin.winTitle = document.createElement("DIV");
DialogWin.winTitle.className = "DialogWinTitle";
DialogWin.winTitle.innerHTML = ""
winFrame.appendChild(DialogWin.winTitle)

var winCont = document.createElement("DIV");
winCont.className = "DialogWinContent";
winFrame.appendChild(winCont)

DialogWin.ContText = document.createElement("DIV");
DialogWin.ContText.className = "DialogWinConText";
winCont.appendChild(DialogWin.ContText)

/*
DialogWin.image = document.createElement("IMG");
//DialogWin.intext.className = "DialogWinTextArea";
DialogWin.image.src = "http://www.mediabase.ch/mediabasefiles/10/thumbnail1/88000/86932.jpg"
DialogWin.image.height = "100"
winCont.appendChild(DialogWin.image)
*/

DialogWin.intext = document.createElement("TEXTAREA");
DialogWin.intext.className = "DialogWinTextArea";
winCont.appendChild(DialogWin.intext)



var winButtons = document.createElement("DIV");
winButtons.className = "DialogWinButtons";
winCont.appendChild(winButtons);


var winOkButton = document.createElement("DIV");
winOkButton.className = "DialogWinButton";
winOkButton.innerHTML = "Download"
winButtons.appendChild(winOkButton);
winOkButton.onmouseup = okDownload;

var winAbortButton = document.createElement("DIV");
    winAbortButton.className = "DialogWinButton";
    winAbortButton.innerHTML = "Abbrechen"
    winButtons.appendChild(winAbortButton);
    winAbortButton.onmouseup = DialogWin.Hide;

DialogWin.ContText2 = document.createElement("DIV");
DialogWin.ContText2.className = "DialogWinConText2";
winButtons.appendChild(DialogWin.ContText2)


}



DialogWin.Hide = function()
{
    Helpers.changeOpac(0,"DialogWinOverlay")
    Helpers.changeOpac(0,"DialogWinContainer")
    DialogWin.overlay.style.visibility = "hidden"
    DialogWin.container.style.visibility = "hidden"
}


DialogWin.Show = function()
{
    DialogWin.overlay.style.visibility = ""
    DialogWin.container.style.visibility = ""
    Helpers.opacity ("DialogWinOverlay", 0, 80, 300)
    Helpers.opacity ("DialogWinContainer", 0, 100, 300)
    DialogWin.intext.focus()
}


function okDownload()
{
//alert(encodeURIComponent(DialogWin.intext.value))
window.location = "http://" + window.location.hostname + DialogWin.OkUrl + "&cmt=" + encodeURIComponent(DialogWin.intext.value)
DialogWin.Hide();
}

function showDownWin(link)
{
    DialogWin.OkUrl = link;
    DialogWin.winTitle.innerHTML = "<b>Bild Download</b>"
    DialogWin.ContText.innerHTML = "Besten Dank f&uuml;r Ihr Interesse an unserer Fotografie. Nachstehend k&ouml;nnen Sie uns bei Bedarf eine Nachricht zum benutzten Bild hinterlegen.<br><br>"
    DialogWin.ContText2.innerHTML = "Das Herunterladen des Bildes gilt normalerweise als verbindliche Nutzung. Ist die Verwendung noch nicht sicher, nutzen Sie bitte die unentgeltliche Funktion &#34;Download zu Layoutzwecken&#34;."
    DialogWin.Show ();
}

	function adddebug (instr)
	{
		if (document.getElementById ("debugf"))
		{
		document.getElementById ("debugf").value = instr + "\n" + document.getElementById ("debugf").value;
		}
	}
    function clearDebug ()
	{
		if (document.getElementById ("debugf"))
		{
		document.getElementById ("debugf").value = "";
		}
	}


var Helpers = {};

Helpers.getPos = function(elem) 
{
	var c = new	Helpers.coords()
	c.x = elem.offsetTop;
	c.y = elem.offsetLeft;
	while (elem == elem.offsetParent) 
	{ 
		c.x += elem.offsetTop;
		c.y += elem.offsetLeft;
	}
	return c;
}

Helpers.coords = function() 
{
	this._x = 0;
	this._y = 0;
}


Helpers.opacity = function (id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("Helpers.changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd ) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("Helpers.changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
Helpers.changeOpac = function(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

Helpers.changeOpacByObject = function(opacity, object) {
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

var ToolTip = {};
ToolTip.built = false;
ToolTip.divFrame = null;
ToolTip.divContent = null;
ToolTip.divltr = null;
ToolTip.divrtc = null;
ToolTip.divlbc = null;
ToolTip.divrbc = null;

ToolTip.show = function(ref,innerHTML)
{

if(ToolTip.built == false)
{
    ToolTip.build();
    ToolTip.built = true;
}
else
{
    ToolTip.divFrame.style.visibility = "";
}
    
    
    c = Helpers.getPos(ref);
    
	
	//ToolTip.divFrame.style.left = (c.x + ref.offsetWidth + 11) + "px";
	//ToolTip.divFrame.style.top = (c.y + 20) + "px";
	
	ToolTip.divFrame.style.left = (ref.offsetLeft + ref.offsetWidth + 11) + "px";
	ToolTip.divFrame.style.top = (ref.offsetTop + (ref.offsetHeight / 2)) + "px";

return null;
}

ToolTip.hide = function()
{
   ToolTip.divFrame.style.visibility = "hidden";
}

ToolTip.build = function()
{
ToolTip.divFrame = document.createElement("DIV");
ToolTip.divFrame.className = "helpBox"
document.body.appendChild(ToolTip.divFrame);


ToolTip.Table = document.createElement("table");
ToolTip.Table.border = "0"
ToolTip.Table.cellPadding = "0"
ToolTip.Table.cellSpacing = "0"
ToolTip.divFrame.appendChild(ToolTip.Table);

ToolTip.tbody = document.createElement("tbody");
ToolTip.Table.appendChild(ToolTip.tbody);

ToolTip.rowTop = document.createElement("tr");
ToolTip.tbody.appendChild(ToolTip.rowTop);

ToolTip.rowMid = document.createElement("tr");
ToolTip.tbody.appendChild(ToolTip.rowMid);

ToolTip.rowBot = document.createElement("tr");
ToolTip.tbody.appendChild(ToolTip.rowBot);

//top row
ToolTip.cellTopLeft = document.createElement("td");
ToolTip.cellTopLeft.className = "helpBoxtdCorner"
ToolTip.rowTop.appendChild(ToolTip.cellTopLeft);

ToolTip.divltc = document.createElement("DIV");
ToolTip.divltc.className = "helpBox_ltc helpBoxCornerStyle"
ToolTip.cellTopLeft.appendChild(ToolTip.divltc);

ToolTip.cellTopMid = document.createElement("td");
ToolTip.cellTopMid.className = "helpBox_mts"
ToolTip.rowTop.appendChild(ToolTip.cellTopMid);

ToolTip.cellTopRight = document.createElement("td");
ToolTip.cellTopRight.className = "helpBoxtdCorner"
ToolTip.rowTop.appendChild(ToolTip.cellTopRight);

ToolTip.divrtc = document.createElement("DIV");
ToolTip.divrtc.className = "helpBox_rtc helpBoxCornerStyle"
ToolTip.cellTopRight.appendChild(ToolTip.divrtc);


//mid row
ToolTip.cellMidLeft = document.createElement("td");
ToolTip.cellMidLeft.className = "helpBox_mls"
ToolTip.rowMid.appendChild(ToolTip.cellMidLeft);


ToolTip.cellMidMid = document.createElement("td");
ToolTip.rowMid.appendChild(ToolTip.cellMidMid);
ToolTip.cellMidMid.className = "helpBox_content"
ToolTip.cellMidMid.innerHTML = "Blabenda in Bluben da"

ToolTip.cellMidRight = document.createElement("td");
ToolTip.cellMidRight.className = "helpBox_mrs"
ToolTip.rowMid.appendChild(ToolTip.cellMidRight);

//bottom row
ToolTip.cellBotLeft = document.createElement("td");
ToolTip.cellBotLeft.className = "helpBoxtdCorner"
ToolTip.rowBot.appendChild(ToolTip.cellBotLeft);

ToolTip.divlbc = document.createElement("DIV");
ToolTip.divlbc.className = "helpBox_lbc helpBoxCornerStyle"
ToolTip.cellBotLeft.appendChild(ToolTip.divlbc);

ToolTip.cellBotMid = document.createElement("td");
ToolTip.cellBotMid.className = "helpBox_mbs"
ToolTip.rowBot.appendChild(ToolTip.cellBotMid);

ToolTip.cellBotRight = document.createElement("td");
ToolTip.cellBotRight.className = "helpBoxtdCorner"
ToolTip.rowBot.appendChild(ToolTip.cellBotRight);

ToolTip.divrbc = document.createElement("DIV");
ToolTip.divrbc.className = "helpBox_rbc helpBoxCornerStyle"
ToolTip.cellBotRight.appendChild(ToolTip.divrbc);


//<table>
//<tr>
//<td></td>
//<td></td>
//<td></td>
//</tr>
//<tr>
//<td></td>
//<td></td>
//<td></td>
//</tr>
//<tr>
//<td></td>
//<td></td>
//<td></td>
//</tr>
//</table>


//ToolTip.divContent = document.createElement("DIV");
//ToolTip.divContent.className = "helpBox_content"
//ToolTip.divFrame.appendChild(ToolTip.divContent);


//ToolTip.divltc = document.createElement("DIV");
//ToolTip.divltc.className = "helpBox_ltc ltc cornerStyle"
//ToolTip.divContent.appendChild(ToolTip.divltc);

//ToolTip.divrtc = document.createElement("DIV");
//ToolTip.divrtc.className = "helpBox_rtc rtc cornerStyle"
//ToolTip.divContent.appendChild(ToolTip.divrtc);


//ToolTip.divlbc = document.createElement("DIV");
//ToolTip.divlbc.className = "helpBox_lbc lbc cornerStyle"
//ToolTip.divContent.appendChild(ToolTip.divlbc);

//ToolTip.divrbc = document.createElement("DIV");
//ToolTip.divrbc.className = "helpBox_rbc rbc cornerStyle"
//ToolTip.divContent.appendChild(ToolTip.divrbc);

ToolTip.divpc = document.createElement("DIV");
ToolTip.divpc.className = "helpBox_pc"
ToolTip.divFrame.appendChild(ToolTip.divpc);

//ToolTip.divHTML = document.createElement("SPAN");
//ToolTip.divHTML.innerHTML = "fuck you punk motherfucker"
//ToolTip.divContent.appendChild(ToolTip.divHTML);

//alert(ToolTip.divFrame.innerHTML);

return null;
}


