/*
    ql_utilities.js

    Created by Heung Tai 6/16/2006

    Description: this file provides basic javascript function to send customization to the customize.php
    setAsQuickLink() is a function that will find all the elements with tag quickLinkElementTagName
    contained by the element with id quickLinkAreaID. Then put customization values in a query string
    base on qlCookieName and qlUrlCookieName. Finally, it makes a request to customize.php along with
    the data in the query string(variable name is newVal). The default procedure for putting customization
    is base on the assumption that quickLinkElementTagName is "input", and the name of the quicklink is in
    the value of it while the url of the quicklink is in the title of it.

    Dependency: create_request.js

    Note: remember to put in correct value of the customization part base on what you put in configure.php.
    Currently the customize.php doesnt send back any useful message, so updatePage() just refresh the page
    to apply new customization

*/

//customization start here
var maxQuickLink = 10; //should be put to be same as $MAX_QUICKLINK in configure.php
var qlCookieName = "fav"; //same as $QL_COOKIE_NAME in configure.php
var qlUrlCookieName = "ql"; // same as $QL_URL_COOKIE_NAME in configure.php
var defaultNotice = "default=yes"; //same as $DEFAULT_KEYWORD . "=" . $DEFAULT_KEYWORD_VALUE in configure.php
var quickLinkAreaID = "quicklinksChoice";
var quickLinkElementTagName = "input"; //if this is not "input", you need to modify two lines as indicated in setAsQuickLink()
//end customization

function setAsQuickLink(){
    var quickLinkArea = document.getElementById(quickLinkAreaID);
    var quickLinks = quickLinkArea.getElementsByTagName(quickLinkElementTagName);
    var newVal = "";
    for(i=0; i < quickLinks.length; i++){
	if(i == quickLinks.length - 1){
	    newVal += qlCookieName + i + "=" + escape(quickLinks[i].value) + "&" + qlUrlCookieName + i + "=" + escape(quickLinks[i].title); //possibly edit this line
	} else {
	    newVal += qlCookieName + i + "=" + escape(quickLinks[i].value) + "&" + qlUrlCookieName + i + "=" + escape(quickLinks[i].title) + "&"; // possibly edit this line
	}
    }
    makeHttpRequest("quick_link_customizer/customize.php?", 'updatePage',false,newVal);
}
function restoreToDefault(){
    makeHttpRequest("quick_link_customizer/customize.php?", 'updatePage', false, defaultNotice);
}
function updatePage(msg){
//    alert(msg);
    location.href = location.href;
}
