// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function Rcertify() 
{
popupWin = window.open('http://www.bbbonline.org/cks.asp?id=10305139032120', 'Participant','location=yes,scrollbars=yes,width=450,height=300'); 
window.name = 'opener';
} 

function popUpVerisign(url){
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=550,height=500');
	self.name = "mainWin"; 
}

function comm_link(id)
{
	if (id == undefined)
		document.location.href='/extranet/communications/new'
	else
		document.location.href='/extranet/communications/'+id
}

function prospect(prospect_id)
{
	document.location.href='/extranet/communications/new?contact_id='+prospect_id
}

function show_contact(id)
{
	document.location.href='/extranet/contacts/'+id
}

function show_order(id)
{
	document.location.href='/extranet/orders/'+id
}

function show_action(select)
{
	$('callback').style.display = 'none';
	$('place_order').style.display = 'none';
	
	$(select.value).style.display = 'block';
}

function populate(item)
{
	$('calendar_picker').style.display = 'none';
	$(item.value).style.display = 'block';
}

function payment_details(select)
{
	
	var id = select.options[select.selectedIndex].text.toLowerCase().replace(/ /g,'_')
	
	$('credit_card').style.display = 'none';
	$('other').style.display = 'none';
	$('eft').style.display = 'none';

	if (id != '30_day_billing')
	{
		$(id).style.display = 'block';
	}
}

function mark_for_destroy(element,css_class)
{
	$(element).next('.should_destroy').value = 1;
	$(element).up(css_class).hide();
}

function toggle_custom_range(value)
{
	if (value == 'create')
	{
		Element.show('custom_date_range')
	}
	else
	{
		Element.hide('custom_date_range')
	}
}

function toggle_other_text_field(value)
{
		if (value == 'other')
		{
			Element.show('other_reason')
		}
		else
		{
			Element.hide('other_reason')
		}
	}
	
	function confirm_DNC(obj)
	{
	if(obj.checked)
	{
	var cf = confirm( 'This will mark this Contact DNC.  Are you sure you want to continue?' );
	if(cf)
	obj.checked = true;
	else
	obj.checked = false;
	}
	}
	
function popWindow(wName)
{
	features = 'width=650,height=600,toolbar=no,location=no,directories=no,menubar=no,scrollbars=1,copyhistory=no,resizable=yes';
	pop = window.open('',wName,features);
	if(pop.focus){ pop.focus(); }
	return true;
}

function addHintToTextInput(inputFieldName, hintText)
{
  inputField = $(inputFieldName);
  
  // gather current settings
  currentColor = inputField.style['color'];
  currentOnfocusHandler = inputField.onfocus;
  
  // add hint
  inputField.value = hintText;
  inputField.style['color'] = 'grey'
  
  // add reset function
  inputField.onfocus = function() { 
    inputField.clear() ;
    inputField.style['color'] = currentColor;
    
    if (currentOnfocusHandler)
    {
      currentOnfocusHandler();
    }
  }
}

function warn_schedule()
{

	if( $('schedule_perform_at').value.length  < 1)
	{ 
		return confirm('NOTE: A blank Schedule Time will create an Open Callback.');
		
	}
	return true;
}

function warn_comment()
{
	if( $('comment_critical').checked )
	{
		return confirm('NOTE: A critical comment will always appear at the top of the page for this contact.');
	}
	return true;
}