var newwin ='';

function newWd(page,width, height) {
    newwin = window.open(page, '', 'screenX=20,screenY=20,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+width+',height='+height); 
	newwin.focus();
} 
function sure()
{
	return confirm('Are you sure you would like to remove this?');
}

var isIE = (document.all) ? true : false;
var displayType = (isIE) ? 'block' : 'table-row-group';

function toggleRows(cid,on_off) {
	if (document.getElementById) {
		document.getElementById(cid).style.display = (on_off) ? displayType : 'none';
	}
}

function showAttachmentDiv(type)
{
	if (type != 'attachments')
		if (parent.document.getElementById('attachments_div'))
			parent.document.getElementById('attachments_div').style.display = 'none';
		else
			document.getElementById('attachments_div').style.display = 'none';
		
	
	if (type != 'cover_letter'){
		if (parent.document.getElementById('cover_letter_div'))
			parent.document.getElementById('cover_letter_div').style.display = 'none';
		else
			document.getElementById('cover_letter_div').style.display = 'none';
			
	}
	
	if (type != 'replace_cover_letter'){
		if (parent.document.getElementById('replace_cover_letter_div'))
			parent.document.getElementById('replace_cover_letter_div').style.display = 'none';
		else
			document.getElementById('replace_cover_letter_div').style.display = 'none';
			
	}
	
	if (type != 'archived_div'){
		if (parent.document.getElementById('archived_div'))
			parent.document.getElementById('archived_div').style.display = 'none';
		else
			document.getElementById('archive_div').style.display = 'none';
			
	}
		
	if (type != '')
		document.getElementById(type+'_div').style.display = 'block';	

	if (type == ""){
		//document.getElementById('attachments_div').style.display = 'none';
		parent.document.getElementById('cover_letter_div').style.display = 'none';
		parent.document.getElementById('replace_cover_letter_div').style.display = 'none';
		parent.document.getElementById('attachments_div').style.display = 'none';
	}	
		
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		home_over = newImage("/pics/home-over.gif");
		services_over = newImage("/pics/services-over.gif");
		about_us_over = newImage("/pics/about_us-over.gif");
		preloadFlag = true;
	}
}

function _getElement(id)
{
	if (document.getElementById && document.getElementById(id)) {
		return document.getElementById(id);
	}
	else if (document.all && document.all[id]) {
		return document.all[id];
	}
	else {
		return false;
	}
}

function setBlockDisplay(id,display_type)
{
	_getElement(id).style.display = display_type;
}

function toggleBlock(id)
{
	if (_getElement(id).style.display == 'none') {
		_getElement(id).style.display = 'block';
		_getElement(id+'pic').src = '/pics/dtable.opened.png';
	}
	else {
		_getElement(id).style.display = 'none';
		_getElement(id+'pic').src = '/pics/dtable.closed.png';
	}
}

function setVisibility(id,is_visible) 
{
	_getElement(id).style.visibility = (is_visible) ? 'visible' : 'hidden';
}

function getSelectedValue(select)
{
	if (!select ||
		select.options == null || 
		!select.options || 
		select.options.length == 0) {
			return '';
	}
	
	return select.options[select.selectedIndex].value;	
}

function calculateTotalPrice(fulfillment_price,self_file_price,all_docs_price,shipping_price)
{
	var total;

	if (document.form1.is_fulfillment[0] && document.form1.is_fulfillment[0].checked){
		document.form1.ship_method_id.disabled = false;
		total = parseFloat(fulfillment_price);
	}
	else{
		document.form1.ship_method_id.disabled = true;
		total = parseFloat(self_file_price); 
	}

	if(document.form1.all_docs && document.form1.all_docs.checked)
		total = parseFloat(total) + parseFloat(all_docs_price);
	total += shipping_price;
	total = total.toFixed(2);	
	document.getElementById('total_div').innerHTML = '$'+total;
	
	
}

function changeVisibility(id)
{
	//if visiblility is not set it will show not hide it
	if (_getElement(id).style.visibility == 'visible')
		setVisibility(id,false);	
	else{
		setVisibility(id,true);	
	}
	return;	
	//alert(_getElement(id).style.visibility.hidden);
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

var last_balloon_content_id;
var last_balloon_relative_to;

function showBalloon(content_id,relative_to)
{
	if (content_id == null) content_id   = last_balloon_content_id;
	if (relative_to == null) relative_to = last_balloon_relative_to;
	
	last_balloon_content_id = content_id;
	last_balloon_relative_to = relative_to;
	
	_getElement('balloon_content').innerHTML = _getElement(content_id).innerHTML;
	_getElement('balloon').style.visibility = 'visible';
	
	var x = findPosX(_getElement(content_id));
	var y = findPosY(_getElement(content_id));
	
	var window_width = 0;
	
	if (document.all) {
		window_width=document.body.offsetWidth;
	}
	else if (window.innerWidth) {
		window_width=window.innerWidth - 13;
	}
	
	if (x > (window_width - 260)) {
		x = window_width - 300;
		setBlockDisplay('balloon_arrow_left','none');
		setBlockDisplay('balloon_arrow_right','none');
	}
	else {
		setBlockDisplay('balloon_arrow_left','block');
		setBlockDisplay('balloon_arrow_right','none');
	}
	
	_getElement('balloon').style.left = x + 'px';
	_getElement('balloon').style.top  = y + 'px';
}

function hideBalloon()
{
	_getElement('balloon').style.visibility = 'hidden';
}

function checkAgree()
{
	if (document.completeFrm.reviewed.checked)
		return true;
	else{
		alert('You must review before moving on');
		return false;	
	}
		
}

function viewTab(tab_id)
{
	setBlockDisplay('zipcode_search','none');
	setBlockDisplay('location_search','none');
	setBlockDisplay('browse_search','none');
	setBlockDisplay('recent_search','none');
	
	setBlockDisplay(tab_id,'block');
}
