//submitScuccess passed back from BVK


function submitSuccess(success) { 
	if (success == true) {
		$("#lead").html('<h2>Thank you for your interest in DeVry University.</h2><p style="margin: .5em 1em 0 1em;">A DeVry University representative will contact you soon to answer any<br />questions you may have about the <a href="http://www.devry.edu/whydevry/quality_education.jsp" rel="external">advantages</a> of a DeVry education.</p>');
		dcsMultiTrack('DCS.dcsuri','MDD Landing Page: RMI Confirmation','WT.ti','MDD Landing Page: RMI Confirmation');
		
//		<!-- Start of DoubleClick Spotlight Tag: Please do not remove-->
//		<!-- Activity Name for this tag is:DeVry MDD Campaign Thank you Page -->
//		<!-- Web site URL where tag should be placed: https://www.devry.edu/?program=mdd -->
//		<!-- This tag must be placed within the opening <body> tag, as close to the beginning of it as possible-->
//		<!-- Creation Date:3/24/2009 -->
//		<SCRIPT language="JavaScript">
		var axel = Math.random()+"";
		var a = axel * 10000000000000;
		
		// edited to not use document.write
		$('#spotlight').html('<IFRAME SRC="https://fls.doubleclick.net/activityi;src=2049738;type=devry202;cat=devry936;ord=1;num='+ a + '?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>');
//		</SCRIPT>
//		<NOSCRIPT>
//		<IFRAME SRC="https://fls.doubleclick.net/activityi;src=2049738;type=devry202;cat=devry936;ord=1;num=1?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>
//		</NOSCRIPT>
//		<!-- End of DoubleClick Spotlight Tag: Please do not remove-->
	}
	if (success == false) {

		var pageURL = "http://www.choosedevry.com/mdd/?vc=140427"

		$("#lead").html('<h2>There was an error in your submission.</h2><p style="margin: .5em 1em 0 1em;">Please click <a href="' + pageURL + '">here</a> to try again.<p>');
	}
}


// Start SWFObject
//function startVideo() { 

//}
// End SWFObject




$(document).ready(function() { //document.ready jquery call go in here

	dcsMultiTrack('DCS.dcsuri','MDD Landing Page: Home','WT.ti','MDD Landing Page: Home');


	$(function() { 
		// Get a parameter value from a querystring
		function getParam(name) {
			name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
			var regexS = "[\\?&]"+name+"=([^&#]*)";
			var regex = new RegExp( regexS );
			var results = regex.exec( window.location.href );
			if( results == null ) {
			  return false;
			  } else {
			  return results[1];
			  };
		};
		var city = getParam('city'); // console.log(city)
		var vc = getParam('vc'); // console.log(vc);
	
		if (city) {
		
//			console.log(city);

		}
		if (vc) {
			// set hidden value to vc code
//			console.log(vc);			
			$('input#vc-pass').val(vc);
		}
	});

	
 	$("a#inline").fancybox({
		'frameWidth': 710,
		'frameHeight': 420,
		'padding': 5,
		'callbackOnStart': function() {	
			
			// tracking
			dcsMultiTrack('DCS.dcsuri','MDD Landing Page: Launch Video','WT.ti','MDD Landing Page: Launch Video');
			
			var params = {
				quality: "high",
				scale: "noscale",
				wmode: "transparent",
				align: "top",
				salign: "left",
				allowscriptaccess: "always",
				bgcolor: "#FFFFFF"
			};
			var flashvars = { AUTO_PLAY: true, baseURL: "", videoFilename: "DeVry_MDD_HomePage_700x394.flv" };
			var attributes = { id: "devryvideo" };
			swfobject.embedSWF("assets/video/devry_vidplayer_v2.swf", "devryvideo", "710", "420", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
		},
		'hideOnContentClick': false
	}); 
	

	
// init auto tab
	// requires jquery auto-tab plugin
	$('#ZipCodeTextBox').autotab({ format: 'numeric' });
	$('#AreaCodeTextBox').autotab({ target: 'SuffixTextBox', format: 'numeric' });
	$('#SuffixTextBox').autotab({ target: 'PhoneTextBox', previous: 'AreaCodeTextBox', format: 'numeric' });
	$('#PhoneTextBox').autotab({ previous: 'AreaCodeTextBox', format: 'numeric' });
	$('#YearEarnedTextBox').autotab({ format: 'numeric' });

	
// setup faux ajax submit via added sript tag
// submit handeler must respond with either submitSuccess(true); or submitSuccess(false);

	var scriptCounter = 1 ;

	var url = 'http://www.kelleradvantage.com/ajaxSubmit.aspx';
	
	function _makeRequest(req) {
		var fullUrl = req;
		var noCacheIE = '&noCacheIE=' + (new Date()).getTime();
		var headLoc = document.getElementsByTagName("head").item(0);
		var scriptId = 'scriptId' + scriptCounter++;
		// Create script object
		var scriptObj = document.createElement("script");
		scriptObj.setAttribute("type", "text/javascript");
		scriptObj.setAttribute("charset", "utf-8");
		scriptObj.setAttribute("src", fullUrl + noCacheIE);
		scriptObj.setAttribute("id", scriptId);
		// Append script object to document head
		headLoc.appendChild(scriptObj);
	};

// init form validation
	// requires jquery validate plugin
	
	$("#lead-form").validate({
		
		// range for date
		// http://docs.jquery.com/Plugins/Validation/Methods/range#range
		rules: {
		   	YearEarnedTextBox: {
				required: true,
				range: [1900, 2100]
			}
		},
		
		invalidHandler: function(form, validator) {	
			$('#validatemsg').html('<span style="color: #E6260F;">Please correct the highlighted fields below.</span>');
		},
		
		submitHandler: function(form) {	
		//	console.log(url);
		 	var FirstNameTextBoxVal = $('#FirstNameTextBox').val();
			var LastNameTextBoxVal = $('#LastNameTextBox').val();
			var AddressTextBoxVal = $('#AddressTextBox').val();
			var ZipCodeTextBoxVal = $('#ZipCodeTextBox').val();
			var EmailTextBoxVal = $('#EmailTextBox').val();
			var AreaCodeTextBoxVal = $('#AreaCodeTextBox').val();
			var SuffixTextBoxVal = $('#SuffixTextBox').val();
			var PhoneTextBoxVal = $('#PhoneTextBox').val();
			var GraduationTypeDropDownVal = $('#GraduationTypeDropDown').val();
			var YearEarnedTextBoxVal = $('#YearEarnedTextBox').val();
			var ClassRoomDropDownVal = $('#ClassRoomDropDown').val();
			var vcVal = $('#vc-pass').val();

			var submitUrl =  url + '?FirstNameTextBox=' + FirstNameTextBoxVal + '&LastNameTextBox=' + LastNameTextBoxVal + '&AddressTextBox=' + AddressTextBoxVal + '&ZipCodeTextBox=' + ZipCodeTextBoxVal + '&EmailTextBox=' + EmailTextBoxVal + '&AreaCodeTextBox=' + AreaCodeTextBoxVal + '&SuffixTextBox=' + SuffixTextBoxVal + '&PhoneTextBox=' + PhoneTextBoxVal + '&GraduationTypeDropDown=' + GraduationTypeDropDownVal + '&YearEarnedTextBox=' + YearEarnedTextBoxVal + '&ClassRoomDropDown=' + ClassRoomDropDownVal + '&vc=' + vcVal;
		//	var submitUrl =  'http://www.kelleradvantage.com/ajaxSubmit.aspx?FirstNameTextBox=tes&LastNameTextBox=tes&AddressTextBox=asdf&ZipCodeTextBox=12345&EmailTextBox=a%40b.c&AreaCodeTextBox=132&SuffixTextBox=456&PhoneTextBox=7891&GraduationTypeDropDown=HS+Diploma&YearEarnedTextBox=1232&ClassRoomDropDown=ONSITE%2FONLINE&vc=166096' ;
		//	console.log(submitUrl);

			_makeRequest(submitUrl);
	   }
	
	});
	
	
	


	// More about popups
	$('.more-about li').each(function () {
	    var distance = 10;
	    var time = 500;
	    var hideDelay = 150;
	    var hideDelayTimer = null;
	    var beingShown = false;
	    var shown = false;
	    var trigger = $('a', this);
	    var info = $('p', this).css('opacity', 0);

	    $([trigger.get(0), info.get(0)]).mouseover(function () {
	        if (hideDelayTimer) clearTimeout(hideDelayTimer);
	        if (beingShown || shown) {
	            // don't trigger the animation again
	            return;
	        } else {
	            // reset position of info box
	            beingShown = true;				
	           	info.css({
	                bottom: 30,
					zindex: 50,
	                display: 'block'
	            }).animate({
	                bottom: '+=' + distance + 'px',
	                opacity: 1
	            }, time, 'swing', function() {
	                beingShown = false;
	                shown = true;
	            });
	        }
	        return false;
	    }).mouseout(function () {
	        if (hideDelayTimer) clearTimeout(hideDelayTimer);
	        hideDelayTimer = setTimeout(function () {
	            hideDelayTimer = null;
	            info.animate({
	                bottom: '-=' + distance + 'px',
	                opacity: 0
	            }, time, 'swing', function () {
	                shown = false;
	                info.css('display', 'none');
	            });
	        }, hideDelay);
	        return false;
	    });
	});


// open from #ID in new window

	$("#form-select-degree").submit(function() {
//		console.log(this.openUrl.value);
		dcsMultiTrack('DCS.dcsuri','MDD Landing Page: Degree Links Go','WT.ti','MDD Landing Page: Degree Links Go');
		if(this.openUrl.value.indexOf('http://') >= 0) {
			window.open(this.openUrl.value);
			return false;
		} else {
			document.location.href = this.openUrl.value;
			return false;
		}
		return false;
    });
    


	// tracking based on class
	// set class="dcstrack" title="Tracking Title"
	$('a.dcstrack').click(function() {
		var tagname = $(this).attr("title");		
//		console.log(tagname);
		dcsMultiTrack('DCS.dcsuri', tagname,'WT.ti',tagname);
//		return false;
	});



	// open all rel="external" in new window

		$('a[rel="external"]').click( function() {
	        window.open( $(this).attr('href') );
	        return false;
	    });


}); // End JQuery

