﻿// JScript File
//        Response.Write("ok");
		//Set today's for cookie : date = date of Today
//		var date = new Date(" + Year(Now()) + "," + (Month(Now())-1) + "," 	Day(Now()) + "," & Hour(Now()) & "," & Minute(Now()) & "," & Second(Now()) & ");") & vbCrlf
		//Response.write ("alert(date);") & vbCrlf
	

function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : self.location.href) + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function Delete_Cookie(name,path,domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
       ( (path) ? ";path=" + path : self.location.href) +
       ( (domain) ? ";domain=" + domain : "") +
       ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

//var today = new Date();
var date = new Date();
// -- For testing purpose -- //
//var zero_date = new Date(y2k(date.getYear()),date.getMonth(),date.getDate());
//today.setTime(today.getTime() - zero_date.getTime());
//var todays_date = new Date(y2k(today.getYear()),today.getMonth(),today.getDate(),0,0,0);
//var expires_date = new Date(todays_date.getTime() + (8 * 7 * 86400));
//var expires_date = new Date(Date.UTC(y2k(date.getYear()),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds()) + (2 * 8640000));
var expires_date = new Date(Date.UTC(y2k(date.getYear()),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds())+ (36700*86400000));
//alert (expires_date);
//alert (Date.UTC(y2k(date.getYear()),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds())+ 8640000);

function storeMasterCookie() {
    if (!Get_Cookie('QPICookie'))
        Set_Cookie('QPICookie','ver1.0');
}

function storeIntelligentCookie(name,value) {
    if (Get_Cookie('QPICookie')) {	//do not check the stored cookie
        var IntelligentCookie = Get_Cookie(name);
        if ((!IntelligentCookie) || (IntelligentCookie != value)) {
		//alert ('stored->'+ 'name: ' + name  + ",value: " + value);
            Set_Cookie(name,value,expires_date);
            var IntelligentCookie = Get_Cookie(name);
            if ((!IntelligentCookie) || (IntelligentCookie != value))
                Delete_Cookie('QPICookie');
        }
    } else {
	//alert ('1st time stored->'+ 'name: ' + name  + ",value: " + value);
        Set_Cookie(name,value,expires_date);
    }
}

function onCheck(string) {
 if (string == "on" || string == "true") {
 	return true;
	}
 return false;
}

var src_loaded = true;

//src_loaded= false;
if (src_loaded) {
	storeMasterCookie();
}


function SetCookie() {
    if(arguments.length < 2) { return; }
    var n = arguments[0];
    var v = arguments[1];
    
    var exp = '';      
	exp = '; expires=' + expires_date.toGMTString();
	
    document.cookie = n + "=" + escape(String(v)) + '; path=/' + exp;    
} // function SetCookie()

function ReadCookie(n) {
    var cookiecontent = new String();
    if(document.cookie.length > 0) {
	    var cookiename = n+ '=';
	    var cookiebegin = document.cookie.indexOf(cookiename);
	    var cookieend = 0;
	    if(cookiebegin > -1) {
		    cookiebegin += cookiename.length;
		    cookieend = document.cookie.indexOf(";",cookiebegin);
		    if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
		    cookiecontent = document.cookie.substring(cookiebegin,cookieend);
		    }
	    }
    return unescape(cookiecontent);
} // function ReadCookie()
// —>



