﻿function ShowLogin() {
    
	var xml = "<Login />";
	if(glbIsFacilityBased) {
		innerHTML = TransformXML(xml,"facilitylogin.xsl");
	}
	else {
		innerHTML = TransformXML(xml,"login.xsl");
	}

	//glbNavigation.innerHTML = "";
	glbNavigation.innerHTML = "&nbsp;";
	setLogginPageSettings(true);
	//glbNavigation.style.display = "none";
	glbNavigation.style.display = "none";
	glbContent.innerHTML = innerHTML;
	AddLoginFormEvents();
}






function AddLoginFormEvents() {
	glbContentEvents.add('strPassword', 'keypress', SubmitLoginForm);
	glbContentEvents.add('remember', 'keypress', SubmitLoginForm);	
	document.getElementById("strEmail").value = "";
	document.getElementById("strPassword").value = "";
	//document.getElementById('strEmail').focus();
}

var UserDetailXML;
function closeModalWindow()
{
   //document.getElementById("PopupTD2").style.display = "block";
    hm();
}
function Forgot1() {
           document.getElementById("PopupTD1").style.display = "block";
           //document.getElementById("PopupTD2").style.display = "none";
          
          if(document.getElementById("inpFirstName").value == "")
          {
              alert("Please Enter First Name");
              document.getElementById("inpFirstName").focus();
              return false;
          }
          if(document.getElementById("inpLastName").value == "")
          {
              alert("Please Enter Last Name");
              document.getElementById("inpLastName").focus();
              return false;
          }
          if(document.getElementById("inpEmail").value == "")
          {
              alert("Please Enter Email");
              document.getElementById("inpEmail").focus();
              return false;
          }
          if (echeck(document.getElementById("inpEmail").value)==false)
          {
		        document.getElementById("inpEmail").value="";
		        document.getElementById("inpEmail").focus();
		        return false;
	      }
          if(document.getElementById("inpPassword").value == "")
          {
              alert("Please Enter Password");
              document.getElementById("inpPassword").focus();
              return false;
          }
          if(document.getElementById("inpPhone").value == "" || document.getElementById("textfield4").value == "") 
          {
              alert("Please Enter Phone");
              if(document.getElementById("inpPhone").value == "")
              {
                  document.getElementById("inpPhone").focus();
              }
              else
              {
                  document.getElementById("textfield4").focus();
              }
              return false;
          }
         
 
    	if(ValidForm("SignupForm","messageSignup")) 
    	{
    	
    	  
    	
//	 window.open("index2.htm","Terms",
//        "menubar=no,width=670,height=500,toolbar=no,scrollbars=yes");
            
                  
         
        
//          var PopupTD =  document.getElementById("PopupTD");
//          if(PopupTD)
//          PopupTD.className ="TOCBOX"
           
          var TempDiv = document.getElementById("mbd");
          if(TempDiv)
          TempDiv.innerHTML ="";  
            
          var TOCRow1 =  document.getElementById("TOC1");
          if(TOCRow1)
          TOCRow1.style.display ="";
          
          
          document.getElementById("PopupContent").src = "index2.htm";
           document.getElementById("PopupContent").style.height = "550";
          sm('divPopup' ,600,650);
          document.getElementById("PopupTD1").style.display = "block";
          
         
    }
     
          ///////// changes for javascript validation //////////////////
         
          
          /////////////////////////////////////////////////////////////
          
}

function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Invalid Email");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid Email");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid Email");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid Email");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid Email");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid Email");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid Email");
		    return false;
		 }

 		 return true;					
	}

function SubmitLoginForm(e) {
 
	if(e && e.type == 'keypress' && (GetEventKey(e) != 13))  return false;
	

	if(ValidForm("loginForm","messageLogin")) {
		var soapData = SoapDataBuilder("CheckLogin", parseForm('loginForm'));
		var xml = AjaxRequest("Login.asmx",soapData,"login.xsl", "Navigation", "messageLogin");   

		if(glbXmlRequest.GotMessageOnly()) {
			AddLoginFormEvents();
			setLogginPageSettings(true);
		}
		else 
		{
			glbHeader.innerHTML = TransformXML(xml,"header.xsl");
			setLogginPageSettings(false);
			
	        location.href="default.htm";
	        btest=true;
		    
		}
		
		
		
		
	}
		
  
}
/*funciton added by hiren for login box settings*/
function setLogginPageSettings(setSettings)
{
    if(setSettings)
    {
        glbNavigation.innerHTML = "&nbsp;";
	    glbNavigation.style.display = "none";
	    document.getElementById("MainTable").width = "975px";
	 }
	 else
	 {
	    glbNavigation.style.display = "block";
	    document.getElementById("MainTable").width = "820px";
	 }

}
/*end function addition*/
function Logout() {
	var soapData = SoapDataBuilder("Logout");
	AjaxRequest("Login.asmx",soapData);
	SessionTimeout();
	CloseHelp();
	setLogginPageSettings(true);
	//added by ankur 9th june 2008
	location.href="login.aspx";
}

function Forgot() {
	//glbContent.innerHTML = TransformXML("<Forgot />","login.xsl");	
	//document.getElementById("divFPWD").style.display = "block";
	//setLogginPageSettings(false);
	sm('box',305,235);
}

function SubmitForgotForm(e) {
	if(ValidForm("ForgotForm")) {
		var soapData = SoapDataBuilder("Forgot", parseForm("ForgotForm"));
		AjaxRequest("Login.asmx",soapData,"login.xsl");
	}
}

function ShowContactUs() {
	glbContent.innerHTML = TransformXML("<Contact />","login.xsl");
	TrimTextAreas("contactForm");
	setLogginPageSettings(false);
}

function SubmitContactForm() {
	if(ValidForm("contactForm")) {
		var soapData = SoapDataBuilder("SendComment", parseForm('contactForm'));
		AjaxRequest("Login.asmx",soapData,"login.xsl");
	}
}

function FirstLogin(save, addAnother) {
	if(save) {
		if(ValidForm("AddUserTeamForm")) {
			if(addAnother) {
				document.getElementById("addAnother").value = "1";
			}
			var soapData = SoapDataBuilder("FirstLoginAddUserTeam", parseForm("AddUserTeamForm"));
			AjaxRequest("Login.asmx",soapData,"login.xsl");	
			AddFirstLoginEvents();
		}	
	}
	else {
		var soapData = SoapDataBuilder("FirstLoginAddUserTeam", parseForm("AddUserTeamForm"));
		AjaxRequest("Login.asmx",soapData,"login.xsl");
		AddFirstLoginEvents();
	}
}

function AddFirstLoginEvents() {
	suggestCollection.add('strAssociation', 'strAssociationSuggest', 'strClub', 'Incident.asmx', 'GetAssociations', new Array('lngSportID'));
	suggestCollection.add('strClub', 'strClubSuggest', 'strTeamGrade', 'Incident.asmx', 'GetClubs', new Array('lngSportID', 'strAssociation'));
	suggestCollection.add('strTeamGrade', 'strTeamGradeSuggest', 'strCoach', 'Incident.asmx', 'GetTeamGrades', new Array('lngSportID', 'strAssociation', 'strClub'));
	suggestCollection.add('strCoach', 'strCoachSuggest', null, 'Incident.asmx', 'GetCoachs', new Array('lngSportID', 'strAssociation', 'strClub', 'strTeamGrade'));
}

function SelectTeamField(fieldName) {
	var queryString = "field="+fieldName;
	switch(fieldName) {
		case "strCoach":
			queryString += "&strTeamGrade=" + document.getElementById("strTeamGrade").value;
		case "strTeamGrade":
			queryString += "&strClub=" + document.getElementById("strClub").value;
		case "strClub":
			queryString += "&strAssociation=" + document.getElementById("strAssociation").value;
		case "strAssociation":
			queryString += "&lngSportID=" + document.getElementById("lngSportID").value;						
	}
	OpenModal("teamfield.aspx?"+queryString, 300, 100);
}

function TeamFieldSelected(fieldName, fieldValue) {
	var field = document.getElementById(fieldName);
	if(field) {
		field.value = fieldValue;
	}
}

