/*
    SiteComponents version:
    6.6.4.1, tag SC_6_6_4_1, created Tue Oct 27 21:28:23 +0100 2009
    $Name: HEAD $

    Disclaimer
    
    While we make every effort to ensure that this code is fit for its intended
    purpose, we make no guarantees as to its functionality. CoreTrek AS will
    accept no responsibility for the loss of data or any other damage or
    financial loss caused by use of this code.


    Copyright
    
    This programming code is copyright of CoreTrek AS. Permission to run this
    code is given to approved users of CoreTrek's publishing system CorePublish.
    
    This source code may not be copied, modified or otherwise repurposed for use
    by a third party without the written permission of CoreTrek AS.
    
    Contact webmaster@coretrek.com for information.
    
*/

/**
 * Configuration for site components javascript
 *
 * Configuration array structure:
 * {<component>: {<parameter>: value, <parameter>: value, ... }, ...}
 */
var siteComponentsConfig = {
    
    // Configuration for the keyword module.
    
    'keywords': {
        'elements': ['placeholder-content'],
        'skiptags': ['h1','h2','h3','h4','h5','h6'],
        'usetooltip': true
    }
    // Remember to add a comma above when enabling more options
    
    /*
    // Use this to move the collapsed debug position to the left, instead
    // of the default right.
    'debug': {
        'collapsedPageInfoPosition': 'left'
    }
    */
    
    /*
    // Use this to override the default position for tooltip.
    // Valid values is:
    //   mouse (default), tooltip follows mouse
    //   element, tooltip is attached to the title element
    
    'tooltip': {
        'positionby': 'mouse'
    }
    */
    
    /*
    // Use this to override the default fontsizes in the fontsize selector
    // (html/lib/fontsize.js)
    
    'fontsize': {
        'sizes': ["10pt", "15pt", "24pt"]
    }
    */
    
};

/* Send form */
function ajaxThis(formId,statusId) {
		
    new Ajax.Request('/xmlhttprequest.php', {
        parameters: $(formId).serialize(true),
        method:'get',
        onSuccess: function(transport){
            var response = transport.responseText || "No response text";
            //$('sms_status').show();            
            //$('sms_status').blinddown();            
            $(statusId).update(response);
        },
        onFailure: function(transport){ 
            //alert(transport.status);
            //$('sms_status').show();
        	//$('sms_status').blinddown();
            $(statusId).update("Sending av skjema feilet! " + transport.status);
        }
        });
}

/**
 * 
 *  !!! Same as cplib.js version 6.6.6, but added allowfullscreen parameter for all flash files. !!!
 *  
 *  Function used to print flash and movies inline
 *
 *  *) These settings might not work in all browser plugins
 *
 *  @src         string The full URL to the video
 *  @sessionName string The session name where users sessionid is stored (used for IE)
 *  @width       int The width
 *  @height      int The height
 *  @mimetype    string The files mimetype
 *  @loop        boolean Whether or not to loop the video *
 *  @autoplay    boolean Whether or not to start the video when it's loaded *
 *  @controller  boolean Whether or not to include plugin controllers *
 */
function kulorWriteMediaObject(src, sessionName, width, height, mimeType, loop, autoplay, controller, objId, flashVars, skipIEWindowOnLoad) {
	
    var objectSettings = '';
    
    if(typeof skipIEWindowOnLoad == 'undefied' && skipIEWindowOnLoad != true) {
        skipIEWindowOnLoad = false;
    }
    
    // Detect protocol for codebase
    var codebaseProtocol = (src.substr(0,5)=='https'?'https':'http');

    // Check if this is a flash movie
    var isFlashMovie = new Object();
    isFlashMovie['video/x-flv'] = true;
    isFlashMovie['application/x-flash-video'] = true;
    isFlashMovie['video/flv'] = true;
    if (isFlashMovie[mimeType] != null){
        var displayheight = null;
        // set to same as height for floating controls
        if(typeof flashVars != 'undefined' && typeof flashVars['floatingcontrols'] != 'undefined' && flashVars['floatingcontrols'] == 'true') {
	        var displayheight = height;
        }
        
	    var flashVars = new Object();
	    flashVars["file"] = encodeURIComponent(src);
	    flashVars["width"] = width;
	    flashVars["height"] = height;
	    
	    if(displayheight != null) {
	        flashVars['displayheight'] = height;
	    }
	    
	    flashVars["overstrech"] = 'true';
	    flashVars["frontcolor"] = '0xFFFFFF';
	    flashVars["backcolor"] = '0x000000';
	    flashVars["lightcolor"] = '0xFFFFFF';
	    flashVars["autostart"] = autoplay?'true':'false';
	    flashVars["repeat"] = loop?'true':'false';
        flashVars["usefullscreen"] = 'true';

        // Add flash movie parameters
        objectSettings += '<param name="allowscriptaccess" value="always" />';
        objectSettings += '<param name="allowfullscreen" value="true" />';
        objectSettings += '<param name="flashvars" value="' + getQueryParamsFromObject(flashVars) + '" />';

        mimeType = 'application/x-shockwave-flash';
        src = CPLIBHTMLROOT +'/mediaplayer.swf';
    }

    // Handling IE specialties
    var rewriteMimeType = new Object();
    if (cpNavigatorUserAgentInfo.isIE){
        rewriteMimeType['audio/mpeg'] = 'application/x-mplayer2';
        rewriteMimeType['video/mpeg'] = 'application/x-mplayer2';
        rewriteMimeType['video/x-msvideo'] = 'video/x-ms-wmv';
    }
    // In some cases we must change the mimetype for IE :/
    if (rewriteMimeType[mimeType] != null){
        mimeType = rewriteMimeType[mimeType];
    }

    // Add object parameters
    if (mimeType != 'application/x-shockwave-flash') {
        objectSettings += '<param name="loop" value="' +(loop?'true':'false') +'" />';
        objectSettings += '<param name="autostart" value="' +(autoplay?'true':'false') +'" />';
        objectSettings += '<param name="controller" value="' +(controller?'true':'false') +'" />';
    } else {    	
    	// Added allowfullscreen here to allow all flash files to use full screen mode. Needed for site specific flash files.
    	objectSettings += '<param name="allowfullscreen" value="true" />';
        objectSettings += '<param name="wmode" value="opaque" />';
        if(typeof flashVars != "undefined") {
            objectSettings += '<param name="flashVars" value="' + getQueryParamsFromObject(flashVars) + '" />';
        }
    }

    // IE: We need to add sessionid to the URL in order for the video plugin to use the same session
    //     as IE. If sessionid is not sent, the video plugin will try to load the URL without a valid
    //     session causing the session to be destoyed.
    //     -----------------------------
    //     NOTE from Kurt: The session id broke together with the new JW FLV player. I first tried removing
    //     this alltogether, and it seem to work, event with user protected files. I can't get it
    //     to break whatever I do. To be sure not to reintroduce old bugs, I move this session stuff
    //     down here. This way it will be added for the non JW FLV players.
    if (cpNavigatorUserAgentInfo.isIE){
        var sep = (src.indexOf('?') > -1?'&':'?');
        var sessionID = cpReadCookie(sessionName);
        if (sessionID != null && sessionID.length > 0){
            var src = src +sep +sessionName +'=' +sessionID;
        }
    }

	// Build object tag and content
    var objectString = '';
    var objectStringStart = '<object type="' +mimeType +'" data="' +src +'" width="' +width +'" height="' +height +'">';
    var objectStringName = '<param name="movie" value="' +src +'" />';
    var objectStringFallback = '<p>(No plugin detected for your OS/browser)</p>';
    var objectStringEnd = '</object>';
    switch (mimeType) {
        case 'application/x-shockwave-flash':
            if (cpNavigatorUserAgentInfo.isIE){
                var objectStringStart = '<object codebase="'+codebaseProtocol+'://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' +width +'" height="' +height +'">';
            }
            break;
        case 'application/x-mplayer2':
        case 'video/x-ms-wmv':
        case 'video/x-msvideo':
    		// WMV, MPEG
            objectStringName = '<param name="src" value="' +src +'" />';
    		break;

    	case 'video/quicktime':
    	    // Quicktime in IE
    	    if (cpNavigatorUserAgentInfo.isIE){
    	        objectStringStart = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="'+codebaseProtocol+'://www.apple.com/qtactivex/qtplugin.cab" width="' +width +'" height="' +height +'">';
                objectStringName  = '<param name="src" value="' +src +'" />';
                break;
    	    }
    	    break;

    	case 'video/x-ms-asf':
    	    // ASF in IE
    	    if (cpNavigatorUserAgentInfo.isIE){
                objectStringName = '<param name="FileName" value="' +src +'" />';
                break;
    	    }
    	    break;

    	default:
    		break;
    }

    objectString += objectStringStart;
    objectString += objectStringName;
    objectString += objectSettings;
    objectString += objectStringFallback;
    objectString += objectStringEnd;
    
    // If no objId is provided, the object is written directly to the document
    // at the current rendering position
    if(objId == null || objId == false) {
        document.write(objectString);
    } else {
        try {
        	// When altering the DOM while the DOM is still loading, Internet
        	// Explorer will sometimes trigger the DOM Ready event to early. This
        	// can cause the infamous Operation Aborted error. We prevent this by
        	// delaying the innerHTML assigning until the DOM is fully loaded.
        	if(cpNavigatorUserAgentInfo.isIE && !skipIEWindowOnLoad) {
    	    	CpAddEvent(window, 'load', function() {
    	    		document.getElementById(objId).innerHTML = objectString;
    	    	});
        	} else {
        		document.getElementById(objId).innerHTML = objectString;
        	}
        } catch(e){
    		document.write(objectString);
        }
    }
}



function clearFormElement(formelement, value) {
	if(formelement.value == value) {		
		formelement.value = "";
	}
}

