/* Click 2 Call to Google Voice                                                        */
/*                                                                                     */
/* Developed by : Razvan Gavril                                                        */
/* License : GPL                                                                       */
/*                                                                                     */
/* More info here: http://razvangavril.com/web-development/custom-google-voice-widget/ */

function click2call(button_id, cid_number, cid_name) {
	var iframe = document.createElement('iframe');
	iframe.style.width = 0;
	iframe.style.height = 0;
	iframe.style.border = 0;
	document.body.appendChild(iframe);

	var doc = null;
	if(iframe.contentDocument)
		doc = iframe.contentDocument;
	else if(iframe.contentWindow)
		doc = iframe.contentWindow.document;
	else if(iframe.document)
		doc = iframe.document;
	if(doc == null)
		throw "Document not initialized";

	doc.open(); doc.write('');doc.close();

	var form = doc.createElement("form");
	form.method="post";
	form.action="https://clients4.google.com/voice/embed/webButtonConnect";
	
	input = doc.createElement("input");
	input.type="text";
	input.name="buttonId";
	input.value= ""+button_id;
	form.appendChild(input);

	input = doc.createElement("input");
	input.type="text";
	input.name="callerNumber";
	input.value= ""+cid_number;
	form.appendChild(input);

	input = doc.createElement("input");
	input.type="text";
	input.name="name";
	input.value="Testing";
	form.appendChild(input);

	input = doc.createElement("input");
	input.type="text";
	input.name="showCallerNumber";
	input.value= "1";
	form.appendChild(input);

	doc.body.appendChild(form);

	form.submit();
}

