
function GetCookie(name){
    alert('tester2');
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            return getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) 
            break;
    }
    return "null";
}



function getCookieVal(offset){
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}

//This function gets the cookies from file.
function grabCookies(form){
    //alert('tester1');
    if (form != null) {
		alert(form);
		var theLength = form.length;
		if (GetCookie(form.elements[0].name) != null) {
			for (var i = 0; i <= (theLength - 1); i++) {
				form.elements[i].value = GetCookie(form.elements[i].name);
			}
		}
	}
}

//This function is called whenever a user clicks a menu button. 
function MenuSubmit(Page){
    var Pagetype = Page + ' ';
    document.forms['TeePlus'].s.value = "-1";
    var tstype;
    if (Page == 1011) {
        Page = 'S101C';
        tstype = 1
    };
    if (Page == 1012) {
        Page = 'S101S';
        tstype = 2
    };
    document.forms['TeePlus'].t.value = Page;
    document.forms['TeePlus'].c.value = "8567094";
    if (Pagetype.slice(0, 2) != "NM_")// If the Page target string starts with NM_ then set the form action to teeplusapiv2.aspx
    {
        this.document.TeePlus.action = "http://teeplus.micropower.com.au/members/teeplusapiv2.aspx"; //This is for member pages
    }
    else {
        this.document.TeePlus.action = "http://teeplus.micropower.com.au/members/teeplusapi2.aspx"; //This is for non-member pages
    }
    document.forms['TeePlus'].submit();
}

//}

//This Fucntion replaces url %20's with blank spaces. Should have maybe used URLUNENCODE Instead
function StripSpace(stIn){
    var spo;
    stLen = stIn.length;
    spo = StringPOS(stIn, "%20", 0);
    if (spo != -1) {
        stIn = stIn.substr(0, spo) + " " + stIn.substr(spo + 3, stLen - spo)
        stIn = StripSpace(stIn); //Recursive Function call
    }
    return stIn;
}

//This Function returns the postion of one string within another
function StringPOS(s, c, startPos){
    var p = startPos;
    var le;
    var clen;
    le = s.length;
    clen = c.length;
    while (p < le) {
        if (s.substr(p, clen) == c) 
            return (p);
        p = p + 1;
    }
    return (-1);
}
