﻿/// <reference path="jquery-1.3.2-vsdoc.js" />
var checkboxHeight = "25";
var radioHeight = "25";
var selectWidth = "190";

var serviceURL = "inspection-poll.ashx";

//var serviceURL="http://localhost:3429/inspection-poll.ashx";
var pollName = "poll1";

function showPollResults() {
    var selection = -1;
    if (document.poll_from.poll[0].checked) selection = 0;
    if (document.poll_from.poll[1]!=undefined && document.poll_from.poll[1].checked) selection = 1;
    if (document.poll_from.poll[2]!=undefined && document.poll_from.poll[2].checked) selection = 2;
    if (document.poll_from.poll[3]!=undefined && document.poll_from.poll[3].checked) selection = 3;
    
    var so = new SWFObject("NJ_polls.swf", "movie", "260", "105", "9");
    so.addVariable("serviceURL", serviceURL);
    so.addVariable("pollName", pollName);
    so.addVariable("option", selection.toString());
    so.addParam("wmode", "transparent");
    so.addParam("name", "NJpolls");
    so.write("poll_so");
    
    $('#poll_so').attr('style','padding:0px;');
    }

function loadFacilitiesSearch() {
    var so = new SWFObject("FacilitiesSearch.swf", "movie", "271", "390", "9");
    so.addParam("wmode", "transparent");
    so.addParam("name", "Facilities");
    so.write("facilities_search");
}
function showQuizResults() {

    
    
    scroll(0,0);
    var fn = document.forms.length

    var xsign = '<div style="padding:15px;"><div class="mark"><img height="20" width="20" src="images/AnswerX.jpg"/></div><div class="text">';
    var vsign = '<div style="padding:15px;"><div class="mark"><img height="20" width="20" src="images/AnswerV.jpg"/></div><div class="text">'
   
   var missing = "";
   for (var i = 0; i < fn; i++) {
       var pollsNum = document.forms[i].poll.length;
       var isempty = true;
       for (var u = 0; u < pollsNum; u++) {
           if (document.forms[i].poll[u].checked) isempty = false;
       }
       if (isempty) missing= missing + ((i+1).toString())+", ";
   }
   missing = missing.substring(0, missing.length-2);
   if (missing!="") {
    alert("You didn't answer the following questions: "+missing);
    return
    }
    $('#checkbtn').hide();
   for (var i=0; i<fn; i++) {
    var correctAns = "";

    var pollsNum = document.forms[i].poll.length;
    for (var x=0; x<pollsNum; x++) {
            try {
                var arr = String(document.forms[i].poll[x].value).split('|');
                for (var u=0; u<4; u++) {
                           if (document.forms[i].poll[u]!=undefined) {
                           
                           var ans = String(document.forms[i].poll[u].value).split('|');
                                if (ans[0]=="true") {
                                    correctAns = "The correct answer is: "+"<b>"+ans[1]+" </b>"+ans[2];
                                } else {
                                }
                            } else {
                            }
                }
                if (document.forms[i].poll[x].checked) {
                    var arr = String(document.forms[i].poll[x].value).split('|');
                    if (arr[0]=="true") {
                        var id = "optcon"+(i+1).toString();
                        $('#'+id).html(vsign+ correctAns + "</div></div>");
                    } else {
                        var result = "You selected: <b>"+arr[1]+" </b>"+arr[2]+"<br/>";
                                    var id = "optcon"+(i+1).toString();                    
                                    $('#'+id).html(xsign+ result+ correctAns +"</div></div>"); 
                    }   
                }
        } catch(err) {
            
        }
      }
   }
}

function showIQResults() {
    var correct = "";
    var xsign = '<div style="padding:10px 25px 10px 0px;"><div class="mark"><img height="20" width="20" src="images/AnswerX.jpg"/></div><div class="text">';
    var vsign = '<div style="padding:10px 25px 10px 0px;"><div class="mark"><img height="20" width="20" src="images/AnswerV.jpg"/></div><div class="text">'
   
    for (var i=0; i<4; i++) {
        var ans = document.IQ_from.IQ[i].value.split("|");
        if (ans[0] == "true") correct = "The correct answer is: "+ans[1];
    }
    //alert (correct);    
    for (var i=0; i<4; i++) {
        if (document.IQ_from.IQ[i].checked) {
            var ans1 = document.IQ_from.IQ[i].value.split("|");
            if (ans1[0] == "true") { 
                   $('#IQ_so').html('<div class="textGray" align="left">'+ vsign + correct+"</div>");            
             } else {
                   $('#IQ_so').html('<div class="textGray" align="left">'+xsign + "You selected: "+ans1[1]+" <br/>"+correct+"</div>");
            }
            
        }
    }
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_findObj(n, d) { //v4.01
    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_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
function MM_openBrWindow(theURL, winName, features) { //v2.0
    window.open(theURL, winName, features);
}

 function openLightBox(w,h, link){

    var lightBoxHtmlContent = "<iframe frameborder=0 id='myIframe' src='" + link + "' width='780' height='870'></iframe>";
    var frame = document.getElementById("lightBoxContent");
    var bg=document.getElementById("frameBg");
    var wrap=document.getElementById("lightBoxDiv");
    frame.innerHTML = lightBoxHtmlContent;

 wrap.style.width=w+"px";
 wrap.style.height=h+"px";

//alert(parseFloat(navigator.appVersion));
    if(parseFloat(navigator.appVersion)==4){
        h+=50;
    }
 frame.style.width=w+"px";
 frame.style.height=h+"px";

 wrap.style.left="50%";
 wrap.style.marginLeft=w/2*(-1)+"px";


 if(document.documentElement.scrollHeight>h){
 bg.style.height=document.documentElement.scrollHeight+"px";
 }else{
 var height = h+20
 bg.style.height=height+"px";
 }


 frame.style.display="block";
 wrap.style.display="block";
 bg.style.display = "block";
 
 
 }

 function closeLightBox(){
 var frame=document.getElementById("lightBoxContent");
 var bg=document.getElementById("frameBg");
 var wrap=document.getElementById("lightBoxDiv");
 frame.style.display="none";
 wrap.style.display="none";
 bg.style.display="none";

}

function loadQestioner(xml, divname, init) {
    var q = "";
    $.get(xml, null, function(data) {
        q += '<form name="'+divname+'_from"><p class="question">' + $(data).find('question').text().toUpperCase() + '</p><div id="'+divname+'_so" class="optionGroup">';

        $(data).find("option").each(function() {
            if ($(this).attr("answer") == "true") {
                q += '<p><input type="radio" name="' + divname + '" class="styled" value="true|'+ $(this).text()+'"/><span class="option ans">' + $(this).text() + '</span></p>'
            } else {
                q += '<p><input type="radio" name="' + divname + '" class="styled" value="false|'+ $(this).text()+'"/><span class="option">' + $(this).text() + '</span></p>'
            }
        })
        q += '</div></form>';
        $("#" + divname).html(q);
        //alert(init);
        if (init) {
            Custom.init();
        }
    });
}

function loadQuize(xml, divname) {
    var q = "";
    var counter = 0;
    $.get(xml, null, function(data) {
        $(data).find('item').each(function() {
            var num = $(this).find('question').attr('number');
            q += '<div class="question" style="width:500px; margin-left: 15px; text-indent: -13px;"><span><b>' + num + ' </b></span><span style="font-weight:normal;">' + $(this).find('question').text() + '</span></div>'
            counter++;
            q+= '<form name="Q'+counter.toString()+'">';    
            q += '<div id="optcon'+counter+'" class="optionGroup">';
            
            $(this).find("option").each(function() {
                var subNun = $(this).attr('number');
                if ($(this).attr("answer") == "true") {
                    q += '<p><input type="radio" name="poll" class="styled" value="true|'+subNun+"|"+ $(this).text()+'"/><span class="option"><b>' + subNun + ' </b>' + $(this).text() + '</span></p>'
                } else {
                    q += '<p><input type="radio" name="poll" class="styled" value="false|'+subNun+"|"+ $(this).text()+'"/><span class="option"><b>' + subNun + ' </b>' + $(this).text() + '</span></p>'
                }
            });
            q += '</div>'; //optGroup
            q += '</form>'; 
            q += '<div style="height:30px;"></div>';

        });
        $("#" + divname).html(q);
        Custom.init();
    });
}

function loadChecklist(xml, divname) {
    var q = ""
    $.get(xml, null, function(data) {
        $(data).find('item').each(function() {
            var num = $(this).find('question').attr('number');
            q += "<div class='checkboxGroup'>";
            q += '<div class="question"><span>' + $(this).find('question').text() + '</span></div><div>';
            $(this).find("option").each(function() {
                var subNun = $(this).attr('number');
                if ($(this).attr("answer") == "true") {
                    q += '<p><input type="checkbox" name="' + num + '" class="styled" /><span class="option">' + $(this).text() + '</span></p>'
                } else {
                q += '<p><input type="checkbox" name="' + num + '" class="styled" /><span class="option">'+ $(this).text() + '</span></p>'
                }
            });
            q += '</div>';
            q += '</div>';
            

        });
        $("#" + divname).html(q);
        Custom.init();
    });
}


$(document).ready(function() {

	$(".howDiff").click(function() {

		$("#poll").append("<img src=images/howdiff.png />");
    	$("#poll_so").remove();
		$(".howDiff").hide();

	
	});
	
	$(".wouldyoudrive").click(function() {

		$("#poll").append("<img src=images/wouldyoudrive.png />");
    	$("#poll_so").remove();
		$(".wouldyoudrive").hide();
	
	});
	
	$(".howOften").click(function() {

		$("#poll").append("<img src=images/howoften.png />");
    	$("#poll_so").remove();
		$(".howOften").hide();
	
	});
	
	$(".saveGas").click(function() {

		$("#poll").append("<img src=images/savegas.png />");
    	$("#poll_so").remove();
		$(".saveGas").hide();
	
	});
	

});

