
    var urlPrefix = "http://xapps.smsconnexion.com/RequestASalesCallback/widget/";
    
    function loadRASCB(div, key, title)
	{		
	    if (title == null){title="Callback Request";}
	    var phDiv = document.getElementById(div);
	    
	    var form = document.createElement('form');	    
	    form.setAttribute('id','formrascb');
	    form.setAttribute('method','get');
	    form.setAttribute('target','_blank');
	    form.setAttribute('action',urlPrefix + 'Submit.aspx');
	    
	    phDiv.appendChild(form);
	    
	    var baseDiv = document.createElement('div');
	    baseDiv.setAttribute('id','divrascb');	  
	    
	    
	    var tbl = document.createElement('table');
	    tbl.setAttribute('cellpadding','4');
	    tbl.setAttribute('cellspacing','0');
	    tbl.setAttribute('border','0');
	    tbl.setAttribute('width','300px');
	    
	    var rowFooter = tbl.insertRow('footerrow');
	    var cellFooterLabel = rowFooter.insertCell(0);
	    cellFooterLabel.setAttribute('colspan','2');
	    cellFooterLabel.setAttribute('class','rascbFooter');
	    cellFooterLabel.innerHTML = "<div id='rascbFooter' class='rascbFooter'></div>";	
	    
	    var rowMobile = tbl.insertRow('mobilerow')
	    var cellMobile = rowMobile.insertCell(0);
	    cellMobile.setAttribute('id','rascbDisplay');
	    cellMobile.setAttribute('valign','bottom');
	    cellMobile.setAttribute('class','rascbMobile');
		
	    cellMobile.innerHTML = "<div class='rascbMobile'>Enter mobile no:</div>";
	    
	    
	    var textMobile = document.createElement('input');	    
	    textMobile.setAttribute('type','text');
	    textMobile.setAttribute('id','txtMobilerascb');
	    textMobile.setAttribute('name','txtMobilerascb');
		  textMobile.setAttribute('size','12');
		    textMobile.setAttribute('maxlength','12');
	    cellMobile.appendChild(textMobile);
	    cellMobile.innerHTML = cellMobile.innerHTML + "&nbsp;&nbsp;";    
    
	    
	    var cmdMobile = document.createElement('input');	    
	    cmdMobile.setAttribute('type','button');
	    cmdMobile.setAttribute('id','cmdSubmitrascb');
	    cmdMobile.setAttribute('name','cmdSubmitrascb');
	    cmdMobile.setAttribute('value','Submit');
	    cmdMobile.setAttribute('onclick','if (!submitRequest("' + key + '")) {return false;}');
	    cellMobile.appendChild(cmdMobile);
	    cellMobile.innerHTML = cellMobile.innerHTML + "<br/><br/><div class='rascbInstruction'>Prefix country code e.g. 919820022331<br/></div>";
	    
	    var cellImage = rowMobile.insertCell(1);
	    cellImage.setAttribute('valign','middle');
	    cellImage.setAttribute('width','20px');
	    var imgMobile = document.createElement('img');	    
	    //imgMobile.setAttribute('src','callback.png');	    
	    cellImage.appendChild(imgMobile);
	    
	    var rowHeader = tbl.insertRow('headerrow');
	    var cellHeaderLabel = rowHeader.insertCell(0);
	    cellHeaderLabel.setAttribute('colspan','2');
	    cellHeaderLabel.setAttribute('class','rascbHeader');
	    cellHeaderLabel.innerHTML = "<div class='rascbHeader'>" + title + "</div>";	 	       	    
	    
	    linkCSS(key);
	    linkScript();
	    
	    baseDiv.appendChild(tbl);
	    form.appendChild(baseDiv);
	    phDiv.appendChild(form);
	}
	
	function submitRequest(key)
	{
	    if (document.getElementById('txtMobilerascb').value == '')
	    {	        
	        document.getElementById('rascbFooter').innerHTML = "<img src='" + urlPrefix + "error.png' align='absbottom' />&nbsp;Field cannot be blank.";
	        return false;	    
	    }
	    
	    if (!validMobile(document.getElementById('txtMobilerascb').value))
	    {	        
	        document.getElementById('rascbFooter').innerHTML = "<img src='" + urlPrefix + "error.png' align='absbottom' />&nbsp;Invalid mobile number.";
	        return false;	    
	    }

        document.getElementById('rascbFooter').innerHTML = "";
        
        postMethod(key);	    
	}
	
	function validMobile(mobile) 
	{
	    var filter = /^\d{8,}$/;
        return filter.test(mobile);
    }    
    
    function getHTTPObject() 
    {
	    var http = false;
	    //Use IE's ActiveX items to load the file.
	    if(typeof ActiveXObject != 'undefined') {
		    try {http = new ActiveXObject("Msxml2.XMLHTTP");}
		    catch (e) {
			    try {http = new ActiveXObject("Microsoft.XMLHTTP");}
			    catch (E) {http = false;}
		    }
	    //If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
	    } else if (XMLHttpRequest) {
		    try {http = new XMLHttpRequest();}
		    catch (e) {http = false;}
	    }
	    return http;
    }

    function handler(data)
    {
        displayResponse(data.webresponse); 
        //document.getElementById('rascbFooter').innerHTML = "<img src='" + urlPrefix + "error.png' align='absbottom' />&nbsp;Error: Unable to submit information.";
    } 
    
    
    var http = getHTTPObject();
    
    function postMethod(key) {
        var url = urlPrefix + "Submit.aspx";    
        var params= "key=" + key + "&mobile=" + document.getElementById('txtMobilerascb').value;

        $.getJSON(url + "?" + params + "&jsoncallback=?", handler);

    }
    
    function displayResponse(response)
    {
        document.getElementById('rascbDisplay').innerHTML = "<div class='rascbResponse'>" + response + "</div><br/>";        
    }
    
    function linkCSS(key)
    {
        //CSS Injection
        var link = document.createElement('link');
        link.setAttribute('type','text/css');
        link.setAttribute('rel','StyleSheet');
        link.setAttribute('href',urlPrefix + "CSS.aspx?key=" + key);
         	    
        document.getElementsByTagName('head')[0].appendChild(link);
    }
    
    function linkScript()
    {
        //CSS Injection
        var script = document.createElement('script');
        script.setAttribute('type','text/javascript');
        script.setAttribute('src','jquery.min.js');
        document.getElementsByTagName('head')[0].appendChild(script);
    } 
