/**
 * @author Rosetta UI dan.zachary
 */
var CCHMC = CCHMC||{};
CCHMC.utils = CCHMC.utils||{};
CCHMC.props = CCHMC.props||{};

/***********************
 *    Configuration    *
 ***********************/
//set to false to turn off
CCHMC.props.showPopup = false;
//variable for percentage of users to show survey to
CCHMC.props.percentCheck = 10;
//URL for popup
CCHMC.props.url ="http://websort.net/s/844388/";
/***********************/


CCHMC.props.date = new Date();
CCHMC.props.date.setYear(CCHMC.props.date.getFullYear() + 1);

//Jquery on doc ready 
$ektron(function(){

	//call show survey function
	CCHMC.utils.showSurvey();
});

//function to only show survey %10 of the time
CCHMC.utils.showSurvey =function()
{
	if ($ektron.cookie("Saw Survey") != "yes" && CCHMC.props.showPopup ) {
		var rand = Math.floor(Math.random() * 100);
		
		if (rand <= CCHMC.props.percentCheck) {
			CCHMC.utils.serveSurvey();
		}
	}
}

CCHMC.utils.declinedSurvey = function(){
	$ektron('#survey').dialog('close');
	$ektron.cookie("Saw Survey", "yes", {expires: CCHMC.props.date});
}

CCHMC.utils.acceptedSurvey = function(){
	var surveypop = window.open(CCHMC.props.url,"surveywindow","location=1,status=1,scrollbars=1,width=750,height=600");
	if (!surveypop) {
		alert("We have detected a popup blocker.\nPlease disable it and try again.\nThank You.");
	}
	else {
		$ektron('#survey').dialog('close');
		$ektron.cookie("Saw Survey", "yes", {expires: CCHMC.props.date});
	}
}

CCHMC.utils.serveSurvey = function(){
	//setup the survey div
	CCHMC.props.survey = '<div id="survey"><div id="surveyContent">'+
		'<img src="includes/cchmc/css/surveypop/images/cchmclogo.gif" alt="Cincinnati Children\'s Hospital Medical Center" />'+
		'<p>Thank You for visiting CincinnatiChildrens.org!</p>'+
		'<p>You have been selected to take part in a patient and family survey. This information will be used to help improve our Web site. All results are strictly confidential.</p>'+
		'<p>You must be a patient or family member of a patient to participate</p></div>'+
		'<div id="surveyButtons">'+
			'<a href="javascript: CCHMC.utils.acceptedSurvey()" ><img src="includes/cchmc/css/surveypop/images/survey_yes.gif" alt="Yes, I\'m Happy to Help" /></a> '+
			'<a href="javascript: CCHMC.utils.declinedSurvey()" ><img src="includes/cchmc/css/surveypop/images/survey_no.gif" alt="No, Thanks" /></a>'+
		'</div>'+
		'</div>';
	
	//ad survey to doc
	$ektron('body').append(CCHMC.props.survey);

	//set up dialog
	$ektron("#survey").dialog({
		//autoOpen: false,
		bgiframe: true,
		modal: true,
		resizable: false,
		draggable: false,
		width: 385,
		height: 290,
		show: "drop",
		hide: "drop"	
	});
	
	//show survey dialog
	$ektron('#survey').dialog('open');
}
;
