﻿// JScript File

function getcookie(name) {
	var cookie = document.cookie;

	// split it into key-value pairs
	var cookie_pieces = cookie.split(';');

	// for each of those pairs, split into key and value
	for(var i=0; i<cookie_pieces.length; i++) {

		// get the cookie piece and trim it
		var piece = trim(cookie_pieces[i]);

		// find the location of the '=' and split the string
		var a = piece.indexOf('=');
		if (a == -1) {
			// there was no '=' - so we have a key and no value
			var key = piece;
			var value = '';
		} else {
			// we found an '=' - split the string in two
			var key = piece.substr(0, a);
			var value = piece.substr(a + 1);
		}

		// now display our cookies
		if (key == name) {
		    return unescape(value);
		}
	}
}

function setcookie(name, value, scope, days) {
    if (scope == null) {
     scope = getscope();
    }
    var cookie = name + '=' + escape(value)
    
    if (days > 0) {
        var cookie_date = new Date();  // current date & time
        cookie_date.setDate(cookie_date.getDate() + days);
        cookie = cookie + '; expires=' + cookie_date.toGMTString();
    }
    
    cookie = cookie + '; path=' + scope + ';';
    
    document.cookie = cookie;
    return true;
}

function trim(str){
	
	if (str>'') {
	    
	    // trim off leading spaces
	    while (str.charAt(0) == ' '){
		    str = str.substring(1);
	    }
    	
	    //trim off trailing spaces
	    while (str.charAt(str.length - 1) == ' '){
		    str = str.substring(0,str.length - 1);
	    }
	    
    }
	return str;
}

function getscope() {
    var location = window.location.pathname;
    var i = location.lastIndexOf('/');
    if (i > 0) {
        location = location.substring(0, i + 1);
    }
    alert(location);
    return location;
}

