var isIE2 = false;
var req2;
var passurl2;
var reffile;
var NameOfCookie= 'RFP';
// if(document.domain =="our-mission-possible.com") { var address2= "http://roseburg.com/cgi-bin/s-mart.pl"; }
// if(document.domain =="www.our-mission-possible.com") { var address2= "http://www.roseburg.com/cgi-bin/s-mart.pl"; }
var address2= "http://roseburg.com/cgi-bin/s-mart.pl";

//---------------------------------------------------------------------||
// FUNCTION:    getCookieVal                                           ||
// PARAMETERS:  offset                                                 ||
// RETURNS:     URL unescaped Cookie Value                             ||
// PURPOSE:     Get a specific value from a cookie                     ||
//---------------------------------------------------------------------||
function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   // alert ("cookie :" + unescape(document.cookie.substring(offset, endstr)));
   // alert ("cookie :" + document.cookie.substring(offset, endstr));
   if ( endstr == -1 )
      endstr = document.cookie.length;
   return(unescape(document.cookie.substring(offset, endstr)));
}


//---------------------------------------------------------------------||
// FUNCTION:    FixCookieDate                                          ||
// PARAMETERS:  date                                                   ||
// RETURNS:     date                                                   ||
// PURPOSE:     Fixes cookie date, stores back in date                 ||
//---------------------------------------------------------------------||
function FixCookieDate (date) {
	var base = new Date(0);
	var skew = base.getTime();
	date.setTime (date.getTime() - skew);
}


//---------------------------------------------------------------------||
// FUNCTION:    GetCookie                                              ||
// PARAMETERS:  Name                                                   ||
// RETURNS:     Value in Cookie                                        ||
// PURPOSE:     Retrieves cookie from users browser                    ||
//---------------------------------------------------------------------||
function GetCookie (name) {
   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:    SetCookie                                              ||
// PARAMETERS:  name, value, expiration date, path, domain, security   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Stores a cookie in the users browser                   ||
//---------------------------------------------------------------------||
function SetCookie (name,value,expires,path,domain,secure) {
// var theDate = new Date();		// create Date object with the current date;
//var temp = theDate.toGMTString();	// convert date to a GMT string;
//var theSecondDate = new Date(temp);	// convert string to a Date object
//expires = theSecondDate;
// alert(name + " - " + value + " - " + expires + " - " + path + " - " + domain + " - " + secure);
// document.cookie = name + "=" + escape (value) +
document.cookie = name + "=" + value + ((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}

//---------------------------------------------------------------------||
// FUNCTION:    DeleteCookie                                           ||
// PARAMETERS:  Cookie name, path, domain                              ||
// RETURNS:     null                                                   ||
// PURPOSE:     Removes a cookie from users browser.                   ||
//---------------------------------------------------------------------||
function DeleteCookie (name,path,domain) {
   if ( GetCookie(name) ) {
      document.cookie = name + "=" +
                        ((path) ? "; path=" + path : "") +
                        ((domain) ? "; domain=" + domain : "") +
                        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
   }
}

function loadXMLStore() {
	// alert("Here is the URL:" + passurl);
	// passurl = url;
	var readurl2;
	var spoiler=new Date();
	// readurl2 = passurl2 + '&host=' + (now.getSeconds());
	// if (host) { readurl2 = passurl2 + '&host=' + host; }
	// else { readurl2 = passurl2 + '&host=' + (now.getSeconds()); }
	readurl2 = passurl2 + '&reffile=' + reffile + '&type=check&spoiler=' + (spoiler.getSeconds());
	// alert("Here is the URL:" + readurl2);
  		
	if (window.XMLHttpRequest) {
		req2 = new XMLHttpRequest();
        req2.onreadystatechange = processReqChange2;
        req2.open("GET", readurl2, true);
        req2.send(null);
    } 
	else if (window.ActiveXObject) {
    	isIE2 = true;
        req2 = new ActiveXObject("Microsoft.XMLHTTP");
        if (req2) {
        	req2.onreadystatechange = processReqChange2;
			req2.open("GET", readurl2, true);
            req2.send();
        }
    }
}

function processReqChange2() {
	if (req2.readyState == 4) {
    	if (req2.status == 200) {
			displaystore();
		} 
		else {
        	alert("There was a problem retrieving the XML data: " + req2.statusText + " " + passurl2);
        }
    }
}

function displaystore() {
	// print resulting data onto page in Store div
	// div = document.getElementById("LogScr");
	// With date
	// div.innerHTML = '<b>' + (new Date).toLocaleString() + '</b><br>' + req.responseText;
	// Without date
	// div.innerHTML = req2.responseText;
	if (req2.responseText == 'Login Found') { 
		alert(req2.responseText + "Login name already exists please choose another"); 
		window.document.register.login.focus();
	}
}

function ShowStore(cmd) {
	// cmd = "?command=nothing"; 
	passurl2 = address2 + cmd;
	// alert ("URL: " + passurl2);
	loadXMLStore();
}

function AddItem(cmd) {
	// document.getElementById("pause").style.color="#FF0000"
	quant = document.getElementById("itemquant").value;
	passurl2 = address2 + cmd + "&itemquant=" + quant;
	// MsgBox ("URL: " + passurl);
	loadXMLStore();
}

function SetCookieValue() {
	theDate = new Date();
	CookieName = NameOfCookie;
	CookieValue = theDate.getUTCFullYear(); // Set Year

	TempVal = (theDate.getUTCMonth() + 1);
	if (TempVal < 10) { TempVal = "0" + TempVal }
	CookieValue = CookieValue + "" + TempVal;  // Set Month

	TempVal = theDate.getUTCDate();
	if (TempVal < 10) { TempVal = "0" + TempVal }
	CookieValue = CookieValue + "" + TempVal;	// Set Day of Month	
	
	TempVal = theDate.getUTCHours();
	if (TempVal < 10) { TempVal = "0" + TempVal }
	CookieValue = CookieValue + "" + TempVal;	// Set Hours 24hr format

	TempVal = theDate.getUTCMinutes();
	if (TempVal < 10) { TempVal = "0" + TempVal }
	CookieValue = CookieValue + "" + TempVal;	// Set Minutes

	TempVal = theDate.getUTCSeconds();
	if (TempVal < 10) { TempVal = "0" + TempVal }
	CookieValue = CookieValue + "" + TempVal;	// Set Seconds

	CookieValue = CookieValue + "" + theDate.getUTCMilliseconds();	// Set Milliseconds
	CookieExpire = "";
	CookiePath = "";
	CookieDomain = "";
	CookieSecurity = "";
	SetCookie(CookieName, CookieValue, CookieExpire, CookiePath, CookieDomain, CookieSecurity);
	reffile = CookieValue;
}

function StampIt() {
	theDate = new Date();
	// CookieName = NameOfCookie;
	CookieValue = theDate.getUTCFullYear(); // Set Year

	TempVal = (theDate.getUTCMonth() + 1);
	if (TempVal < 10) { TempVal = "0" + TempVal }
	CookieValue = CookieValue + "" + TempVal;  // Set Month

	TempVal = theDate.getUTCDate();
	if (TempVal < 10) { TempVal = "0" + TempVal }
	CookieValue = CookieValue + "" + TempVal;	// Set Day of Month	
	
	TempVal = theDate.getUTCHours();
	if (TempVal < 10) { TempVal = "0" + TempVal }
	CookieValue = CookieValue + "" + TempVal;	// Set Hours 24hr format

	TempVal = theDate.getUTCMinutes();
	if (TempVal < 10) { TempVal = "0" + TempVal }
	CookieValue = CookieValue + "" + TempVal;	// Set Minutes

	TempVal = theDate.getUTCSeconds();
	if (TempVal < 10) { TempVal = "0" + TempVal }
	CookieValue = CookieValue + "" + TempVal;	// Set Seconds

	CookieValue = CookieValue + "" + theDate.getUTCMilliseconds();	// Set Milliseconds
	CookieExpire = "";
	CookiePath = "";
	CookieDomain = "";
	CookieSecurity = "";
	// reffile = CookieValue;
	return CookieValue;
}

function DisplayCookie() {
	CookieName = document.getElementById("COName").value;
	data = GetCookie(CookieName);
	// alert("data from cookie Named :" + CookieName + " : " + data);
	OutPutSpan();
}

function checklogin(pass) {
	CookieName = NameOfCookie;
	data = GetCookie(CookieName);
	// alert("Data :" + pass);
	
	if (!data) { 
		// SetCookieValue(); 
		passurl2 = address2 + pass;
	}
	else { 
		// stamp = data; 
		passurl2 = address2 + pass;
	}
	// alert ("URL: " + passurl2);
	// setRetRef();
	loadXMLStore();
}

function comppass() {
password = document.getElementById("password").value;
password2 = document.getElementById("password2").value;
if (password != password2) {
	alert("Passwords do not match please re-enter");
	window.document.register.password.focus();
}
}

// function passcookie() {
// 	CookieName = NameOfCookie;
// 	document.getElementById("COName").value = GetCookie(CookieName);
// }

function myobject() {
  this.containedValue = 0;
  this.othercontainedValue = 0;
  this.anothercontainedValue = 0;
}



// window.onload=initstore;
