function setFaq() {
    $j("#faq .categorySection .categoryHeader").click(function() {
        toggleQuestions($j(this));
        return false;
    });

    $j("#faq .categorySection .questions .qa .question").click(function() {
        toggleAnswers($j(this));
        return false;
    });
}



function toggleQuestions(currentElementContainer) {
        var currentQuestions = currentElementContainer.next();
    currentQuestions.slideToggle(400, function() 
        {
        });
}

function toggleAnswers(currentElementContainer) {
    var currentAnswer = currentElementContainer.next();
    currentAnswer.slideToggle(400, function() {
    });
}

// When the DOM has loaded, init the form link.
$(
	function() {
	    // Get the add new upload link.
	    var jAddNewUpload = $j("#add-file-upload");

	    // Hook up the click event.
	    jAddNewUpload
			.attr("href", "javascript:void( 0 )")
			.click(
				function(objEvent) {
				    AddNewUpload();

				    // Prevent the default action.
				    objEvent.preventDefault();
				    return (false);
				}
				)
		;

	}
	)





// This adds a new file upload to the form.
function AddNewUpload() {
    // Get a reference to the upload container.
    var jFilesContainer = $j("#files");

    // Get the file upload template.
    var jUploadTemplate = $j("#element-templates div.row");

    // Duplicate the upload template. This will give us a copy
    // of the templated element, not attached to any DOM.
    var jUpload = jUploadTemplate.clone();

    // At this point, we have an exact copy. This gives us two
    // problems; on one hand, the values are not correct. On
    // the other hand, some browsers cannot dynamically rename
    // form inputs. To get around the FORM input name issue, we
    // have to strip out the inner HTML and dynamically generate
    // it with the new values.
    var strNewHTML = jUpload.html();

    // Now, we have the HTML as a string. Let's replace the
    // template values with the correct ones. To do this, we need
    // to see how many upload elements we have so far.
    var intNewFileCount = (jFilesContainer.find("div.row").length + 1);
    $j("#fileCount").val(intNewFileCount);
    // Set the proper ID.
    jUpload.attr("id", ("file" + intNewFileCount));

    // Replace the values.
    strNewHTML = strNewHTML
		.replace(
			new RegExp("::FIELD2::", "i"),
			intNewFileCount
			)
		.replace(
			new RegExp("::FIELD3::", "i"),
			("connectionFeeFile" + intNewFileCount)
			)
	;

    // Now that we have the new HTML, we can replace the
    // HTML of our new upload element.
    jUpload.html(strNewHTML);

    // At this point, we have a totally intialized file upload
    // node. Let's attach it to the DOM.
    jFilesContainer.append(jUpload);
}





// When the DOM has loaded, init the form link.
$(
	function() {
	    // Get the add new upload link.
	    var jAddNewUpload = $j("#add-new-street");

	    // Hook up the click event.
	    jAddNewUpload
			.attr("href", "javascript:void( 0 )")
			.click(
				function(objEvent) {
	    AddNewRoad();

				    // Prevent the default action.
				    objEvent.preventDefault();
				    return (false);
				}
				)
		;

	}
	)

function AddNewRoad()
{
    InsertNewRoad("", "", "", "", "");
    
}


// This adds a new file upload to the form.
function InsertNewRoad(streetName, zip, city, fromNumber, toNumber) {
    // Get a reference to the upload container.
    var dynamicContainer = $j("#dynamicRoads");

    // Get the file upload template.
    var template = $j("#element-templates-street div.row");

    // Duplicate the upload template. This will give us a copy
    // of the templated element, not attached to any DOM.
    var newRow = template.clone();

    // At this point, we have an exact copy. This gives us two
    // problems; on one hand, the values are not correct. On
    // the other hand, some browsers cannot dynamically rename
    // form inputs. To get around the FORM input name issue, we
    // have to strip out the inner HTML and dynamically generate
    // it with the new values.
    var strNewHTML = newRow.html();

    // Now, we have the HTML as a string. Let's replace the
    // template values with the correct ones. To do this, we need
    // to see how many upload elements we have so far.
    var intNewFileCount = (dynamicContainer.find("div.row").length);
    $j("#streetCount").val(intNewFileCount + 1);
    // Set the proper ID.
    newRow.attr("id", (intNewFileCount));

    // Replace the values.
    var regExp = new RegExp("::FIELDNR::", "g");
    strNewHTML = strNewHTML.replace(regExp, intNewFileCount);

    // Now that we have the new HTML, we can replace the
    // HTML of our new upload element.
    newRow.html(strNewHTML);

    // At this point, we have a totally intialized file upload
    // node. Let's attach it to the DOM.
    dynamicContainer.append(newRow);

    // Bind "Google list element clicked"
    $(".selector" + intNewFileCount).bind("autocompleteselect", function(event, ui) {
    $.post('/Model/Address/AddressHandler.ashx?function=getallnumbers&input=' + Url.encode(ui.item.value), function(data) {
    var ddl = $(".dropdown" + intNewFileCount);
            var arData = data.split("|");

            //Clear ddl
            ddl.find("option").remove();

            //Fill ddl
            for (i = 0; i < arData.length; i++) {
                var optionValues = arData[i].split("#");

                ddl.append('<option value=' + optionValues[0] + '>' + optionValues[1] + '</option>');
            }
        });
    });

    // insert values: roadname, from/to numbers
    if (streetName != '')
       $("#txtStreet" + ($j("#streetCount").val()-1)).val(streetName+', '+zip+' '+city);
    if (streetName != "")
        SetNumbers(streetName, zip, city, $j("#streetCount").val()-1, fromNumber, toNumber);
}

function SetNumbers(streetName, zip, city, ddlNumber, fromNumber, toNumber)
{

    $.post('/Model/Address/AddressHandler.ashx?function=getnumbers&input=' + Url.encode(streetName +", " + zip + " " + city), function(data) {
        
        var ddlFrom = $("select#ddlNumberFrom" + ddlNumber);
        var ddlTo = $("select#ddlNumberTo" + ddlNumber);
        var arData = data.split("|")
        
        //Clear ddl
        ddlFrom.find("option").remove()
        ddlTo.find("option").remove()
        
        //Fill ddl
        for (i = 0; i < arData.length; i++) {
            var optionValues = arData[i].split("#");
            if (optionValues[1] == fromNumber)
                ddlFrom.append('<option value=' + optionValues[0] + ' selected>' + optionValues[1] + '</option>');
            else
                ddlFrom.append('<option value=' + optionValues[0] + '>' + optionValues[1] + '</option>');

            if (optionValues[1] == toNumber)
                ddlTo.append('<option value=' + optionValues[0] + ' selected>' + optionValues[1] + '</option>');
            else
                ddlTo.append('<option value=' + optionValues[0] + '>' + optionValues[1] + '</option>');
        }
       
    });
}

// When the DOM has loaded, init the form link.
$(
	function() {
	    // Get the add new upload link.
	    var jAddNewUpload = $j("#add-new-zip");

	    // Hook up the click event.
	    jAddNewUpload
			.attr("href", "javascript:void( 0 )")
			.click(
				function(objEvent) {
				    AddNewZip();

				    // Prevent the default action.
				    objEvent.preventDefault();
				    return (false);
				}
				)
		;

	}
	)

function AddNewZip()
{
    InsertNewZip("");
}


// This adds a new file upload to the form.
function InsertNewZip(value) {
    // Get a reference to the upload container.
    var dynamicContainer = $j("#dynamicZips");

    // Get the file upload template.
    var template = $j("#element-templates-zip div.row");

    // Duplicate the upload template. This will give us a copy
    // of the templated element, not attached to any DOM.
    var newRow = template.clone();

    // At this point, we have an exact copy. This gives us two
    // problems; on one hand, the values are not correct. On
    // the other hand, some browsers cannot dynamically rename
    // form inputs. To get around the FORM input name issue, we
    // have to strip out the inner HTML and dynamically generate
    // it with the new values.
    var strNewHTML = newRow.html();

    // Now, we have the HTML as a string. Let's replace the
    // template values with the correct ones. To do this, we need
    // to see how many upload elements we have so far.
    var intNewFileCount = (dynamicContainer.find("div.row").length);
    $j("#zipCount").val(intNewFileCount + 1);
    // Set the proper ID.
    newRow.attr("id", (intNewFileCount));

    // Replace the values.
    var regExp = new RegExp("::FIELDNR::", "g");
    strNewHTML = strNewHTML.replace(regExp, intNewFileCount);

    // Now that we have the new HTML, we can replace the
    // HTML of our new upload element.
    newRow.html(strNewHTML);

    // At this point, we have a totally intialized file upload
    // node. Let's attach it to the DOM.
    dynamicContainer.append(newRow);


    // set the selected value
    
    if (value != "")
        $("select#ddlArea" + intNewFileCount).val(value);
}




var Url = {

    // public method for url encoding
    encode: function(string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode: function(string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode: function(string) {
        string = string.replace(/\r\n/g, "\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode: function(utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while (i < utftext.length) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if ((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i + 1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i + 1);
                c3 = utftext.charCodeAt(i + 2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

function ShowVideo(div, url, image, autostart) {
    
    var element = document.getElementById(div);
    
    if(element)
    {
        var showWidth = element.style.width.replace("px", "");
        var showHeight = element.style.height.replace("px", "");
 
        try {
            var flashvars = {};
            flashvars.height = showHeight;
            flashvars.width = showWidth;
            flashvars.file = url;
            flashvars.type = "video";
            flashvars.autostart = Boolean(Number(autostart));
            flashvars.image = image;
            
            var params = {};
            params.allowscriptaccess = "sameDomain";
            params.allowfullscreen = "true";
            var attributes = {};
            
            swfobject.embedSWF('/resources/Argon/flash/player.swf', element.id, showWidth, showHeight, "9.0.0", "/resources/Argon/flash/expressInstall.swf", flashvars, params, attributes);

        } catch (exception) {}
    }
}
