
var submitForm = false;

function setClick()
{

  submitForm = true;
}

//clear manufacturer page
function clearPhoneOnManufacturer(){
	clearPhone();
	//clearThanksMsg();
	
}
/*
function clearThanksMsg(){
	document.getElementById("divThanksMsg").style.display = "none";
}
*/
/*
//check for displaying thanks msg on home page. To be invoke onload of includeFindBankMerchant.jsp
function checkIfLogSubmitted(){
	var cameFrom = document.getElementById("indicator").value;
	
	var isLogSubmitted = document.getElementById("showThanksMsg").value;
	

	if(cameFrom == "home" && isLogSubmitted == "true"){
		document.getElementById("errorNoBankSelected").style.display = "none";
		document.getElementById("divThanks").style.display = "inline";
		
	}
	else{
		document.getElementById("divThanks").style.display = "none";
	}
}
*/

/*
*invoke onload of SelectManufacturer & SelectModel page
//check for displaying thanks msg on manufacturer
function checkIfLogSubmittedOnDeviceIncompatible(){
	var cameFrom = document.getElementById("indicator").value;
	var isLogSubmitted = document.getElementById("showThanksMsg").value;

	if((cameFrom == "manufacturer" || cameFrom == "model") && isLogSubmitted == "true"){
		document.getElementById("divThanksMsg").style.display = "inline";
		document.getElementById("showThanksMsg").value = "false";
	}
	else{
		document.getElementById("divThanksMsg").style.display = "none";
	}
}
*/
//IncludePremiumBankRedirection
function hitBankUrl(bankUrl){
	submitForm = true;
	window.location.replace(bankUrl);
}

//ContainerInstallation.jsp
function containerSubmit(context){
	
     submitForm = true;
	window.document.forms[0].action = context+"/enrollment/enroll";
	
	window.document.forms[0].submit();
}

function showHome(context){
	submitForm = true;
	window.document.forms[0].action = context+"/enrollment/index";
	window.document.forms[0].submit();
}

//When User selects a particular bank
function selectBankSubmit(strContext,strBankName,strBankType,bankUrl){
	
	submitForm = true;
	document.getElementById("bankType").value = strBankType;
	document.getElementById("bankName").value = strBankName;
	document.getElementById("bankUrl").value = bankUrl;
	
	window.document.forms[0].action = strContext+"/enrollment/isinstalled";
	window.document.forms[0].submit();
}


 
//When user clicks on container installation link on Welcome screen.
function initiateProvisioningProcess(strContext){
	
	window.document.forms[0].action = strContext+"/enrollment/getmanufacturer";
	window.document.forms[0].submit();
}

//When user clicks on the Banks & Merchants Navigation tab
function viewBankMerchantList(strContext){
	submitForm = true;
	
	window.document.forms[0].action = strContext+"/enrollment/displaybankmerchant";
	window.document.forms[0].submit();

}




function enrollAccount(strContext){

	submitForm = true;
	var strBankName = document.getElementById("bankName").value;
	
	if((strBankName == 'none') || (strBankName == null) || (strBankName == 'null')){
		
		window.document.forms[0].action = strContext+"/enrollment/getbankmerchant";
		window.document.forms[0].submit();
	}
	else {
		
		window.document.forms[0].action = strContext+"/enrollment/enroll";
		window.document.forms[0].submit();
	
	}

}
//setSignUpPage
function setSignUpPage(){
	document.getElementById("errorTxtWel6").style.display = "none";
	document.getElementById("email").focus();
}


/**
* invoked when user hits the submit button on DeviceIncompatible/SignUp page
//collect signUp data
function collectSignUpData(strContext){
	var tested = false;
	submitForm = true;
	//validate email
	var strEmail = document.getElementById("email").value;
	
	if(strEmail !=""){
		document.getElementById("errorTxtWel6").style.display = "none";
		tested = true;
		var	isEmailValid = emailValidator(strEmail);
		if(isEmailValid == false){
			return false;
		}
	}
	//collect & validate phone num
	var phone1 = document.getElementById("phoneNum1").value;
	var phone2 = document.getElementById("phoneNum2").value;
	var phone3 = document.getElementById("phoneNum3").value;
	var phoneDisplay = phone1+"-"+phone2+"-"+phone3;
	var completePhoneNum = phone1.concat((phone2.concat(phone3)));
	//email
	var strEmail = document.getElementById("email").value;
	
	if(completePhoneNum == "" && strEmail == ""){
		clearError();
		document.getElementById("errorTxtWel6").style.display = "inline";
		document.getElementById("email").focus();
		return false;
	}

	
	if(completePhoneNum !="" || tested == false){
		
		document.getElementById("errorTxtWel6").style.display = "none";
		var isPhoneValid = validatePhone(completePhoneNum);
		if(isPhoneValid == false){
			return false;
		}
	}
	
	var strEmail = document.getElementById("email").value;
	if(strEmail == ""){
		strEmail = "None";
	}
	if(completePhoneNum == ""){
		completePhoneNum = "None";
	}
	
	var logDetails = completePhoneNum+"|"+strEmail;
	var strIndicator = document.getElementById("indicator").value;
		
	if(strIndicator == "manufacturer"){
	//set manufacturer value back to 'manufacturer' in case user comes from model page to manufacturer page & hits DeviceIncompatible link
	document.getElementById("manufacturer").value = "manufacturer";
	window.document.forms[0].action = strContext+"/enrollment/getmanufacturer";
	}
	else if(strIndicator == "model"){
	
		window.document.forms[0].action = strContext+"/enrollment/getmodel";
	}
	else if(strIndicator == "home"){
	
		window.document.forms[0].action = strContext+"/enrollment/index";
	}
	document.getElementById("message").value = logDetails;
	window.document.forms[0].submit();
}
*/

/**
*invoked when user hits the signUp link on Welcome page
function signUp(strContext){
	
	submitForm = true;
	window.document.forms[0].action = strContext+"/enrollment/signup";
	window.document.forms[0].submit();
}
*/

function bankSelectionNotify(){
	//use bankName as flag
	document.getElementById("errorNoBankSelected").style.display = "none";
	document.getElementById("bankName").value = "bank";
}

function findBankSubmit(strContext)
{ 
	//check if bank is selected
	var test = document.getElementById("bankName").value;
	
	if (test==''){
		
		//clear Thanks msg for log submission if any
		//document.getElementById("divThanks").style.display = "none";
		
		//bank not selected. Show error
		document.getElementById("errorNoBankSelected").style.display = "inline";
		return false;
	}
    submitForm = true;
   
   	var bankAndMerchantList = document.getElementById("bankList");
    //get details of the selected bank
    var strBankDetails= bankAndMerchantList.options[bankAndMerchantList.selectedIndex].value;
    
    
    //split bank details
    var bankDetails = new Array();
	bankDetails = strBankDetails.split('|');
	strBankName=bankDetails[0];
	strBankType=bankDetails[1];
	strbankUrl=bankDetails[2];
	
    
	document.getElementById("bankType").value = strBankType;
	document.getElementById("bankName").value = strBankName;
	document.getElementById("bankUrl").value = strbankUrl;
	
	window.document.forms[0].action = strContext+"/enrollment/isinstalled";
	window.document.forms[0].submit();
}

function clearError(){
	document.getElementById("errorTxtWel").style.display = "none";
	document.getElementById("errorTxtWel1").style.display = "none";
	document.getElementById("errorTxtWel2").style.display = "none";
	document.getElementById("errorTxtWel3").style.display = "none";
	document.getElementById("errorTxtWel4").style.display = "none";
}


 //prevent browser forward
  
 
 function goFor()
 {
	
   if(!submitForm)
   {
      
    	if (window.navigator.appName == 'Netscape')
    	{
    		window.history.go(0);    
    	}
    	else
    	{
    		    		
    		window.history.go(-1);
    		window.history.go(1);

    	}
    }
 }

//FAQ start
function displayFaq(strContext){
	submitForm = true;
	window.document.forms[0].action = strContext+"/enrollment/showfaq";
	window.document.forms[0].submit();
}

//FAQ end

//display Privacy, Terms & Conditions

function displayTermsAndConditions(strContext){
	submitForm = true;
	window.document.forms[0].action = strContext+"/enrollment/terms";
	window.document.forms[0].submit();
}



//Welcome - Enter Phone. START

function checkPhoneSubmit()
{	
	
	submitForm = true;
	var frmForm = window.document.forms[0];

	var phone1 = frmForm.phoneNum1.value;
	var phone2 = frmForm.phoneNum2.value;
	var phone3 = frmForm.phoneNum3.value;
	var phoneDisplay = phone1+"-"+phone2+"-"+phone3;
	
	var completePhoneNum = phone1.concat((phone2.concat(phone3)));
	
   var phoneRE = /^[2-9]\d{9}$/; 
 //Phone number should have only 10 digits and should 1st digit should be between 2 - 9
 	if (completePhoneNum.match(phoneRE)) {
 	
	   	frmForm.phoneNum.value = completePhoneNum;
	   	frmForm.phoneNumDisplay.value = phoneDisplay;
	   	//isPhoneValid = 'true';
	   	return 'true';
 	} 
 	else if (completePhoneNum == null || completePhoneNum == '')
 	{
 	   clearPhone();
 	   document.getElementById("errorTxtWel1").style.display = "inline";
		return false;
 	}
 	else if (isNaN(completePhoneNum))
 	{
 	   clearPhone();
 	   document.getElementById("errorTxtWel2").style.display = "inline";

		return false;
 	}
 	else if (completePhoneNum.length < 10 || phone1.length < 3 || phone2.length < 3 || phone3.length < 4)
 	{
 	   clearPhone();
 	   document.getElementById("errorTxtWel3").style.display = "inline";
 		return false;
 	}
 	else if (completePhoneNum.toString().charAt(0) == 0 || completePhoneNum.toString().charAt(0) == 1)
 	{
 	   clearPhone();
 	   document.getElementById("errorTxtWel4").style.display = "inline";
 	   
		return false;
 	   
 	}
 	 else 	
 	{
 		//display error 
	   	clearPhone();
	   	document.getElementById("errorTxtWel").style.display = "inline";
	
		return false;
 	} 
}

//validate phone
function validatePhone(completePhoneNum){

  var phoneRE = /^[2-9]\d{9}$/; 
 
 //Phone number should have only 10 digits and should 1st digit should be between 2 - 9
 	if (completePhoneNum.match(phoneRE)) {
 		
	   	return 'true';
 	} 
 	else if (completePhoneNum == null || completePhoneNum == '')
 	{
 	 
 	   clearPhone();
 	    document.getElementById("errorTxtWel1").style.display = "inline";
		return false;
 	}
 	else if (isNaN(completePhoneNum))
 	{
 	
 	   clearPhone();
 	    document.getElementById("errorTxtWel2").style.display = "inline";
 		return false;
 	}
 	else if (completePhoneNum.length < 10)
 	{
 	
 	   clearPhone();
 	    document.getElementById("errorTxtWel3").style.display = "inline";
		return false;
 	}
 	else if (completePhoneNum.toString().charAt(0) == 0 || completePhoneNum.toString().charAt(0) == 1)
 	{
 	
 	   clearPhone();
 	    document.getElementById("errorTxtWel4").style.display = "inline";
		return false;
 	   
 	}
 	 else 	
 	{
 	
	   	clearPhone();
	   	document.getElementById("errorTxtWel").style.display = "inline";
		return false;
 	} 

}//validatePhone END

function phoneAutoFocus(id)
{
	//phoneNum1
	if(id=="phoneNum1"){
	var len = document.getElementById("phoneNum1").value.length;
		if(len==3){
			document.getElementById("phoneNum2").focus();
		}
	}
	//phoneNum2
	if(id=="phoneNum2"){
	var len = document.getElementById("phoneNum2").value.length;
		if(len==3){
			document.getElementById("phoneNum3").focus();
		}
	}

}

/**
*invoked onload of DeviceIncompatible page. Used to clear email & phone & set focus
function loadDeviceIncompatible(){
	clearPhone();
	document.getElementById("errorTxtWel6").style.display = "none";
	document.getElementById("email").value="";
	document.getElementById("email").focus();
}
*/


function clearPhone(){

clearError();
 	//clear phone number
		document.getElementById("phoneNum1").value="";
		document.getElementById("phoneNum2").value="";
		document.getElementById("phoneNum3").value="";
		
		document.getElementById("phoneNum1").focus();

}


//SelectManufacturer START

function manufacturerSubmit(manufacturer, smsHost)
{ 
		
		submitForm = true;
		var oForm = window.document.forms[0];
		var isPhoneValid = checkPhoneSubmit();
		
		
		if(isPhoneValid == 'true'){
			
			setClick();
			oForm.manufacturer.value = manufacturer;
			oForm.smsHost.value = smsHost;
	        oForm.submit();
        }
      
}

function ManufacturerNotAvaliableSubmit(Context){
	submitForm = true;
	window.document.forms[0].action = Context+"/enrollment/deviceincompatible";
	window.document.forms[0].submit();
}

//SelectManufacturer END

//SelectModel START

function modelSubmit(modelId, modelName,modelInstructionUrl)

{ 
		submitForm = true;
        var oForm = window.document.forms[0];
        oForm.deviceId.value = modelId;
        oForm.model.value = modelName;
        oForm.instructionsPath.value = modelInstructionUrl;
        oForm.submit();
}

function deviceIncompatibleSubmit(strContext){
	submitForm = true;
	window.document.forms[0].action = strContext+"/enrollment/deviceincompatible";
	window.document.forms[0].submit();
}

function findMyPhoneModelSubmit(Context){
	submitForm = true;
	window.document.forms[0].action = Context+"/enrollment/showfaq#J7";
	window.document.forms[0].submit();
}

//display FAQ content specific to finding compatible handsets
function findCompatibleHandsetFaq(Context){
	submitForm = true;
	window.document.forms[0].action = Context+"/enrollment/showfaq#J5";
	window.document.forms[0].submit();
}

//SelectModel END




//ContainerInstallation - START

function installationCheckSubmit(context)
{ 
        submitForm = true;
        window.document.forms[0].action = context+"/enrollment/getmanufacturer";
        window.document.forms[0].submit();
}

//ContainerInstallation - END

//open url in new window
   function open_win(url_add)
   {
      var newWindow;
        newWindow = window.open(url_add,"welcome","width=600,height=400,toolbar=1,location=1,status=1,scrollbars=1,menubar=1,resizable=1");
        
   }
   
//email validation
function emailValidator(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
	
		var emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/
		
		if (str.match(emailRe)) {
			return true;
		}
		else{
			clearPhone();
		   document.getElementById("errorTxtWel").style.display = "inline";
		   document.getElementById("email").value = "";
		 
		   document.getElementById("email").focus();
		   return false
		}
			
	}
