/*checks if the product is in the project array
function isinproject(prodno) {
    var myProjectString = getCookie('myproject');
    
    if(!myProjectString) {
	return false;
    }
	var sender = createRequestObject();
	sender.open("get", "projectFunctions?option=inProj&projNum=" + myProjectString + "&prodno=" + prodno);

	var myProjectArray = myProjectString.split(",");

    for(var i=0; i<myProjectArray.length;i++) {
	if(myProjectArray[i] == prodno) {
	    return true;
	}
    }

    return false;
} */
function removeFromProj(prodnoArray) {
	var prodno = "";
	for (i=0;i<prodnoArray.length;i++)
	{
		prodno = prodno + "'" + prodnoArray[i] + "'";
		if (i != prodnoArray.length-1)
		{
			prodno = prodno + ",";
		}
	}
    //var myProjectString = getCookie('myproject2');
	sendReq('delete', prodno);   
}
function sendReq(option,prodno)
{
	http.open('get', '/projectFuncs.php?option=' + option + '&prodno=' + prodno);
    http.send(null);
}


function addToProj(prodno) {

    /*if(isSafari) {
	alert("The My Project feature requires Mozilla, Firefox, or IE for Mac");
	return;
    }*/

    var myProjectString = getCookie('myproject');

    if(!myProjectString) {
	myProjectString = prodno;
    } else {
	myProjectString += ",";
	myProjectString += prodno;
    }

    deleteCookie('myproject');
    setCookie('myproject', myProjectString, getExpDate(300,0,0));
	    
    //myProjectSetup();

    return false;
}

function setCookie(name, value, expires, path, domain, secure) {
path = "/";
	document.cookie = name + "=" + escape (value) + 
	((expires) ? ";	expires=" + expires : "") +
        ((path) ? "; path=" + path : "; path=/") +
        ((domain) ? "; domain=" + ".grohecatalog.com" : "; domain=.grohecatalog.com") +
        ((secure) ? "; secure" : "");
}

// utility function called by getCookie()
function getCookieVal(offset) {

    var endstr = document.cookie.indexOf (";", offset);

    if (endstr == -1) {
        endstr = document.cookie.length;
    }

    return unescape(document.cookie.substring(offset, endstr));
}

// primary function to retrieve cookie by name
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 deleteCookie( name, path, domain ) 
{
	while ( getCookie( name ) == null )
	{
		document.cookie = name + "=" +
		( ( path ) ? ";path=" + path : "") +
		( ( domain ) ? ";domain=" + domain : "" ) +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
}

function getExpDate(days, hours, minutes) {    
    
    var expDate = new Date();    
    
    if (typeof days == "number" && typeof hours == "number" && typeof hours == "number") {
        expDate.setDate(expDate.getDate() + parseInt(days));
        expDate.setHours(expDate.getHours() + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
        return expDate.toGMTString();
    }
}

