/*****************************************************************************************
* Site Code - anything site specific goes here
******************************************************************************************/

var gfVAT = '1.2';
var gsBaseURL = (document.location.href.indexOf('local') > 0) ? 'http://local.mediamarmot.com' : 'http://www.mediamarmot.com';
var gsSite = 'mediamarmot';

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-25381191-1']);
_gaq.push(['_trackPageview']);

(function () {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

//-----------------------------------------------------------------------------------------

document.onclick = check;

function check(e) {
    try {
        var target = (e && e.target) || (event && event.srcElement);
        checkParent(target) ? document.getElementById('addtobasket').style.display = 'none' : null;
    } catch (e) {}
}
function checkParent(t) {
    while (t.parentNode) {
        if (t == document.getElementById('addtobasket')) {
            return false
        }
        t = t.parentNode;
    }
    return true
} 

//-----------------------------------------------------------------------------------------

function openWindow(lsName, lsURL, lsTitle, liWidth, liHeight) {
    //lsURL += '&nc=' + (new Date()).getTime();
    if (liWidth == null) liWidth = 700;
    if (liHeight == null) liHeight = 400;

    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    liPosX = (myWidth / 2) - (liWidth/2);
    liPosY = (myHeight / 2) - (liHeight/2);

    if (document.getElementById(lsName)) {
        $.focusWindow(lsName);
    } else {

        $.newWindow({ id: lsName,
            title: lsTitle,
            content: "<iframe id='" + lsName + "' src='" + gsBaseURL + lsURL + "' frameborder='0' scrolling='auto'>",
            width: liWidth,
            height: liHeight,
            posx: liPosX,
            posy: liPosY,
            modal: true,
            type: "iframe"
        });
    }
}
//http://hernan.amiune.com/labs/jQuery-Windows-Engine-Plugin/jQuery-Windows-Engine-Plugin.html

//-----------------------------------------------------------------------------------------






//-----------------------------------------------------------------------------------------// Front End Web site Functions//-----------------------------------------------------------------------------------------

function domainSearchEnter(e, lsDomain) {
    if (e.keyCode == 13) {
        domainSearch(lsDomain);
        return false;
    }
}

function domainSearch(lsDomain) {
    if (lsDomain.length > 2) {
        document.getElementById('domainsearch_results').innerHTML = '<img src="/'+gsSite+'/img/indicator.gif" />';
        //alert(gsBaseURL + '/service/?s=domainsearch&domain=' + lsDomain);
        ajaxPost(gsBaseURL + '/service/?s=domainsearch&domain=' + lsDomain, 'domainsearch_results');
    }
}


//-----------------------------------------------------------------------------------------

/* Google Analytics Code */
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-25381191-1']);
  _gaq.push(['_trackPageview']);

  (function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

/* Random Marmot Facts *///-----------------------------------------------------------------------------------------var Fact=new Array();Fact[0] = "Every year February 2nd is Marmot Day in Alaska.";Fact[1] = "In Latin Marmot is 'mus montanus' which means 'mountain mouse'.";Fact[2] = "Marmots have been known since antiquity.";Fact[3] = "Marmot meat is a delicacy in Mongolia !";Fact[4] = "The Golden Marmot is found in Pakistan.";Fact[5] = "Kazakhstan is home to the Grey Marmot.";Fact[6] = "Each litter will produce 2 to 5 marmot pups.";Fact[7] = "It takes one month from birth for a marmot to grow all it's fur.";Fact[8] = "Marmot's hibernate in burrows in the ground.";Fact[9] = "Marmot's are the fat part of the squirrel family.";
var giFactNo = Math.round(Math.random()*(Fact.length-1));function showFact() { 	giFactNo += 1;	if (giFactNo>Fact.length-1)		giFactNo = 1;	var lsFact = Fact[giFactNo];	lsFact += '<br /><a href="#" onClick="showFact();return false;" style="float:right;">More&nbsp;Triva</a>';	document.getElementById('randomfact').innerHTML = lsFact;}// Load up the following //-----------------------------------------------------------------------------------------//window.onload = function () {showFact(); };function cancelCheck(loCheckbox) {    loCheckbox.checked = !loCheckbox.checked;}function highlightTransactionOrder( liOrderID, lbSwitch) {        var lbChecked = !document.getElementById('orderid_' + liOrderID).checked;    document.getElementById('orderid_' + liOrderID).checked = lbChecked;        //Update prices    var loElement = document.getElementById('transactionform').elements;    var lfOrderRRP = 0;        for(var i = 0; i < loElement.length; i++) {
		if (loElement[i].name == 'orderid' && loElement[i].type.match(/radio|checkbox/i) && loElement[i].checked) {		    lfOrderRRP += parseFloat(document.getElementById('orderrrp_' + loElement[i].value).value);		}	}    document.getElementById('transactioncharged').value=lfOrderRRP.toFixed(2);            if (lbChecked)        document.getElementById('orderidrow_' + liOrderID).style.background = '#ffff99';    else        document.getElementById('orderidrow_' + liOrderID).style.background = '#ffffff';}

//-----------------------------------------------------------------------------------------
// Basket Functions
//-----------------------------------------------------------------------------------------

function addToBasketFromSearch(lsCurrentDomain) {
    var lsURL = gsBaseURL + '/service/?s=updateandrenderbasketsummary&productid=' + document.getElementById('productid_domain_' + lsCurrentDomain).value + 
                '&productid=' + document.getElementById('productid_hosting_' + lsCurrentDomain).value +
                '&productelementselectionid=' + document.getElementById('productelementselectionid_' + lsCurrentDomain).value +
                '&promotionid=' + document.getElementById('promotionid_' + lsCurrentDomain).value +
                '&productelementid=1&productelementvalue=' + lsCurrentDomain;
    //alert(lsURL);
    //ajaxPost(lsURL, 'basketsummary', null, null, null, 'Loading...');
    ajaxPost(lsURL, 'basketsummary', 'highlightOrderRow(\'' + lsCurrentDomain + '\');');  //, null, null, 'Loading...');
}

//-----------------------------------------------------------------------------------------

function addToBasketFromRenew(liOrderID) {
    var lsURL = gsBaseURL + '/service/?s=updateandrenderbasketsummary&orderid_renew=' + liOrderID;

    //ajaxPost(lsURL, 'basketsummary', 'highlightOrderRow(\'' + liOrderID  + '\');', null, null, 'Loading...');
    ajaxPost(lsURL, 'basketsummary', 'highlightOrderRow(\'' + liOrderID + '\');');  //, null, null, 'Loading...');
}

function addToBasketFromCustomInvoice(liInvoiceCustomID) {
    var lsURL = gsBaseURL + '/service/?s=updateandrenderbasketsummary&invoicecustomid=' + liInvoiceCustomID;
    //ajaxPost(lsURL, 'basketsummary', 'highlightOrderRow(\'' + liOrderID  + '\');', null, null, 'Loading...');
    ajaxPost(lsURL, 'basketsummary', 'highlightOrderRow(\'invoice' + liInvoiceCustomID + '\');');  //, null, null, 'Loading...');
}


//-----------------------------------------------------------------------------------------

function setOrderActive(liOrderID) {
    var lsURL = gsBaseURL + '/service/?s=updateandrenderbasketsummary&orderid_setactive=' + liOrderID + '&rem=2';
    ajaxPost(lsURL, 'basketsummary', 'removeOrderRow(\'' + liOrderID + '\');');  //, null, null, 'Loading...');
}

function doNotRenew(liOrderID) {
    if (confirm('Are you sure you DO NOT want to renew this order? \nBy clicking OK the order will become inactive.')) {
        var lsURL = gsBaseURL + '/service/?s=updateandrenderbasketsummary&orderid_renew=' + liOrderID + '&rem=2';

        //ajaxPost(lsURL, 'basketsummary', 'highlightOrderRow(\'' + liOrderID  + '\');', null, null, 'Loading...');
        ajaxPost(lsURL, 'basketsummary', 'removeOrderRow(\'' + liOrderID + '\');');  //, null, null, 'Loading...');
    }
}

//-----------------------------------------------------------------------------------------

function removeOrderRow(lsLayer) {
    // Hightlight background
    document.getElementById('row_' + lsLayer).style.display = 'none';
}

function highlightOrderRow(lsLayer) {
    // Display added to basket
    document.getElementById('addtobasket').style.display = 'block';
    //setTimeout("document.getElementById('addtobasket').style.display = 'none';", 2000);

    // Hightlight background
    document.getElementById('row_' + lsLayer).style.background = '#ff6';
    
    // Display added text
    document.getElementById('button_' + lsLayer).style.display = 'block';
    document.getElementById('added_' + lsLayer).style.display = 'none';
}

//-----------------------------------------------------------------------------------------

function renderBasketSummary() {
    var lsURL = gsBaseURL + '/service/?s=renderbasketsummary';
    ajaxPost(lsURL, 'basketsummary', '', null, null, 'Loading...');
}

//-----------------------------------------------------------------------------------------

function loadSupportAnswer(liSupportQuestionID) {
    if (liSupportQuestionID == -1) {
        document.getElementById('supportanswer').style.display = 'none';
        document.getElementById('supportform').style.display = 'block';
    } else {
        var lsURL = gsBaseURL + '/service/?s=supportanswer&supportquestionid=' + liSupportQuestionID;
        document.getElementById('supportform').style.display = 'none';
        ajaxPost(lsURL, 'supportanswer', '', null, null, 'Loading...');
    }
}

function hideShowSelection(loLayer, liSelection, liTotal) {
    if (document.getElementById(loLayer + liSelection).style.display == 'block') {
        document.getElementById(loLayer + liSelection).style.display = 'none';
    } else {
        for (i = 1; i <= liTotal; i++) {
            if (i == liSelection) {
                document.getElementById(loLayer + i).style.display = 'block';
            } else {
                document.getElementById(loLayer + i).style.display = 'none';
            }
        }
    }
}


//-----------------------------------------------------------------------------------------
// Basket/Checkout Functions
//-----------------------------------------------------------------------------------------

function setupInvoice(liInvoiceID, liForceEmail) {
    var lsURL = gsBaseURL + '/service/?s=setupinvoice&id=' + liInvoiceID + '&forceemail=' + liForceEmail;
    ajaxPost(lsURL, 'setup_results');
}

//-----------------------------------------------------------------------------------------

function remBasketOrder(liBasketOrderID) {
    var lsURL = gsBaseURL + '/service/?s=updateandrenderbasket&rem=1&basketorderid=' + liBasketOrderID;
    ajaxPost(lsURL, 'basket', 'renderBasketSummary()', null, null, 'Updating...');
}

//-----------------------------------------------------------------------------------------

function voucherBasketOrder(liBasketOrderID) {
    var lsPromotionCode = document.getElementById('promotioncode').value;
    if (lsPromotionCode.length > 2) {
        var lsURL = gsBaseURL + '/service/?s=updateandrenderbasket&promotioncode=' + lsPromotionCode + '&basketorderid=' + liBasketOrderID;
        ajaxPost(lsURL, 'basket', 'renderBasketSummary()', null, null, 'Updating...');
    }
}

//-----------------------------------------------------------------------------------------

function updateBasketOrder(liBasketOrderID) {
    var lsURL = gsBaseURL + '/service/?s=updateandrenderbasket&basketorderid=' + liBasketOrderID;

    
    loElement = document.getElementsByTagName("input");
    loopThroughItems();
    loElement = document.getElementsByTagName("select");
    loopThroughItems();
    loElement = document.getElementsByTagName("radio");
    loopThroughItems();
    loElement = document.getElementsByTagName("checkbox");
    loopThroughItems();

    function loopThroughItems() {
        for (var i = 0; i < loElement.length; i++) {
            if ('productid_' + liBasketOrderID == loElement[i].name && loElement[i].value != '')
                lsURL += '&productid=' + loElement[i].value;
            else if ('productelementid_' + liBasketOrderID == loElement[i].name && loElement[i].value != '')
                lsURL += '&productelementid=' + loElement[i].value;
            else if ('productelementselectionid_' + liBasketOrderID == loElement[i].name && loElement[i].value != '')
                lsURL += '&productelementselectionid=' + loElement[i].value;
        }
    }


    //alert(lsURL);
    //alert(lsProductID_List);
    //alert(lsProductElementID_List);
    //alert(lsProductElementSelectionID_List);
    ajaxPost(lsURL, 'basket', null, null, null, 'Updating...');
}


//-----------------------------------------------------------------------------------------


























//-----------------------------------------------------------------------------------------
// Admin Functions
//-----------------------------------------------------------------------------------------
function renderAdminProduct( liOrderID, liProductNo, liProductID_parent, liProductID) {
    var lsURL = gsBaseURL   + '/service/?s=adminproduct&orderid=' + liOrderID 
                            + '&productid_parent=' + liProductID_parent + '&productid=' + liProductID + '&productno=' + liProductNo;
    
    ajaxPost(lsURL, 'product_' + liProductNo, 'renderProductCost()', null, null, 'Loading...');
}

//-----------------------------------------------------------------------------------------

function renderProductCost(liPromotionID) {
    var lsProductIDList = ',';
    var lsPromotionIDList = ',';
    
    var loElement = document.getElementById('orderform').elements;
    
    if (liPromotionID) {
        for(var i = 0; i < loElement.length; i++) {
		    if (loElement[i].name == 'promotionid') {
		        if (loElement[i].value != liPromotionID && loElement[i].className=='individualcheckbox') 
    		        loElement[i].checked = false;
		    }
	    }
	}
	
    var loElement = document.getElementById('orderform').elements;
    for(var i = 0; i < loElement.length; i++) {
		if (loElement[i].name == 'productid') {
		    lsProductIDList += loElement[i].value + ',';
		} else if (loElement[i].name == 'promotionid') {
		    if (loElement[i].checked) {
    		    lsPromotionIDList += loElement[i].value + ',';
    	    }
		}
	}
	
	var lsURL = gsBaseURL   + '/service/?s=adminproductcost&productidlist=' + lsProductIDList + '&promotionidlist=' + lsPromotionIDList;
    ajaxPost(lsURL, 'ordercost', null, null, null, 'Loading...');
}

//-----------------------------------------------------------------------------------------







//-----------------------------------------------------------------------------------------
// Admin Processing
//-----------------------------------------------------------------------------------------

function loadPage( lsLayerList, lsValueList) {

    if (lsLayerList) {
        // Construct URL's
        var laLayerList = lsLayerList.split('/');
        var liLayerNo = laLayerList.length - 1;
        var lsUrlHash = '#' + lsLayerList;
        var lsAjaxURL = gsBaseURL + '/service/?s=admin&layerno=' + liLayerNo + '&layerarray=' + lsLayerList.replace('/', ',');
        if (lsValueList) {
            lsUrlHash += '/' + lsValueList.replace('&', '/');
            lsAjaxURL += '&' + lsValueList.replace('/', '&');
        }
        
        //Reconstruct URL Hash
        document.location.href = lsUrlHash;

        //Loading screen
        if (liLayerNo>0)
            document.getElementById('layer' + liLayerNo).innerHTML = '<img src="/' + gsSite + '/img/indicator.gif" />';

        //Post ajax
        ajaxPost( lsAjaxURL, 'layer' + liLayerNo);
    }
}

//-----------------------------------------------------------------------------------------

function loadPageFromURL() {
    var lsCurrentURL = document.location.href;
    var lsTab;
    var lsSection;
    var liSectionID;
    var liPageNo;
    var lsSearch;
    if (lsCurrentURL.indexOf('#') > 0) {
        lsCurrentURL = lsCurrentURL.substring(lsCurrentURL.indexOf('#') + 1, lsCurrentURL.length);
        var laURLArray = lsCurrentURL.split('/');
        if (lsCurrentURL.length >= 0) lsTab = laURLArray[0];
        if (lsCurrentURL.length >= 1) lsSection = laURLArray[1];
        if (lsCurrentURL.length >= 2) liSectionID = laURLArray[2];
        if (lsCurrentURL.length >= 3) liPageNo = laURLArray[3];
        if (lsCurrentURL.length >= 4) lsSearch = laURLArray[4];

        var lsHTML = '';
        var lsAction = 'list';
        var lsValueList = '';
        var lsLayerList = '';

        for (i = 0; i < laURLArray.length; i++) {
            if (laURLArray[i] != '') {
                if (laURLArray[i] == 'add' || laURLArray[i] == 'edit' || laURLArray[i] == 'list') {
                    lsAction = laURLArray[i];
                } else if (laURLArray[i].indexOf('=') > 0) {
                    lsValueList += '&' + laURLArray[i]
                } else {
                    if (lsLayerList != '')
                        lsLayerList += ',';
                    lsLayerList += laURLArray[i]
                }
            }
        }
        if (!lsLayerList)
            lsLayerList = 'client';

        //open ajax page
        lsURL = gsBaseURL + '/service/?s=admin&layerno=0&layerarray=' + lsLayerList + lsValueList + '&action=' + lsAction;

        //Post ajax
        ajaxPost(lsURL, 'layer0');

    }
    //loadPage(lsTab, lsSection, liSectionID, liPageNo, lsSearch);
}

//-----------------------------------------------------------------------------------------

//Loading page once tab is loaded
function loadPage2( lsTab, lsSection, liSectionID, liPageNo, lsSearch, loFunction) {
    var lsURL;
    var lsRedirectURL;

    if (!lsTab) lsTab = 'client';
    if (!lsSection) lsSection = 'order';
    if (!liSectionID) liSectionID = '';
    if (!liPageNo) liPageNo = 1;
    if (!lsSearch) lsSearch = '';

    if (!gbAjaxProcessing) {

        lsRedirectURL = '#' + lsTab + '/' + lsSection;
        if (liSectionID)    lsRedirectURL += '/' + liSectionID;
        if (liPageNo>1)       lsRedirectURL += '/' + liPageNo;
        if (lsSearch)       lsRedirectURL += '/' + lsSearch;

        // Set hash URL
        //document.location.href = lsRedirectURL;

        //Load tabs
        loadTab(lsTab);

		//Set loading frame
		document.getElementById(lsTab+'PageContent').innerHTML = '<div class="loading"><img src="' + gsBaseURL +'/img/indicator.gif" /></div>';
	    
		//Store opened page in session
		//ajaxPost(gsBaseURL + '/service/?s=setsession&session=tab#service#section#sectionid#pageno#search&value='+lsTab+'#'+lsService+'#'+lsSection+'#'+liSectionID+'#'+liPageNo+'#'+lsSearch);
	    
	    //open ajax page
		lsURL = gsBaseURL + '/service/?s=adminpage&tab=' + lsTab + '&section=' + lsSection + '&sectionid=' + liSectionID + '&pageno=' + liPageNo + '&search=' + lsSearch;
		
		//Post ajax
		ajaxPost(lsURL, lsTab + 'PageContent', loFunction);
	}
}


























//-----------------------------------------------------------------------------------------

// Load the full on tab at the top of the page
function loadTab( lsTab) {

    var loTab = document.getElementById(lsTab + 'Page');

    // Loop through all other menu items and hide pages
    var loElement = document.getElementsByTagName("div");
    for (var i = 0; i < loElement.length; i++) { //
        if (loElement[i].className == 'menuTab selectedTab') {
            loElement[i].className = "menuTab";
            document.getElementById(loElement[i].getAttribute('id') + "Content").style.display = 'none';
        }
    }

    // Display selected page
    loTab.className = "menuTab selectedTab";

    if (document.getElementById(loTab.getAttribute('id') + "Content").innerHTML == '')
        document.getElementById(loTab.getAttribute('id') + "Content").style.display = 'block';
    else
        document.getElementById(loTab.getAttribute('id') + "Content").style.display = 'block';
}

//----------------------------------------------------------------------------

//Posting a form
function ajaxFormSubmit( lsFormName) {
	var lsPostData = '';
	var lsURL = '';
	
	var loElement = document.getElementById(lsFormName).elements;
	for(var i = 0; i < loElement.length; i++) {
		
		lbDisplay = true;
		if (loElement[i].type.match(/radio|checkbox/i) && !loElement[i].checked)
			lbDisplay = false;
		
		if (lbDisplay) {
		    if (lsPostData!='') lsPostData += '&';
		    lsPostData += loElement[i].name + '=' + escape(loElement[i].value);
		}
		
		lsURL = gsBaseURL + '/default.asp';
	}
	ajaxPost(lsURL, 'saved', null, null, lsPostData);
	$('#saved').slideToggle(300);
	//setTimeout("$('#saved').slideToggle(600);",3000);
}

//-----------------------------------------------------------------------------------------

var searchTimer;
function loadTab_FromSearch(lsSearch) {
    if(lsSearch.length>2 || lsSearch.length == 0) {
        clearTimeout(searchTimer);
        searchTimer = setTimeout("loadTab('','"+lsSearch+"',1)",300);
    }
}

function loadLayer( lsURL, loLayer) {
    if (document.getElementById(loLayer).style.display == 'none') {
        loadPage( lsURL, loLayer, '$(\'#'+loLayer+'\').show(\'slow\');');
    } else {
        $('#'+loLayer).hide('slow');
    }
}

function showHideFilters(loSource, loTarget, lsShowText, lsHideText) {
    
    if (document.getElementById( loTarget).style.display == 'none') {
        document.getElementById( loTarget).style.display = 'block';
        //$('#'+loTarget).show('slow');
        loSource.innerHTML = lsHideText;
        ajaxPost(gsBaseURL + '/service.asp?service=setsession&session=hidefilters&value=0');
    } else {
        //$('#'+loTarget).hide('slow');
        document.getElementById( loTarget).style.display = 'none';
        loSource.innerHTML = lsShowText;
        ajaxPost(gsBaseURL + '/service.asp?service=setsession&session=hidefilters&value=1');
    }
}


//Whois Search
function whoIsSearch() {
    var loForm = document.forms.form1;
    var lsDomain = loForm.DomainName.value;
    var lsDomainExt = loForm.DomainExtensionID[loForm.DomainExtensionID.selectedIndex].text;
	var lsDomainName = lsDomain + lsDomainExt;
	if (loForm.DomainName.value.length > 1 && lsDomainExt!='')
    	openWindow( 'whois_' + lsDomainName, 'tools_domainsearch.asp?FullDomain=' + lsDomainName,'WhoIS Search ' + lsDomainName, 800, 450, 1);
}	    


//-----------------------------------------------------------------------------------------
// Ajax Functions
//-----------------------------------------------------------------------------------------
var gbRunDomainAPI = false;

function loadServiceDetails() {
    var lsURL;
    var loLayer = 'serviceDetails_layer';
    var liOrderItemID = document.forms.form1.OrderItemID.value;
    var liOrderItemID_Renewal = document.forms.form1.OrderItemID_Renewal.value;
    var liServiceID = document.forms.form1.ServiceID.value;
    var liTransferID;
    if (!liOrderItemID && liOrderItemID_Renewal) {
        liOrderItemID = document.forms.form1.OrderItemID_Renewal.value;
        liTransferID = 4;
    } else if (!liOrderItemID) {
        liTransferID = 1;
    }
    
    // Do final ajax post
    if (liServiceID) {
        document.getElementById( loLayer).innerHTML = 'Loading Details....';
        lsURL = gsBaseURL + '/service.asp?service=servicedetails' +
                        '&OrderItemID=' + liOrderItemID +
                        '&TransferID=' + liTransferID +
                        '&ServiceID=' + liServiceID;
        ajaxPost(lsURL, loLayer, 'loadServicePrice();');
    }
}

function loadRenewalHistory() {
    var lsURL;
    var liOrderItemID = document.forms.form1.OrderItemID.value;
    var liOrderItemID_Renewal = document.forms.form1.OrderItemID_Renewal.value;
    lsURL = gsBaseURL + '/service.asp?service=renewalhistory' +
                        '&OrderItemID=' + liOrderItemID + 
                        '&OrderItemID_Renewal=' + liOrderItemID_Renewal;
    // Do final ajax post
    ajaxPost(lsURL, 'renewalhistory_layer');
}

function loadServicePrice(lbUpdatePeriod) {

    var lsURL;
    var liDomainExtenionID = '';
    var liTransferID = '';
    var liServiceID = document.forms.form1.ServiceID.value;
    var liOrderPeriod = document.forms.form1.OrderPeriod.value;
    try {
        liDomainExtenionID = document.forms.form1.DomainExtensionID.value;
        liTransferID = document.forms.form1.TransferID.value;
    } catch (e) {}
    
    if (liServiceID) {
        lsURL = gsBaseURL + '/service.asp?service=serviceprice' +
                            '&DomainExtenionID=' + liDomainExtenionID +
                            '&ServiceID=' + liServiceID +
                            '&TransferID=' + liTransferID +
                            '&OrderPeriod=' + liOrderPeriod;
        // Do final ajax post
        ajaxPost(lsURL, null, 'loadServicePrice_populate(\'{ajax}\');updateRenewalDate(false,'+lbUpdatePeriod+');');
    } else {
        updateStartDate();
    }
}

function loadServicePrice_populate( lsAjax) {
    var lsRRPHTML = '';
    var lsOrderPeriodHTML = '';
    var laServiceArray = lsAjax.split(",");
    //OfferID,ServiceDurationID,MinPurchasePeriod,MaxPurchasePeriod,ServicePriceVAT,ServicePrice,DomainPriceVAT,DomainPrice,CombinedPriceVAT,CombinedPrice
    var liOfferID = laServiceArray[0];
    var liServiceDurationID = parseInt(laServiceArray[1]);
    var liMinPurchasePeriod = laServiceArray[2];
    var liMaxPurchasePeriod = laServiceArray[3];
    var liServicePriceVAT = laServiceArray[4];
    var liServicePrice = laServiceArray[5];
    var liDomainPriceVAT = laServiceArray[6];
    var liDomainPrice = laServiceArray[7];
    var liCombinedPriceVAT = laServiceArray[8];
    var liCombinedPrice = laServiceArray[9];
    var liOrderItemID = document.forms.form1.OrderItemID.value;
    
    var liOrderPriceVAT = document.forms.form1.OrderPriceVAT.value;
    var liOrderPrice = document.forms.form1.OrderPrice.value;
    var liOrderPeriod = document.getElementById('OrderPeriod').value;
    
    //Update OfferID
    document.forms.form1.OfferID.value = liOfferID;
    
    //Update order period
    lsOrderPeriodHTML = '<select name="OrderPeriod" id="OrderPeriod" onChange="loadServicePrice(true);">';
    for (var n = liMinPurchasePeriod; n <=liMaxPurchasePeriod; n++) {
        lsOrderPeriodHTML += '<option value="'+n+'"';
        if (liOrderPeriod == n)
            lsOrderPeriodHTML += ' selected';
        lsOrderPeriodHTML += '>' + n + ' ';
        if (liServiceDurationID == 1)
            lsOrderPeriodHTML += 'Years';
        else if (liServiceDurationID == 2)
            lsOrderPeriodHTML += 'Months';
        else
            lsOrderPeriodHTML += '?';
        lsOrderPeriodHTML += '</option>'
    }
    lsOrderPeriodHTML += '</select>';
    document.getElementById( 'orderperiod_layer').innerHTML = lsOrderPeriodHTML;
    
    //Update RPP pricing
    if (liOfferID!='')
        lsRRPHTML = '<table cellpadding=1 cellspacing=0 border=0>' +
                    '<tr><td>Service Price </td><td><strong>&pound;</strong> ' + liServicePriceVAT + '<span class="tiny">inc VAT</span></td><td><strong>&pound;</strong> ' + liServicePrice + '<span class="tiny">ex VAT</span></td></tr>' +
                    '<tr><td style="border-bottom:solid 1px #999;">Domain Price </td><td style="border-bottom:solid 1px #999;"><strong>&pound;</strong> ' + liDomainPriceVAT + '<span class="tiny">inc VAT</span></td><td style="border-bottom:solid 1px #999;"><strong>&pound;</strong> ' + liDomainPrice + '<span class="tiny">ex VAT</span></td></tr>' +
                    '<tr><td>Combined Price </td><td><strong style="color:#c00">&pound; ' + liCombinedPriceVAT + '</strong><span class="tiny">inc VAT</span></td><td><strong style="color:#c00;">&pound; ' + liCombinedPrice + '</strong><span class="tiny">ex VAT</span></td></tr>' +
                    '</table>';
    else
        lsRRPHTML = '<strong>&pound;</strong> ' + liCombinedPriceVAT + '<span class="tiny">inc VAT</span> &nbsp; &nbsp;  ' +
                    '<strong>&pound;</strong> ' + liCombinedPrice + '<span class="tiny">ex VAT</span>';
    if (!liOrderItemID) {
        document.forms.form1.OrderPriceVAT.value = liServicePriceVAT;
        document.forms.form1.OrderPrice.value = liServicePrice; 
    } else if (liOrderPriceVAT != liCombinedPriceVAT || liOrderPrice != liCombinedPrice) {
        lsRRPHTML += '<div id="updateprice_layer"> - <a href="#" onClick="document.forms.form1.OrderPriceVAT.value = \'' + liServicePriceVAT + '\'; document.forms.form1.OrderPrice.value = \'' + liServicePrice + '\'; document.getElementById(\'updateprice_layer\').style.display = \'none\';return false;" style="color:red;font-weight:bold;"">Set to RRP</a></div>';
    }
    document.getElementById( 'serviceRRP_layer').innerHTML = lsRRPHTML;
    
    //Update start date
    updateStartDate();
    
    
    if (!gbRunDomainAPI) {
        gbRunDomainAPI = true;
        //populateAPIService('domain', 'domain_layer');
        //populateAPIService('hosting', 'hosting_layer');
    }

}

function updateStartDate(lbUpdatePeriod) {
    var liOrderItemID = document.forms.form1.OrderItemID.value;
    var liOrderPeriod = document.getElementById('OrderPeriod').value;
    var ldRenewlDate = new Date(getJSDateFromString(document.forms.form1.RenewlDate.value));
    
    //Update Start Date
    document.getElementById( 'startdate_layer').innerHTML = '(' + dateFormat(DateAdd('y',-liOrderPeriod,ldRenewlDate), "dS mmmm, yyyy") + ')';
    
    if (!lbUpdatePeriod) {
        document.forms.form1.StartDate.value = dateFormat(DateAdd('y',-liOrderPeriod,ldRenewlDate), "d/m/yyyy");
    }
    
    //Add Order Period if changed from original
    var ldStartDate = document.forms.form1.StartDate.value;
    if (!ldStartDate) {
        document.forms.form1.StartDate.value = dateFormat(DateAdd('y',-liOrderPeriod,ldRenewlDate), "d/m/yyyy");
    } else {
        ldStartDate = new Date(getJSDateFromString(ldStartDate));
        document.forms.form1.RenewlDate.value = dateFormat(DateAdd('y',liOrderPeriod,ldStartDate), "d/m/yyyy");
        updateRenewalDate( true);
    }    
}

function updateRenewalDate( lbIgnoreStartDateUpdate, lbUpdatePeriod) {
    var ldRenewlDate = new Date(getJSDateFromString(document.forms.form1.RenewlDate.value));
    var liOrderItemID = document.forms.form1.OrderItemID.value;
    var lbArchive = document.forms.form1.Archive.value;
    var liAccountID = document.forms.form1.AccountID.value;
    var liContactID = document.forms.form1.ContactID.value;
    //var laDate = ldRenewlDate.split('/');
    //var ldRenewlDate = laDate[1] + '/' + laDate[0] + '/' + laDate[2];
    //var lsDate = dateFormat(ldRenewlDate, "dddd, mmmm dS, yyyy, h:MM:ss TT");
    var lsDate = dateFormat(ldRenewlDate, "dddd, dS mmmm, yyyy");
    var liDays = DateDiff.inDays(new Date(), ldRenewlDate);
    var liWeeks = DateDiff.inWeeks(new Date(), ldRenewlDate);
    var liMonths = DateDiff.inMonths(new Date(), ldRenewlDate);
    var liYears = DateDiff.inYears(new Date(), ldRenewlDate);
    
    lsDate += '<br /><span style="color:#c00;">';
    if (liDays<0)
        lsDate += 'Expired';
    else if (liDays<=60)
        lsDate += 'Renewal Due In ' + liDays + ' Days';
    else if (liWeeks<=8)
        lsDate += 'Renewal Due In ' + liWeeks + ' Weeks';
    else if (liMonths<=23)
        lsDate += 'Renewal Due In ' + liMonths + ' Months';
    else
        lsDate += 'Renewal Due In ' + liYears + ' Years';
    lsDate += '</span>';
    
    if (liOrderItemID && lbArchive==0)
        lsDate += ' - <a href="#" onClick="openWindow( \'order_new\', \'serviceAdmin.asp?action=Add&section=account&subsection=Order&OrderItemID_Renewal='+liOrderItemID+'&AccountID='+liAccountID+'&ContactID='+liContactID+'\',\'Renew Order\', 800, 450, 1); return false;">Renew Order Now</a>'
    
    document.getElementById('renewaldate_layer').innerHTML = lsDate;
    if (!lbIgnoreStartDateUpdate) {
        updateStartDate(lbUpdatePeriod);
    }
}






function loadServiceOffers() {
    var lsURL;
    var loLayer = 'serviceoffers_layer';
    var liServiceTypeID = document.forms.form1.ServiceTypeID.value;
    var lsServiceName = document.forms.form1.ServiceName.value;
    var liServicePrice = document.forms.form1.ServicePrice.value;
    var liServicePriceVAT = document.forms.form1.ServicePriceVAT.value;
    var liServiceID = document.forms.form1.ServiceID.value;
    
    document.getElementById( loLayer).innerHTML = '';
    if (liServiceTypeID)  {
        if (liServiceTypeID >= 1 || liServiceTypeID <= 3) {
            lsURL = gsBaseURL + '/service.asp?service=serviceoffers' +
                                '&ServiceTypeID=' + liServiceTypeID +
                                '&ServiceName=' + lsServiceName +
                                '&ServicePrice=' + liServicePrice +
                                '&ServicePriceVAT=' + liServicePriceVAT +
                                '&ServiceID=' + liServiceID;
            // Do final ajax post
            ajaxPost(lsURL, loLayer);
        }
    }
}


function updateCentralnicDomain() {
    if (confirm('Are you sure you wish to update this domain?')) { 
        var loForm = document.forms.form1;
        var liOrderItemID = loForm.OrderItemID.value;
        var lsDomain = loForm.DomainName.value + loForm.DomainExtensionID[loForm.DomainExtensionID.selectedIndex].text;
        var lsPrimaryDNS = document.getElementById('PrimaryDNS').value;
        var lsPrimaryIP = document.getElementById('PrimaryIP').value;
        var lsSecondaryDNS = document.getElementById('SecondaryDNS').value;
        var lsSecondaryIP = document.getElementById('SecondaryIP').value;
        var lsDomain_Locked = document.getElementById( 'Domain_Locked').value;
        var loLayer = 'domain_layer';
        var lsURL = gsBaseURL + '/service.asp?service=centralnic_update&domain=' + lsDomain + '&orderitemid=' + liOrderItemID + 
                                '&Domain_Locked=' + lsDomain_Locked  + 
                                '&primarydns=' + lsPrimaryDNS + '&primaryip=' + lsPrimaryIP + '&secondarydns=' + lsSecondaryDNS + '&secondaryip=' + lsSecondaryIP;
        document.getElementById( loLayer).innerHTML = 'Updating domain....'
        ajaxPost(lsURL, loLayer);
    }
}

//-----------------------------------------------------------------------------------------

function renewCentralnicDomain() {
    if (confirm('Are you sure you wish to renew this domain?')) { 
        var loForm = document.forms.form1;
        var liOrderItemID = loForm.OrderItemID.value;
        var lsDomain = loForm.DomainName.value + loForm.DomainExtensionID[loForm.DomainExtensionID.selectedIndex].text;
        var lsDomainOrderPeriod = document.getElementById('DomainOrderPeriod').value;
        var lsDomain_currentexpirationyear = document.getElementById( 'Domain_currentexpirationyear').value;
        var loLayer = 'domain_layer';
        var lsURL = gsBaseURL + '/service.asp?service=centralnic_renew&domain=' + lsDomain + '&orderitemid=' + liOrderItemID + 
                                '&DomainOrderPeriod=' + lsDomainOrderPeriod + 
                                '&Domain_currentexpirationyear=' + lsDomain_currentexpirationyear;
        document.getElementById( loLayer).innerHTML = 'Renewing domain....'
        ajaxPost(lsURL, loLayer);
    }
}

//-----------------------------------------------------------------------------------------

function registerCentralnicDomain() {
    if (confirm('Are you sure you want to register this domain via the Centralnic API?')) { 
        var loForm = document.forms.form1;
        var liOrderItemID = loForm.OrderItemID.value;
        var lsDomain = loForm.DomainName.value
        var lsDomainExtension = loForm.DomainExtensionID[loForm.DomainExtensionID.selectedIndex].text;
        var lsPrimaryDNS = document.getElementById('PrimaryDNS').value;
        var lsPrimaryIP = document.getElementById('PrimaryIP').value;
        var lsSecondaryDNS = document.getElementById('SecondaryDNS').value;
        var lsSecondaryIP = document.getElementById('SecondaryIP').value;
        var lsDomainPrivate = document.getElementById( 'DomainPrivate').value;
        var lsDomainOrderPeriod = document.getElementById('DomainOrderPeriod').value;
        var lsChandle = document.getElementById('chandle').value;
        var loLayer = 'domain_layer';
        var lsURL = gsBaseURL + '/service.asp?service=centralnic_registerdomain&domain=' + lsDomain + '&domainextension = ' + lsDomainExtension + '&orderitemid=' + liOrderItemID + 
                                '&PrivateDomain=' + lsDomainPrivate + '&primarydns=' + lsPrimaryDNS + '&secondarydns=' + lsSecondaryDNS + '&primaryip=' + lsPrimaryIP + '&secondaryip=' + lsSecondaryIP +
                                '&DomainOrderPeriod=' + lsDomainOrderPeriod + '&chandle=' + lsChandle;
        document.getElementById( loLayer).innerHTML = 'Registering domain....<br /><br /> (this can take up to 30 seconds)'
        ajaxPost(lsURL, loLayer);
    }
}



//-----------------------------------------------------------------------------------------

function registerOpenSRSDomain() {
    if (confirm('Are you sure you want to register this domain via the OpenSRS API?')) { 
        var loForm = document.forms.form1;
        var liOrderItemID = loForm.OrderItemID.value;
        var lsDomain = loForm.DomainName.value + loForm.DomainExtensionID[loForm.DomainExtensionID.selectedIndex].text;
        var lsPrimaryDNS = document.getElementById('PrimaryDNS').value;
        var lsPrimaryIP = document.getElementById('PrimaryIP').value;
        var lsSecondaryDNS = document.getElementById('SecondaryDNS').value;
        var lsSecondaryIP = document.getElementById('SecondaryIP').value;
        var lsDomain_AutoRenew = document.getElementById( 'Domain_AutoRenew').value;
        var lsDomain_Locked = document.getElementById( 'Domain_Locked').value;
        var lsDomainPrivate = document.getElementById( 'DomainPrivate').value;
        var lsDomainOrderPeriod = document.getElementById('DomainOrderPeriod').value;
        
        var loLayer = 'domain_layer';
        var lsURL = gsBaseURL + '/service.asp?service=opensrs_registerdomain&domain=' + lsDomain + '&orderitemid=' + liOrderItemID + 
                                '&PrivateDomain=' + lsDomainPrivate + '&Domain_AutoRenew=' + lsDomain_AutoRenew  + '&Domain_Locked=' + lsDomain_Locked  + 
                                '&primarydns=' + lsPrimaryDNS + '&secondarydns=' + lsSecondaryDNS + '&primaryip=' + lsPrimaryIP + '&secondaryip=' + lsSecondaryIP +
                                '&DomainOrderPeriod=' + lsDomainOrderPeriod;
        document.getElementById( loLayer).innerHTML = 'Registering domain....<br /><br /> (this can take up to 30 seconds)'
        ajaxPost(lsURL, loLayer);
    }
}
//-----------------------------------------------------------------------------------------

function updateOpenSRSDomain() {
    if (confirm('Are you sure you wish to update this domain?')) { 
        var loForm = document.forms.form1;
        var liOrderItemID = loForm.OrderItemID.value;
        var lsDomain = loForm.DomainName.value + loForm.DomainExtensionID[loForm.DomainExtensionID.selectedIndex].text;
        var lsPrimaryDNS = document.getElementById('PrimaryDNS').value;
        var lsPrimaryIP = document.getElementById('PrimaryIP').value;
        var lsSecondaryDNS = document.getElementById('SecondaryDNS').value;
        var lsSecondaryIP = document.getElementById('SecondaryIP').value;
        var lsDomain_AutoRenew = document.getElementById( 'Domain_AutoRenew').value;
        var lsDomain_Locked = document.getElementById( 'Domain_Locked').value;
        var loLayer = 'domain_layer';
        var lsURL = gsBaseURL + '/service.asp?service=opensrs_update&domain=' + lsDomain + '&orderitemid=' + liOrderItemID + 
                                '&Domain_AutoRenew=' + lsDomain_AutoRenew  + '&Domain_Locked=' + lsDomain_Locked  + 
                                '&primarydns=' + lsPrimaryDNS + '&primaryip=' + lsPrimaryIP + '&secondarydns=' + lsSecondaryDNS + '&secondaryip=' + lsSecondaryIP;
        document.getElementById( loLayer).innerHTML = 'Updating domain....'
        ajaxPost(lsURL, loLayer);
    }
}

//-----------------------------------------------------------------------------------------

function renewOpenSRSDomain() {
    if (confirm('Are you sure you wish to renew this domain?')) { 
        var loForm = document.forms.form1;
        var liOrderItemID = loForm.OrderItemID.value;
        var lsDomain = loForm.DomainName.value + loForm.DomainExtensionID[loForm.DomainExtensionID.selectedIndex].text;
        var lsDomainOrderPeriod = document.getElementById('DomainOrderPeriod').value;
        var lsDomain_AutoRenew = document.getElementById( 'Domain_AutoRenew').value;
        var lsDomain_currentexpirationyear = document.getElementById( 'Domain_currentexpirationyear').value;
        var loLayer = 'domain_layer';
        var lsURL = gsBaseURL + '/service.asp?service=opensrs_renew&domain=' + lsDomain + '&orderitemid=' + liOrderItemID + 
                                '&DomainOrderPeriod=' + lsDomainOrderPeriod + '&Domain_AutoRenew=' + lsDomain_AutoRenew + 
                                '&Domain_currentexpirationyear=' + lsDomain_currentexpirationyear;
        document.getElementById( loLayer).innerHTML = 'Renewing domain....'
        ajaxPost(lsURL, loLayer);
    }
}

//-----------------------------------------------------------------------------------------

function registerNominetDomain( ) {
    if (confirm('Are you sure you want to register this domain via the Nominet API?')) { 
        var loForm = document.forms.form1;
        var liOrderItemID = loForm.OrderItemID.value;
        var lsDomain = loForm.DomainName.value + loForm.DomainExtensionID[loForm.DomainExtensionID.selectedIndex].text;
        var lsPrimaryDNS = document.getElementById('PrimaryDNS').value;
        var lsPrimaryIP = document.getElementById('PrimaryIP').value;
        var lsSecondaryDNS = document.getElementById('SecondaryDNS').value;
        var lsSecondaryIP = document.getElementById('SecondaryIP').value;
        var lsDomainPrivate = document.getElementById('DomainPrivate').value;
        var lsServiceType = document.getElementById( 'nominet_accounttype').value; //BUG - taken from ID as dynamically generated
        var loLayer = 'domain_layer';
        var lsURL = gsBaseURL + '/service.asp?service=nominet_registerdomain&domain=' + lsDomain + '&orderitemid=' + liOrderItemID + '&servicetype=' + lsServiceType  + '&primarydns=' + lsPrimaryDNS + '&primaryip=' + lsPrimaryIP + '&secondarydns=' + lsSecondaryDNS + '&secondaryip=' + lsSecondaryIP + '&domainprivate=' + lsDomainPrivate;
        document.getElementById( loLayer).innerHTML = 'Registering domain....<br /><br /> (this can take up to 30 seconds)'
        ajaxPost(lsURL, loLayer);
    }
}

//-----------------------------------------------------------------------------------------

function transferNominetDomain() {
    if (confirm('Are you sure you want to transfer this domain?')) { 
        if (confirm('Do you understand that the domain will no longer be under UKHosts control once transfered?')) { 
            var loForm = document.forms.form1;
            var liOrderItemID = loForm.OrderItemID.value;
            var lsDomain = loForm.DomainName.value + loForm.DomainExtensionID[loForm.DomainExtensionID.selectedIndex].text;
            var lsDomainTAG = document.getElementById('DomainTAG').value;
            var loLayer = 'domain_layer';
            var lsURL = gsBaseURL + '/service.asp?service=nominet_transfer&domain=' + lsDomain + '&orderitemid=' + liOrderItemID + '&domaintag=' + lsDomainTAG;
            document.getElementById( loLayer).innerHTML = 'Transferring domain....'
            ajaxPost(lsURL, loLayer);
        }
    }
}

//-----------------------------------------------------------------------------------------

function updateNominetDomain() {
    if (confirm('Are you sure you wish to update this domain?')) { 
        var loForm = document.forms.form1;
        var liOrderItemID = loForm.OrderItemID.value;
        var lsDomain = loForm.DomainName.value + loForm.DomainExtensionID[loForm.DomainExtensionID.selectedIndex].text;
        var lsPrimaryDNS = document.getElementById('PrimaryDNS').value;
        var lsPrimaryIP = document.getElementById('PrimaryIP').value;
        var lsSecondaryDNS = document.getElementById('SecondaryDNS').value;
        var lsSecondaryIP = document.getElementById('SecondaryIP').value;
        var lsDomainPrivate = document.getElementById('DomainPrivate').value;
        var loLayer = 'domain_layer';
        var lsURL = gsBaseURL + '/service.asp?service=nominet_update&domain=' + lsDomain + '&orderitemid=' + liOrderItemID + '&primarydns=' + lsPrimaryDNS + '&primaryip=' + lsPrimaryIP + '&secondarydns=' + lsSecondaryDNS + '&secondaryip=' + lsSecondaryIP + '&domainprivate=' + lsDomainPrivate;
        document.getElementById( loLayer).innerHTML = 'Updating domain....'
        ajaxPost(lsURL, loLayer);
    }
}
//-----------------------------------------------------------------------------------------

function renewNominetDomain() {
    if (confirm('Are you sure you wish to renew this domain?')) { 
        var loForm = document.forms.form1;
        var liOrderItemID = loForm.OrderItemID.value;
        var lsDomain = loForm.DomainName.value + loForm.DomainExtensionID[loForm.DomainExtensionID.selectedIndex].text;
        var loLayer = 'domain_layer';
        var lsURL = gsBaseURL + '/service.asp?service=nominet_renew&domain=' + lsDomain + '&orderitemid=' + liOrderItemID;
        document.getElementById( loLayer).innerHTML = 'Renewing domain....'
        ajaxPost(lsURL, loLayer);
    }
}

//-----------------------------------------------------------------------------------------

function resetPassword( lsPasswordType, loLayer) {
    if (confirm('Are you sure you want to reset \'' + lsPasswordType + '\' password?')) {
        var loForm = document.forms.form1;
        var liOrderItemID = loForm.OrderItemID.value;
        var lsDomain = loForm.DomainName.value + loForm.DomainExtensionID[loForm.DomainExtensionID.selectedIndex].text;
        if (confirm('Generate NEW \'' + lsPasswordType + '\' password?')) {
            var lsURL = gsBaseURL + '/service.asp?service=resetpassword&generatenewpassword=1&passwordtype=' + lsPasswordType + '&domain=' + lsDomain + '&orderitemid=' + liOrderItemID;
        } else {
            var lsURL = gsBaseURL + '/service.asp?service=resetpassword&generatenewpassword=0&passwordtype=' + lsPasswordType + '&domain=' + lsDomain + '&orderitemid=' + liOrderItemID;
        }
        ajaxPost(lsURL, loLayer);
    }
}

//-----------------------------------------------------------------------------------------

function setupHostingOnHeart() {
    if (confirm('Are you sure you wish to setup hosting on this domain?')) { 
        var loForm = document.forms.form1;
        var liOrderItemID = loForm.OrderItemID.value;
        var lsDomain = loForm.DomainName.value + loForm.DomainExtensionID[loForm.DomainExtensionID.selectedIndex].text;
        var liPackageTypeID = document.getElementById( 'packagetypeid').value;
        var loLayer = 'hosting_layer'
        var lsURL = gsBaseURL + '/service.asp?service=setuphosting&domain=' + lsDomain + '&orderitemid=' + liOrderItemID + '&packagetypeid=' + liPackageTypeID;
        document.getElementById( loLayer).innerHTML = 'Setting up hosting....<br />(this can take up to 30 seconds)'
        ajaxPost(lsURL, loLayer);
    }
}

//-----------------------------------------------------------------------------------------

function updateCommentAjax( lsComment){
	var liActivtyID;
	liActivtyID = document.getElementById('ActivityID').value;
	lsURL = gsBaseURL + '/service.asp?service=comments&activityid='+liActivtyID;
	if (lsComment) {
		lsURL += '&comment='+lsComment;
		document.getElementById('activitycomment').value = '';
	}
	ajaxPost(lsURL, 'activitycomment_layer');
}


//-----------------------------------------------------------------------------------------

function populateAPIService( lsService, loLayer, lsDomain) {
    var loForm = document.forms.form1;
    var liOrderItemID = loForm.OrderItemID.value;
    
    //If order item ID is blank, try and get the renewal ID
    if (!liOrderItemID)
        liOrderItemID = loForm.OrderItemID_Renewal.value;
    
    if (!lsDomain) {
        try {
            if (loForm.DomainName.value!='')
                lsDomain = loForm.DomainName.value + loForm.DomainExtensionID[loForm.DomainExtensionID.selectedIndex].text;
        
        //Firefox fix
        } catch(err) {
            if (document.getElementById('DomainName').value!='')
                lsDomain = document.getElementById('DomainName').value + document.getElementById('DomainExtensionID')[document.getElementById('DomainExtensionID').selectedIndex].text;
        }
    }
    
    if (lsDomain) {
        document.getElementById( loLayer).style.display = 'block';
        var lsURL = gsBaseURL + '/service.asp?service=' + lsService + 
                                '&domain=' + lsDomain + 
                                '&orderitemid=' + liOrderItemID;
        if (lsService=='domain')
            document.getElementById( loLayer).innerHTML = 'Loading Domain API....';
        else if (lsService=='hosting')
            document.getElementById( loLayer).innerHTML = 'Loading Hosting API....';
        else
            document.getElementById( loLayer).innerHTML = 'Loading....';
        ajaxPost(lsURL, loLayer);
    }
}





//-----------------------------------------------------------------------------------------
// Other Functions
//-----------------------------------------------------------------------------------------
function ValidateDomain(domain)
{
	domain_newval='';
	eValidCharsExp = new RegExp("[\\w\\d\\-]+");
	for (n=0;n<domain.length;n++)
	{
		if (domain.substr(n,1).match(eValidCharsExp)&&domain.substr(n,1)!='_'&&domain.substr(n,2)!='--')
			if (!(n==0&&domain.substr(n,1)=='-'))
				if (!(n==domain.length-1&&domain.substr(n,1)=='-'))
					domain_newval+=domain.substr(n,1);
		if(domain_newval=='-')
			domain_newval='';
	}
	document.forms.domainsearch.domain.value=domain_newval;
}

//-----------------------------------------------------------------------------------------

function SubmitDomain()
	{
	ValidateDomain(document.forms.domainsearch.domain.value);
	if(document.forms.domainsearch.domain.value.length>2)
		{
		document.forms.domainsearch.searchdomain.disabled=true;
		document.forms.domainsearch.submit();
		}
	else
		alert('The domain needs to be at least 3 characters in length');
	}


//----------------------------------------------------------------------------

function autopopulateCosts( loForm) {
    
    var lsURL = gsBaseURL + '/serviceAdmin.asp?ajax=servicecost&serviceid=' + loForm.ServiceID.value + 
                '&DomainExtensionID=' + loForm.DomainExtensionID.value + 
                '&OrderPeriod=' + loForm.OrderPeriod.value + 
                '&TransferID=' + loForm.TransferID.value;
                //'&OfferID=' + loForm.OfferID.value + 
                
    var xmlHttp = GetXmlHttpObject();
    if (xmlHttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    } 
    xmlHttp.onreadystatechange = stateChanged;
    xmlHttp.open( "GET", lsURL, true);
    xmlHttp.send( null);
    
    function stateChanged() { 
        var lsResponseStr;
        if (xmlHttp.readyState==4){
            var lsResponseText = xmlHttp.responseText;
            if (lsResponseText!='') {
                var laResponseArray = lsResponseText.split("|");
                
                loForm.SetupPrice.value = laResponseArray[0];
                loForm.SetupPriceVAT.value = laResponseArray[1];
                //addVAT( loForm.SetupPrice, loForm.SetupPriceVAT);
                
                loForm.MonthlyPrice.value = laResponseArray[2];
                loForm.MonthlyPriceVAT.value = laResponseArray[3];
                //addVAT( loForm.MonthlyPrice, loForm.MonthlyPriceVAT);
                
                loForm.OrderPrice.value = laResponseArray[4];
                loForm.OrderPriceVAT.value = laResponseArray[5];
                //addVAT( loForm.OrderPrice, loForm.OrderPriceVAT);
                
                loForm.OfferID.value = laResponseArray[6];
                
                document.getElementById( 'OfferDescription').innerHTML = laResponseArray[7];
            }
        }
    }
}

//----------------------------------------------------------------------------

function updateInvoiceAmount( loCheckbox, lfCommission) {
    var loForm = loCheckbox.form;
    
    if (loCheckbox.checked) {
        loForm.InvoiceAmount.value = (parseFloat(loForm.InvoiceAmount.value) + parseFloat(lfCommission)).toFixed(2);
    } else {
        loForm.InvoiceAmount.value = (parseFloat(loForm.InvoiceAmount.value) - parseFloat(lfCommission)).toFixed(2);
    }
    
}

//----------------------------------------------------------------------------

function updateCommissionExample (loForm) {
    var lfCommission = ( parseFloat(loForm.serviceexample.value) / 100 ) * parseFloat(loForm.CommissionPercentage.value);
    var lsHTML = 'Cost = &pound;' + parseFloat(loForm.serviceexample.value).toFixed(2) + 
                '<br />Commission = &pound;' + lfCommission.toFixed(2)
    document.getElementById( 'commission_example').innerHTML = lsHTML;
    
}

//----------------------------------------------------------------------------

function loadPaymentType() {
	
	var liPaymentTypeID = document.getElementById( 'paymenttypeid').value;
	
	document.getElementById( 'payment_online').style.display = 'none';
	document.getElementById( 'payment_transaction').style.display = 'none';
	document.getElementById( 'payment_notes').style.display = 'none';
	
	//Paypoint, paypal
	if (liPaymentTypeID==3 || liPaymentTypeID==4) {
		document.getElementById( 'payment_online').style.display = 'block';
	
	} //BACS,Cheque,Credit card
	else if (liPaymentTypeID==1 || liPaymentTypeID==5 || liPaymentTypeID==6) {
		document.getElementById( 'payment_transaction').style.display = 'block';
		if (liPaymentTypeID==1)
			document.getElementById( 'payment_label').innerHTML = 'TransactionID';
		else if (liPaymentTypeID==5)
			document.getElementById( 'payment_label').innerHTML = 'BACS No';
		else if (liPaymentTypeID==6) 
			document.getElementById( 'payment_label').innerHTML = 'Cheque No';
		
	} //Payment Notes
	else if (liPaymentTypeID!='') {
		document.getElementById( 'payment_notes').style.display = 'block';
	}
	
}

//-----------------------------------------------------------------------------------------
