/* startup events
-----------------------------------------------------------*/
var index = {};

index.init = function(){

	addEvent($("searchButton"),"click",function(){
										//$("domainText").value.toLowerCase();
										$("domainText").value=$("domainText").value.toLowerCase();
										var v = $("domainText").value.toLowerCase();
										var allowSearch = true;
										if (v.indexOf("www")>-1){
											alert('Please change the name you\'re searching for -\nThere\'s no need to include "www".');
											allowSearch = false;
										}
										if (v.indexOf("statefarm")>-1 || (v.indexOf("goodneighbor")>-1) || (v.indexOf("st8")>-1) || (v.indexOf("financialservices")>-1) || (v.indexOf("isthere")>-1) || (v.indexOf("ishere")>-1) || (v.indexOf("imthere")>-1) || (v.indexOf("imhere")>-1) || (v.indexOf("livingred")>-1) || (v.indexOf("agency")>-1)){
											alert('Please change the name you\'re searching for.\n State Farm Guidelines restrict the use of the following words or phrases in a domain name: \n"statefarm"\n"good neighbor"\n"st8"\n"financial services"\n"is there"\n"is here"\n"im there"\n"im here"\n"living red"\n"agency" **\n\n** Please contact us if you are incorporated and wish to use the word "agency". ');
											allowSearch = false;
										}
										if (allowSearch){
											domain.check($("domainText").value);
										}
									},false);
	$("domainSearchForm").onsubmit = function(){return false;};
	$("transferForm").onsubmit = function(){return false;};
	
	dom.toggle("transferProgressDiv",false);

	domain.check(null,domain.FQDNAgentNameCombo());
	$("domainText").style.color = "#888";
	$("domainText").value = domain.settings.defaultdomain;
		
	addEvent($("domainText"),"focus",function(){																		
										if ($("domainText").value == domain.settings.defaultdomain){
											$("domainText").value="";
											$("domainText").style.color = "#000";
										}
									},false);
															
	addEvent($("domainText"),"blur",function(){																		
									if (!$("domainText").value){
										$("domainText").style.color = "#aaa";
										$("domainText").value = domain.settings.defaultdomain;
									}
									},false);

	if ($("loginButton")){
		addEvent($("loginButton"),"click",function(){agent.agentLogin();});
	}
	addEvent($("transferButton"),"click",function(){domain.transfer();});
	

	//cart.addTotals();

	
	dom.setFieldFormat($("domainText"),{keyup:"alphanumericdash",minlength:3,maxlength:63,nomark:true,clean:true}); 
	dom.setFieldFormat($("domainTransferSLD"),{keyup:"alphanumericdash",minlength:3,maxlength:63,nomark:true,clean:true});

	
	
	
	
	
	
	addEvent("faq1","click",function(e){dom.showModalDialog("faq1_answer",{title:"What makes a good domain name?"});});
	addEvent("faq2","click",function(e){dom.showModalDialog("faq2_answer",{title:"Should I get more than one domain name?"});});
	addEvent("faq3","click",function(e){dom.showModalDialog("faq3_answer",{title:"What is the cost?"});});
	addEvent("faq4","click",function(e){dom.showModalDialog("faq4_answer",{title:'What is a "Domain Transfer"?'});});
	addEvent("faq5","click",function(e){dom.showModalDialog("faq5_answer",{title:"How does a transfer work?"});});
	addEvent("faq6","click",function(e){dom.showModalDialog("faq6_answer",{title:"What is the cost to transfer?"});});
	addEvent("faq7","click",function(e){dom.showModalDialog("faq7_answer",{title:"Unlocking a Domain"});});
	addEvent("faq8","click",function(e){dom.showModalDialog("faq8_answer",{title:"Using a Professional Spokesperson"});});
	addEvent("faq9","click",function(e){dom.showModalDialog("faq9_answer",{title:"Corporate Approved Scripts"});});
	addEvent("faq10","click",function(e){dom.showModalDialog("faq10_answer",{title:"How do I get E-Mail?"});});
	addEvent("faq11","click",function(e){dom.showModalDialog("faq11_answer",{title:"Video Production Options"});});
	addEvent("faq12","click",function(e){dom.showModalDialog("faq12_answer",{title:"Video Production Options"});});
	addEvent("faq13","click",function(e){dom.showModalDialog("faq13_answer",{title:"Video Tips for Aspiring Actors"});});
	addEvent("faq14","click",function(e){dom.showModalDialog("faq14_answer",{title:"Getting the Video Back to Us"});});
	addEvent("faq15","click",function(e){dom.showModalDialog("faq15_answer",{title:"My State Farm Domain vs. The Other Guys"});});

	//addEvent("emailAlert","click",function(e){dom.showModalDialog("faq10_answer",{title:"How do I get E-Mail?"})});
	addEvent("faq100","click",function(e){dom.showModalDialog("faq100_answer",{title:"How are domain names and e-mails related?"});});
	//addEvent("emailDomainFAQ","click",function(e){dom.showModalDialog("faq100_answer",{title:"How are domain names and e-mails related?"})});
	
	agent.loadAgentInfo(readCookie("agentTempGUID"));
	
	if (cart.settings.allowemailpurchase){
		dom.toggle("__agentDomainManagementTable",true);
		dom.toggle("emailAlert",true);
		agent.handleLoginInterface("start");
	}
	cart.refresh(true);
};
addEvent(window,"load",index.init,false); //initialize the system

function forgotPassword(e,sendNoMail,xhrObj){
	//if we're not loaded yet
	if (e && !xhrObj){
		var supForm = dom.addForm("supForm");
		dom.addFormData(supForm,"alias",e);
		dom.addFormData(supForm,"func","sup");
		if (sendNoMail){
			dom.addFormData(supForm,"nomail","true");
		}
		var xmlURL = rootPath + "incs/siteXHR.asp"; // base query URL
		xhr.connect(xmlURL,"POST",forgotPassword,[null,sendNoMail],"supForm",false);
		dom.removeObject(supForm);
	}else if(xhrObj){
		var s = xhr.XMLtoObj(xhrObj.getElementsByTagName("root")[0]).status;
		//$("loginStatusResponse").style.color = "#ffffff";
		if (s == "success"){
			if (sendNoMail){
				agent.handleLoginInterface("password",true,true);
			}else{
				agent.statusChange('We found your info and sent the email. You should be getting it in a few minutes.','error');
				//$("loginStatusResponse").innerHTML = "<br>We found your info and sent the email. You should be getting it in a few minutes.<br>";
			}
			fadeCSS.fade("loginStatusResponse","color","#ffffff","#3AAC2B");
		}else{
			agent.statusChange('We couldn\'t locate that alias.  Please check and re-enter your alias, or call us if you\'re stuck.','error',3500);
			//$("loginStatusResponse").innerHTML = "<br>We couldn't locate that alias.  Please check and re-enter your alias, or call us if you're stuck.<br>";
			//fadeCSS.fade("loginStatusResponse","color","#ffffff","#C23033");
			return false;
		}
	}else{
		alert("Try a valid alias.");
	}
	dom.removeObject("supForm");
}



function agentLogout(){
	eraseCookie("agentTempGUID");
	window.location = rootPath;
}