﻿function GoUCLLogin(evt) {
    var charCode = evt.which;
    if (typeof(charCode) == "undefined") charCode = evt.keyCode;
    if (charCode == 13) {
        ValidateUser(1);
        return false;
    }
}

function GoFormLogin(evt) {
    var charCode = evt.which;
    if (typeof(charCode) == "undefined") charCode = evt.keyCode;
    if (charCode == 13) {
        ValidateUser(2);
        return false;
    }
}


function Tellusabout(){
    var txtLookingFor=document.getElementById("txtLookingFor")
    var rdoOverallExperience=document.getElementsByName("rdoOverallExperience")
    var StatusrdoOverallExperience=""
    var EasyNavigation=document.getElementsByName("rdoEasyNavigation")
    var StatusEasyNavigation=""
    var language_opinion=document.getElementsByName("language_opinion")
    var Statuslanguage_opinion=""
    var ReferAFriend=document.getElementsByName("ReferAFriend")
    var StatusReferAFriend=""
	
    if(txtLookingFor.value =='' ){
	    alert("Please provide what you were looking for");
	    txtLookingFor.focus();
	    txtLookingFor.select();
	    return false;
    }

	for(i=0;i<rdoOverallExperience.length;i++){
		if(rdoOverallExperience[i].checked){
			StatusrdoOverallExperience=rdoOverallExperience[i].value;
			break
		}
	}
	
	if(StatusrdoOverallExperience==""){
		alert("Please provide Feedback for Q1" );
		rdoOverallExperience[0].focus();
		return false;
	}

	for(i=0;i<EasyNavigation.length;i++){
		if(EasyNavigation[i].checked){
			StatusEasyNavigation=EasyNavigation[i].value;
			break
		}
	}

	if(StatusEasyNavigation==""){
		alert("Please provide Feedback for Q2" );
		EasyNavigation[0].focus();
		return false;
	}
	
	for(i=0;i<language_opinion.length;i++){
		if(language_opinion[i].checked){
			Statuslanguage_opinion=language_opinion[i].value;
			break
		}
	}
	
	if(Statuslanguage_opinion==""){
		alert("Please provide Feedback for Q3" );
		language_opinion[0].focus();
		return false;
	}

    for(i=0;i<ReferAFriend.length;i++){
	    if(ReferAFriend[i].checked){
		    StatusReferAFriend=ReferAFriend[i].value;
		    break
	    }
    }
    
    if(StatusReferAFriend==""){
	    alert("Please provide Feedback for Q4" );
	    ReferAFriend[0].focus();
	    return false;
    }
    showWait(true);
    UserControl_Login.Tellusabout(txtLookingFor.value,StatusrdoOverallExperience,StatusEasyNavigation,Statuslanguage_opinion,StatusReferAFriend,function(objResponse) {
        showWait(false);
        var sResponseText = trim(objResponse.value);
        if(sResponseText.indexOf("SfException:") != -1){
            alert(trim(sResponseText.replace("SfException:", "")));
        }
        else if(sResponseText == "Success"){
            closePopup();
           alert("Thank you for your valuable feedback")
        }
        else if(sResponseText == "Failure"){
            alert("Unable to update your confirm mail. Please try again!");
        }     
    });
}

function ValidateUser(sLoginType) {
    var txtLoginId = (sLoginType == 1) ? document.getElementById("txtLoginId") : document.getElementById("txtLogin");
    var txtPassword = (sLoginType == 1) ? document.getElementById("txtPassword") : document.getElementById("txtPwd");
    var sLoginId = trim(txtLoginId.value);
    var sPassword = trim(txtPassword.value);
    if (sLoginId != "") {
        if (sPassword != "") {
            UserControl_Login.ValidateUser(sLoginId, sPassword, function(objResponse) {
                var sResponseText = objResponse.value;
	            if (sResponseText.indexOf("SfException:") != -1) {
                    alert(trim(sResponseText.replace("SfException:", "")) + ".");
                }
                else if (sResponseText == "ExistingCustomerNotVerified") {
                    window.location = "/mysf/register/ConfirmationMail/confirmmail.aspx";
                }
	            else if (sResponseText == "NotVerified") {
                    alert("Your Email ID has not been verified.");
                }
                else if (sResponseText == "Success") {
	                window.location = "/mysf/mypage.aspx";
	            }
	            else if (sResponseText == "UpdateZoneId") {
	                window.location = "/mysf/register/updatetimezone.aspx";
	            }
	            else if (sResponseText == "Invalid Password") {
	                txtPassword.value = "";
	                alert(sResponseText + ".");
	            }
	            else if (sResponseText == "Invalid Login ID") {
                    txtLoginId.value = "";
                    txtPassword.value = "";
                    alert(sResponseText + ".");
                }
            });
        }
        else {
            alert("Please enter Password.");
            return false;
        }
    }
    else {
        alert("Please enter Login ID.");
        return false;
    }
}

function ShowHideLoginMenu(showFlag) {
    if (showFlag == true) {
        document.getElementById("tabLogin").style.display = "block";
        document.getElementById("Menu5").href = "javascript:void(0);";
        document.getElementById("Menu5").style.cursor = "hand";
    }
    else {
        document.getElementById("tabLogin").style.display = "none";
        document.getElementById("Menu5").href = "/mysf/mypage.aspx";
        document.getElementById("Menu5").style.cursor = "hand";
    }
}

