function iclogin()
{
	document.login_form.submit();
}


function viewSampleIntelePulse () {
	centerPop('/media/intelepulse_sample.php',460,400);	
}

function viewCompareSubscription() {
	centerPop('/pix/downloads/Intelecare-EditionsComparison_20100403.pdf',460,400);	
}

function centerPop(page,w,h,args){
	if (w > 0) {
	} else {
		w = 650
	}
	if (h > 0) {
	} else {
		h = 550
	}
	var width
	var height
	var leftdist
	var topdist
	width = screen.width;
	height = screen.height;
	leftdist = Math.round((width - w) / 2);
	topdist = Math.round((height - h) / 2);
	if (!args) {
		args = 'resizable=1,menubar=0,location=0,scrollbars=1,status=1,toolbar=0';
	}
	cpw = window.open(page,'cpw','width='+ w +',height='+ h +',top='+topdist+',left='+leftdist+','+ args);
	cpw.focus();
}

function goToRegister(url)
{
	location.href = url;
	return false;
}

function deleteReminder(id)
{
//	var confirmation = 
	popUpConfirm('Are you sure you want to permanently delete this reminder?','deleteReminderConfirmed',id);
//	if(true == confirmation)
//	{
//		location.href = '/' + client['directory'] + '/client/home/delete/' + id;
//	}
}

function deleteReminderConfirmed(id) {
	//if(true == confirmation)
//	{
		location.href = '/' + client['directory'] + '/client/home/delete/' + id;
//	}
}

function checkContact(element)
{
	if(element.checked)
	{
		$('contact').checked = true;
	}
}

var deactivateYes = false;

function submitTabForm()
{
	if($('active') == null)
	{
		return true;
	} else if($('activeNo').checked) {
		if (deactivateYes){
			return true;
		} else {
			popUpConfirm('Are you sure you want to deactivate your account?','deactivateConfirmed');
			return false;
		}
	} else {
	}
	return true;
}

function deactivateConfirmed () {
	deactivateYes = true;
//	$('tabFrm').writeAttribute('onSubmit','return true;');
//	$('tabFrm').action = self.location.href;
	$('tabFrm').submit();
	return true;
//	document.forms['tabFrm'].submit();
}



function interestToggle(action,element)
{
	var checkboxes = $$('.interest_column input');
	checkboxes.each(function(checkbox)
	{
		if(action == 'on')
		{
			checkbox.checked = true;
		} else {
			checkbox.checked = false;
		}
	});
	
	if(action == 'on')
	{
		$('contact').checked = true
	}
	element.checked = false;
}

// * * * Callendar Functions * */

var currentField = false;

function showCalendar (anchor) {
	currentField = anchor;

	if (self.document.getElementById('popUpCal')) {
	} else {
		var calElm = new Element('div', { 'id':'popUpCal','style':'position:absolute' } );
		$('client_content').insert(calElm);
		$('popUpCal').addClassName('yui-skin-sam');
		$('popUpCal').update('<div align=right><a href="javascript:closeCal()">close calendar</a></div><div id=cal1Container></div>');
		$('popUpCal').hide();
	}
	
	var contentOffset = $('client_content').cumulativeOffset();
	var anchorOffset = $(anchor).cumulativeOffset();
	
	var x = (anchorOffset[0] - contentOffset[0]) + $(anchor).getWidth() - 10;
	var y = (anchorOffset[1] - contentOffset[1]) - 50;
	
	$('popUpCal').style.top = y +'px';
	$('popUpCal').style.left = x +'px';

	$('popUpCal').show();

	    YAHOO.namespace("example.calendar"); 
	 
	 //   YAHOO.example.calendar.init = function() { 
	 //       YAHOO.example.calendar.cal1.render(); 
	 //   } 
	
	
	YAHOO.example.calendar.cal1 = new YAHOO.widget.Calendar("cal1","cal1Container");	
	
//	YAHOO.example.calendar.init();
	
   	var fieldValue = $(currentField).value;
	var datePatt = new RegExp('^[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}$');
	if (datePatt.test(fieldValue)) {
		YAHOO.example.calendar.cal1.select(fieldValue); 
        var selectedDates = YAHOO.example.calendar.cal1.getSelectedDates(); 
        if (selectedDates.length > 0) { 
            var firstDate = selectedDates[0]; 
            YAHOO.example.calendar.cal1.cfg.setProperty("pagedate", (firstDate.getMonth()+1) + "/" + firstDate.getFullYear()); 
		} else {
		//	top.alert('nope..');
		}
	} else {
	//	top.alert('not valid');
	}

	YAHOO.example.calendar.cal1.selectEvent.subscribe(dateSelect, YAHOO.example.calendar.cal1, true); 		
    YAHOO.example.calendar.cal1.render(); 

}

function dateSelect(type,args,obj) { 
   	var dates = args[0]; 
   	var date = dates[0]; 
   	var year = date[0], month = date[1], day = date[2]; 

  	 	// var txtDate1 = document.getElementById(); 
   	// $(currentField).value = year +'-'+ month + "-"+ day; 
   	$(currentField).value = month + "/"+ day +'/'+ year; 
   	closeCal();
}

function closeCal () {
   	currentField = false;
   	$('popUpCal').hide();
}

function setBreadcrumbs()
{
	if($('breadcrumbs_side') != null)
	{
		var html = breadcrumbsSideHTML();
		$('breadcrumbs_side').innerHTML = html;
		$('breadcrumbs_side').show();
	} else {
		var html = breadcrumbsHTML();
		$('breadcrumbs').innerHTML = html;
		$('breadcrumbs').show();
	}
	if($('breadcrumbs_heading') != null)
	{
		$('breadcrumbs_heading').innerHTML = breadcrumb_header;
		$('breadcrumbs_heading').show();
	}
}

function breadcrumbsHTML()
{
	var output = '';
	var x = 1;
	crumbs.each(function(item) {
		var itemArray = item.toString().split(',');
		if(x != 1)
		{
			output += ' > ';
		}
		x++;
		if(itemArray[0] == currentCrumb)
		{
			output += '<span class="currentBreadcrumb">' + itemArray[1] + '</span>';
		} else {
			output += itemArray[1];
		}
	});
	return output;
}

function breadcrumbsSideHTML()
{
	var output = '<ul>';
	var x = 1;
	crumbs.each(function(item) {
		var itemArray = item.toString().split(',');
		if(x == crumbs.size() && breadcrumb_header == 'Register')
		{
			output += '<li><b>' + itemArray[1] + '</b></li>';
		} else if(itemArray[0] == currentCrumb) {
			output += '<li class="currentBreadcrumb breadcrumb_border"><b>Step ' + x + ':</b><br>' + itemArray[1] + '</li>';
		} else {
			var bclass = '';
			if(x != crumbs.size())
			{
				bclass = ' class="breadcrumb_border"';
			}
			output += '<li' + bclass + '><b>Step ' + x + ':</b><br>' + itemArray[1] + '</li>';
		}
		x++;
	});
	output += '</ul>';
	
	return output;
}


/* 
 * pop up message 
 */

function popUpMake () {

	if (document.getElementById('msgTxt')) {
		// does exist
		msgTxt = $('msgTxt');
	} else {
		// create.
		msgTxt = new Element('div',{ id:'msgTxt', style:'position:absolute;top:0px;left:0px;'});
		msgTxt.update("<div id='msgTop'></div><div id='msgWrap'><div id='msgMedia'></div><div id='msgText'></div><div style='clear:both'></div></div><div id='msgBottom'></div>");
		$('client_content').insert(msgTxt);
		msgTxt.hide();
//		top.alert('create');
	}

}

function popUpMsg (txt) {
	
		popUpMake();
		
		$('msgText').update(txt +"<br><br><input type=button value='OK' class=button id='msgBtn' onClick='popUpMsgClose()'>");
		
		msgTxt.show();
		
		$('msgBtn').focus();
		
		movePopUp();
	
}

function popUpConfirm (txt,callback,arg) {

	popUpMake();
	
	$('msgText').update(txt +"<br><br><input type=button value='OK' class=button onClick='"+ callback +"("+ arg +");popUpMsgClose();' id='msgBtn'> <input type=button value='Cancel' onClick='popUpMsgClose()' class=button>");
	
	msgTxt.show();
	
	$('msgBtn').focus();
	
	movePopUp();
	
}

function movePopUp() {

	contentW  = $('client_content').getWidth();
	contentH  = $('client_content').getHeight();
	
  
	msgW  = $('msgTxt').getWidth();
	msgH  = $('msgTxt').getHeight();
	
	$('msgTxt').style.left = Math.round((contentW - msgW)/2) +'px';
	$('msgTxt').style.top = (Math.round((contentH - msgH)/2) + 50)  +'px';

}

function popUpMsgClose () {
	$('msgTxt').hide();
}

function showHideCC(elm)
{
	if(elm.value == 'plus' || elm.value == 'platinum')
	{
		$('ccinfo').show();
	} else {
		$('ccinfo').hide();
		$('ccnum').value = '';
	}
}

/*
 *  function for displaying rules for a valid password
 */
function passwordRules () {
	popUpMsg("Passwords must be at least 6 characters long, containing at least 1 alphabetic and 1 numeric character with no spaces.");
}
