function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_showHideLayers() {
 var i,p,v,obj,args=MM_showHideLayers.arguments;
 for (i=0; i<(args.length-2); i+=3)
   if ((obj=MM_findObj(args[i]))!=null)
   { 
     v=args[i+2];
     if (obj.style)
     {
      obj=obj.style;
      v=(v=='show')?'block':(v=='hide')?'none':v;
     }
     obj.display=v;
   }
}
/*
function MM_showHideLayers() {
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
    obj.display=v; }
}
*/
function change_kulbutton_status()
{ 
  var i, p, v,obj,args=change_kulbutton_status.arguments;
  for (i=0; i<(args.length-1); i+=2)
   if ((obj=MM_findObj(args[i]))!=null)
   {
     v=args[i+1];
     if(v=='on')
     {
       p =  "/custom/karten/images/map_change__" + args[i] + "_1.gif";
     }
     else
     {
       p =  "/custom/karten/images/map_change__" + args[i] + "_2.gif";
     }
     obj.setAttribute("src", p);
   }
}
function change_map_pic(map_id, set_pic)
{
  if((obj=MM_findObj(map_id))!=null && set_pic != null)
  {
    set_pic = "/custom/karten/images/" + set_pic;
    obj.setAttribute("src", set_pic);
  }
}

function openWindow(theURL,winName,features) {
  mywindow=window.open(theURL,"popupwindow",features);
  //window.open("/abc/","title","");
}
function addfavorite() 
{
	if (window.external) 
	{
         external.AddFavorite(document.location.href,document.title);
    } 
    return;
}
function IFRAME_size_to_content(iframe_id) 
{
		 var the_height=document.getElementById(iframe_id).contentWindow.document.body.scrollHeight;//find the height of the internal page
		 document.getElementById(iframe_id).style.height=the_height + "px";		
     //container div in layout must also be resized 
     document.getElementById(iframe_id + '_container').style.height = the_height + 'px';
}   

function createcontent (folderid,secdescid)
{
	return window.open ("/admin/worklist/contextedit/itemcreatein.asp?secdescid=" + secdescid + "&awfolderid=" + folderid,"CONTEXTEDIT","toolbar=no,width=780,height=650,directions=no,status=yes,scrollbars=yes,menubar=no");
}

function show_main_menu(position, set_active, count_children)
{
  try 
  {
    if(position != "")
    {
      var dom_node_main = document.getElementById(position + "_main");
      if(count_children > 0)
      {
        var dom_node_subbox = document.getElementById(position + "_subbox");    
        if(dom_node_subbox.style.display == 'block')
          dom_node_subbox.style.display = 'none';
        else
          dom_node_subbox.style.display = 'block';
      }
    }
    if(set_active!=1)
    {
      //dom_node_main.style.backgroundImage = 'url(/custom/kws/images/navigation/kws_saat_ag__navi_aktiv.jpg)';
        //dom_node_main.style.color = '#FFF';
        
        // alto: setAttribte-class funktioniert leider nicht im MSIE
        
        var isIe/*@cc_on = true@*/;
        if(isIe)
          dom_node_main.setAttribute("className", "main_menu_link_act");
        else
          dom_node_main.setAttribute("class","main_menu_link_act");
    }
  } 
  catch (e) {};
}
      
function hide_main_menu(position, set_active)
{
  try
  {
    var dom_node_subbox = document.getElementById(position + "_subbox");
    var dom_node_main = document.getElementById(position + "_main");
        
    if(position != "")
    {
      dom_node_subbox.style.display = 'none';
      if(set_active!=1)
      {
        //dom_node_main.style.backgroundImage = 'url(/custom/kws/images/navigation/kws_saat_ag__navi_inaktiv.jpg)';
        //dom_node_main.style.color = '#000';
        
        // alto: setAttribte-class funktioniert leider nicht im MSIE
        var isIe/*@cc_on = true@*/;
        if(isIe)
          dom_node_main.setAttribute("className", "main_menu_link");
        else
          dom_node_main.setAttribute("class","main_menu_link");

      }
    }
  }
  catch (e) {};
}

function getmaincontent(strlink) {
    if(strlink.indexOf('?')==-1)    
       addparams="?";    
    else    
       addparams="&";
    

    $.ajax({
        type: "GET",
        dataType: "html",       
        url: strlink + addparams + "g=" + guid(),
        //contentType: "application/x-www-form-urlencoded;charset=ISO-8859-1",
        success: function (htmlcontent) {

            var blockhtml = $(htmlcontent).find("#block_1_large > div");
            if (blockhtml.length == 0) {
                blockhtml = $(htmlcontent).find("#block_1 > div");
            }            
            if (blockhtml.length > 0) {
                var block = $("#block_1");
                if (block.length == 0) {
                    block = $("#block_1_large");
                }
                if (block.length > 0) {
                    var linklistmiddle = $("#linklistmiddle");
                    if (linklistmiddle.length > 0) {
                        linklistmiddle.prev().remove();
                        linklistmiddle.before(blockhtml);
                    }
                    else {
                        block.html(blockhtml);
                    }
                }
                //blockhtml.insertAfter("#block_1 > div");
                //$("<h2>test</h2>").insertAfter("#block_1");



                /*$(this).prev('input')

                if (block.length > 0) {
                
                }*/
            }
        }
    });
}


function S4() {
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
function guid() {
    return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}


function denyFrameParent()
{
  if (top!=self) { top.location=self.location; }
}

function uploadsurveyfile(surveyitemid) {
    
    var options = {
        //target: '#output1',   // target element(s) to be updated with server response 
        //target: "div#doc_" + surveyitemid,
        //beforeSubmit: showRequest,  // pre-submit callback 
        success: showResponse,  // post-submit callback 

        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        type: "post"        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  "xml"        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 

        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    };

    // bind form using 'ajaxForm'    
    $('#form_' + surveyitemid).ajaxForm(options);
    $('#currentuploaditem').val(surveyitemid);
    $('#form_' + surveyitemid).submit();
}

function showResponse(responseText, statusText) {
    
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 

    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 

    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 

    //alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + '\n\nThe output div should have already been updated with the responseText.');    

    //Enable Rating CSS Stuff
    //$(function() { $('input[@type=radio].star').rating(); });
    //$(function() { $('input[@type=radio].staractive').rating(); });

    responseText=decodeURIComponent(responseText);
    var response_array = responseText.split("|||");
    var id = response_array[0];
    var name = response_array[1];
    
    var currentuploaditem = $('#currentuploaditem').val();
    $('#Frage_' + currentuploaditem + "_document").val(id);
    $('#Frage_' + currentuploaditem + "_documentname").val(name);
    $('#fileupload_' + currentuploaditem + "_name").html(" (" + name + ")");
    $('#docupload_' + currentuploaditem).hide();
    $('#fileupload_' + currentuploaditem).show();

}

function showuploaddiv(surveyitemid) {
    //alert($('#fileupload_' + surveyitemid).offset().top);
    //$('#loader').css('top', postop + halfscreenheight - 100);   
    $('#docupload_' + surveyitemid).css('top', $('#fileupload_' + surveyitemid).offset().top);
    $('#fileupload_' + surveyitemid).hide();
    $('#docupload_' + surveyitemid).show();

}
