//window.history.forward(1);
var newwindow;
function poptastic(url)
{
	newwindow=window.open(url,'name','height=500,width=600');
	if (window.focus) {newwindow.focus()}
}
//	Getting Radio button value
function get_Radiobuttonvalue(rdobtn){
	var val = "";
	for (i=0;i<rdobtn.length;i++) {
		if (rdobtn[i].checked==true)
			val = rdobtn[i].value;
	}
	return val;
}
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		try {
			if(document.forma1.service_type[1].checked && len==4) 
				document.forma1.users.focus();
			else 
				input.form[(getIndex(input)+1) % input.form.length].focus();
		}
		catch(er){
			
		}
	}
	return true;
}
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
			if(arr[index] == ele)
				found = true;
			else
				index++;
		return found;
	}
	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
			if (input.form[i] == input)index = i;
			else i++;
		return index;
	}

//	Trim function
 
function seats() 	{
	a=document.forma1.users.value;
	for(i=0;i<a.length;i++) {
		z=a.charCodeAt(i);
		if(z<48 || z>57 || !parseInt(a)>0) {
			alert("Enter numeric value only");
			document.forma1.users.value="";
			document.forma1.users.focus();
			break;
		}
	}
}
function zip_code() 	{
	a=document.forma1.zipcode.value;
	for(i=0;i<a.length;i++) {
		z=a.charCodeAt(i);
		if(z<48 || z>57 || !parseInt(a)>0) {
			alert("Enter numeric value only");
			document.forma1.zipcode.value="";
			document.forma1.zipcode.focus();
			break;
		}
	}
}
function zipcode_resi() 	{
	a=document.forma1.zipcode_res.value;
	for(i=0;i<a.length;i++) {
		z=a.charCodeAt(i);
		if(z<48 || z>57 || !parseInt(a)>0) {
			alert("Enter numeric value only");
			document.forma1.zipcode_res.value="";
			document.forma1.zipcode_res.focus();
			break;
		}
	}
}
function phone(obj,val) {    
	a=val;
	for(i=0;i<a.length;i++) {
		z=a.charCodeAt(i);
		if(z<48 || z>57) {
			alert("Enter numeric value only");
			obj.value="";
			obj.focus();
			break;
		}
	}
}
function Trim(s){
	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')) 
		s = s.substring(1,s.length);
	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')) 
		s = s.substring(0,s.length-1);
	return s;
}

function IsvalidEmail(email) {		
		var str=email;
		var flag=true;
		var at="@";
		var dot=".";
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1) {
			flag=false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
			flag=false;
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
			flag=false;
		if (str.indexOf(at,(lat+1))!=-1)
			flag=false;
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
			flag=false;
		if (str.indexOf(dot,(lat+2))==-1)
			flag=false;
		if (str.indexOf(" ")!=-1)
			flag=false;
		 if(flag)
			return true;
		 else
		 return false;
}

function provjeria1()
{	
	
	//alert(document.forma1.service_type.value);
	//if(document.forma1.service_type.value=='home')
	//	document.forma1.action="http://voipreview.org/service.all2.aspx?lpid=bbn&source1=voipntl";
	//else
	//	document.forma1.action="quote.php";
	/* if(document.forma1.) {
	} */
	//alert(get_Radiobuttonvalue(document.forma1.service_type));
	if (get_Radiobuttonvalue(document.forma1.service_type)=="business")
	{
		var str ="";
		if(Trim(document.forma1.name.value)=="") {
			str +="Name.\n";
		}
		if(Trim(document.forma1.email.value)=="") {
			str +="Email Address.\n";
		}
		else if(Trim(document.forma1.email.value)!="" && !IsvalidEmail(Trim(document.forma1.email.value))) {
			str +="Valid Email Address.\n";
		}
		if(document.forma1.servicephone1.value=="" && document.forma1.servicephone1.value=="" && document.forma1.servicephone1.value=="") {
		str+="phone number.\n";
	   }
	  else if(document.forma1.servicephone1.value.length !=3 || document.forma1.servicephone2.value.length !=3 || document.forma1.servicephone3.value.length !=4) {
		str+="Valid phone number.\n";
		}
		
		if(Trim(document.forma1.users.value)==""){
			str+="Number of lines.\n";
		}
		if(Trim(document.forma1.zipcode.value)=="") {
		str +="Zip Code.\n";
		}
		else if(document.forma1.zipcode.value.length!='5'){
		str +="Valid Zip Code.\n";
		}
		if(Trim(document.forma1.company_name.value)==""){
			str+="Company Name.\n";
		}
		if(Trim(document.forma1.broadband_solution.value)==""){
			str+="Current Broadband/High Speed Data.\n";
		}	
		
	  	if(Trim(document.forma1.phone_satisfaction.value)==""){ 
			str+="Select phone system.\n";
		}
		if(Trim(document.forma1.phone_satisfaction.value)=="Yes"){ 
		if(Trim(document.forma1.newphone.value)==""){ 
			str+="Select Lease or Purchase.\n";
			}
		}
		if(Trim(document.forma1.installation.value)==""){ 
			str+="Select Installation Services.\n";
		}
		if(Trim(document.forma1.location.value)==""){ 
			str+="Select Location.\n";
		}
		/* if(!document.forma1.instsrv[0].checked && !document.forma1.instsrv[1].checked){ 
			str+="Select installation services.\n";
		} */
		
		if (str!="") {
			msg="Please enter the following details\n";
			msg =msg + "----------------------------------------------------\n";
			msg =msg + str;
			alert(msg);
			return false;
		}

		else {
			document.forma1.action ="../../quote_busi.php";
			document.forma1.submit();
			return false;
			
		} 
	}
	else {
		var str ="";
		if(Trim(document.forma1.name.value)=="") {
			str +="Name.\n";
		}
		if(Trim(document.forma1.email.value)=="") {
			str +="Email Address.\n";
		}
		else if(Trim(document.forma1.email.value)!="" && !IsvalidEmail(Trim(document.forma1.email.value))) {
			str +="Valid Email Address.\n";
		}
		if(document.forma1.servicephone1.value=="" && document.forma1.servicephone1.value=="" && document.forma1.servicephone1.value=="") {
		str+="phone number.\n";
	   }
	  else if(document.forma1.servicephone1.value.length !=3 || document.forma1.servicephone2.value.length !=3 || document.forma1.servicephone3.value.length !=4) {
		str+="Valid phone number.\n";
		}
		if(Trim(document.forma1.zipcode_res.value)=="") {
		str +="Zip Code.\n";
		}
		else if(document.forma1.zipcode_res.value.length!='5'){
		str +="Valid Zip Code.\n";
		}
	if (str!="") {
			msg="Please enter the following details\n";
			msg =msg + "----------------------------------------------------\n";
			msg =msg + str;
			alert(msg);
			return false;
		}
		
	}
	if(get_Radiobuttonvalue(document.forma1.service_type)=="home") {
		//document.forma1.action = "http://voipreview.org/service.all2.aspx?lpid=bbn&source1=voipntl";
		document.forma1.action = "../../quote-residential.php";
	}
	else {
		document.forma1.action = "../../quote.php";
	}
	document.forma1.submit();
	return true;
}
function SamoBroj(o)
{
	var t;
	t = o.value;
	if (isNaN(t)) {
		while(isNaN(t)) {
			if (t.length>0) {
				o.value = t.substr(0,o.value.length-1);
				t = o.value;
			}
		}
		alert("Only numbers are allowed");
		return false;
	}
}
//-->

var adaptor_count = 0;

function showlaptop(theTable)
{
     obj = document.getElementsByTagName('TR');
      for (i=0; i<obj.length; i++)
     {
          if (obj[i].id == theTable)
          obj[i].style.display = 'block';
     }
}
//-->

function hidelaptop(theTable)
{
     obj = document.getElementsByTagName('TR');
      for (i=0; i<obj.length; i++)
     {
          if (obj[i].id == theTable)
          obj[i].style.display = 'none';
     }
}
//-->


function showlaptop1(theTable)
{
     obj = document.getElementsByTagName('TR');
      for (i=0; i<obj.length; i++)
     {
          if (obj[i].id == theTable)
          obj[i].style.display = 'block';
     }
}
//-->


function hidelaptop1(theTable)
{
     obj = document.getElementsByTagName('TR');
      for (i=0; i<obj.length; i++)
     {
          if (obj[i].id == theTable)
          obj[i].style.display = 'none';
     }
}
function show() {
	document.getElementById("newphone").style.display="block";
}
function hide() {
	document.getElementById("newphone").style.display="none";
}
//-->
