
function $(id) { return document.getElementById(id); }

function formatcontent(o) {
	var ct='quickcode_type_text';
	for (i=0;i<o.quickcode_type.length;i++) {
		if (o.quickcode_type[i].checked==true) {
			ct = o.quickcode_type[i].id;
		}
	}
	hf=$('quickcode_frmt');
	switch(ct) {
		case 'quickcode_type_sms':
			hf.value = 'SMSTO:' + $('quickcode_0').value + ':' + $('quickcode').value;
		break;
		
		case 'quickcode_type_text':
			hf.value =  $('quickcode').value;
		break;

		
		case 'quickcode_type_tel':
			hf.value = 'TEL:'+ $('quickcode').value;
		break;
		
		case 'quickcode_type_url':
			hf.value = $('quickcode').value;
		break;
		
		default:
			return false;
		break;
	}
	return true;
}	
function eventTrigger (e) {
    if (! e)
        e = event;
    return e.target || e.srcElement;
}

function radioClick (e) {
    cct( eventTrigger (e) );
    return true;
}

function textCounter(field, maxlimit) {
	countfield = $('cc');
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.innerHTML = maxlimit - field.value.length;
	}
}
 
function cct(o) {
	var isIE=document.all?true:false;
	c=$('quickcode');
	container=$('fs');
	
	while (container.firstChild) {
		container.removeChild(container.firstChild);
	}
 
	switch(o.value) {
		case 'quickcode_type_sms':
		
		
			newl1=document.createElement('label');
			newl1.setAttribute('for','quickcode_0');
			newl1.innerHTML = 'Nr:';
			container.appendChild(newl1);
			
			newo1 = document.createElement('input');
			newo1.type='text';
			newo1.id='quickcode_0';
			newo1.name='quickcode_0';
			container.appendChild(newo1);
			
			newc=document.createElement('span');
			newc.id='counter';
			newc.innerHTML='<strong id="cc">160</strong> characters left';
			container.appendChild(newc);
			
 
			newl=document.createElement('label');
			newl.setAttribute('for','quickcode');
			newl.innerHTML = 'Message:';
			container.appendChild(newl);
			
			newo = document.createElement('textarea');
			newo.id='quickcode';
			newo.name='quickcode';
			if (isIE) {
      	newo.onkeydown = function() { textCounter(this,160); }
      	newo.onkeyup = function() { textCounter(this,160); }
      } else {
      	newo.setAttribute('onkeydown','textCounter(this,160);');
				newo.setAttribute('onkeyup','textCounter(this,160);');
			}
 
			container.appendChild(newo);
		break;
		
		case 'quickcode_type_text':
			newc=document.createElement('span');
			newc.id='counter';
			newc.innerHTML='<strong id="cc">250</strong> characters left<br />';
			container.appendChild(newc);
			
			newl=document.createElement('label');
			newl.setAttribute('for','quickcode');
			newl.innerHTML = '. Enter your text:<br> ';
			container.appendChild(newl);
			
			newo = document.createElement('textarea');
			newo.id='quickcode';
			newo.name='quickcode';
			if (isIE) {
      	newo.onkeydown = function() { textCounter(this,250); }
      	newo.onkeyup = function() { textCounter(this,250); }
      } else {
      	newo.setAttribute('onkeydown','textCounter(this,250);');
				newo.setAttribute('onkeyup','textCounter(this,250);');
			}
			container.appendChild(newo);
		break;
		
		case 'quickcode_type_tel':
			newl=document.createElement('label');
			newl.setAttribute('for','quickcode');
			newl.innerHTML = 'Phone number:';
			container.appendChild(newl);
			
			newo = document.createElement('input');
			newo.type='text';
			newo.id='quickcode';
			newo.name='quickcode';
			container.appendChild(newo);
		break;
		
		case 'quickcode_type_url':
			newl=document.createElement('label');
			newl.setAttribute('for','quickcode');
			newl.innerHTML = 'URL:';
			container.appendChild(newl);
			
			newo = document.createElement('input');
			newo.type='text';
			newo.value='http://';
			newo.id='quickcode';
			newo.name='quickcode';
			container.appendChild(newo);
		break;
		
		default:
		break;
		
	}
}


