<!--

/*
	JavaScript Utility functions
	Functions:
	
	1. setMyCookie(value) - Set the value to the Cookie, replace the previous value
	2. appendMyCookie(value) - Appends the value to the Cookie
	3. getMyCookie() - Get the value stored in the cookie as String
	4. removeCookieValue()	- Remove the value from the Cookie
	5. removeMyCookie() - Set the Cookie empty
*/

var path="/";
var name="occcm";

function getAlertInfo(value)
{
	var alertInfo;
	switch(value) {
		case 'bidspec':
			alertInfo = 'Bid & Specification Contractor';
			break;
		case 'homeowner':
			alertInfo = 'Facility Owner';
			break;
		case 'designbuild':
			alertInfo = 'Design Build Contractor';
			break;
		case 'engineer':
			alertInfo = 'Consulting Engineer';
			break;
		case 'wholesaler':
			alertInfo = 'Wholesaler';
			break;
		case 'oem':
			alertInfo = 'Original Equipment manufacturers';
			break;
		case 'service':
			alertInfo = 'Service Dealer';
			break;		
	}
	return(alertInfo);
}

function setMyCookie(value)
{
	var strTemp = new String(getMyCookie());
	var strEscape = new String(escape(value));
	var expires=new Date("July 31, 2010");
	
	for(i = 0; i<value.length; i++){	
		strEscape =  strEscape.replace("","%20");
	}
	
	document.cookie = name + "="  + escape(value)  + ( (expires) ? ";expires=" + expires.toGMTString() : "") + 	( (path) ? ";path=" + path : "");
	
	var dispValue = getAlertInfo(value);
	alert('You have set up ' + dispValue + ' as your homepage');
	
}


function appendMyCookie(value)
{
	var strTemp = new String(getMyCookie())
	var strEscape = new String(escape(value))
	var expires=new Date("July 31, 2010");
	
	for(i = 0; i<value.length; i++){
	//strEscape =  strEscape.replace("%20", " ")
	strEscape =  strEscape.replace("","%20")
	}
//	alert(strTemp)
//	alert(strEscape)
//	alert(strTemp.indexOf(strEscape))
	
	if(strTemp.indexOf(escape(value))>=0)
	{
		alert("You've already submited it!")
		return;
	}
	
	
	if(!getMyCookie()){
		document.cookie = name + "="  + escape(value)  + ( (expires) ? ";expires=" + expires.toGMTString() : "") + 	( (path) ? ";path=" + path : "") 
	}else{
		document.cookie = name + "="  + getMyCookie() + ":" + escape(value) + ( (expires) ? ";expires=" + expires.toGMTString() : "")  + ( (path) ? ";path=" + path : "") //appending values to make one string, can then split
	}
	//alert(getMyCookie())
	//alert(expires.toGMTString());
	//window.close();
	//goToNextPage();
	
}

/*document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");*/


function getMyCookie()
{
	var start,len,end;
	start = document.cookie.indexOf(name+"=");
	len = start+name.length+1;
	if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
	if (start == -1) return null;
	end = document.cookie.indexOf(";",len);
	if (end == -1) end = document.cookie.length;
	//return ( unescape(document.cookie.substring(len,end)));
	return ( document.cookie.substring(len,end));
    
}

function removeCookieValue(strVal)
{
	var strTemp = new String(getMyCookie())
	var strRemove = new String(":"+strVal)
	strTemp =  unescape(strTemp)
	strTemp=strTemp.replace(strVal, "")
	strTemp=strTemp.replace("::", ":")
	document.cookie = name + "="  + escape(strTemp) + ( (path) ? ";path=" + path : "")
	document.location.reload();
}

function removeMyCookie()
{	
	document.cookie = name + "=" + ( (path) ? ";path=" + path : "")
	alert('Use the default homepage.');
	document.location.reload();
	
}
//-->


