﻿function GeoCoding(address) 
{
    map = new GMap2(document.getElementById('map_canvas'));
    var SearchAddress = address; 
    geocoder = new GClientGeocoder();
    if (geocoder) 
    {
        geocoder.getLatLng(SearchAddress,
            function (point) 
            {
                if (!point) 
                {
                    alert(SearchAddress + ' was not found!');
                } else 
                {
                    map.setCenter(point, 13);
                    var marker = new GMarker(point);
                    map.addOverlay(marker);
                    marker.openInfoWindowHtml(SearchAddress);
                 }
             });
    }
}

function SelectContact(selectedId, address) {  
    
    if (document.getElementById('ctl00_SPWebPartManager1_ContactList1_ctl00_SelectedContact').value.length > 0) {
        $('#' + document.getElementById('ctl00_SPWebPartManager1_ContactList1_ctl00_SelectedContact').value + '_details').attr("class", "contatctdetails_hidden"); 
        $('#' + document.getElementById('ctl00_SPWebPartManager1_ContactList1_ctl00_SelectedContact').value + '_link').attr("class", "row");         
    }       

    // Store the newlwy selected item
    document.getElementById('ctl00_SPWebPartManager1_ContactList1_ctl00_SelectedContact').value = selectedId;
    
    $('#' + document.getElementById('ctl00_SPWebPartManager1_ContactList1_ctl00_SelectedContact').value + '_details').attr("class", "contatctdetails"); 
    $('#' + document.getElementById('ctl00_SPWebPartManager1_ContactList1_ctl00_SelectedContact').value + '_link').attr("class", "row active");         
    
    if ($.browser.msie) {
        $(".contact_also .active").corner("10px");
    } else if ($.browser.mozilla) {
        $(".contact_also .active").css("-moz-border-radius","10px");
    } else if ($.browser.webkit) {
        $(".contact_also .active").css("-webkit-border-radius","10px");
    }
 
    
    GeoCoding(address);
    
    //__doPostBack('__Page', 'MyCustomArgument');
}

function PerformSearch(url) 
{
    var searchValue = document.getElementById('search_text').value;
    // var url = window.location.href;
          
    //window.location = url + escape(searchValue);
    window.location = url + searchValue;
}

function InitMenu($ids)
{
$(document).ready(function() {   
        var soapEnv =
            "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
                <soapenv:Body> \
                     <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                        <listName>Tasks</listName> \
                        <viewFields> \
                            <ViewFields> \
                               <FieldRef Name='Title' /> \
                           </ViewFields> \
                        </viewFields> \
                    </GetListItems> \
                </soapenv:Body> \
            </soapenv:Envelope>";

        $.ajax({
            url: "http://2k3_moss2k7:3030/_vti_bin/lists.asmx",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            contentType: "text/xml; charset=\"utf-8\""
        });
    });
    
      function processResult(xData, status) {
        $(xData.responseXML).find("z\\:row").each(function() {
            var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>";
            $("#tasksUL").append(liHtml);
        });
    }
}	


function Accordion() 
{
    $('#accordion ul').hide(); // hide all unordered lists inside the accordion list   
    
    //$('#accordion a.active').parent().find('ul').show(); //show the active unordered list inside the accordion 
    
    $('#accordion a.active').closest('ul').show();  
    $('#accordion a.active').siblings('ul').show();     		
    
    $('#accordion li a').click(
	    function() {
	        var checkElement = $(this).next();
	        if ((checkElement.is('ul')) && (checkElement.is(':visible'))) { //if you click on an unordered list and this list is opened (visible)   
	            return false; //nothing happens   
	        }
	        if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) { //if you click on an unordered list and this list is not opened (visible)   
	            $($('#accordion ul:visible').parent()).find('a').removeClass("active")
	            $($('#accordion ul:visible').parent()).find('SPAN').html("Se alle &gt;")
	            $('#accordion ul:visible').slideUp('fast'); // the list that is visible will close (slideUp) 
	            /*$($('#accordion ul:visible').parent()).slideUp('fast'); // the list that is visible will close (slideUp) */
	            $(this).addClass("active");
	            $(this).children().html("&or;")
	            checkElement.parent().parent().slideDown('fast');
	            checkElement.parent().slideDown('fast');
	            checkElement.slideDown('fast'); //the list you clicked will open (slideDown)   
                //window.location = $($('#accordion ul:visible').parent()).find('a')[0].href;	            
                window.location = $($(this).parent()).find('a')[0].href;
	            return false;
	        }
	    }
    );
    
    $('#accordion a.active').parent().parent().parent().slideDown('fast')        
    $('#accordion a.active').parent().parent().slideDown('fast')    
}

function shareOnFacebook() {
    t = document.title;
    u = location.href;
    window.open('http://www.facebook.com/sharer.php?u=' + u + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436');
    return false;
}

function shareOnTwitter() {
    t = document.title;
    u = location.href;
    window.open('http://twitter.com/home?status=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'menubar=yes,toolbar=yes,resizable=yes,scrollbars=yes,width=600,height=600');
}

function ShowMore(list) 
{
    $(list + " > .item-hidden").attr("class", "item"); 
    $(list + " > .item-hidden-newline").attr("class", "item newline");     
}
function ShowAll(list) 
{
    $(list + " > .item-all").attr("class", "item"); 
    $(list + " > .item-all-newline").attr("class", "item newline");     
}

