function MakeMyInt(myString)
{
	outString = myString.replace(/,[0-9]*/g,"");
	outString = outString.replace(/-/g,"");
	outString = outString.replace(/\./g,"");
	return outString;
}

function MM_openBrWindow(theURL,winName,features){
	//var winwidth = screen.width/2; 
	//var winheight = screen.height/2; 
	var winwidth = 700; 
	var winheight = 800; 
	var posw = (screen.width - winwidth)/2; 
	//var posv = (screen.height - winheight)/2; 
	var posv = 50; 
	features = features + ",width=" + winwidth + ",height=" + winheight + ",left=" + posw + ",top="+ posv;
	insurancepop = window.open(theURL,winName,features); 
	insurancepop.focus(); 
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
	
	document.special.price.value = MakeMyInt(document.special.price.value);
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' skal indeholde en e-mail adresse.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' skal indeholde et tal.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' skal indeholde et tal mellem '+min+' og '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' skal udfyldes.\n'; }
  } if (errors) alert('Følgende fejl blev fundet:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function cForm(features) {
   win = window.open('','myWin',features);            
   document.create_insurance.target='myWin';
   document.create_insurance.submit();
}

function takemeoutofhere(whereto){
	if (whereto == 'create') 
	{
		MM_openBrWindow('popups/create-insurance.html','','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=630,height=200');
	}else if(whereto == 'calculator'){
		MM_openBrWindow('../calculator.php','calc','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=900');	
	}else{
		MM_openBrWindow('../latest-insurances.php','','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=900');
	}
}

function changeCountry(mode){
 	document.base_setup.countries_idx.value = cindexes[document.base_setup.countries_id.value];
	if (mode == 'admin'){
	 	document.base_setup.countries_description.value = cdescription[document.base_setup.countries_id.value];
 	}
}

function changeCondition(){
 	document.conditions_form.condition.value = unescape(conditions[document.conditions_form.language.value]);
}

function kill_queen_and_country(countryid){
	
 if (countryid == 0){
	 alert("Vælg venligt et land i listen\n");
	 return true;
 }else{
	  var where_to = confirm("Vil du slette det valgte land?\n"+cdescription[countryid]);
	 if (where_to==true){
	   window.location="/admin/base-setup.php?del=countries&idx="+countryid;
	 }else{
		return true;
	 }
 }
}

function do_insurance(mode, iid){
	if (mode == 'del'){
	  var where_to = confirm("Vil du slette den valgte forsikring?\n");
	  if (where_to==true){
		window.location="/drafts.php?mode="+mode+"&iid="+iid;
	  }else{
		return true;
	  }
	}else if (mode == 'dellatest'){
	  var where_to = confirm("Vil du slette den valgte forsikring?\n");
	  if (where_to==true){
		window.location="/latest-insurances.php?mode="+mode+"&iid="+iid;
	  }else{
		return true;
	  }
	}else if (mode == 'delarchive'){
	  var where_to = confirm("Vil du slette den valgte forsikring?\n");
	  if (where_to==true){
		window.location="/archive.php?mode="+mode+"&iid="+iid;
	  }else{
		return true;
	  }
	}else if (mode == 'conv'){
	  var where_to = confirm("Vil du konvertere kladen til en forsikring?\n");
	  if (where_to==true){
		window.location="/drafts.php?mode="+mode+"&iid="+iid;
	  }else{
		return true;
	  }
	}else if (mode == 'damage'){
	  var where_to = confirm("Vil du anmelde en skade vedrørende denne forsikring?\n\nVIGTIGT:\n\n SKADEN ER IKKE ANMELDT FØR SKEMAET I NÆSTE VINDUE\n ER UDFYLDT OG AFSENDT\n\nLæs om Anmeld Skade under Seneste Forsikringer");
	  if (where_to==true){
		window.open("https://www.tryg.dk/netinsurance01/snotes.do?uniklink=EAnmeldTransport",'_blank');
		window.location="/latest-insurances.php?mode="+mode+"&iid="+iid;
	  }else{
		return true;
	  }
	}else if (mode == 'edit'){
		window.location="/create-insurance.php?edit=1&iid="+iid;
	}else if (mode == 'special_accept'){
	  var where_to = confirm("Vil du acceptere tegning af special forsikring?\n");
	  if (where_to==true){
		window.location="/latest-insurances.php?mode="+mode+"&iid="+iid;
	  }else{
		return true;
	  }
	}
}

function del_setting(mode, type, iid){
	if (mode == 'delbasic'){
	  var where_to = confirm("Vil du slette den valgte nøgle?\n");
	  if (where_to==true){
		window.location="/admin/base-setup.php?del="+type+"&idx="+iid;
	  }else{
		return true;
	  }
	}else if (mode == 'deluser'){
	  var where_to = confirm("Vil du slette den valgte nøgle?\n");
	  if (where_to==true){
		window.location="/admin/administrate-users.php?del="+type+"&idx="+iid;		  
	  }else{
		return true;
	  }
	}
}

function translate(mode, lang, iid){
//	if (mode == 'basic'){
	  var where_to = confirm("Vil du oversætte denne nøgle?\n");
	  if (where_to==true){
		//window.location="/admin/popups/translation.php?mode="+mode+"&lang="+lang+"&idx="+iid;
		MM_openBrWindow('/admin/popups/translation.php?mode='+mode+'&t='+lang+'&i='+iid,'popUp','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=650,height=150');		
	   //document.create_insurance.target='myWin';
   		//document.create_insurance.submit();
	  }else{
		return true;
	  }
//	}else if (mode == 'user'){
//	  var where_to = confirm("Vil du oversætte denne nøgle?\n");
//	  if (where_to==true){
//		window.location="/admin/administrate-users.php?del="+lang+"&idx="+iid;		  
//	  }else{
//		return true;
//	  }
//	}
}

function translate_country(countryid){
	 if (countryid == 0){
		 alert("Vælg venligt et land i listen\n");
		 return true;
	 }else{
		  var where_to = confirm("Vil du oversætte\n"+cdescription[countryid]);
		 if (where_to==true){
			MM_openBrWindow('/admin/popups/translation.php?mode=basic&t=countries&i='+countryid,'popUp','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=650,height=150');
		 }else{
			return true;
		 }
	 }
}


function checkSpecial(item){
	if ((item.value == 'special')){
		if (item.type == 'checkbox' && item.checked){
			alert ("Du har valgt \nANDET\nDette medfører en special-forsikring ved oprettelsen.");
		}else if (item.type != 'checkbox'){
	  		alert ("Du har valgt \nANDET\nDette medfører en special-forsikring ved oprettelsen.");
		}
	}
}

var draftpopup = null;

