var search_col;

function openLookup(type, target_id) {
	url = sccc_path + 'lookup.php?type=' + type + "&target_obj=" + target_id;
	options = 'height=265, width=410, resizable=yes, location=no, menubar=no, status=no, scrollbars=yes, toolbar=no, titlebar=yes';
	
	popup = window.open(url, '_blank', options, true);
	popup.focus();
}

//Added for Link Alliance
function openLinkLookup(type, target_id) {
	url = sccc_path + 'lookup_link_alliance.php?type=' + type + "&target_obj=" + target_id;
	options = 'height=265, width=410, resizable=yes, location=no, menubar=no, status=no, scrollbars=yes, toolbar=no, titlebar=yes';
	
	popup = window.open(url, '_blank', options, true);
	popup.focus();
}
function openStateLookup(type, target_id, country) {
	url = sccc_path + 'lookup.php?type=' + type + "&target_obj=" + target_id+ "&country=" + country;
	options = 'height=265, width=410, resizable=yes, location=no, menubar=no, status=no, scrollbars=yes, toolbar=no, titlebar=yes';
	
	popup = window.open(url, '_blank', options, true);
	popup.focus();
}

//Added for Link Alliance

function openLookup_with_checkbox(type, target_id) {
	
	url = sccc_path + 'lookup_check_box.php?type=' + type + "&target_obj=" + target_id;
	options = 'height=300, width=500, resizable=yes, location=no, menubar=no, status=no, scrollbars=yes, toolbar=no, titlebar=yes';
	
	popup = window.open(url, '_blank', options, true);
	popup.focus();
}

function initializeOptions(order) {
	search_col = order - 1;

	loadOptions(search_col);
}

function clearLookup(lookup) {
	var lookup_value = eval(doc + lookup + doc2);
	var lookup_display = eval(doc + lookup + "_display" + doc2);
	
	lookup_value.value = "";
	lookup_display.value = "";
}

function changeSearchType(col) {
	txt = eval(doc + "lookup_search_txt" + doc2);

	search_col = col;
	updateOptions(txt.value);	
}

function updateOptions(txt) {
	tbl = eval(doc + "lookup_options_tbl" + doc2);

	loadOptions(search_col);
	
	txt = txt.toLowerCase();
		
	num_rows = tbl.rows.length;
	cnt = 1;
	for (i = 1; i < num_rows; i ++) {
		cell_txt = tbl.rows[cnt].cells[search_col].innerHTML.toLowerCase();
		
		if (cell_txt.indexOf(txt) == -1) {
			tbl.deleteRow(cnt);
		} else {
			cnt ++;
		}
	}
}

function colorLookupOver() {
	colorRow(event.srcElement.parentElement, 'over', event.srcElement.parentElement.className);
}

function colorLookupOut() {
	colorRow(event.srcElement.parentElement, 'out', event.srcElement.parentElement.className);
}

function returnLookupOption() {
	returnOption(event.srcElement.parentElement.id);
}

function loadOptions(order) {
	option_tbl = eval(doc + "lookup_options_tbl" + doc2);
	sort_tbl = eval(doc + "sort_options_tbl_" + order + doc2);
	
	num_rows = option_tbl.rows.length;
	for (i = 1; i < num_rows ; i ++) {
		option_tbl.deleteRow(1);
	}
	
	for (i = 0; i < sort_tbl.rows.length; i ++) {
		seq = "even";
	
		row = option_tbl.insertRow(option_tbl.rows.length);
			
		if (document.all) {
			row.id = sort_tbl.rows[i].id;
			row.className = seq;
			
			row.attachEvent("onmouseover", colorLookupOver);
			row.attachEvent("onmouseout", colorLookupOut);
			row.attachEvent("onclick", returnLookupOption);
		} else {
			row.id = sort_tbl.rows[i].id;
			row.className = seq;
		
			row.setAttribute("onmouseover", "colorRow(this, 'over', '" + seq + "')", 0);
			row.setAttribute("onmouseout", "colorRow(this, 'out', '" + seq + "')", 0);
			row.setAttribute("onclick", "returnOption('" + sort_tbl.rows[i].id + "')", 0);
		}
			
		for (j = 0; j < sort_tbl.rows[i].cells.length; j ++) {
			cell = row.insertCell(j);
				
			cell.className = "option_cell " + seq;
			cell.innerHTML = sort_tbl.rows[i].cells[j].innerHTML;
		}
	}
		
	txt = eval(doc + "lookup_search_txt" + doc2);
	txt.focus();
	
	col = document.getElementsByName("option_heading");
	for (i = 0; i < col.length; i ++) {
		col[i].style.color = "#555555";
		col[i].style.textDecoration = "none";
	}
	
	sort_col = eval(doc + "option_heading_" + order + doc2);
	sort_txt = sort_col.getElementsByTagName('a')[0];
	
	sort_txt.style.color = "black";
	sort_txt.style.textDecoration = "underline";
}

function returnOption1(selection_id) {
opener.document.cp_survey_frm.eblast_header_img_display.value = selection_id;
opener.document.cp_survey_frm.eblast_header_img.value = selection_id;
opener.document.cp_survey_frm.eblast_header_img_field_error.value = 'N';




self.close();
}
function returnOption(selection_id) {
	var selected_row = document.getElementsByName(selection_id)[0];
	var target_id = eval(doc + "target_id" + doc2 + ".value");
       
	if (target_id == 'site') { 	
		if (document.all) {
			site = window.opener.document.getElementById('site');
		} else {
			site = window.opener.document.getElementsByTagName("select")[0];
		}
	
		selected = 0;
		for (i = 0; i < site.options.length; i ++) {
			if (site.options[i].value == selection_id) {
				selected = i;
			}
		}
		
		site.selectedIndex = selected;
	
		window.opener.changeSite(selection_id);
	} else {
		var display_col = eval(doc + "display_col" + doc2 + ".value");
		
		var target_obj;
		var target_display_obj;
			
		if (document.all) {
			target_obj = window.opener.document.getElementById(target_id);
			target_display_obj = window.opener.document.getElementById(target_id + "_display");
		} else {
			target_obj = window.opener.document.getElementsByName(target_id)[0];
			target_display_obj = window.opener.document.getElementsByName(target_id + "_display")[0];

			target_display_obj.value = "";		
		}
			
		target_obj.value = selection_id;
		target_display_obj.value = selected_row.cells[display_col - 1].innerHTML;

		target_display_obj.disabled = false;
		
		if (document.all) {
			target_display_obj.focus();
			target_display_obj.disabled = true;
		} else {
			window.setTimeout("killTime()", 500);
	
			if (target_display_obj.getAttribute('onFocus').indexOf('parent.document') == -1) {		
				on_focus = target_display_obj.getAttribute('onFocus').replace('document.', 'window.opener.document.');
			} else {
				on_focus = target_display_obj.getAttribute('onFocus').replace('parent.document.', 'window.opener.parent.document.');
			}
			
//			eval("window.opener." + target_display_obj.getAttribute('onFocus'));
			eval("window.opener." + on_focus);
//			alert("window.opener." + on_focus);
			target_display_obj.disabled = true;
		}
	}
	
	window.close();
}

function setManualInput(lookup) {
	var lookup_value = eval(doc + lookup.replace("_display", "") + doc2);
	var lookup_display = eval(doc + lookup + doc2);

	lookup_value.value = lookup_display.value;
}

function killTime() {
	// So ... How are the kids?  Great!  Anyways, I gotta run, but we should keep in touch ...
}

