var KeuzeId = new Array ();
var KeuzeDesc = new Array ();
var ProductId = new Array ();
var ProductDesc = new Array ();
var ProductModuleListId = new Array();
var ModuleListId = new Array();
var ModuleListDesc = new Array();
var ProductVersieListId = new Array();
var VersieListId = new Array();
var VersieListDesc = new Array();

/**************************************************************************************************/
/*									KEUZE SELECT												  */
/**************************************************************************************************/

function checkChoice ()
{
	var MyBool = (document.frmSearch.cg [document.frmSearch.cg.selectedIndex].value == 17)

	document.frmSearch.pm.disabled = MyBool;
	document.frmSearch.pg.disabled = MyBool;
	document.frmSearch.Versie.disabled = MyBool;
}

/**************************************************************************************************/
/*									PRODUCT SELECT												  */
/**************************************************************************************************/

function loadProduct ()
{
	for (var i = 0; i < ProductId.length; i++)
	{
		//fillProduct (ProductId [i]);
		var id = ProductId [i];
		for (var j = 1; j < ProductId.length; j++)
			if (id == ProductId[j])
			{
				// addProductItem (i);
				var strTempDesc = new String ();
				strTempDesc = ProductDesc [j];
				var optie = new Option ();
				var length = document.frmSearch.pg.options.length;
				optie.value = ProductId [j];
				optie.text = strTempDesc;
				document.frmSearch.pg.options[length] = optie;
				//end addProductItem (i);
			}
		if (ProductId.length == 1)
			document.frmSearch.pg.selectedIndex = 1;
		//end fillProduct (ProductId [i]);
	}
}

//Functie die producten toevoegt
function addProduct (arrCnt, id, desc)
{
	ProductId [arrCnt] = id;
	ProductDesc [arrCnt] = desc;
}


/**************************************************************************************************/
/*									MODULE SELECT												  */
/**************************************************************************************************/

// Functie die een module toevoegt
function addProductModule (lngcnt, strProductID, strModuleID, strModuleDesc)
{
	ProductModuleListId [lngcnt] = strProductID;
	ModuleListId [lngcnt] = strModuleID;
	ModuleListDesc [lngcnt] = strModuleDesc;
}

function addProductVersie (lngcnt, strProductID, strVersieID, strVersieDesc)
{
	ProductVersieListId [lngcnt] = strProductID;
  VersieListId [lngcnt] = strVersieID;
  VersieListDesc [lngcnt] = strVersieDesc;
}

function addProductModuleItem (i)
{
	var opt=new Option ();
	if ( i >= 0 ) {
  	opt.value = ModuleListId [i];
	  opt.text = ModuleListDesc [i];
	} else {
	  opt.value = -1;
	  opt.text = "Alle modules";
	}
	document.frmSearch.pm.options [ document.frmSearch.pm.options.length ] = opt;
}

function fillProductModules (productid, AllOption)
{
	for (var i = document.frmSearch.pm.length; i > 0; i--)
		document.frmSearch.pm.options [i - 1] = null;

	document.frmSearch.pm.selectedIndex = 0;
  
  if ( AllOption )
    addProductModuleItem( -1 );
  
	for (var i =0; i < ProductModuleListId.length; i++)
		if (productid == ProductModuleListId [i])
		{
			addProductModuleItem (i);
		}
		if (ProductModuleListId.length == 1)
			document.frmSearch.pm.selectedIndex = 1;
}

function addProductVersieItem (i)
{
  var opt=new Option ();
	if ( i >= 0 ) {
	  opt.value = VersieListId [i];
	  opt.text = VersieListDesc [i];
	} else {
	  opt.value = -1;
	  opt.text = "Alle versies";
	}
  document.frmSearch.pv.options [document.frmSearch.pv.options.length] = opt;
}

function fillProductVersies (productid, AllOption)
{
	for (var i = document.frmSearch.pv.length; i > 0; i--)
		document.frmSearch.pv.options [i - 1] = null;

	document.frmSearch.pv.selectedIndex = 0;
  
  if ( AllOption )
    addProductVersieItem( -1 );
    
	for (var i =0; i < ProductVersieListId.length; i++)
		if (productid == ProductVersieListId [i])
		{
			addProductVersieItem (i);
		}
		if (ProductVersieListId.length == 1)
			document.frmSearch.pv.selectedIndex = 1;
}



//  add/replace url param

function insertParam(key, value) 
{ 
    key = escape(key); value = escape(value); 
 
    var kvp = document.location.search.substr(1).split('&'); 
 
    var i=kvp.length; var x; while(i--)  
    { 
        x = kvp[i].split('='); 
 
        if (x[0]==key) 
        { 
                x[1] = value; 
                kvp[i] = x.join('='); 
                break; 
        } 
    } 
 
    if(i<0) {kvp[kvp.length] = [key,value].join('=');} 
 
    //this will reload the page, it's likely better to store this until finished 
    document.location.search = kvp.join('&');  
} 
 
// change to other support form, based on categorie selected from dropdown
function ChangeForm()
{
	var currentpage;
	currentpage = document.frmSearch.supporttype [document.frmSearch.supporttype.selectedIndex].value;
	insertParam('SPID',currentpage);
}

function getProductDetails( AllOption )
{
	var productid;
	productid = document.frmSearch.pg [document.frmSearch.pg.selectedIndex].value
	if (document.frmSearch.pm != null) fillProductModules (productid, AllOption);
	if (document.frmSearch.pv != null) fillProductVersies (productid, AllOption);
}

/**************************************************************************************************/
/*									SUBMIT FUNCTIONS											  */
/**************************************************************************************************/

function addCurrMVToPgPm()
{
	var opt=new Option ();
	 
	if (document.frmSearch.pm.options.length>0)
	{
	  opt.value = document.frmSearch.pg [document.frmSearch.pg.selectedIndex].value;
	  opt.value = opt.value+'/'+document.frmSearch.pm [document.frmSearch.pm.selectedIndex].value;
	  opt.value = opt.value+'/'+document.frmSearch.pv [document.frmSearch.pv.selectedIndex].value;

	  opt.text = document.frmSearch.pg [document.frmSearch.pg.selectedIndex].text;
	  opt.text = opt.text+' ('+document.frmSearch.pv [document.frmSearch.pv.selectedIndex].text+')';
	  opt.text = opt.text+', '+document.frmSearch.pm [document.frmSearch.pm.selectedIndex].text;
	  
  	var found = false;
	  for (var i = document.frmSearch.pgpmShow.length; i > 0; i--)
	  	if (document.frmSearch.pgpmShow.options [i - 1].value == opt.value)
	  	  found = true;
	    
	  if (!found)
	    document.frmSearch.pgpmShow.options [document.frmSearch.pgpmShow.options.length] = opt;
	  else
	    alert(opt.text+' is al aanwezig...');
	}
	opt = null;
}

function delCurrPgPm()
{
  if (document.frmSearch.pgpmShow.selectedIndex >= 0)
	  document.frmSearch.pgpmShow.options [document.frmSearch.pgpmShow.selectedIndex] = null;
}

function selectpmvbyrow()
{
  if (document.frmSearch.pgpmShow.selectedIndex >= 0)
  {
	  var spl,p,m,v,i,s
	  s = document.frmSearch.pgpmShow.options [document.frmSearch.pgpmShow.selectedIndex].value
	  spl = s.split("/");
    for (i = 0; i < document.frmSearch.pg.length; i++)
      if (document.frmSearch.pg.options[i].value == spl[0])
        document.frmSearch.pg.options[i].selected = true;
    
    getProductDetails();
    
    for (i = 0; i < document.frmSearch.pm.length; i++)
      if (document.frmSearch.pm.options[i].value == spl[1])
        document.frmSearch.pm.options[i].selected = true;

    for (i = 0; i < document.frmSearch.pv.length; i++)
      if (document.frmSearch.pv.options[i].value == spl[2])
        document.frmSearch.pv.options[i].selected = true;
        
	}
}

// Functie die ervoor zorgt dat er ge-submit word als je op <ENTER> drukt
function what_key (event)
{
	if (event.keyCode == 13) submitSearch ();
}

// De functie die de submit verzorgt
function submitSearch ()
{
	document.frmSearch.Product.value = document.frmSearch.pg [document.frmSearch.pg.selectedIndex].text; 
	document.frmSearch.Module.value = document.frmSearch.pm [document.frmSearch.pm.selectedIndex].text;
	document.frmSearch.Keyword.value = escape(document.frmSearch.Keyword.value);
	
	document.frmSearch.method = "Post";
	document.frmSearch.action = "";
	document.frmSearch.submit ();
}

function addAttachment (id)
{
  window.open('include/support/_addAttachment.asp?sid='+id, '_new', 'menubar=0,resizable=0,width=450,height=538');
}

function Clear(what, check)
{
  if (what.value == check) what.value = "";
}

function submitAccountAanvraagForm()
{
	if ( document.frmSearch.Contactpersoon.value == "" ) {
		alert ("Geen Contactpersoon ingevoerd!")
		document.frmSearch.Contactpersoon.focus ();
		return
	}

	if ( document.frmSearch.Bedrijfsnaam.value == "" ) {
		alert ("Geen Bedrijfsnaam ingevoerd!")
		document.frmSearch.Bedrijfsnaam.focus ();
		return
	}

	if ( document.frmSearch.Adres.value == "" ) {
		alert ("Geen Adres ingevoerd!")
		document.frmSearch.Adres.focus ();
		return
	}

	if ( document.frmSearch.Postcode.value == "" ) {
		alert ("Geen Postcode ingevoerd!")
		document.frmSearch.Postcode.focus ();
		return
	}

	if ( document.frmSearch.Plaats.value == "" ) {
		alert ("Geen Plaats ingevoerd!")
		document.frmSearch.Plaats.focus ();
		return
	}

	if ( document.frmSearch.Email_Bedrijf.value == "" ) {
		alert ("Geen Email ingevoerd!")
		document.frmSearch.Email_Bedrijf.focus ();
		return
	}
  
	document.frmSearch.action = "mailform/mailform.asp";
	document.frmSearch.target = "supportmain";
	document.frmSearch.method = "Post";
	document.frmSearch.content= "text/html; charset=iso-8859-1";
	document.frmSearch.submit();
}

// De functie die alle velden valideert en de submit verzorgt
function submitSuppAssForm()
{
	if ( document.frmSearch.Beschrijving.value == "" )
	{
		alert ("Geen beschrijving ingevoerd!")
		document.frmSearch.Beschrijving.focus ();
		return
	}
	
	var email = document.frmSearch.Emailadres.value
  //Controleer of er een @ en een . in voorkomen en of de lengte groter is dan 5

  if (!( 
    email.indexOf("@") > 0 && 
    email.lastIndexOf(".") > 2 && 
    email.length > 5 && 
    email.lastIndexOf(";") < 0 ))
	{
		alert ("Geen (geldig) e-mail adres ingevoerd!")
		document.frmSearch.Emailadres.focus ();
		return
	} 
	
	if ( document.frmSearch.Contactpersoon.value == "" )
	{
		alert ("Geen contactpersoon ingevoerd!")
		document.frmSearch.Contactpersoon.focus ();
		return
	}
	
	document.frmSearch.Product.value = document.frmSearch.pg [document.frmSearch.pg.selectedIndex].text;
	document.frmSearch.Module.value = document.frmSearch.pm [document.frmSearch.pm.selectedIndex].text;
	document.frmSearch.Versie.value = document.frmSearch.pv [document.frmSearch.pv.selectedIndex].text;

	//Hier worden de waarden van de melding aan de mail toegevoegd
	
	document.frmSearch.body.value += "<br>From: [" + document.frmSearch.from.value + "]<br>";
	document.frmSearch.body.value += "Cc: [" + document.frmSearch.Emailadres.value + "]<br><br>";
	document.frmSearch.body.value += "Product: " + document.frmSearch.Product.value + "<br>";
	document.frmSearch.body.value += "Module: " + document.frmSearch.Module.value + "<br>";
	document.frmSearch.body.value += "Versie: " + document.frmSearch.Versie.value + "<br>";
	document.frmSearch.body.value += "Onderwerp: " + document.frmSearch.Onderwerp.value + "<br>";
	document.frmSearch.body.value += "Beschrijving: " + document.frmSearch.Beschrijving.value + "<br>";
	if (document.getElementsByName("Norm").length == 1) 
	  if (document.frmSearch.body.value == "Bijvoorbeeld: NEN1010 pag 43") 
  	  document.frmSearch.body.value += "Norm: " + document.frmSearch.Norm.value + "<br>";
  	else
  	  document.frmSearch.body.value += "Norm: <br>";
	document.frmSearch.body.value += "Inlognr/Debnr: " + document.frmSearch.Inlognummer.value + "<br>";
	document.frmSearch.body.value += "Contactpersoon: " + document.frmSearch.Contactpersoon.value + "<br>";
	document.frmSearch.body.value += "TelefoonNr: " + document.frmSearch.Telefoonnummer.value + "<br>";
	document.frmSearch.body.value += "LET OP: Eventueel bijlagen."
	
	document.frmSearch.cc.value = document.frmSearch.Emailadres.value;
	
	document.frmSearch.target = "supportmain";
	document.frmSearch.method = "Post";
	document.frmSearch.content= "text/html; charset=iso-8859-1";
	document.frmSearch.action = "";
	document.frmSearch.submit ();
}

function submitMailToFriend()
{
  var email = document.frmMailToFriend.to.value
  // Controleer of er een @ en een . en geen ; in voorkomen en of de lengte groter is dan 5
  if ( email.indexOf("@") > 0 && 
    email.lastIndexOf(".") > 2 && 
    email.lastIndexOf(";") < 0 && 
    email.length > 5)
  {
	  document.frmMailToFriend.method = "Post";
	  document.frmMailToFriend.action = "";
	  document.frmMailToFriend.submit();
	}
	else
	{
	  alert("Het email adres in het veld 'Aan' is niet juist!");
	  document.frmMailToFriend.to.Focus;
	}
}

function resetDownload()
{
  document.frmSearch.reset();
}

function submitSaveDownload()
{
  document.frmSearch.pg.options.length = 0;
  document.frmSearch.pm.options.length = 0;
  document.frmSearch.pv.options.length = 0;
  if (document.frmSearch.pgpmShow.length == 0) {
    document.frmSearch.pgpm.value = "";
  }
  else
  {
    var result = document.frmSearch.pgpmShow.options[0].value;
    for (var i = 1; i < document.frmSearch.pgpmShow.length; i++)
      result += ", "+document.frmSearch.pgpmShow.options[i].value;
    document.frmSearch.pgpm.value = result;
	}
  document.frmSearch.submit();
}

function submitSaveFaq()
{
  document.frmSearch.pg.options.length = 0;
  document.frmSearch.pm.options.length = 0;
  document.frmSearch.pv.options.length = 0;
  if (document.frmSearch.pgpmShow.length == 0) {
    document.frmSearch.pgpm.value = "";
  }
  else
  {
    var result = document.frmSearch.pgpmShow.options[0].value;
    for (var i = 1; i < document.frmSearch.pgpmShow.length; i++)
      result += ", "+document.frmSearch.pgpmShow.options[i].value;
    document.frmSearch.pgpm.value = result;
	}
  document.frmSearch.submit();
}
