
			var ERROR_TEXT_LOGIN = "The highlighted fields need to be entered with valid information";
			var ERROR_TEXT_DEVICE = "Please enter a valid Phone Number";
			var ERROR_TEXT_COUNTRY_CODE = "Please select your country code";
			var ERROR_CONFIRM_AGREE = "Please confirm you have read the Agreement above by checking the box";
			var agreeClicked;
			var proceedClicked;
			agreeClicked = false;
			proceedClicked = false;
							
			function validateForm()
			{
				var sAccountNo;
				var sPassword;
				var sDeviceNumber;
				var sEmail;
				var bLoginError;
				var divErrorText;
				var divMobInstall;
				var divEmail;
				var mobileNumberError;
				
				//var errorDevice;		
				
				// Check if called from Login or Agreement page 
				if(proceedClicked == true)
				{
					if (agreeClicked == true)
					{
						return true;
					}
					return false;					
				} 
				
				sAccountNo = document.getElementById("txtAccountNo");
				sPassword = document.getElementById("txtPassword");				
				divMobInstall = document.getElementById("divMobInstall");
				divErrorText = document.getElementById("divErrorText");
				
			    //errorDevice = document.getElementById("divErrorDevice");
				bLoginError = false;
				mobileNumberError = false;								
				//if (sAccountNo == null)
				//	return false;
				if (divMobInstall == null)
				{
					clearFormError(sAccountNo, divErrorText);
					clearFormError(sPassword, divErrorText);

					if (sAccountNo.value == "")
					{						
						raiseFormError(sAccountNo, divErrorText, ERROR_TEXT_LOGIN);						
						bLoginError = true;
					}
					if (sPassword.value == "")
					{						
						raiseFormError(sPassword, divErrorText, ERROR_TEXT_LOGIN);						
						bLoginError = true;
					}
					if (bLoginError == true)
					{
						return false;
					}
				}
				else
				{
				    sDeviceNumber = document.getElementById("txtMobNumber");

				    if (validateCountryCode()==false)
				        mobileNumberError = true;

				    if (!validateDeviceNumber(sDeviceNumber)) // validate device number
				        mobileNumberError = true;

				    if (mobileNumberError) {
						return false;
					}
				}				
				return true;
			}
			
			function validateAgreement()
			{
				var chkAgreement;
				chkAgreement = document.getElementById("chkAgreement");				
				proceedClicked = true;
				agreeClicked = true;
				
				if (chkAgreement.checked != true)
				{
					alert(ERROR_CONFIRM_AGREE);
					agreeClicked = false;	
					return;									
				}						
			}
			
			function raiseFormError(formItem, errorDiv, errorText)
			{			    
				eval("errorDiv.innerHTML = errorText");
				eval("errorDiv.style.visibility = 'visible'"); 
				eval("formItem.className = 'midbackred'");
			}
			
			function clearFormError(formItem, errorText)
			{
			    eval("errorText.style.visibility = 'hidden'"); 
				if (formItem != null)
				    eval("formItem.className = ''");
			}  
			
			function validateDeviceNumber(deviceNumber)
			{
				var divErrorDevice;
				divErrorDevice = document.getElementById("divErrorDevice");
				clearFormError(deviceNumber, divErrorDevice);
				
				if (deviceNumber.value == "")
				{
				    raiseFormError(deviceNumber, divErrorDevice, ERROR_TEXT_DEVICE);							
					return false;
				}
				if (!checkNumber(deviceNumber, divErrorDevice))
				{
					return false
				}
				return true;
			}


			function validateCountryCode()
			{
			    var divErrorCode;
			    divErrorCode = document.getElementById("divErrorCode");
			    
			    if (document.getElementById("countryCodeList"))
			    {
			        var countryCodeSelect = document.getElementById("countryCodeList");
			        
			        if (countryCodeSelect.options[countryCodeSelect.selectedIndex].value == "-")
			        {
			            // countryCodeSelect.className = 'midbackred';
			            updateInternationalCode(" ");
			            raiseFormError(countryCodeSelect, divErrorCode, ERROR_TEXT_COUNTRY_CODE);						
			            return false;
			        }
					else
					{
						var intCode = countryCodeSelect.options[countryCodeSelect.selectedIndex].value;
						//countryCodeSelect.className = '';
						clearFormError(countryCodeSelect, divErrorCode);
						updateInternationalCode("+"+intCode);
					}			         
			    }
			    return true;
			}
			
			function updateInternationalCode(intCode)
			{
			    if (document.getElementById("internationalCode"))
			    {
			        document.getElementById("internationalCode").innerHTML = intCode;
			    }
			}
			
			function checkNumber(formField, divErrorDevice)
			{
				var s; 
				s = formField.value.toUpperCase();
				
				for(var i = 0; i < s.length; i++)
				{
					if ((s.charCodeAt(i) < 48) || (s.charCodeAt(i) > 59))   /* not number */
					{
						if ((s.charAt(i) != " ") && (s.charAt(i) != "+") && (s.charAt(i) != "(") && (s.charAt(i) != "-") && (s.charAt(i) != ")"))
						{
							/* invalid character */
							raiseFormError(formField, divErrorDevice, ERROR_TEXT_DEVICE);							
							return false;  			
						}
					}
					if (s.length < 10)
					{							
						raiseFormError(formField, divErrorDevice, ERROR_TEXT_DEVICE);							
						return false;   
					}		
				}
				return true;
             }

            function getBrandImages() 
            {
                var ref = location.search.substring(1); 
                var brandDirectory = ref.slice(3);
                var imgArr = ['btnSubmitImg','btnCloseImg','btnInstallImg','btnErrorCloseImg'];                

                for (var i = 0; i < imgArr.length; i++)
                {
                    var thisID = imgArr[i];
                    if (document.getElementById(thisID) != null)
                    {
                        var srcRef = document.getElementById(imgArr[i]).src;

                        var t = srcRef.lastIndexOf('/');
                        srcRef = srcRef.substr(t+1);
                        var newRef = "App_Themes/" + brandDirectory + "/images/" + srcRef;
                        document.getElementById(imgArr[i]).src = newRef;
                    }
                }
            }
