var newwindow = window 

function openGarant(GarItem, x, y)
{
    newwindow = window.open(GarItem, "garantiewindow",
        "scrollbars=no,resizable=no,width=" + x + ",height=" + y +
        ",left=200,top=0");
}



function checkModel()
{
 var a = true
 for (i = 0; i < document.forms.length && a; i++) 
 try {
   if (document.forms[i].f_merk.value != "")
   {
      relate(document.forms[i], document.forms[i].f_merk.selectedIndex);
      a = false;
   }
 } catch (e) {  
  if (e instanceof TypeError) {
  // vang type error op
  } 
 }  
};

function checkModelNAV()
{
if ( document.formnav.f_merk.value != "")
{
  relate(document.formnav, document.formnav.f_merk.selectedIndex);
}
};

//Valideer Veld Focus
function selectField(field)
{
field.focus();
field.select();
return;
}

//Valideer Postcode Lengte en Formaat.
function check(Postcode)
{
if (Postcode.value == null || Postcode.value == "")
{
return false;
}
if ( ((Postcode.value/Postcode.value) != 1) && (Postcode.value != 0) )
{
return true;
}
if (Postcode.value.length != 4)
{
return true;
}
return false;
}

//Valideer formulier
function checkForm()
{
var a = true
for (i = 0; i < self.document.forms.length && a; i++) 
 try {
//Valideer postcode waarde.
   if (check(self.document.forms[i].f_pc_cijfers))
   {
    alert("Vul de eerste 4 cijfers van uw postcode in.");
    selectField(form.f_pc_cijfers);
    return false;
   } 
   a = false;	 
  } catch (e) {  
  if (e instanceof TypeError) {
  // vang type error op
  }
 }  
return true;
}

//Scripts voor uidgebreid zoeken van merk model, plaatsen van merk en model in keuze merk model box
function addOption(addTo, addFrom_1, addFrom_2)
	{
		if(addFrom_2.selectedIndex >= 0)
		{
			txt_1 = addFrom_1.options[addFrom_1.selectedIndex].text;
			val_1 = addFrom_1.options[addFrom_1.selectedIndex].value;
			txt_2 = addFrom_2.options[addFrom_2.selectedIndex].text;
			val_2 = addFrom_2.options[addFrom_2.selectedIndex].value;
			txt_3 = txt_1 + " " + txt_2;
			val_3 = val_1 + " " + val_2;
			addFrom_2.options[addFrom_2.selectedIndex].selected = false;
			if((val_2 != '') && !optionExists(val_3, addTo))
			{
				newOption = new Option(txt_3, val_3);
				if (addTo.length == 1 && (addTo.options[0].value == '')) {
					 addTo.options[0] = newOption;
				} else {
					//onderstaande regel is ingebouwd om de gebruiker te beperken is het aantal gekozen
 					//merk - model combinaties
					//Het getal '10' staat voor maximaal 10 merk model combinaties
					if (addTo.length < 10)
					{
				  addTo.options[addTo.length] = newOption;
					}
				}
				newOption.selected = false;
			}
		}
	}


function optionExists(val, field)
	{
		for(var i = 0;i < field.length;i++)
		{
			if(field.options[i].value==val)
				return true;
		}
			return false;
	}

function removeOption(field) {
	if(field.options[field.selectedIndex].value != '') {
		if (field.length == 1) {
			field.options[0].selected = false;
			newOption = new Option(' ','');
			field.options[0] = newOption;
		} else {
			field.options[field.selectedIndex] = null;
		}
	} else {
            field.options[field.selectedIndex].selected = false;
        }
}

function openHelp(Help, width, height)
{
    var w;
    var h;

    if ( width != undefined ) w = width; else w = 300;
    if ( height != undefined ) h = height; else h = 200;

    newwindow = window.open(Help, "helpwindow",
        "scrollbars=yes,resizable=no,width="+w+",height="+h+",left=200,top=200");
}


function chooseAll(left){
	if (left != null){
	for(i = 0;i < (left.length);i++){
	    left.options[i].selected = true;
	}
	return true; } 
}

//voor auto van het jaar verkiezing:
function openWindowVerk(theURL,winName,features) 
{ 
  window.open(theURL,winName,features);
}


//voor het checken van hoevaak de submitknop is indedrukt:
var submitcount=0;

function submitOnce() {
   if (submitcount == 0)
      {
      submitcount++;
      return true;
      }
   else 
      {
      alert("Even geduld AUB, uw zoekopdracht wordt verwerkt. Klik op OK om door te gaan.");
      return false;
      }
   }

// PMa, zoeken is aangepast. Ajax om model te bepalen
function ajaxCheckModelHome()
{
  if ( document.forms[0].f_merk.value != "")
  {
    var url = '';
    url = '/owa_dima/owa/att_occsearch.getOccModellen_xml?p_merk=' + document.forms[0].f_merk.value + 
                                                        '&p_brandstof=' + document.forms[0].f_brandstof.value + 
                                                        '&p_soort_voertuig=' + document.forms[0].f_categorie_2.value;
    xmlhttpHandler2(url,'reload');
  }
}

// PMa, zoeken is aangepast. Ajax om model te bepalen
function ajaxCheckModelUitgebreid()
{

  if ( document.forms[0].f_merk.value != "")
  {
    var url = '';
   url = '/owa_dima/owa/att_occsearch.getOccModellen_xml?p_merk='+document.forms[0].f_merk.value+
                                                        '&p_brandstof='+document.forms[0].f_brandstof.value+
                                                        '&p_soort_voertuig='+document.forms[0].f_categorie_2.value+
                                                        '&p_bak='+document.forms[0].f_bak.value+
                                                        '&p_kleur='+document.forms[0].f_kleuren.value+
                                                        '&p_deur='+document.forms[0].f_deur.value+
                                                        '&p_categorie='+document.forms[0].f_categorie.value;
    xmlhttpHandler2(url,'reload');
  }
}

// PMa, zoeken is aangepast. Ajax om model te bepalen
function ajaxCheckModelNav()
{

  if ( document.forms[0].f_merk.value != "")
  {
    var url = '';
    url = '/owa_dima/owa/att_nav_search.getPopList_xml?p_soort_poplist=MERK'+
                                                     '&p_merk='+document.occasion.f_merk.value+
                                                     '&p_model='+document.occasion.f_model.value+
                                                     '&p_brandstof='+document.occasion.n_brandstof.value+
                                                     '&p_transmissie='+document.occasion.n_transmissie.value+
                                                     '&p_carrosserie='+document.occasion.n_carros.value+
                                                     '&p_deuren='+document.occasion.n_deur.value+
                                                     '&p_kleur='+document.occasion.n_kleur.value+
                                                     '&p_soort_auto='+document.occasion.n_soort.value;

    xmlhttpHandler2(url, 'MERK');
  }
}


// PMa, zoeken is aangepast. Ajax om model te bepalen
// Patrick Schreibing; 28-03-2008
function ajaxCheckModelFormNav()
{
  if ( document.forms[0].f_merk.value != "")
  {
    var url = '';
    url = '/owa_dima/owa/att_nav_search.getPopList_xml?p_soort_poplist=MERK'+
                                                     '&p_merk='+document.formnav.f_merk.value+
                                                     '&p_model='+document.formnav.f_model.value+
                                                     '&p_brandstof='+document.formnav.n_brandstof.value+
                                                     '&p_transmissie='+document.formnav.n_transmissie.value+
                                                     '&p_carrosserie='+document.formnav.n_carros.value+
                                                     '&p_deuren='+document.formnav.n_deur.value+
                                                     '&p_kleur='+document.formnav.n_kleur.value+
                                                     '&p_soort_auto='+document.formnav.n_soort.value;

    xmlhttpHandler2(url, 'MERK');
  }
}


// Selecteer een default merk voor in de zoeklijst
// Patrick Schreibing; 18-12-2007
//
function setDefaultMerk(def_merk) {
   var x=document.getElementById("f_merk");
   for (i=0;i<x.length;i++)
   {
      if (x.options[i].value==def_merk)
      {
         x.selectedIndex=i;
      }
   }
}

// Open een Helpscherm dat sizable is
// Patrick Schreibing; 8-1-2008
//
function openHelpSizable(Help, x, y)
{
    newwindow = window.open(Help, "helpwindow","scrollbars=no,resizable=no,width=" + x + ",height=" + y + ",left=200,top=200");
}

function setVestiging(cijfers) {
    document.occasion.f_pc_cijfers.value = cijfers;
    document.occasion.f_straal_postc.value = "1";
}

function checkVestiging() {
    document.occasion.f_pc_cijfers.value = document.occasion.f_vestiging.value;
    document.occasion.f_straal_postc.value = "1";
}

function checkVestiging2() {
	document.occasion.f_pc_cijfers.value = document.occasion.f_vestiging.value;
	document.occasion.f_straal_postc.value = "4";
 }

function verstop_postc_sort() {
 for (i = 0; i < document.occasion.f_sorteren.length; i++) {
   if (document.occasion.f_sorteren[i].value == "A") {
       document.occasion.f_sorteren.remove(i);
   }
 }
}
function resizePartnerFrame(newHeight) {
 var partnerFrame = document.getElementById('main_frame');
 var charHeight = newHeight +"";
 if (charHeight.indexOf('px')>0){
 charHeight = charHeight.substr(1,charHeight.indexOf('px'));
 }
 partnerFrame.height = parseInt(charHeight) + 50;
 //partnerFrame.width = newWidth;
}
function resizePartnerFrame2(newHeight) {
 var partnerFrame = document.getElementById('main_frame');
 var charHeight = newHeight +"";
 if (charHeight.indexOf('px')>0){
 charHeight = charHeight.substr(1,charHeight.indexOf('px'));
 }
 partnerFrame.height = parseInt(charHeight) + 100;
 //partnerFrame.width = newWidth;
}

