function submitMeetingForm()
{
	
//	alert(document.meetingsForm.strFornavn.value);
	//alert("fn called");
    document.meetingsForm.submit();
}

function submitProductsForm()
{
	
//	alert(document.meetingsForm.strFornavn.value);
	//alert("fn called");
    document.productListingForm.submit();
}
function submitBrochuresForm()
{
	
//	alert(document.meetingsForm.strFornavn.value);
	//alert("fn called");
    document.brochureDetailsForm.submit();
}
function validateBrochureData(frm)
{

 if(document.forms[frm].strNavn.value.length==0||document.forms[frm].strNavn.value==null)
	{
	 alert("Vennligst oppgi navn");
	 document.forms[frm].strNavn.focus();
	 return false;
	}
	else if(document.forms[frm].strArbeidsplass.value.length==0||document.forms[frm].strArbeidsplass.value==null)
	{
	 alert("Vennligs oppgi arbeidsplass");
	 document.forms[frm].strArbeidsplass.focus();
	 return false;
	}
	else if(document.forms[frm].strAdresse.value.length==0||document.forms[frm].strAdresse.value==null)
	{
	 alert("Vennligst oppgi adresse");
	 document.forms[frm].strAdresse.focus();
	 return false;
	}
	else if(document.forms[frm].strPostnr.value.length==0||document.forms[frm].strPostnr.value==null)
	{
	 alert("Vennligst fyll inn postnr. og sted");
	 document.forms[frm].strPostnr.focus();
	 return false;
	}
	else if(document.forms[frm].strTelefon.value.length==0||document.forms[frm].strTelefon.value==null)
	{
	 alert("Vennligst fyll inn telefon");
	 document.forms[frm].strTelefon.focus();
	 return false;
	}
	else if(!document.forms[frm].strTerms.checked)
	{
	 alert("Vennligst bekreft at betingelser og vilk&aring;r er lest");
	
	 return false;
	}
	else if(!validateEmail(frm))
	{
		return false;
	}
	else if(!validatePhoneNumber(frm))
	{
		 return false;
	}
	
	else if(!validateQuantity(frm))
	{
		return false;
	}
    
	
	return true;
}
function validateData(frm)
{
  
 if(document.forms[frm].strFornavn.value.length==0||document.forms[frm].strFornavn.value==null)
	{
	 alert("Vennligst oppgi fornavn");
	 document.forms[frm].strFornavn.focus();
	 return false;
	}
	else if(document.forms[frm].strEtternavn.value.length==0||document.forms[frm].strEtternavn.value==null)
	{
	 alert("Vennligst oppgi etternavn");
	 document.forms[frm].strEtternavn.focus();
	 return false;
	}
	else if(document.forms[frm].strArbeidsplass.value.length==0||document.forms[frm].strArbeidsplass.value==null)
	{
	 alert("Vennligs oppgi arbeidsplass");
	 document.forms[frm].strArbeidsplass.focus();
	 return false;
	}
	else if(document.forms[frm].strAdresse.value.length==0||document.forms[frm].strAdresse.value==null)
	{
	 alert("Vennligst oppgi adresse");
	 document.forms[frm].strAdresse.focus();
	 return false;
	}
	else if(document.forms[frm].strPostnr.value.length==0||document.forms[frm].strPostnr.value==null)
	{
	 alert("Vennligst fyll inn postnr. og sted");
	 document.forms[frm].strPostnr.focus();
	 return false;
	}
	else if(document.forms[frm].strTelefon.value.length==0||document.forms[frm].strTelefon.value==null)
	{
	 alert("Vennligst fyll inn telefon");
	 document.forms[frm].strTelefon.focus();
	 return false;
	}
	else if(document.forms[frm].strEpostadresse.value.length==0||document.forms[frm].strEpostadresse.value==null)
	{
	 alert("Vennligst oppgi en gyldig e-postadresse");
	 document.forms[frm].strEpostadresse.focus();
	 return false;
	}
    else if(!document.forms[frm].strConditionOne.checked)
	{
	 alert("Vennligst bekreft at betingelser og vilk&aring;r er lest");
	
	 return false;
	}
 else if(!document.forms[frm].strConditionTwo.checked)
	{
	 alert("Vennligst bekreft at betingelser og vilk&aring;r er lest");
	
	 return false;
	}
	/* else if(!document.forms[frm].strConditionThree.checked)
	{
	 alert("Vennligst bekreft at betingelser og vilk&aring;r er lest");
	
	 return false;
	}*/
	 else if(!document.forms[frm].strConditionFour.checked)
	{
	 alert("Vennligst bekreft at betingelser og vilk&aring;r er lest");
	
	 return false;
	}
   else if(!validateEmail(frm))
	{
		return false;
	}
	else if(!validatePhoneNumber(frm))
	{
		 return false;
	}
	return true;
	      
}
function validatePhoneNumber(frm)
{
	 var phonenumber =document.forms[frm].strTelefon.value;
	//Added the characters (,),+, (white space) to the list of valid characters
		 var validValues="0123456789-+() ";
		 var ind;
		 for (i = 0;  i < phonenumber.length;  i++)
              {
              ch = phonenumber.charAt(i);
              if(validValues.indexOf(ch)== -1)
			   {
				  alert("Feil telefonnummer");
				  document.forms[frm].strTelefon.focus();
				  return false;
			   }
			  
				   
			 
		   }
		   return true;
}

function validateEmail(frm)
{
	
  var addr=document.forms[frm].strEpostadresse.value;
  var man=true;
  var db=true;
	if (addr == '' && man) {
		   if (db) alert('e-post adresse er obligatorisk');
		   document.forms[frm].strEpostadresse.focus();
		   return false;
		}
		var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
		for (i=0; i<invalidChars.length; i++) {
		   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
			  if (db) alert('e-postadressen inneholder ugyldig tegn');
			  document.forms[frm].strEpostadresse.focus();
			  return false;
		   }
		}
		for (i=0; i<addr.length; i++) {
		   if (addr.charCodeAt(i)>127) {
			  if (db) alert("e-postadressen inneholder tegn som ikke er i henhold til ascii-standarden");
			  document.forms[frm].strEpostadresse.focus();
			  return false;
		   }
		}

		var atPos = addr.indexOf('@',0);
		if (atPos == -1) {
		   if (db) alert('Alle e-postadresser m&aring; inneholde @');
		   document.forms[frm].strEpostadresse.focus();
		   return false;
		}
		else if (atPos == 0) {
		   if (db) alert('E-postadresser er ugyldige hvis de starter med @');
		   document.forms[frm].strEpostadresse.focus();
		   return false;
		}
		else if (addr.indexOf('@', atPos + 1) > - 1) {
		   if (db) alert('E-postadresser kan ikke inneholde mer enn en @');
		   document.forms[frm].strEpostadresse.focus();
		   return false;
		}
		else if (addr.indexOf('.', atPos) == -1) {
		   if (db) alert('E-postadresser m&aring; inneholde et punktum');
		   document.forms[frm].strEpostadresse.focus();
		   return false;
		}
		else if (addr.indexOf('@.',0) != -1) {
		   if (db) alert('Punktumet i e-postadressen skal ikke direkte etterf&oslash;lge @');
		   document.forms[frm].strEpostadresse.focus();
		   return false;
		}
		else if (addr.indexOf('.@',0) != -1){
		   if (db) alert('Punktumet i e-postadressen skal ikke komme rett f&oslash;r @');
		   document.forms[frm].strEpostadresse.focus();
		   return false;
		}
		else if (addr.indexOf('..',0) != -1) {
		   if (db) alert('En e-postadresse kan ikke inneholde mer enn et punktum');
		   document.forms[frm].strEpostadresse.focus();
		   return false;
		}
		var suffix = addr.substring(addr.lastIndexOf('.')+1);
		 if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
		   if (db) alert('Ugyldig prim&aelig;rdomene i e-postadressen');
		   document.forms[frm].strEpostadresse.focus();
		   return false;
         }
	
		return true;

}

function viewProductInfo()
{
  // alert("hello");
 
	//var selectedURL = document.productListingForm.strSubProductSelect.options[document.productListingForm.strSubProductSelect.selectedIndex].value;
	//window.open(document.productListingForm.strSubProductSelect.options[document.productListingForm.strSubProductSelect.selectedIndex].value,'prodcut_page','');
}

function redirectToRegister(ind)
{
	
	document.location.href="../jsp/meetingRegistration.jsp?selindex="+ind;
}

function setQuantity(selind)
{
	
	qty=document.brochureDetailsForm.strQuantity;
	
	/* if(selind==0)
	{
      if(qty[selind].value!="0")
		{
		  
	      qty[selind].value="0"; 
	    }
		else if(qty[selind].value=="0")
		{
			
			 qty[selind].value=" "; 
		}
	}
	else
	{
		if(qty[selind].value!="0")
		{
			
	      qty[selind-1].value="0"; 
	    }
		else if(qty[selind].value=="0")
		{
			
			 qty[selind-1].value=" "; 
		}
   
	}*/
	
		
		   if(qty[selind].value!="0")
			{
			  
			  qty[selind].value="0"; 
			}
			else if(qty[selind].value=="0")
			{
				
			  qty[selind].value=" "; 
			}
			
		
	//document.getElementById(selind).value="0";
}


function validateQuantity(frm)
{
	
	qty=document.forms[frm].strQuantity;
	chk=document.forms[frm].strSelectedProducts;
	selvalues=document.forms[frm].strSelectedQuantityIndex;
	cnt=0;
	
	for (j=0;j<qty.length;j++)
   {
		
		if(chk[j].checked)
	   {	
			
			
			document.forms[frm].strSelectedQuantityIndex[cnt].value=j;
			
			if(qty[j].value<=0||qty[j].value==""||qty[j].value==null)
			  {
				
			alert("Ugyldig antall");
			qty[j].focus();
			return false;
			}
			else if(!validateQuantityInput(qty[j].value))
		   {
				qty[j].focus();
			return false;
		   }
		   cnt= cnt+1;
	
	  }
	  else if(!chk[j].checked)
	   {
          if(qty[j].value>0||qty[j].value.length>0)
		   {
			  alert("Vennligst velg et produkt");
			  chk[j].focus();	
			  return false;
		   }

	   }

 
   }
 
	
	
	
return true;
	   
 
	
}
function validateQuantityInput(quantity)
{
	
	 // qty=document.forms[frm].strQuantity;
	
		 var validValues="0123456789";
		 var ind;
		 for (i = 0;  i < quantity.length;  i++)
           {
			
			
				  ch = quantity.charAt(i);
				  if(validValues.indexOf(ch)== -1)
				   {
					  alert("Ugyldig antall");
					
					  return false;
				   }
			 
			  
				   
			 
		   }
		 return true;
}

function OpenProductURL(ind)
{
	
	produrl=document.productListingForm.strSubProductSelect;
	
   
	window.open(produrl[ind].options[produrl[ind].selectedIndex].value,'prodcut_page','');
}

function OpenRegulationSection(secno)
{
	var url ="./medinfo/refusjonspunkter.html#"+secno;
 var regwin=window.open(url,'prodcut_page','');
  regwin.focus();
}

function sortProdListing(field,type,order)
{
	
	document.location.href="ProductsHome.do?optype=sort&field="+field+"&type="+type+"&order="+order;
}
function sortBrochureOrdering(field,type,order)
{
	document.location.href="BrochuresHome.do?optype=sort&field="+field+"&type="+type+"&order="+order;
	
}

function validateSpirolabDialab(frm)
{
	if(document.forms[frm].strNavn.value.length==0||document.forms[frm].strNavn.value==null)
	{
	 alert("Vennligst oppgi navn");
	 document.forms[frm].strNavn.focus();
	 return false;
	}

	
return validateEmail(frm);


}

function validateBrochureDataForBrochureHomeInputs(frm)		{

	for(index=0; index < document.forms[frm].strSelectedProducts.length; index++)	{
	
		var selectedProductEach = document.forms[frm].strSelectedProducts[index];
		var quantityEach = document.forms[frm].strQuantity[index].value;
		var isOneProductAndQuantitySelectedAtleast='false';

		if( eval(selectedProductEach.checked) && quantityEach.length > 0 )	{
			isOneProductAndQuantitySelectedAtleast='true';
			break;
		}
	}
	
	if(isOneProductAndQuantitySelectedAtleast == 'false')	{
	
		var isOneProductSelectedAndNoQuantity='false';
		var isOneProductNotSelectedAndQuantityEntered='false';
			
		for(index=0; index < document.forms[frm].strSelectedProducts.length; index++)	{
		
			var selectedProductEach = document.forms[frm].strSelectedProducts[index];
			var quantityEach = document.forms[frm].strQuantity[index].value;
			
			if( eval(selectedProductEach.checked) && quantityEach.length == 0)	{
				isOneProductSelectedAndNoQuantity='true';
				break;
			}
			else if( !eval(selectedProductEach.checked) && quantityEach.length > 0)	{
				isOneProductNotSelectedAndQuantityEntered='true';
				break;			
			}
		}
		
	
		if(isOneProductSelectedAndNoQuantity =='true')	{
			alert("Vennligst oppgi Quantity");
		 	document.forms[frm].strQuantity[index].focus();
			return false;		
		}
		else if(isOneProductNotSelectedAndQuantityEntered=='true')	{
			alert("Vennligst oppgi Select box og Product");
		 	document.forms[frm].strSelectedProducts[index].focus();
			return false;		
		}
		else	{
			alert("Vennligst oppgi Select box & corresponding Quantity");
		 	document.forms[frm].strSelectedProducts[0].focus();
			return false;
		}
	}		
	else {
		return validateBrochureData(frm);
	}
}

