
/** Definition of ajax file path **/

var ptajax = 'scripts/ajaxfile.php';

function url( url ){
	location.href = url;
}

function goFaceBook() {

	targetURL  = 'http://www.facebook.com/sharer.php?u=';
	targetURL += encodeURIComponent(location.href);
	targetURL += '&t='+encodeURIComponent(document.title);
	window.open(targetURL,'sharer','toolbar=0,status=0,width=626,height=436');
}

function goMySpace() {

    var T ='Hvilket politisk parti er DU mest enig med?';
    var C  = '<p><b>Ditt valg. Din stemme.</b></p>';
    	C += '<p>Nå har du sjansen til å ta en test som er tilpasset deg!</p>';
	C += '<p>Du kan velge mellom en effektiv, middels eller grundig,<br />';
	C += ' alt etter hvor god tid du har!</p>';

	C += '<i>Partitesten Teamet</i></p>';
    var U  = 'http://www.partitesten.no';

    var targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent(T)
    + '&c=' + encodeURIComponent(C) + '&u=' + encodeURIComponent(U) + '&l=' + 2;
    window.open(targetUrl);
}

function goNettby() {

	var name = escape('Partitesten.no');
	var url = escape('http://www.partitesten.no');
	var description = escape('Din stemme - Ditt valg.');

	wnd  = window.open('http://www.nettby.no/user/edit_link.php?name='+name+'&url=' + url+'&description='+description,'edit_link','scrollbars=no,width=450,height=430');
	wnd.focus();
}

var inDisplayNow = "";

function display(ID){

	if(inDisplayNow != ID) {
	document.getElementById(ID).style.display = "block";

	if (inDisplayNow != "")
	document.getElementById(inDisplayNow).style.display = "none";

	inDisplayNow = ID;
	}
}


function tilbake(ID) {
	document.QuestionForm.trace.value=ID;
	submitQF();
}

function submitQF() {
	document.QuestionForm.submit();
}

function besvart(){

   var status = false;

	for ( s = 0; s < document.QuestionForm.svar.length; s++ ) {
	 if (document.QuestionForm.svar[s].checked) status = true;
	}

   return status;
}

function verify() {

	if ( ! besvart() ) {
	
		$("#dialog-message").dialog({
			width: 400,
			modal: true,
			buttons: {
				Ok: function() {
					$(this).dialog('destroy');
				}
			}
		});
		
		return false;
	
	} else return true;
}


function setAnswer(ID){
	document.getElementById(ID).checked = true;
}

function setSource(source) {
	document.kundeskjema.kilde.value = source;
}

function selectSource() {
	document.kundeskjema.file.value.selected = true;
}

function changeLook(pointer) {
	pointer.style.background = "#f3e8c3";

}

function reverseLook(pointer) {
	pointer.style.background = "#fff6d8";
}

function showHint(){
	
	$("#Hint").dialog({
		width: 400,
		modal: true,
		buttons: {
			Ok: function() {
				$(this).dialog('destroy');
			}
		}
	});
}

function swap(object) {

	var image = object.getElementsByTagName('img');
	var mark  = "_h.gif";

	var seperator = image[0].src.split(".gif");
	image[0].src = seperator[0]+mark;
}

function fade(object) {

	var image = object.getElementsByTagName('img');
	var mark  = ".gif";

	var seperator = image[0].src.split("_h.gif");
	image[0].src = seperator[0]+mark;
}

function showGrabIcon(pointer){
  document.body.style.cursor = "pointer";
  pointer.style.background = "transparent url(bilder/template/tint.png) no-repeat bottom center";
}

function hideGrabIcon(pointer){
  document.body.style.cursor = "auto";
  pointer.style.background = "transparent";
}

function showFlash(){
	// Major version of Flash required
	var requiredMajorVersion = 8;
	// Minor version of Flash required
	var requiredMinorVersion = 0;
	// Minor version of Flash required
	var requiredRevision = 0;
	// Version check based upon the values entered above in "Globals"
	return hasBigScreen() && DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
}


function hasBigScreen(){
	return pageWidth() > 300;
}

// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy the pageWidth() function but please keep the copyright notice as well
function pageWidth() {

		return window.innerWidth != null? window.innerWidth : 
				document.documentElement && document.documentElement.clientWidth ? 
				document.documentElement.clientWidth : document.body != null ? 
				document.body.clientWidth : null;
}





/** jQuery Style!!! */


function openChart( region )
{
    $.post(
        ptajax, {
            f: 'openchart',
            data: region 
        },
        function( response )
        {
            $("#region_full").html( response );

            $( "#region_full" ).dialog({
                height: 500,
                width: 600,
                modal: true
            });
        }
    );
}

function clearSession()
{
     $.post(
        ptajax, {
            f: 'clear_session'
        },
        function( response )
        {
            location.href = location.href;
        }
    );
}

function shadowIn( element )
{
     $( element ).animate({
        opacity: .6
     }, 300, "linear",
     function(){});
}

function shadowOut(element)
{
     $( element ).animate({
        opacity: 1
     }, 300, "linear",
     function(){});
}
