//var next = '?url=https://secure.uwsystems.com/prodnu/default.aspx?CarrierID=7104e99a-d8a0-4392-ab53-1bb4f494dc63&ProgramCode=WED&BrokerFlag=BROKER';
// combined client side check for non- and wedding product check for consumer and brokers

//alert('loading yahoo.dialog.js');

				var next = '';
				var weddingProductCheck = false;
				
				//var nextUrl = window.location.href;
				YAHOO.namespace("example.container");

				function init() {
					
					// Define various event handlers for Dialog
					var handleSubmit = function() {
						//alert('handleSubmit');
						success = validate();
						if ( success ) {
							//alert('success code');
							//this.submit();
						} else {
							//alert('failure code');
						}
					};
					var handleCancel = function() {
						//alert('handleCancel');
						this.cancel();
					};
					var handleSuccess = function(o) {
						//alert("handleSuccess");
					};
					var handleFailure = function(o) {
						//alert("done.");
					};

					// Instantiate the Dialog
					YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1", 
																				{ width : "400px",
																				  height : "400px",
																				  close : false,
																				  modal : true,
																				  fixedcenter : true,
																				  visible : false, 
																				  constraintoviewport : true,
																				  buttons : [ { text:"Submit", handler:handleSubmit } ]
																				 } );
					
					
					// Validate the entries in the form to require that both first and last name are entered
					YAHOO.example.container.dialog1.validate = function() {
						var data = this.getData();
						if (data.firstname == "" || data.lastname == "") {
							return false;
						} else {
							return true;
						}
					};

					// Wire up the success and failure handlers
					YAHOO.example.container.dialog1.callback = { success: handleSuccess, failure: handleFailure };
				
					
					// Render the Dialog
					YAHOO.example.container.dialog1.render();

					YAHOO.util.Event.addListener("show", "click", YAHOO.example.container.dialog1.show, YAHOO.example.container.dialog1, true);
					YAHOO.util.Event.addListener("hide", "click", YAHOO.example.container.dialog1.hide, YAHOO.example.container.dialog1, true);
				}

				YAHOO.util.Event.addListener(window, "load", init);
			
			
				function validate(){

					myOption = -1;
					for (i=document.dlgForm.radiobuttons.length-1; i > -1; i--) {
						if (document.dlgForm.radiobuttons[i].checked) {
							myOption = i; i = -1;
						}
					}
					
					if (myOption == -1) {
						//alert("Please select your customer profile.");
						$('#error').show();
						//showdiv("error");
						return false;
						
					} else if (myOption == 0) {
						//alert("Consumer.");
						createCookie('prod','consumer',1);
						// check
						value = getCookie('prod');
						
						if(value == null || value == ""){
							alert('Your browser is currently set to block Cookies which are required for this website to function properly.');
						
						} else {
						//alert('document.dlgForm.consumerUrl.value:' + document.dlgForm.consumerUrl.value);
							$('#dialog1').hide();
							window.location.href = document.dlgForm.consumerUrl.value ;
						}
						
					
					} else if (myOption == 1){
					
						createCookie('prod','broker',1);
						value = getCookie('prod');
						if(value == null || value == ""){
							alert('Your browser is currently set to block Cookies which are required for this website to function properly.');
						
						} else {
							// XXX
							
							if(weddingProductCheck){
								
								license = getCookie('license');
								if( license == null || license == '' ) {
									$('#dialog1').hide();
									window.location.href = 'http://www.rvnuccio.com/broker/'  + next;
								} else if( license == '0'){
									$('#dialog1').hide();
									window.location.href = 'http://www.nasep.org/wedding-insurance.jsp';
								} else {
									$('#dialog1').hide();
									window.location.href = document.dlgForm.brokerUrl.value ;
								}
								
							} else {
								
								window.location.href = document.dlgForm.brokerUrl.value ;
								
							}// end if weddingProductCheck
							
							
							
							
						}
					
					} else {
						alert("unsupported option");
						return false;
					}
				
				}	
			
				
				
				function checkProduct(brokerUrl, consumerUrl, extraBrokerCheck) {
					//alert('checkProduct');
					weddingProductCheck = extraBrokerCheck;
					$('#dialog1').show();
					$('#error').hide();
					//hidediv('error')
					value = getCookie('prod');
					//alert('cookie prod: ' + value);
					
					if( value != null && value.length > 0){
					
						//alert('cookie value = ' + value);
					
						if(value=="broker"){
							
							
							//alert('is broker');
							
							if(weddingProductCheck){
								//alert('weddingProductCheck');
								
								license = getCookie('license');
								//alert('license: ' + license);
								if( license != null && license == '1'){
									$('#dialog1').hide();
									window.location.href = brokerUrl;
									//alert('1');
								} else  if( license == null || license == '') {
									$('#dialog1').hide();
									window.location.href = 'http://www.rvnuccio.com/broker' + next;
									//alert('2');
								} else if(license != null && license == '0') {
									$('#dialog1').hide();
									window.location.href = 'http://www.nasep.org/wedding-insurance.jsp';
									//alert('3');	
								} else {
								
									alert('unsupported: license is: ' + license);
								}
							
							} else {
								
								window.location.href = brokerUrl ;
								
							}// end if weddingProductCheck
							
							
						} else if(value=="consumer") {
							//alert('4');
							$('#dialog1').hide();
							window.location.href = consumerUrl;
							// new dispatch out for next check:
							
							
							
						} else {
							//alert('5');
							document.dlgForm.brokerUrl.value = brokerUrl;
							document.dlgForm.consumerUrl.value = consumerUrl ;
							YAHOO.example.container.dialog1.show();
						} // end value=="broker"
						
					} else {
						//alert('6');
							document.dlgForm.brokerUrl.value = brokerUrl;
							document.dlgForm.consumerUrl.value = consumerUrl ;
							YAHOO.example.container.dialog1.show();
					} // end value != null && value.length > 0
					
				} // end function
				
//				function check(url) {
//					hidediv('error')
//					document.dlgForm.url.value = url.href;
//					
//					value = getCookie('prod');
//					if( value != null && value.length > 0){
//						return true;
//					} else {
//						YAHOO.example.container.dialog1.show();
//						return false;
//					}
//				}
				
				function createCookie(name,value,days) {
					if (days) {
						var date = new Date();
						date.setTime(date.getTime()+(days*24*60*60*1000));
						var expires = "; expires="+date.toGMTString();
					}
					else var expires = "";
					document.cookie = name+"="+value+expires+"; path=/; domain=rvnuccio.com;";
				}
				
				function getCookie(c_name) {
					if (document.cookie.length>0)  {
					  c_start=document.cookie.indexOf(c_name + "=")
					  if (c_start!=-1) { 
						c_start=c_start + c_name.length+1 
						c_end=document.cookie.indexOf(";",c_start)
						if (c_end==-1) c_end=document.cookie.length
							return unescape(document.cookie.substring(c_start,c_end))
						} 
					  }
					return ""
				}
				
	