function SSLMenuLink(strHREFMain)
{
	var intPosFrame;
	var strHREFFrame;
	var intAppId;
	var strContentFrame;
	var serverName = "<% = DYN_FULLSERVER_NAME %>"
	var strHTTPS = "<% = HTTPS_STRING %>"
	
	strHREFFrame = parent.window.location.href;
	
	intAppId = GetAppId(strHREFFrame);
	
	switch (intAppId)
	{
		case 0 :
			// customer service app
			if (strHREFFrame.search("https")==-1)
			{
				strHREFFrame = strHREFFrame.replace("http","https");
			}
			intPosFrame = strHREFFrame.search("consumersenergy.com/");
			strContentFrame = strHREFFrame.substr(0,intPosFrame + 20);
			parent.frames[1].location = strContentFrame + FixLink(strHREFMain);
			break;
		case 1 :
			// online customer service app
			if (strHREFFrame.search("https")==-1)
			{
				strHREFFrame = strHREFFrame.replace("http","https");
			}
			intPosFrame = strHREFFrame.search("consumersenergy.com/");
			strContentFrame = strHREFFrame.substr(0,intPosFrame + 20);
			parent.frames[1].location = strContentFrame + FixLink(strHREFMain);
			break;
		case 2 :
			// Window Link app
			
			window.location.href = strHTTPS +"://" + serverName + "/" + strHREFMain;
			break;	
		default :
			// SSL "Smart Forms"
			///////////////////////////////////
			//  - get the lower frame's url and pull off the domain
			//  - Added name value pair to the link below - name = lasturl and value is the truncated 
			//    url from the lower frame performed via GetLastFrameLink
			///////////////////////////////////
			var framelink;
			framelink = GetLastFrameLink(serverName);
			parent.window.location.href =  strHTTPS +"://" + serverName + "/contact.asp?" + strHREFMain + "&lasturl=" + framelink;			
	}
}

function NonSSLMenuLink(strHREFMain)
{
	var intPosFrame;
	var strHREFFrame;
	var intAppId;
	var strContentFrame;

	if (strHREFMain == "" ) return;

	strHREFFrame = parent.window.location.href;

	intAppId = GetAppId(strHREFFrame);
	
	switch (intAppId)
	{
		case 0 :
			// customer service app
			if (strHREFFrame.search("https")>-1)
			{
				strHREFFrame = strHREFFrame.replace("https","http");
			}
			intPosFrame = strHREFFrame.search("consumersenergy.com/");
			strContentFrame = strHREFFrame.substr(0,intPosFrame + 20);
			parent.frames[1].location = strContentFrame + FixLink(strHREFMain);
			break;
		default :
			// this is pw's code (unchanged)
			if (strHREFFrame.search("https")>-1){
				strHREFFrame = strHREFFrame.replace("https","http");
				intPosFrame = strHREFFrame.search("welcome.htm");
				if (intPosFrame > -1) {
				 strHREFFrame = strHREFFrame.substr(0,intPosFrame + 11);
				}
				parent.window.location.href =  strHREFFrame +  "?" + strHREFMain;
			}
			else {
				top.main.location.href = strHREFMain;
			}
	}
}

function GetAppId(strHREFFrame)
{
	var AppId;
	var AppKeyword = new Array();

	// AppKeyword() contains the names of applications. The string 
	// entered into the array will identify that the parent url
	// is not the website. A parent url that does not contain one 
	// of the app keywords will be assumed to be a website url.

	// Add new app keywords to the array as needed.
	// The array position becomes the AppId to use in the 
	// case structure in Non/SSLMenuLink.

	AppKeyword[0] = 'CustServ'
	AppKeyword[1] = 'OCSIndex'
	AppKeyword[2] = 'WinLink'
	
	for(AppId=0;AppId<AppKeyword.length;AppId++)
	{
		if (strHREFFrame.search(AppKeyword[AppId],"i") != -1)
		{
			break;
		}
	}

	return AppId;
}

function FixLink(strPage)
{
	// some cm links start with '../../'
	var i;
	i=0;
	while (i<strPage.length)
	{		
		if (strPage.substr(i).search("\\.\\.\\/")==-1)
		{
			break;
		}
		else
		{
			i += 3;
		}
	}
	return strPage.substr(i)
}

//  consumers energy - 11/27/2001
//  function will get the id of the main frame and will be used to paste onto the ssl link 
function GetLastFrameLink(serverName)
{	
	var framelink;

	framelink = parent.main.location.href;

	// remove the question mark - first position
	framelink = framelink.substring(framelink.indexOf(serverName) + serverName.length, framelink.length)

	// url encode in case there are multiple name value pairs on the frame link
	framelink = escape(framelink)

	return framelink;
}


