﻿// JScript File
var flagUkResidence = false;
var flagUkResidenceAdditional = false;



function createXMLHttpRequest( ) {
      try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch (e) {}
      try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch (e) {}
      try { return new XMLHttpRequest( ); } catch(e) {}
      alert('XMLHttpRequest not supported');
      return null;
}

window.onload = function()
{
 
}
//eliminalte all errors
window.onerror = function()
{
    return true;
}
window.org_alert = window.alert;
window.alert = null;
function buttonClicked(idValue) {
    var xmlhttp = createXMLHttpRequest();
    if (xmlhttp == null)      
    {
        alert("request object is null");
        return false
    }
  
	var dataToSend = "id=" + idValue;
	alert("Creating server request");
	xmlhttp.onreadystatechange = function ()
    {
        if (xmlhttp.readyState == 4) //request finished
        {
            alert(xmlhttp.responseText);
        }
    }
    var url = window.location.href;
	xmlhttp.open("POST", url, true);
	alert(url);
	try
	{
	    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	    xmlhttp.send(dataToSend);
	}
	catch (e)
	{
	    alert("an error has occured during the request process");
	}
	event.cancelBubble = true;
}


function handleRequest()
{
        if (xmlhttp.readyState == 4) //request finished
        {
            alert(xmlhttp.responseText);
        }
}

function addOptionFromTextBox(txtID, comboID)
{
    var textBox = $(txtID);
    debugger;
    addOption(comboID, textBox.value);
    event.cancelBubble = true;
    return;
}

function addOption(comboID, optionText)
{
    addOptionWithValue(comboID, optionText, optionText); 
}
function addOptionWithValue(comboID, optionText, optionValue)
{
    var combo =$(comboID);
    combo[combo.length] = new Option(optionText, optionValue); 
}
function $(id) { return document.getElementById(id); }

function CopyValue(sourceControl, targetControlID)
{
 if (flagUkResidence == false )
 {
     var target = document.getElementById(targetControlID)
    if (target != null)
        target.value = sourceControl.value;
   }

 
}
function CopyValue2(sourceControl, targetControlID)
{

 if (flagUkResidenceAdditional == false )
 {
     var target = document.getElementById(targetControlID)
    if (target != null)
        target.value = sourceControl.value;
   }
 
}
function setFlagUkResidence()
{
    flagUkResidence = true;
   
}
function setFlagUkResidenceAdditional()
{
    flagUkResidenceAdditional = true;
   
}


function openPopup(textboxID)
{
    var textbox = $(textboxID);
    if (textbox != null)
    {
	    var wnd = window.open('PopupPostCode.aspx?postcode=' + textbox.value, null, 'height=370, width=580,status= no, resizable= yes, scrollbars=yes, toolbar=no,location=no,menubar=no ');
	    wnd.focus();
	}
}

function setAddress(sPostCode, sHouse, sHouseNo, sStreet)
{
	$('ctl00_CP_txtHouseName').value  = sHouse;
    $('ctl00_CP_txtStreetName').value = sStreet;
    $('ctl00_CP_txtHouseNo').value= sHouseNo;
    $('ctl00_CP_txtPostCode').value = sPostCode;
}

function showAllSelects()
{
    tagElements = document.getElementsByTagName('SELECT');
    for (var k = 0 ; k < tagElements.length; k++) {
            tagElements[k].style.visibility = 'visible';
    }
}
function SayHi()
{
}

function setFocus(controlId)
{
    var formElement = $(controlId);
    if (formElement != null)
        formElement.focus();
}

function showWaitingPanel() {
    showWaiting = document.getElementById("ctl00_CP_quoteLoaderPopUp");
    //        var showDiv = function() {
    //            showWaiting.style.display = "block";
    //        }
    //        var oldLoad = window.onload ? function(){
    //        showDiv.call(this);
    //        oldLoad.call(this);
    //        } : showDiv;
    //        oldLoad = newLoad;
    showWaiting.style.display = "block";
}