function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return '';
}


var flyvoip_keywords = getCookie('keywords');

function sending_form_checkField(field)
{
	var status = true;
	if(field.val() == '')
	{
		status = false;
		field.css('background-color','#FCC');
	}
	else
	{
		field.css('background-color','#FFF');
	}
	
	return status;
}

function sending_form_checkDemoFields(form)
{
	var name = $(form+" input[name=name]");
	var company = $(form+" input[name=company]");
	var email = $(form+" input[name=email]");
	var brand = $(form+" input[name=brand]");
	var model = $(form+" input[name=model]");
	var configuration = $(form+" select[name=configuration]");
	
	var status = true;
	var elem;
	if(!sending_form_checkField(name)){status = false;}
	if(!sending_form_checkField(company)){status = false;}
	if(!sending_form_checkField(email)){status = false;}
	if(!sending_form_checkField(brand)){status = false;}
	if(!sending_form_checkField(model)){status = false;}
	if(!sending_form_checkField(configuration)){status = false;}
	
	return status;
}

function sending_form_sendDemoRequest(form)
{
	if(!sending_form_checkDemoFields(form)){return;}

	var name = encodeURIComponent($(form+" input[name=name]").val());
	var company = encodeURIComponent($(form+" input[name=company]").val());
	var position = encodeURIComponent($(form+" input[name=position]").val());
	var email = encodeURIComponent($(form+" input[name=email]").val());
	var tel = encodeURIComponent($(form+" input[name=tel]").val());
	var skype = encodeURIComponent($(form+" input[name=skype]").val());
	var msn = encodeURIComponent($(form+" input[name=msn]").val());
	var yahoo = encodeURIComponent($(form+" input[name=yahoo]").val());
	var googletalk = encodeURIComponent($(form+" input[name=googletalk]").val());
	var brand = encodeURIComponent($(form+" input[name=brand]").val());
	var model = encodeURIComponent($(form+" input[name=model]").val());
	var configuration = encodeURIComponent($(form+" select[name=configuration]").val());
	var details = encodeURIComponent($(form+" textarea[name=details]").val());
	var keywords = $(form+" input[name=keywords]").val();
	
	var params = "n="+name;
	params += "&c="+company;
	params += "&p="+position;
	params += "&e="+email;
	params += "&t="+tel;
	params += "&sk="+skype;
	params += "&ms="+msn;
	params += "&ya="+yahoo;
	params += "&gt="+googletalk;
	params += "&b="+brand;
	params += "&m="+model;
	params += "&conf="+configuration;
	params += "&d="+details;
	params += "&kw="+keywords;

	$('#send_request').val('Sending...').attr("disabled", true);
	
	$.getJSON('http://www.flyvoip.com/request.php?type=demo&'+params, "", function(data)
	{
	});
	setTimeout("$('#send_request').val('Sent');$('"+form+"').dialog('close');",2000);
}

function sending_form_openRequestDemoForm(form)
{
	html = '<table border="0" style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;text-align:left;">';
	html += '<tr><td>*</td><td width=120>Name:</td><td><input name="name" style="width:170px"></td></tr>';
	html += '<tr><td>*</td><td>Company:</td><td><input name="company" style="width:170px"></td></tr>';
	html += '<tr><td></td><td>Position:</td><td><input name="position" style="width:170px"></td></tr>';
	html += '<tr><td>*</td><td>E-mail:</td><td><input name="email" style="width:170px"></td></tr>';
	html += '<tr><td></td><td>Tel:</td><td><input name="tel" style="width:170px"></td></tr>';
	html += '<tr><td></td><td>Skype:</td><td><input name="skype" style="width:170px"></td></tr>';
	html += '<tr><td></td><td>MSN:</td><td><input name="msn" style="width:170px"></td></tr>';
	html += '<tr><td></td><td>Yahoo!:</td><td><input name="yahoo" style="width:170px"></td></tr>';
	html += '<tr><td></td><td>Google Talk:</td><td><input name="googletalk" style="width:170px"></td></tr>';
	html += '<tr><td>*</td><td>Brand (e.g. Nokia):</td><td><input name="brand" style="width:170px"></td></tr>';
	html += '<tr><td>*</td><td>Model (e.g. N95):</td><td><input name="model" style="width:170px"></td></tr>';
	html += '<tr><td>*</td><td>Configuration:</td><td><select name="configuration" style="width:170px">';
		html += '<option default></option>';
		html += '<option>Calling Cards</option>';
		html += '<option>ANI Call-Through</option>';
		html += '<option>ANI Call-Back</option>';
		html += '<option>SMS Call-Back</option>';
		html += '<option>Web Call-Back</option>';
		html += '<option>USSD Call-Back</option>';
	html += '</select></td></tr>';
	html += '<input type="hidden" value="'+flyvoip_keywords+'" name="keywords" />';
	html += '<tr><td></td><td>Additional details:</td><td><textarea name="details" style="width:170px;height:100px"></textarea></td></tr>';
	html += '<tr><td></td><td><input id="send_request" type="button" value="Send" onClick="sending_form_sendDemoRequest(\''+form+'\')"></td><td style="color:#777" align="right">* Required fields</td></tr>';
	html += '</table>';

	$(form).dialog(
		{
			bgiframe: true,
			autoOpen: false,
			width: 350,
			modal: true,
			resizable: false
		});
	$(form).html(html);
	$(form).dialog('option', 'title', 'Mobile Dialer: Request a demo');
	$(form).dialog('open');

}

















function sending_form_checkQuoteFields(form)
{
	var name = $(form+" input[name=name]");
	var company = $(form+" input[name=company]");
	var email = $(form+" input[name=email]");
	var configuration = $(form+" select[name=configuration]");
	
	var status = true;
	var elem;
	if(!sending_form_checkField(name)){status = false;}
	if(!sending_form_checkField(company)){status = false;}
	if(!sending_form_checkField(email)){status = false;}
	if(!sending_form_checkField(configuration)){status = false;}
	
	return status;
}


function sending_form_sendQuoteRequest(form)
{
	if(!sending_form_checkQuoteFields(form)){return;}

	var name = encodeURIComponent($(form+" input[name=name]").val());
	var company = encodeURIComponent($(form+" input[name=company]").val());
	var position = encodeURIComponent($(form+" input[name=position]").val());
	var email = encodeURIComponent($(form+" input[name=email]").val());
	var tel = encodeURIComponent($(form+" input[name=tel]").val());
	var skype = encodeURIComponent($(form+" input[name=skype]").val());
	var msn = encodeURIComponent($(form+" input[name=msn]").val());
	var yahoo = encodeURIComponent($(form+" input[name=yahoo]").val());
	var googletalk = encodeURIComponent($(form+" input[name=googletalk]").val());

	var iphone = encodeURIComponent($(form+" input[name=iphone]").val());
	var symbian_s60 = encodeURIComponent($(form+" input[name=s60]").val());
	var symbian_uiq = encodeURIComponent($(form+" input[name=uiq]").val());
	var blackberry = encodeURIComponent($(form+" input[name=blackberry]").val());
	var j2me = encodeURIComponent($(form+" input[name=j2me]").val());
	var android = encodeURIComponent($(form+" input[name=android]").val());
	var windows_mobile = encodeURIComponent($(form+" input[name=wm]").val());

	var configuration = encodeURIComponent($(form+" select[name=configuration]").val());
	var details = encodeURIComponent($(form+" textarea[name=details]").val());
	var keywords = $(form+" input[name=keywords]").val();
	
	var params = "n="+name;
	params += "&c="+company;
	params += "&p="+position;
	params += "&e="+email;
	params += "&t="+tel;
	params += "&sk="+skype;
	params += "&ms="+msn;
	params += "&ya="+yahoo;
	params += "&gt="+googletalk;
	params += "&conf="+configuration;
	params += "&d="+details;
	params += "&kw="+keywords;

	$('#send_request').val('Sending...').attr("disabled", true);
	
	$.getJSON('http://www.flyvoip.com/request.php?type=quote&'+params, "", function(data)
	{
	});
	setTimeout("$('#send_request').val('Sent');$('"+form+"').dialog('close');",2000);
}

function sending_form_openRequestQuoteForm(form)
{
	html = '<table border="0" style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;text-align:left;">';
	html += '<tr><td>*</td><td width=120>Name:</td><td><input name="name" style="width:170px"></td></tr>';
	html += '<tr><td>*</td><td>Company:</td><td><input name="company" style="width:170px"></td></tr>';
	html += '<tr><td></td><td>Position:</td><td><input name="position" style="width:170px"></td></tr>';
	html += '<tr><td>*</td><td>E-mail:</td><td><input name="email" style="width:170px"></td></tr>';
	html += '<tr><td></td><td>Tel:</td><td><input name="tel" style="width:170px"></td></tr>';
	html += '<tr><td></td><td>Skype:</td><td><input name="skype" style="width:170px"></td></tr>';
	html += '<tr><td></td><td>MSN:</td><td><input name="msn" style="width:170px"></td></tr>';
	html += '<tr><td></td><td>Yahoo!:</td><td><input name="yahoo" style="width:170px"></td></tr>';
	html += '<tr><td></td><td>Google Talk:</td><td><input name="googletalk" style="width:170px"></td></tr>';
	html += '<tr><td></td><td>Platforms:</td><td>';
	html += '<input type="checkbox" name="iphone" checked> iPhone<br>';
	html += '<input type="checkbox" name="s60"> Symbian S60<br>';
	html += '<input type="checkbox" name="j2me"> J2ME<br>';
	html += '<input type="checkbox" name="blackberry"> BlackBerry<br>';
	html += '<input type="checkbox" name="wm"> Windows Mobile<br>';
	html += '<input type="checkbox" name="uiq"> Symbian UIQ<br>';
	html += '<input type="checkbox" name="android"> Android<br>';
	html += '</td></tr>';
	html += '<tr><td>*</td><td>Configuration:</td><td><select name="configuration" style="width:170px">';
		html += '<option default></option>';
		html += '<option>Calling Cards</option>';
		html += '<option>ANI Call-Through</option>';
		html += '<option>ANI Call-Back</option>';
		html += '<option>SMS Call-Back</option>';
		html += '<option>Web Call-Back</option>';
		html += '<option>USSD Call-Back</option>';
	html += '</select></td></tr>';
	html += '<input type="hidden" value="'+flyvoip_keywords+'" name="keywords" />';
	html += '<tr><td></td><td>Additional details:</td><td><textarea name="details" style="width:170px;height:100px"></textarea></td></tr>';
	html += '<tr><td></td><td><input id="send_request" type="button" value="Send" onClick="sending_form_sendQuoteRequest(\''+form+'\')"></td><td style="color:#777" align="right">* Required fields</td></tr>';
	html += '</table>';

	$(form).dialog(
		{
			bgiframe: true,
			autoOpen: false,
			width: 350,
			modal: true,
			resizable: false
		});
	$(form).html(html);
	$(form).dialog('option', 'title', 'Mobile Dialer');
	$(form).dialog('open');

}


