﻿$(document).ready(function() {
    $(".withDefaultValue").focus(function() {
        if ($(this).val() == this.defaultValue) {
            $(this).val('');
        }
    }).blur(function() {
        if ($(this).val() == '') {
            $(this).val(this.defaultValue);
        }
    });
});

// connor @2010-12-08
// returns an object which has fields like follow: (ig. The url is 'http://www.example.com/page.aspx?q=abc&p=efg')
// protocal[string]: the url protocal, the value can be 'http', 'https', 'ftp'. The default value is undefined.
// domain[string]: the ur domain, the value can be 'www.example.com'. The default value is undefined.
// pathAndQuery[string]: the url's path and query, the value can be '/page.aspx?q=abc&p=efg'. The default value is undefined.
// path[string]: the path without querystring, the value can be 'page.aspx'. The default value is undefined.
// query[string]: the querystring, the value can be 'q=abc&p=efg'(Notic that there isn't a '?' in this section). The default value is undefined.
// queries[object]: an object contains the query's key-value pair, the value is unescaped, each pair's default value is undefined, usage: var queryP = myUrl.queries['p']; or var queryP = myUrl.queries.p;
// page[string]: the request page name, the value can be 'page.aspx'. The default value is undefined.
// url[string]: the orignal url itself.

function SplitUrl(url) {
    var urlSections = {};
    var tempArray;
    var urlArray = url.split("//");
    var urlWithoutProtocalAndSlashes;
    var firstSlash_position;

    var protocal;
    var domain;
    var pathAndQuery;
    var query;
    var queries = {};
    var path;
    var page;

    if (urlArray.length > 1) {
        protocal = urlArray[0].substring(0, urlArray[0].length - 1); //the result will be 'http'|'https'|'ftp'
        urlWithoutProtocalAndSlashes = urlArray[1];
    }
    else {
        urlWithoutProtocalAndSlashes = urlArray[0];
    }
    firstSlash_position = urlWithoutProtocalAndSlashes.indexOf("/");
    if (firstSlash_position != -1) {
        domain = urlWithoutProtocalAndSlashes.substring(0, firstSlash_position);
    }
    pathAndQuery = urlWithoutProtocalAndSlashes.substring(firstSlash_position, urlWithoutProtocalAndSlashes.length);
    tempArray = pathAndQuery.split('?');
    path = tempArray[0];
    if (tempArray.length > 1) {
        query = tempArray[1];
        tempArray = query.split('&');
        for (i = 0; i < tempArray.length; i++) {
            var keyValuePair = tempArray[i].split('=');

            if (keyValuePair.length == 2) {
                queries[keyValuePair[0].toLowerCase()] = queries[keyValuePair[0].toUpperCase()] = keyValuePair.length > 1 ? unescape(keyValuePair[1]) : undefined;
            }
        }
    }
    tempArray = path.split('/');
    page = tempArray[tempArray.length - 1];

    urlSections.protocal = protocal;
    urlSections.domain = domain;
    urlSections.pathAndQuery = pathAndQuery;
    urlSections.path = path;
    urlSections.query = query;
    urlSections.queries = queries;
    urlSections.page = page;
    urlSections.url = url;

    return urlSections;
}

window.url = SplitUrl(window.location.href);

//split url end
