var divid = "formbody";
var url = "../create_twelio.php";

function select_text()
{
	surl = document.getElementById('short_url');
	if (surl.createTextRange){
		var oRange = surl.createTextRange();
		oRange.moveStart("character", 0);
		oRange.moveEnd("character", surl.value.length);
		oRange.select();
	} else if (surl.setSelectionRange) {
	surl.setSelectionRange(0, surl.value.length);
	}
	surl.focus();
}

function copy_to_clipboard()  
  {  
     var text = document.getElementById('short_url').value;
	 if(window.clipboardData)  
      {  
      window.clipboardData.setData('text',text);  
      }  
      else  
      {  
          var clipboarddiv=document.getElementById('divclipboardswf');  
      if(clipboarddiv==null)  
      {  
         clipboarddiv=document.createElement('div');  
             clipboarddiv.setAttribute("name", "divclipboardswf");  
         clipboarddiv.setAttribute("id", "divclipboardswf");  
         document.body.appendChild(clipboarddiv);  
      }  
          clipboarddiv.innerHTML='<embed src="clipboard.swf" FlashVars="clipboard='+  
  encodeURIComponent(text)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';  
      }  
      return false;  
  }



function setContent(operation,elementid){

var xmlHttp;
try{
xmlHttp=new XMLHttpRequest(); 
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("Your browser does not support AJAX.");
return false;
}
}
}

fetch_unix_timestamp = function()
{
return parseInt(new Date().getTime().toString().substring(0, 10))
}

var timestamp = fetch_unix_timestamp();
var nocacheurl = url+"?t="+timestamp;

xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState!=4){
document.getElementById(divid).innerHTML='<img src="images/loader.gif" alt="Processing..." /> Processing...';
}
if(xmlHttp.readyState==4){
document.getElementById(divid).innerHTML=xmlHttp.responseText;
document.getElementById("short_url").focus();
}
}
var long_url = document.getElementById("long_url").value;
var user_ip = document.getElementById("user_ip").value;
if (long_url.match(/^[^#]*#(.*)/)) {
	var hv = long_url.match(/^[^#]*#(.*)/)[1];
} else {
	var hash_value = false;
}
pageTracker._trackEvent('Usage', 'URL Shortened', long_url);
xmlHttp.open("post",nocacheurl+"&operation="+operation+"&long_url="+long_url+"&hv="+hv+"&user_ip="+user_ip,true);
xmlHttp.send(null);
}
