

// idriveClipSideload
//
// Mama function to clip or sideload anything.
// if there are two args, the sideload action will take place in a pop-up window; else, it'll happen in the site's window

// ************moved from whatis page
// getValueFromCookie
	function getValueFromCookie(parameter)
	{
		var allcookies = document.cookie;
		var allcookies = unescape(allcookies);
		var cookieParam = 'IDRIVE_SIGNUP';

		// initialize lame vars
		var paramValue = '';
		var item = '';

		// get the cookieVal for cookieParam
		var start = allcookies.indexOf(cookieParam + '=');
		if (start == -1) return 'Save';
		start += cookieParam.length + 1;
		var end = allcookies.indexOf(';', start);
		if (end == -1) end = allcookies.length;
		var cookieVal = allcookies.substring(start, end);

		var a = cookieVal.split('&');

		for(var i=0; i < a.length; i++)
		{
			item = a[i].split('=');
			//alert(item);
			if (item[0] == parameter)
			{
				paramValue = item[1];
			}
		}

		if ((parameter == "objectType") && ((paramValue == "clipping") || (paramValue == "Clip") || (paramValue == "clip")))  
		{
			return 'Clip';
		}
		else if ((parameter == "objectType") && (paramValue != "clipping") && (paramValue != "Clip") && (paramValue != "clip")) 
		{
			return 'Sideload&#153;';
		}
		else
		{
			return unescape(paramValue);
		}	
	}
	
	// redirect to signup page if user has no idrive 
	function redirectNo()
	{
		var params = getParameters();
		var redirectURL = "/mydrive/accounts/signupZD.jsp" + params;
		parent.main.location.href = redirectURL;
	}

	// redirect to login page if user has idrive 
	function redirectYes()
	{
		var params = getParameters();
		var redirectURL = "home.html" + params;
		parent.main.location.href = redirectURL;
	}
	
	
	// Get the parameters from href
	function getParameters()
	{
		var result = "";	

		var url			= parent.main.location.href;
		var beginParams	= url.indexOf("?");
		
		if (beginParams != -1)
		{
			var start	= beginParams;
			var end = url.length;

			result = url.substring(start, end);
		}

		return result;
	}

// **********************

function 
idriveClipSideload(inURL, inRealWorldName, inLoadOrClip, inWantNewWindow)
{
	var kSideloadURL	= "http://www.idrive.com/mydrive/sideload.jsp";
	var params			= "partner=generic" + "&path=" + escape(inURL) + "&realWorldName=" + escape(inRealWorldName) + "&objectType=" + inLoadOrClip;
	var url				= kSideloadURL + "?" + params;
	

		// Open up in a new window and do the sideload stuff
		var newWin = window.open(url, 'sideloadWin', 'toolbar=0,menubar=0,scrollbars=1,fullscreen=0,resizable=0,width=510,height=420');
		
		// Bring that window to front.
		newWin.focus();
}


// idriveClip
//
// Grab the url of the current document and clip that page to idrive.
//
// Now accepts 2 params; if no values are passed in, pageToBeClipped and titleToBeClipped will simply
// be the page that has the clip button on it, as before
function 
idriveClip(pageToBeClipped, titleToBeClipped)
{	
	var openerPageURL;
	var openerPageTitle;
	
	if (pageToBeClipped != null)
	{
		openerPageURL = pageToBeClipped;
	}
	else
	{
		// Grab the URL of the page/frame being clipped
		openerPageURL = document.URL;
	}

	if (titleToBeClipped != null)
	{
		openerPageTitle = titleToBeClipped;
	}
	else
	{
		// Grab the title of the page being clipped (gets the frameset title, since this is the only title the user ever sees...)
		openerPageTitle = top.document.title;
	}

	// clipping is the "type" that the sideloader uses for knowing what kind
	// of object is being sideload (tm) saved.
	idriveClipSideload(openerPageURL, openerPageTitle, 'clipping', false);
}


// idriveSideload
//
// Sideload the url to an i-drive.
function 
idriveSideload(targetFileURL, realWorldName)
{	
	idriveClipSideload(targetFileURL, realWorldName, 'file', false);
}

