function faqPopup (url) {
	formWindow = window.open(url, 'faq', "width=800,height=600,toolbars=no,location=no,scrollbars=yes,resizable=yes,status=no");
	formWindow.focus();
}

function tosPopup (url, name, width, height) {
	tosWindow = window.open(url, name, "width=" + width + ",height=" + height + 
	",toolbars=no,location=no,scrollbars=yes,resizable=yes,status=no");
	tosWindow.focus();
}

function comment(com) {
	if (com == 'Please provide a short description of how we can help you.') {
		document.getElementById('user_comments').value = '';
	} 
}

function submitenter(myfield,e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13) {
		myfield.form.submit();
		return false;
	}
	else {
		return true;
	}
}

//this is for account center
var filename;
function detailFill(name,product,id,transid,key,date,status,sf,sortrev,pct) {
	//reload page for details
	self.location = 
	self.location.protocol+'//'
	+self.location.host
	+self.location.pathname+'?name='+name+'&id='+id+'&product='+product+'&s_f='+sf+'&s_r='+sortrev+'#'+product+transid;
	//populate download link with appropriate name, id, and key
	if (product == 'LG') {
		//document.getElementById('list_id').value = id;
		//document.getElementById('list_key').value = key;
		filename = name;
	} else if (product == 'LU') {
		//document.getElementById('batch_id').value = id;
		//document.getElementById('lu_id_key').value = key;
		filename = name;
	} else {
		//document.getElementById('profile_id').value = id;
		//document.getElementById('lp_id_key').value = key;
		filename = name;
	}
}

function lg_action(lg_name) {
	var a = '/mailing-lists/download/' + lg_name + '.xls';
	var b = '/mailing-lists/download/' + lg_name + '.csv';
	var c = '/mailing-lists/download/' + lg_name + '.rtf';
	if (document.getElementById('lg_xls').checked == true) {
		document.getElementById('lg_form').setAttribute('action', a );
	} else if (document.getElementById('lg_csv').checked == true) {
		document.getElementById('lg_form').setAttribute('action', b );
	} else {
		document.getElementById('lg_form').setAttribute('action', c );
	}
}

function lu_action(lu_name) {
	var d = '/list-update/download/' + lu_name + '.xls';
	var e = '/list-update/download/' + lu_name + '_match.xls';
	var f = '/list-update/download/' + lu_name + '_nomatch.xls';
	var g = '/list-update/download/' + lu_name + '_combined.xls';
	with (document.download_lu) {
		if (document.getElementById('lu_xls').checked == true) {
			document.getElementById('lu_form').setAttribute('action', d );
			document.getElementById('lu_type').value = 'xls';
		} else {
			document.getElementById('lu_form').setAttribute('action', g );
			document.getElementById('lu_type').value = 'combined';
		}
	}
}

function lp_action(lp_name) {
	var h = '/list-profile/download/' + lp_name + '.xls';
	var i = '/list-profile/download/' + lp_name + '_match.xls';
	var j = '/list-profile/download/' + lp_name + '_nomatch.xls';
	var k = '/list-profile/download/' + lp_name + '_combined.xls';
	with (document.download_lp) {
		if (document.getElementById('lp_xls').checked == true) {
			document.getElementById('lp_form').setAttribute('action', h );
			document.getElementById('lp_type').value = 'xls';
		} else if (document.getElementById('lp_match').checked == true) {
			document.getElementById('lp_form').setAttribute('action', i );
			document.getElementById('lp_type').value = 'match';
		} else if (document.getElementById('lp_nomatch').checked == true) {
			document.getElementById('lp_form').setAttribute('action', j );
			document.getElementById('lp_type').value = 'no_match';
		} else {
			document.getElementById('lp_form').setAttribute('action', k );
			document.getElementById('lp_type').value = 'combined';
		}
	}
}

function details_display(product) {
	if (document.getElementById('details_bottom').style.display == 'none') {
		document.getElementById('details_bottom').style.display = 'block';
		document.getElementById('list_details_link').style.backgroundImage = 'url(/static/images/toggle_arrow_up_blue.gif)';
		if (product == 'LG') {	
			document.getElementById('list_details_link').innerHTML = 'Hide Mailing List Details';
			document.getElementById('list_details_link').className = 'list_det_width_long_lg';
			document.getElementById('list_col_table_bg').style.maxHeight = '570px';
		} else if (product == 'LU') {
			document.getElementById('list_details_link').innerHTML = 'Hide Updated List Details';
			document.getElementById('list_details_link').className = 'list_det_width_long_lu';
			document.getElementById('list_col_table_bg').style.maxHeight = '600px';
		} else {
			document.getElementById('list_details_link').innerHTML = 'Hide Enhanced List Details';
			document.getElementById('list_details_link').className = 'list_det_width_long_lp';
			document.getElementById('list_col_table_bg').style.maxHeight = '540px';
		}
	} else {
		document.getElementById('details_bottom').style.display = 'none';
		document.getElementById('list_details_link').style.backgroundImage = 'url(/static/images/toggle_arrow_down_blue.gif)';
		if (product == 'LG') {	
			document.getElementById('list_details_link').innerHTML = 'Mailing List Details';
			document.getElementById('list_details_link').className = 'list_det_width_lg';
			document.getElementById('list_col_table_bg').style.maxHeight = '390px';
		} else if (product == 'LU') {
			document.getElementById('list_details_link').innerHTML = 'Updated List Details';
			document.getElementById('list_details_link').className = 'list_det_width_lu';
			document.getElementById('list_col_table_bg').style.maxHeight = '390px';
		} else {
			document.getElementById('list_details_link').innerHTML = 'Enhanced List Details';
			document.getElementById('list_details_link').className = 'list_det_width_lp';
			document.getElementById('list_col_table_bg').style.maxHeight = '390px';
		}
	}
}

function nojob_lg_mouseover() {
	if (document.getElementById('lg_nojob').className == 'odd_bg') {
		document.getElementById('lg_nojob').className='row_hover';
	} else {
		document.getElementById('lg_nojob').className='odd_bg_bold';
	}
}

function nojob_lu_mouseover() {
	if (document.getElementById('lu_nojob').className == 'even_bg') {
		document.getElementById('lu_nojob').className='row_hover';
	} else {
		document.getElementById('lu_nojob').className='even_bg_bold';
	}
}

function nojob_lp_mouseover() {
	if (document.getElementById('lp_nojob').className == 'odd_bg') {
		document.getElementById('lp_nojob').className='row_hover';
	} else {
		document.getElementById('lp_nojob').className='odd_bg_bold';
	}
}

function nojob_lg_mouseout() {
	if (document.getElementById('lg_nojob').className == 'odd_bg_bold') {
		document.getElementById('lg_nojob').className='odd_bg_bold';
	} else {
		document.getElementById('lg_nojob').className='odd_bg';
	}
}

function nojob_lu_mouseout() {
	if (document.getElementById('lu_nojob').className == 'even_bg_bold') {
		document.getElementById('lu_nojob').className='even_bg_bold';
	} else {
		document.getElementById('lu_nojob').className='even_bg';
	}
}

function nojob_lp_mouseout() {
	if (document.getElementById('lp_nojob').className == 'odd_bg_bold') {
		document.getElementById('lp_nojob').className='odd_bg_bold';
	} else {
		document.getElementById('lp_nojob').className='odd_bg';
	}
}

function nojob_lu_select() {
	document.getElementById('nojob_lg_mod').style.display='none';
	document.getElementById('nojob_lp_mod').style.display='none';
	document.getElementById('nojob_lu_mod').style.display='block';
	document.getElementById('nojob_header').innerHTML = 'Update Customer Lists';
	if (document.getElementById('lu_nojob').className = 'even_bg') {
		document.getElementById('lu_nojob').className = 'even_bg_bold';
		document.getElementById('lg_nojob').className = 'odd_bg';
		document.getElementById('lp_nojob').className = 'odd_bg';
	}
}

function nojob_lg_select() {
	document.getElementById('nojob_lu_mod').style.display='none';
	document.getElementById('nojob_lp_mod').style.display='none';
	document.getElementById('nojob_lg_mod').style.display='block';
	document.getElementById('nojob_header').innerHTML = 'Create Mailing Lists';
	if (document.getElementById('lg_nojob').className = 'odd_bg') {
		document.getElementById('lu_nojob').className = 'even_bg';
		document.getElementById('lg_nojob').className = 'odd_bg_bold';
		document.getElementById('lp_nojob').className = 'odd_bg';
	}
}

function nojob_lp_select() {
	document.getElementById('nojob_lu_mod').style.display='none';
	document.getElementById('nojob_lp_mod').style.display='block';
	document.getElementById('nojob_lg_mod').style.display='none';
	document.getElementById('nojob_header').innerHTML = 'Profile Customer Lists';
	if (document.getElementById('lp_nojob').className = 'odd_bg') {
		document.getElementById('lu_nojob').className = 'even_bg';
		document.getElementById('lp_nojob').className = 'odd_bg_bold';
		document.getElementById('lg_nojob').className = 'odd_bg';
	}
}
//end account center stuff

function milestone(num) {
	if (document.getElementById('milestone'+num).style.display == 'none') {
		document.getElementById('milestone'+num).style.display = 'block';
	} else {
		document.getElementById('milestone'+num).style.display = 'none';
	}
}

function mh_on(num) {
	document.getElementById('milestone_heading'+num).style.color = '#f5821f';
}

function mh_out(num) {
	document.getElementById('milestone_heading'+num).style.color = '#2a7bcd';
}

function open_all() {
	if (document.getElementById('open_all').innerHTML == 'open all') {
		document.getElementById('open_all').innerHTML = 'close all';
		document.getElementById('open_all').style.backgroundImage = 'url(/static/images/up.gif)';
		for (num=2;num<=17;num++) {
			document.getElementById('milestone'+num).style.display = 'block';
		}	
	} else {
		document.getElementById('open_all').innerHTML = 'open all';
		document.getElementById('open_all').style.backgroundImage = 'url(/static/images/down.gif)';
		for (num=2;num<=17;num++) {
			document.getElementById('milestone'+num).style.display = 'none';
		}	
	
	}
}

function solutionsTab(type) {
	if (type == 'dm') {
		document.getElementById('hs_tab').style.backgroundImage = 'url(/static/images/home_off.gif)';
		document.getElementById('dm_tab').style.backgroundImage = 'url(/static/images/direct_on.gif)';
		document.getElementById('re_tab').style.backgroundImage = 'url(/static/images/estate_off.gif)';
		document.getElementById('rt_tab').style.backgroundImage = 'url(/static/images/retail_off.gif)';
		document.getElementById('dm_tab').style.cursor = 'default';
		document.getElementById('hs_tab').style.cursor = 'pointer';
		document.getElementById('re_tab').style.cursor = 'pointer';
		document.getElementById('rt_tab').style.cursor = 'pointer';
		document.getElementById('dm_info').style.display = 'block';
		document.getElementById('hs_info').style.display = 'none';
		document.getElementById('re_info').style.display = 'none';
		document.getElementById('rt_info').style.display = 'none';
	} else if (type == 'hs') {
		document.getElementById('hs_tab').style.backgroundImage = 'url(/static/images/home_on.gif)';
		document.getElementById('dm_tab').style.backgroundImage = 'url(/static/images/direct_off.gif)';
		document.getElementById('re_tab').style.backgroundImage = 'url(/static/images/estate_off.gif)';
		document.getElementById('rt_tab').style.backgroundImage = 'url(/static/images/retail_off.gif)';
		document.getElementById('hs_tab').style.cursor = 'default';
		document.getElementById('dm_tab').style.cursor = 'pointer';
		document.getElementById('re_tab').style.cursor = 'pointer';
		document.getElementById('rt_tab').style.cursor = 'pointer';
		document.getElementById('hs_info').style.display = 'block';
		document.getElementById('dm_info').style.display = 'none';
		document.getElementById('re_info').style.display = 'none';
		document.getElementById('rt_info').style.display = 'none';
	} else if (type == 're') {
		document.getElementById('hs_tab').style.backgroundImage = 'url(/static/images/home_off.gif)';
		document.getElementById('dm_tab').style.backgroundImage = 'url(/static/images/direct_off.gif)';
		document.getElementById('re_tab').style.backgroundImage = 'url(/static/images/estate_on.gif)';
		document.getElementById('rt_tab').style.backgroundImage = 'url(/static/images/retail_off.gif)';
		document.getElementById('re_tab').style.cursor = 'default';
		document.getElementById('dm_tab').style.cursor = 'pointer';
		document.getElementById('hs_tab').style.cursor = 'pointer';
		document.getElementById('rt_tab').style.cursor = 'pointer';
		document.getElementById('re_info').style.display = 'block';
		document.getElementById('hs_info').style.display = 'none';
		document.getElementById('dm_info').style.display = 'none';
		document.getElementById('rt_info').style.display = 'none';
	} else {
		document.getElementById('hs_tab').style.backgroundImage = 'url(/static/images/home_off.gif)';
		document.getElementById('dm_tab').style.backgroundImage = 'url(/static/images/direct_off.gif)';
		document.getElementById('re_tab').style.backgroundImage = 'url(/static/images/estate_off.gif)';
		document.getElementById('rt_tab').style.backgroundImage = 'url(/static/images/retail_on.gif)';
		document.getElementById('rt_tab').style.cursor = 'default';
		document.getElementById('dm_tab').style.cursor = 'pointer';
		document.getElementById('re_tab').style.cursor = 'pointer';
		document.getElementById('hs_tab').style.cursor = 'pointer';
		document.getElementById('rt_info').style.display = 'block';
		document.getElementById('hs_info').style.display = 'none';
		document.getElementById('re_info').style.display = 'none';
		document.getElementById('dm_info').style.display = 'none';
	}
}

function TabOver(type) {
	if ((type == 'dm') && (document.getElementById(type+'_info').style.display == 'none')) {
		document.getElementById('dm_tab').style.backgroundImage = 'url(/static/images/direct_over.gif)';
	} 
	if ((type == 'hs') && (document.getElementById(type+'_info').style.display == 'none')) {
		document.getElementById('hs_tab').style.backgroundImage = 'url(/static/images/home_over.gif)';
	} 
	if ((type == 're') && (document.getElementById(type+'_info').style.display == 'none')) {
		document.getElementById('re_tab').style.backgroundImage = 'url(/static/images/estate_over.gif)';
	} 
	if ((type == 'rt') && (document.getElementById(type+'_info').style.display == 'none')) {
		document.getElementById('rt_tab').style.backgroundImage = 'url(/static/images/retail_over.gif)';
	}
}

function TabOut(type) {
	if ((type == 'dm') && (document.getElementById(type+'_info').style.display == 'none')) {
		document.getElementById('dm_tab').style.backgroundImage = 'url(/static/images/direct_off.gif)';
	}
	if ((type == 'hs') && (document.getElementById(type+'_info').style.display == 'none')) {
		document.getElementById('hs_tab').style.backgroundImage = 'url(/static/images/home_off.gif)';
	}
	if ((type == 're') && (document.getElementById(type+'_info').style.display == 'none')) {
		document.getElementById('re_tab').style.backgroundImage = 'url(/static/images/estate_off.gif)';
	}
	if ((type == 'rt') && (document.getElementById(type+'_info').style.display == 'none')) {
		document.getElementById('rt_tab').style.backgroundImage = 'url(/static/images/retail_off.gif)';
	}
}

/* Begin Account Summary/My Lists page JS code */

var selectedName = '';

function showDetailsPop(sender,data) {
	// console.log(sender.offsetParent.offsetLeft);
	// console.log(sender.offsetParent.offsetParent.offsetTop);

	hideDetailsPop();
	hideDownloadPop();
	var left = sender.offsetLeft;
	var top = sender.offsetParent.offsetTop;
	var details_pop = document.getElementById('details_pop');
	
	// Show/hide details based on status
	if (data['append_rate']) {
		document.getElementById('details_complete').style.display = 'block';
	} else {
		document.getElementById('details_incomplete').style.display = 'block';
	}
	
	// Loop through hash object, filling data in popup div
	for (var name in data) {
		var element = $('#details_pop_' + name);
		if (element) {
			$('#details_pop_' + name).text(data[name]);
		}
	}
	
	details_pop.style.left = left + 379;
	details_pop.style.top = top - 133;
	details_pop.style.display = 'block';
}

function hideDetailsPop() {
	var details_pop = document.getElementById('details_pop');
	details_pop.style.display = 'none';
	document.getElementById('details_complete').style.display = 'none';
	document.getElementById('details_incomplete').style.display = 'none';
}

function showDownloadPop(sender,name,product,id,transid,key,date,status,sf,sortrev,pct) {
	// console.log(sender.offsetParent.offsetLeft);
	// console.log(sender.offsetParent.offsetParent.offsetTop);
	hideDetailsPop();
	hideDownloadPop();
	var left = sender.offsetLeft;
	var top = sender.offsetParent.offsetTop;
	var download_pop = document.getElementById('download_pop');
	download_pop.style.left = left + 395;
	download_pop.style.top = top - 76;
	download_pop.style.display = 'block';
	
	var form = $('#lu_form');
	var keyInput = $('#lu_id_key');
	var batchInput = $('#batch_id');
	var formAction = "/list-update/download/" + name + ".xls";
	
	form.attr('action', formAction);
	batchInput.val(id);
	keyInput.val(key);
	selectedName = name;
}

function hideDownloadPop() {
	var download_pop = document.getElementById('download_pop');
	download_pop.style.display = 'none';
}
