function callreset(){

	document.getElementById("ans").value = "";
	frm.proceed.disabled=true;
}
function validateNumber(field, msg) { 
var mytext = document.getElementById("buildingsum");
if (isNaN(field)) {

	//if ( (parseInt(mytext) != mytext) ) { 
		alert(msg); 
		 
		document.getElementById("buildingsum").select();
		mytext.focus(); 
		mytext.select();
		
		return false; 
	} 
return true; 
}
function validateNumber1(field, msg) { 
var mytext1 = document.getElementById("contentsum");
if (isNaN(field)) {

	//if ( (parseInt(mytext1) != mytext1) ) { 
		alert(msg); 
		 
		document.getElementById("contentsum").select();
		mytext1.focus(); 
		mytext1.select();
		return false; 
	} 
return true; 
}
function validateNumber2(field, msg) { 
var mytext1 = document.getElementById("premium");
if (isNaN(field)) {

	//if ( (parseInt(mytext1) != mytext1) ) { 
		alert(msg); 
		 
		document.getElementById("premium").select();
		mytext1.focus(); 
		mytext1.select();
		return false; 
	} 
return true; 
}
function validateEmail(email){	
	var regEx = /^[\w\.\+-]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,6}$/;
	if (!regEx.test(email)) {
		return false;
	} 
return true;
}


var rootdomain="http://"+window.location.hostname 
function ajaxinclude(url) { 
var page_request = false 
if (window.XMLHttpRequest) // if Mozilla, Safari etc 
page_request = new XMLHttpRequest() 
else if (window.ActiveXObject){ // if IE 
try { 
page_request = new ActiveXObject("Msxml2.XMLHTTP") 
} 
catch (e){ 
try{ 
page_request = new ActiveXObject("Microsoft.XMLHTTP") 
} 
catch (e){} 
} 
} 
else 
return false 
page_request.open('GET', url, false) //get page synchronously 
page_request.send(null) 
writecontent(page_request) 
} 
function writecontent(page_request){ 
if (window.location.href.indexOf("http")==-1 || page_request.status==200) 
document.write(page_request.responseText) 
} 

if( document.addEventListener ) document.addEventListener( 'DOMContentLoaded', cmxform, false );

function cmxform(){
  // Hide forms
  $( 'form.cmxform' ).hide().end();
  
  // Processing
  $( 'form.cmxform' ).find( 'li/label' ).not( '.nocmx' ).each( function( i ){
    var labelContent = this.innerHTML;
    var labelWidth = document.defaultView.getComputedStyle( this, '' ).getPropertyValue( 'width' );
    var labelSpan = document.createElement( 'span' );
        labelSpan.style.display = 'block';
        labelSpan.style.width = labelWidth;
        labelSpan.innerHTML = labelContent;
    this.style.display = '-moz-inline-box';
    this.innerHTML = null;
    this.appendChild( labelSpan );
  } ).end();
  
  // Show forms
  $( 'form.cmxform' ).show().end();
}


function createXmlHttpObject() {
  var req = null;
  try {
    req = new XMLHttpRequest(); //ie7, ff, safari
  }
  catch (e) {
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP"); //later ie
    }
    catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP") // earlier ie
      }
      catch (e) {
        // could not create XMLHttpRequest object
        return false;
      }
    }
  }
  return req;
}
function call(frm) {
	

	var yname=document.getElementById('urname').value;
	if(yname ==''){ 
		alert('Please Enter Your Name');
		document.getElementById('urname').select();
		return false; 
	}

	
	var ytell=document.getElementById('contactno').value;
	if(ytell ==''){ 
		alert('Please Enter Your Mobile or Telephone Number');
		document.getElementById('contactno').select();
		return false; 
	}
	if(!ValidateNo(document.getElementById('contactno').value,"1234567890+- ")) 
	{ 
		alert("Please Enter Only Number"); 
		document.getElementById('contactno').focus(); 
		frm.contactno.select();
		//document.getElementById('contactno').style.border = '1px #FF0000 solid';
		return false; 
	}
	//alert(ytell);



	var pst = frm.postcode.value;
	
	
	if (pst == "") { 
	alert ("Please Enter your Postcode");
	frm.postcode.value = "";
	frm.postcode.focus();
	return false; 
	}

	var bsi = frm.buildingsum.value;
	if (bsi == "") 
	{ 
		bsi = 0; 
	} else{
		if (bsi > 500000 || bsi < 35000) { 
			alert ("Enter the Building Insurance amount. the maximum amount is 500,000.00 & minimum amount is 35000");
			frm.buildingsum.value = "";
			frm.buildingsum.focus();
			return false; 
		}
	}


	var csi = frm.contentsum.value;
	if (csi == ""){ 
		csi = 0; 
	} else {
		if (csi > 30000 || csi < 1000) { 
			alert ("Enter the Content Insurance amount. the maximum amount is 30,000.00 & minimum amount is 1000");
			frm.contentsum.value = "";
			frm.contentsum.focus();
			return false; 
		}
	}
	
	
	if( bsi == 0 && csi == 0){
		alert("Please write one of Building Insurance amount or Content Insurance amount");
		frm.ans.value = "";
		//document.getElementById("ans").innerHTML = "";
		return false;
	}
	
	var c = frm.type.value;
	var typeOf = document.getElementById('type').selectedIndex;

	if (c == "") { 
	alert ("Please select one of the Tenancy Type");
	frm.type.focus();
	return false; 
	}

	var x = (parseFloat(bsi)/1000 * c).toFixed(2);
	//alert (x);
	var y = ((parseFloat(csi)/1000)*5).toFixed(2);
	//alert (y);
	var val;

	if( x > 0 && y >= 0 )
	{
		if ( parseFloat(x)+parseFloat(y) <= 100)
		{
			val = 100;
			//alert("total less then 100")
		} else 
		{
			val = parseFloat(x)+parseFloat(y);
			//alert("total more thn 100");
		}
	
	} 	
	
	if(x <= 0 && y <= 100)
	{
		val = 100;
		//alert("use 50");
	} 
	if(x <= 0 && y > 100)
	{
		val = parseFloat(x)+parseFloat(y);
	}
	

	//alert (parseFloat(val));
	var ipt = ((parseFloat(val)/100)*5).toFixed(2);
	//alert ("ipt ="+ ipt);
	var percent = parseFloat(ipt)+parseFloat(val);
	//alert ("percent");
	//alert (percent);
	//var tot = (parseFloat(x) + parseFloat(y) + parseFloat(percent)).toFixed(2);
	var tot = (parseFloat(percent)).toFixed(2);
	//alert (tot);
	parseFloat(tot); 
	var params="tname="+yname+"&ttell="+ytell+"&postcd="+pst+"&bsi="+bsi+"&csi="+csi+"&Type="+typeOf+"&prim="+tot;
	//frm.ans.value = tot;
	//frm.proceed.disabled=false;

		objXMLHttp=createXmlHttpObject();
		
		if (objXMLHttp==null) {
			alert ('Your browser does not support the XMLHttpRequest object!');
			return;
		}
		//alert(params);
		var url='sendquote.php'; // prevent caching
		objXMLHttp.onreadystatechange = result;
		objXMLHttp.open('POST',url,true); // GET method
		objXMLHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
		objXMLHttp.send(params); // always use null for GET method


frm.ans.value = tot;
frm.proceed.disabled=false;
	
	//alert(params);
}





//alert (x);
function result()
{

} 

function expandingWindow(website) {
window.open(website,'mywindow',"status = 1, height = 720, width = 780, scrollbars=yes,status=yes" )
}

function WindowC()
{
expandingWindow('http://quote.touch10.co.uk/OnlineQuoteEngine/menu.aspx?ac=OTE1OA==');
}



function validate_form ()
{


    if ( document.frm.NAME.value == "" )
    {
        alert ( "Please fill in the 'Your Name' box." );
		document.frm.NAME.focus();
        return false;
    }
	apos=document.frm.FROM.value.indexOf("@");
	dotpos=document.frm.FROM.value.lastIndexOf(".");
	if (document.frm.FROM.value == "" || apos<1 || dotpos-apos<2)
	{
		alert("Please fix: email");
		document.frm.FROM.focus();
		return false;
	}
	if ( document.frm.COMMENTS.value == "" )
    {
        alert ( "Please fill in the 'Your Message' box." );
		document.frm.COMMENTS.focus();
        return false;
    }
	if(document.frm.w1.checked == true)
	{
			if ( document.frm.tel.value == "" )
			{
				alert ( "Please fill in the 'Your contact' box." );
				document.frm.tel.focus();
				return false;
			}
			if(isNaN(document.frm.tel.value)) {
				alert ( "Please fill Your contact number." );
				document.frm.tel.select();
				document.frm.tel.style.border = '1px #FF0000 solid';
				return false;
			}
			if ( document.frm.interest.selectedIndex == 0 )
			{
				alert ( "Please select your Interested in." );
				document.frm.interest.focus();
				return false;
			}
			if ( document.frm.time.selectedIndex == 0 )
			{
				alert ( "Please select your Time to call." );
				document.frm.time.focus();
				return false;
			}
			return true;
	}
	return true;
}


function validate_rform ()
{
	

	var pst = rfrm.postcde.value;


			if (pst == "") { 
			alert ("Please Enter your Postcode");
			rfrm.postcde.value = "";
			rfrm.postcde.focus();
			return false; 
			}
			
			var bsi = rfrm.buildingsum.value;
			if (bsi == "") 
			{ 
				bsi = 0; 
			} else{
				if (bsi > 500000 || bsi < 35000) { 
					alert ("Enter the Building Insurance amount. the maximum amount is 500,000.00 & minimum amount is 35000");
					rfrm.buildingsum.value = "";
					rfrm.buildingsum.focus();
					return false; 
				}
			}
			
			
			var csi = rfrm.contentsum.value;
			if (csi == ""){ 
				csi = 0; 
			} else {
				if (csi > 30000 || csi < 1000) { 
					alert ("Enter the Content Insurance amount. the maximum amount is 30,000.00 & minimum amount is 1000");
					rfrm.contentsum.value = "";
					rfrm.contentsum.focus();
					return false; 
				}
			}
			
			
			if( bsi == 0 && csi == 0){
				alert("Please write one of Building Insurance amount or Content Insurance amount");
				rfrm.buildingsum.focus();
				return false;
			}
	
	if ( rfrm.premium.value == "" )
    {
        alert ( "Please fill Premium" );
		rfrm.premium.focus();
        return false;
    }
	            
	if ( isNaN(rfrm.premium.value))
    {
        alert ( "Please fill Premium in digits" );
		rfrm.premium.value = "";
		rfrm.premium.focus();
        return false;
    }

	return true;
}

function detail_rform ()
{
	if ( m.tel.value == "" )
	{
		alert ( "Please fill your contact Number." );
		m.tel.focus();
		return false;
	}
	if(!ValidateNo(m.tel.value,"1234567890+- ")) 
	{ 
		alert("Please Enter Only Number"); 
		m.tel.focus(); 
		m.tel.style.border = '1px #FF0000 solid';
		return false; 
	}	
	return true;
}
function ValidateNo(NumStr, String) 
{ 
    for(var Idx=0; Idx<NumStr.length; Idx++) 
    { 
        var Char = NumStr.charAt(Idx); 
        var Match = false; 

        for(var Idx1=0; Idx1<String.length; Idx1++) 
        { 
            if(Char == String.charAt (Idx1)) 
                Match = true; 
        } 

        if (!Match) 
            return false; 
    } 
    return true; 
}
