
function c2c(){

}

c2c.prototype.display = function(){
    var html = "<div class=\"c2c\" id=\"c2c_box\">";
	html = html + "<div style=\"float:right\"><span title=\"Close window\" id=\"c2c_close\" onclick=\"$('window_container').innerHTML = '';\">X</span></div>";
    html = html + "<h1 style=\"margin:0\">Click to call</h1>";
    html = html + "<p>Please type in your phone number and click call. We will call you within 60 seconds.</p>";
    html = html + "<label>Phone number &nbsp;</label>";
    html = html + "<input type=\"text\" id=\"c2c_number\" />&nbsp;";
    html = html + "<button id=\"c2c_button\">Call</button>";
    html = html + "</div>";

    if ($('window_container')){
        $('window_container').innerHTML = html;
    }
    
    if ($('c2c_button')){
        $('c2c_button').observe('click', this.call);
    }

    this.center();

    return false;
}

c2c.prototype.call = function(){
    var number = "";

    if ($('c2c_number')){
        number = $F('c2c_number');
    }

    if (number.match(/^0[127][0-9]{9,9}$/)){
        
        var img = new Image();
        //img.src = "http://www.invomo2go.com/dispatcher/webr?destination=noworriescbr&account=NoWorriesLoansLtd&c2c_id=noworries&c2c_telephone=" + number;
	img.src = "http://cbr-api.gcicom.net/invoke.asmx/RequestCallback?Destination=gcicbr&Account=gcicbr&c2c_id=noworries&postpone=0&leg1_cli=&leg2_cli=&c2c_telephone=" + number;
        img.style.display = 'none';
        $('window_container').insert(img);

        var html = "<div class=\"c2c\" id=\"c2c_box\">";
        html = html + "<h2>We are about to call you...</h2>";
        html = html + "<button id=\"c2c_close\" onclick=\"$('window_container').innerHTML = '';\">OK</button>";
        html = html + "</div>";
    
        if ($('window_container')){
            $('window_container').innerHTML = html;
            c2c.center();
        }

    }else{
        alert('The phone number you have entered does not appear to be valid. Please try again.');
    }
}


c2c.prototype.center = function(){
    var d = $('c2c_box').getDimensions();
    var vd = document.viewport.getDimensions();
    
    var left = (vd.width / 1.5) - (d.width / 2);
    var top = (vd.height / 6) - (d.height / 2);
    
    $('c2c_box').style.top = top + 'px';
    $('c2c_box').style.left = left + 'px';
}

c2c.prototype.close = function(){
    if ($('window_container')){
        //$('window_container').innerHTML = '';
    }
}

var c2c = new c2c();
