/* common shared watch list functions */

// get value of query string param
function getQueryParamValue(param) {
	var q = document.location.search || document.location.href.split("#")[1];
	if (q) {
		var detectIndex = q.indexOf(param +"=");
		var endIndex = (q.indexOf("&", detectIndex) > -1) ? q.indexOf("&", detectIndex) : q.length;
		if (q.length > 1 && detectIndex > -1) {
			return q.substring(q.indexOf("=", detectIndex)+1, endIndex);
		} else {
			return "";
		}
	}
}

// load window in parent and handle case when window has been closed
function loadInParent(url, windowName) {   
	if(window.opener == null || !window.opener || window.opener.closed) { 
		window.open(url,windowName);  
	} else { 
  		window.opener.focus();
  		window.opener.location = url; 
  	}
}

// sign up from a pop-up and get back to original page
function doRegister() {
	path = getQueryParamValue('path');
	if (path.indexOf('/3001-') > -1) {
		path = path + '&amp;idl=n';
	}
	url = 'http://www.download.com/1300-20_4-151.html?tag=wl_faq&path=' + path;
	loadInParent(url, 'cnetParent');
}

function openWatchListFAQ() {
	var path = escape(parent.location.href);
	var url = 'http://www.download.com/1200-20_4-5155971.html?path=' + path;
	popupWin = window.open(url, 'wl_faq', 'scrollbars,resizable,width=500,height=481');
	window.self.name = 'cnetParent';
}