/*
'---------------------------------------------------------------------------------------------
'                                       COMPONENT
'---------------------------------------------------------------------------------------------
' File Name........:    Global.js
' Type.............:    Javascript
' Reference........:    SWR XXXX - DB Mortgages.
' Author...........:    Kian Shore	
' Date.............:    10th November 2006
' Description......:    Global Javascript functions.
' Warning/Notes....:    
'---------------------------------------------------------------------------------------------

'---------------------------------------------------------------------------------------------
'                                    AMENDMENT HISTORY
'---------------------------------------------------------------------------------------------
' Reference........:    Project reference number, SWR number, Helpdesk call number, etc.
' Author...........:    Programmer's name
' Date.............:    Amendment date #1
' Description......:    Reason for amendment
' Warning/Notes....:    Must include limitations, constrains, etc.
'---------------------------------------------------------------------------------------------
' Reference........:    Project reference number, SWR number, Helpdesk call number, etc.
' Author...........:    Programmer's name
' Date.............:    Amendment date #2
' Description......:    Reason for amendment
' Warning/Notes....:    Must include limitations, constrains, recommendations, etc.
'---------------------------------------------------------------------------------------------
*/


//function closeWindow() {
//   window.opener='x';
//   var win = window.open("","_self");
//    win.close();
//}

function closeWindow() {
window.open('','_parent','');
window.close();
}


function noPaste() {

    return !((event.keyCode == 86) && (event.ctrlKey));
}

/**************************************************************/
// Generic DIV Toggle Display function 
/**************************************************************/

function ToggleDisplay(id)
	{
		var elem = document.getElementById('d' + id);
		var elemImage = document.getElementById('i' + id);
		
		if (elem)
		{
			if  (elem.style.display != 'block')
			{
				elem.style.display = 'block';
				elem.style.visibility = 'visible';
				elemImage.src = '../../Image/DesktopTitleImages/dblup.gif';
			}
			else
			{
				elem.style.display = 'none';
				elem.style.visibility = 'hidden';
				elemImage.src = '../../Image/DesktopTitleImages/dbldn.gif';
			}
		}
	}
	
/**************************************************************/
// Hide DIV Function
/**************************************************************/

function HideDivision(division){
	
	document.all[division].style.display = "none";	
}	

/**************************************************************/
// Show DIV Function
/**************************************************************/

function ShowDivision(division){
	
	document.all[division].style.display = "block";	
}	
	
/***************************************************************/
// Default button control
/***************************************************************/

function DefaultButtonHandler(control, name, btnName)
{
	// Only process when the [Enter] key is pressed
	if (event.keyCode == 13)
	{
		// Cancel the default submit
		event.returnValue = false;
		event.cancel = true;
		
		// Create the control button name
		button = control.id;
		button = button.replace(name, btnName);
		
		// Submit the form by programmatically clicking the specified button
		document.getElementById(button).click();
	}		
}

// **************************************************************************
// To Upper Case function
// **************************************************************************
				
function ToUpperCase(control) {

var elemText = document.getElementById(control.id);
	
	// Set the value in the text field to upper case
	elemText.value = elemText.value.toUpperCase();
				
}

// **************************************************************************
// Validator Turn-Off function
// **************************************************************************
				
function ValidatorDisable(control, controlName, ValidatorName) {

// Create the control

	Validator = control.id;
	Validator = Validator.replace(controlName, ValidatorName);

//Declare element
	var elemValidator = document.getElementById(Validator);

	elemValidator.enabled = false;
}



// **************************************************************************
// CheckNumeric_Money (including decimal place character)
// **************************************************************************
		
function checkNumeric_Money( control ) {

	// Add leading zero if required
	if (control.value.indexOf('.') == 0){
		control.value = "0" + control.value;
	}	

	// Find which key was pressed.		
	var evt = (evt) ? evt : ((window.event) ? event : null); 
	var charCode = (evt.charCode) ? evt.charCode : evt.keyCode;

	// If not any of below pressed
	if ((charCode == '8')||(charCode == '46')||    // Delete, Backspace
		(charCode == '9')||                        // Tab Key	
		(charCode == '37')||					   // Cursor Left
		(charCode == '38')||					   // Cursor Up
		(charCode == '39')||					   // Cursor Right
		(charCode == '40')||					   // Cursor Down
		(charCode == '13')||					   // Return
		(charCode == '48')||(charCode == '96')||   // 0 , 0 (keypad)
		(charCode == '49')||(charCode == '97')||   // 1 , 1 (keypad)			
		(charCode == '50')||(charCode == '98')||   // 2 , 2 (keypad)
		(charCode == '51')||(charCode == '99')||   // 3 , 3 (keypad)
		(charCode == '52')||(charCode == '100')||  // 4 , 4 (keypad)
		(charCode == '53')||(charCode == '101')||  // 5 , 5 (keypad)
		(charCode == '54')||(charCode == '102')||  // 6 , 6 (keypad)
		(charCode == '55')||(charCode == '103')||  // 7 , 7 (keypad)
		(charCode == '56')||(charCode == '104')||  // 8 , 8 (keypad)
		(charCode == '57')||(charCode == '105')||  // 9 , 9 (keypad)
		(charCode == '110')||(charCode == '190')){ // . , . (keypad)
		
		
			if ((charCode == '8')||(charCode == '46')||    // Delete, Backspace
			(charCode == '9')||                        // Tab Key	
			(charCode == '37')||					   // Cursor Left
			(charCode == '38')||					   // Cursor Up
			(charCode == '39')||					   // Cursor Right
			(charCode == '40')){}					   // Cursor Down
			else{
			  					   
				// If there is a decimal
				if (control.value.indexOf('.') != -1){
					// Only allow one decimal point
					var DecimalPoints = new Array();
					DecimalPoints = control.value.split('.');
					if (DecimalPoints.length == 2 && ((charCode == '110')||(charCode == '190'))){
						return false;
					}	
					//Only allow two decimal places
					dectext = control.value.substring(control.value.indexOf('.') + 1, control.value.length);
					if (dectext.length >= 2){
						control.value = control.value.substring(0, control.value.indexOf('.') + 3);
						return false;
					}
				}	
			}
		}	
		else{
			return false;
		}	
}

// *************************************************************************
// Check Numeric (Numeric Only)
// *************************************************************************
function checkNumeric( control ) {

// Find which key was pressed.		
var evt = (evt) ? evt : ((window.event) ? event : null); 
var charCode = (evt.charCode) ? evt.charCode : evt.keyCode;

// If not a tab , delete or backspace, set FirmName and Postcode fields to ""
	if ((charCode == '8')||(charCode == '46')||    // Delete, Backspace
		(charCode == '9')||                        // Tab Key	
		(charCode == '37')||					   // Cursor Left
		(charCode == '38')||					   // Cursor Up
		(charCode == '39')||					   // Cursor Right
		(charCode == '40')||					   // Cursor Down
		(charCode == '48')||(charCode == '96')||   // 0 , 0 (keypad)
		(charCode == '49')||(charCode == '97')||   // 1 , 1 (keypad)			
		(charCode == '50')||(charCode == '98')||   // 2 , 2 (keypad)
		(charCode == '51')||(charCode == '99')||   // 3 , 3 (keypad)
		(charCode == '52')||(charCode == '100')||  // 4 , 4 (keypad)
		(charCode == '53')||(charCode == '101')||  // 5 , 5 (keypad)
		(charCode == '54')||(charCode == '102')||  // 6 , 6 (keypad)
		(charCode == '55')||(charCode == '103')||  // 7 , 7 (keypad)
		(charCode == '56')||(charCode == '104')||  // 8 , 8 (keypad)
		(charCode == '57')||(charCode == '105')    // 9 , 9 (keypad)
		){ 
	}	
	else{
		return false;
	}	
}

// *************************************************************************
// Right Trim
// *************************************************************************
function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	
	if(v_length < 0){
		return"";
	}
	
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	} 
	return strTemp;
} 
// *************************************************************************
// Left Trim
// *************************************************************************

function LTrim(VALUE){

	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}

	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} 
	return strTemp;
} 

// **************************************************************************
// DivToggleYesEqualsShow
// **************************************************************************

function DivToggleYesEqualsShow(control, ControlName, divisionTextbox, division){

	// Define division Text Box
	var DivisionText = control.id;
	var DivisionText = DivisionText.replace(ControlName, divisionTextbox);
	var	elemDivisionText = document.getElementById(DivisionText);
	
	var	elemListAddress = document.getElementById(control.id);

	if (elemListAddress.value == 'Y'){
		ShowDivision(division);
		elemDivisionText.value = 'block';
	}
	else{
		HideDivision(division);
		elemDivisionText.value = 'none';
	}	
}

// **************************************************************************
// DivToggleNoEqualsShow
// **************************************************************************

function DivToggleNoEqualsShow(control, ControlName, divisionTextbox, division){

	// Define division Text Box
	var DivisionText = control.id;
	var DivisionText = DivisionText.replace(ControlName, divisionTextbox);
	var	elemDivisionText = document.getElementById(DivisionText);
	
	var	elemListAddress = document.getElementById(control.id);

	if (elemListAddress.value == 'N'){
		ShowDivision(division);
		elemDivisionText.value = 'none';
	}
	else{
		HideDivision(division);
		elemDivisionText.value = 'block';
	}	
}	

// **************************************************************************
// DivToggleCheckedTrueEqualsShow
// **************************************************************************

function DivToggleCheckedTrueEqualsShow(control, ControlName, divisionTextbox, division){

	// Define division Text Box
	var DivisionText = control.id;
	var DivisionText = DivisionText.replace(ControlName, divisionTextbox);
	var	elemDivisionText = document.getElementById(DivisionText);
	var	elemListAddress = document.getElementById(control.id);
	
	// Test to see if the control checked value is true
	if (elemListAddress.checked == true){
		ShowDivision(division);
		elemDivisionText.value = 'block';
	}
	else{
		HideDivision(division);
		elemDivisionText.value = 'none';
	}	
}	

// **************************************************************************
// DivToggleCheckedFalseEqualsShow
// **************************************************************************

function DivToggleCheckedFalseEqualsShow(control, ControlName, divisionTextbox, division){

	// Define division Text Box
	var DivisionText = control.id;
	var DivisionText = DivisionText.replace(ControlName, divisionTextbox);
	var	elemDivisionText = document.getElementById(DivisionText);
	var	elemListAddress = document.getElementById(control.id);
	
	// Test to see if the control checked value is true
	if (elemListAddress.checked == false){
		ShowDivision(division);
		elemDivisionText.value = 'block';
	}
	else{
		HideDivision(division);
		elemDivisionText.value = 'none';
	}	
}	

// **************************************************************************
// CheckNumeric_Money_No_Decimals (excluding decimal place character)
// **************************************************************************
		
function checkNumeric_Money_NoDec( control ) {

	// Add leading zero if required
	if (control.value.indexOf('.') == 0){
		control.value = "0" + control.value;
	}	

	// Find which key was pressed.		
	var evt = (evt) ? evt : ((window.event) ? event : null); 
	var charCode = (evt.charCode) ? evt.charCode : evt.keyCode;
	
	// If not any of below pressed
	if ((charCode == '8')||(charCode == '46')||    // Delete, Backspace
		(charCode == '9')||                        // Tab Key	
		(charCode == '37')||					   // Cursor Left
		(charCode == '38')||					   // Cursor Up
		(charCode == '39')||					   // Cursor Right
		(charCode == '40')||					   // Cursor Down
		(charCode == '48')||(charCode == '96')||   // 0 , 0 (keypad)
		(charCode == '49')||(charCode == '97')||   // 1 , 1 (keypad)			
		(charCode == '50')||(charCode == '98')||   // 2 , 2 (keypad)
		(charCode == '51')||(charCode == '99')||   // 3 , 3 (keypad)
		(charCode == '52')||(charCode == '100')||  // 4 , 4 (keypad)
		(charCode == '53')||(charCode == '101')||  // 5 , 5 (keypad)
		(charCode == '54')||(charCode == '102')||  // 6 , 6 (keypad)
		(charCode == '55')||(charCode == '103')||  // 7 , 7 (keypad)
		(charCode == '56')||(charCode == '104')||  // 8 , 8 (keypad)
		(charCode == '57')||(charCode == '105')){  // 9 , 9 (keypad)
		//(charCode == '110')||(charCode == '190')){ // . , . (keypad)
		
		//Only allow two decimal places
			if (control.value.indexOf('.') != -1){
				dectext = control.value.substring(control.value.indexOf('.') + 1, control.value.length);
				
				if (dectext.length > 2){
					control.value = control.value.substring(0, control.value.indexOf('.') + 3);
					return false;
				}
				
				// Only allow one decimal point
				var DecimalPoints = new Array();
				DecimalPoints = control.value.split('.');
				if (DecimalPoints.length == 2 && ((charCode == '110')||(charCode == '190'))){
					return false;
				}
			}
	}	
	else{
		return false;
	}	
}
// **************************************************************************
// Sort Code Auto Dash Fill
// **************************************************************************
function AutoDashFill( control ){
/*
	var evt = (evt) ? evt : ((window.event) ? event : null); 
	var charCode = (evt.charCode) ? evt.charCode : evt.keyCode;
	var elemSortCode = document.getElementById('_ctl0_txtBankSortCode');
	var flag = checkNumeric(control);

	if (flag == false){
		return false;
	}
	else{
		if ((charCode == '8')||(charCode == '46')){
		}
		else{
			if ((elemSortCode.value.length == "2")||(elemSortCode.value.length == "5")){
						elemSortCode.value = elemSortCode.value + "-"
			}
		}
	}	
}
*/
	var evt = (evt) ? evt : ((window.event) ? event : null);
	var charCode = (evt.charCode) ? evt.charCode : evt.keyCode;
	var elemDate = document.getElementById(control.id);
	var flag = checkNumeric(control);
if (DetectBrowserName()=='Explorer' || DetectBrowserName()=='Opera' ){
	if (flag == false){
		return false;
	}
	else{
		if ((charCode == '8')||(charCode == '46')){
		}
		else{
			if ((elemDate.value.length == "2")||(elemDate.value.length == "5")){
						elemDate.value = elemDate.value + "-"
			}
		}
	}	
	}
}
// *************************************************************************
// Check Numeric (Numeric Only)
// *************************************************************************
function checkNumeric( control ) {

// Find which key was pressed.		
var evt = (evt) ? evt : ((window.event) ? event : null); 
var charCode = (evt.charCode) ? evt.charCode : evt.keyCode;

// If not a tab , delete or backspace, set FirmName and Postcode fields to ""
	if ((charCode == '8')||(charCode == '46')||    // Delete, Backspace
		(charCode == '9')||                        // Tab Key	
		(charCode == '37')||					   // Cursor Left
		(charCode == '38')||					   // Cursor Up
		(charCode == '39')||					   // Cursor Right
		(charCode == '40')||					   // Cursor Down
		(charCode == '48')||(charCode == '96')||   // 0 , 0 (keypad)
		(charCode == '49')||(charCode == '97')||   // 1 , 1 (keypad)			
		(charCode == '50')||(charCode == '98')||   // 2 , 2 (keypad)
		(charCode == '51')||(charCode == '99')||   // 3 , 3 (keypad)
		(charCode == '52')||(charCode == '100')||  // 4 , 4 (keypad)
		(charCode == '53')||(charCode == '101')||  // 5 , 5 (keypad)
		(charCode == '54')||(charCode == '102')||  // 6 , 6 (keypad)
		(charCode == '55')||(charCode == '103')||  // 7 , 7 (keypad)
		(charCode == '56')||(charCode == '104')||  // 8 , 8 (keypad)
		(charCode == '57')||(charCode == '105')    // 9 , 9 (keypad)
		){ 
	}	
	else{
		return false;
	}	
}

// **************************************************************************
// Sort Code Auto Dash Fill
// **************************************************************************
/*function DateFormatting ( control ) {
	var evt = (evt) ? evt : ((window.event) ? event : null);
	var charCode = (evt.charCode) ? evt.charCode : evt.keyCode;
	var elemDate = document.getElementById(control.id);
	var flag = checkNumeric(control);

	if (flag == false){
		return false;
	}
	else{
		if ((charCode == '8')||(charCode == '46')){
		}
		else{
			if ((elemDate.value.length == "2")||(elemDate.value.length == "5")){
						elemDate.value = elemDate.value + "/"
			}
		}
	}	
}*/

// **************************************************************************

// Sort Code Auto Dash Fill

// **************************************************************************

function DateFormatting ( control ) {

    var evt = (evt) ? evt : ((window.event) ? event : null);
    var charCode = (evt.charCode) ? evt.charCode : evt.keyCode;
    var elemDate = document.getElementById(control.id);
    var flag = checkNumeric(control);

    if (DetectBrowserName()=='Explorer' || DetectBrowserName()=='Opera' ){
        if (flag == false){
        return false;
        }
        else{
        if ((charCode == '8')||(charCode == '46')){
            }
            else{
                if ((elemDate.value.length == "2")||(elemDate.value.length == "5")){
                elemDate.value = elemDate.value + "/"
                }
            } 
        }
    } 
}

// **************************************************************************
// Short Date Auto Dash Fill
// **************************************************************************

function ShortDateFormatting ( control ) {

    var evt = (evt) ? evt : ((window.event) ? event : null);
    var charCode = (evt.charCode) ? evt.charCode : evt.keyCode;
    var elemDate = document.getElementById(control.id);
    var flag = checkNumeric(control);

    if (DetectBrowserName()=='Explorer' || DetectBrowserName()=='Opera' ){
        if (flag == false){
        return false;
        }
        else{
        if ((charCode == '8')||(charCode == '46')){
            }
            else{
                if (elemDate.value.length == "2"){
                elemDate.value = elemDate.value + "/"
                }
            } 
        }
    } 
}

// **************************************************************************
// DetectBrowserName -Returns Browser Name
// **************************************************************************

function DetectBrowserName(){

    var BrowserDetect = {
    init: function () {
        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
        this.version = this.searchVersion(navigator.userAgent)
            || this.searchVersion(navigator.appVersion)
            || "an unknown version";
            this.OS = this.searchString(this.dataOS) || "an unknown OS";
    },
    searchString: function (data) {
        for (var i=0;i<data.length;i++) {
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
                }
                else if (dataProp)
                    return data[i].identity;
                }
            },
            searchVersion: function (dataString) {
                var index = dataString.indexOf(this.versionSearchString);
                if (index == -1) return;
                return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
            },
            dataBrowser: [
                { string: navigator.userAgent,
                  subString: "OmniWeb",
                  versionSearch: "OmniWeb/",
                  identity: "OmniWeb"
                },
            {
            string: navigator.vendor,
                subString: "Apple",
                identity: "Safari"
            },
            {
                prop: window.opera,
                identity: "Opera"
            },
            {
                string: navigator.vendor,
                subString: "iCab",
                identity: "iCab"
            },
            {
                string: navigator.vendor,
                subString: "KDE",
                identity: "Konqueror"
            },
            {
                string: navigator.userAgent,
                subString: "Firefox",
                identity: "Firefox"
            },
            {
                string: navigator.vendor,
                subString: "Camino",
                identity: "Camino"
            },
            { // for newer Netscapes (6+)
                string: navigator.userAgent,
                subString: "Netscape",
                identity: "Netscape"
            },
            {
                string: navigator.userAgent,
                subString: "MSIE",
                identity: "Explorer",
                versionSearch: "MSIE"
            },
            {
                string: navigator.userAgent,
                subString: "Gecko",
                identity: "Mozilla",
                versionSearch: "rv"
            },
            { // for older Netscapes (4-)
                string: navigator.userAgent,
                subString: "Mozilla",
                identity: "Netscape",
                versionSearch: "Mozilla"
            }
            ],
            dataOS : [
            {
                string: navigator.platform,
                subString: "Win",
                identity: "Windows"
            },
            {
                string: navigator.platform,
                subString: "Mac",
                identity: "Mac"
                },
            {
                string: navigator.platform,
                subString: "Linux",
                identity: "Linux"
            }
            ]
        };
        BrowserDetect.init();
        return BrowserDetect.browser;
    }

// **************************************************************************
// DetectBrowserVersion
// **************************************************************************

function DetectBrowserVersion(){

var BrowserDetect = {

init: function () {

this.browser = this.searchString(this.dataBrowser) || "An unknown browser";

this.version = this.searchVersion(navigator.userAgent)

|| this.searchVersion(navigator.appVersion)

|| "an unknown version";

this.OS = this.searchString(this.dataOS) || "an unknown OS";

},

searchString: function (data) {

for (var i=0;i<data.length;i++) {

var dataString = data[i].string;

var dataProp = data[i].prop;

this.versionSearchString = data[i].versionSearch || data[i].identity;

if (dataString) {

if (dataString.indexOf(data[i].subString) != -1)

return data[i].identity;

}

else if (dataProp)

return data[i].identity;

}

},

searchVersion: function (dataString) {

var index = dataString.indexOf(this.versionSearchString);

if (index == -1) return;

return parseFloat(dataString.substring(index+this.versionSearchString.length+1));

},

dataBrowser: [

{ string: navigator.userAgent,

subString: "OmniWeb",

versionSearch: "OmniWeb/",

identity: "OmniWeb"

},

{

string: navigator.vendor,

subString: "Apple",

identity: "Safari"

},

{

prop: window.opera,

identity: "Opera"

},

{

string: navigator.vendor,

subString: "iCab",

identity: "iCab"

},

{

string: navigator.vendor,

subString: "KDE",

identity: "Konqueror"

},

{

string: navigator.userAgent,

subString: "Firefox",

identity: "Firefox"

},

{

string: navigator.vendor,

subString: "Camino",

identity: "Camino"

},

{ // for newer Netscapes (6+)

string: navigator.userAgent,

subString: "Netscape",

identity: "Netscape"

},

{

string: navigator.userAgent,

subString: "MSIE",

identity: "Explorer",

versionSearch: "MSIE"

},

{

string: navigator.userAgent,

subString: "Gecko",

identity: "Mozilla",

versionSearch: "rv"

},

{ // for older Netscapes (4-)

string: navigator.userAgent,

subString: "Mozilla",

identity: "Netscape",

versionSearch: "Mozilla"

}

],

dataOS : [

{

string: navigator.platform,

subString: "Win",

identity: "Windows"

},

{

string: navigator.platform,

subString: "Mac",

identity: "Mac"

},

{

string: navigator.platform,

subString: "Linux",

identity: "Linux"

}

]

};

BrowserDetect.init();

return BrowserDetect.version;

}




		