//------------------------------------
// Menu functies
//------------------------------------
function StartTab() {
	SelectMenuAndSubMenu('start','welkom');
}
//------------------------------------
function SearchTab() {
	SelectMenuAndSubMenu('zoeken','zoeken');
}
//------------------------------------
function PedigreeTab() {
	SelectMenuAndSubMenu('stamboom','stamboom');
}
//------------------------------------
function LitterTab() {
	SelectMenuAndSubMenu('nesten','nesten');
}
//------------------------------------
function StudTab() {
	SelectMenuAndSubMenu('dekreuen','dekreuen');
}
//------------------------------------
function ForSaleTab() {
	SelectMenuAndSubMenu('tekoop','tekoop');
}
//------------------------------------
function LoginTab() {
	SelectMenuAndSubMenu('login','login');
}
//------------------------------------
// Navigatie functies
//------------------------------------
function SelectMenu(menu) {
	SetCookie('SelectedMenuOption' , menu, 365);
	top.location.reload();
}
//------------------------------------
function SelectSubMenu(menu) {
	SetCookie('SelectedSubMenuOption' , menu, 365);
	top.location.reload();
}
//------------------------------------
function SelectMenuAndSubMenu(menuOption, subMenuOption) {
	SetCookie('SelectedMenuOption' , menuOption, 365);
	SetCookie('SelectedSubMenuOption' , subMenuOption, 365);
	top.location.reload();
}
//------------------------------------
function SetCookie(cookieName, cookieValue, nDays) { 
	var today = new Date(); 
	var expire = new Date(); 
	expire.setTime(today.getTime() + 3600000*24*nDays); 
	top.document.cookie = cookieName+"="+escape(cookieValue)+";expires="+expire.toGMTString()+";path=/;domain=bloedlijnen.nl;" ; 
}
//------------------------------------
function GetCookie(cookieName) {
	if (top.document.cookie.length > 0) {
		c_start = top.document.cookie.indexOf(cookieName + "=");
		if (c_start != -1) { 
			c_start = c_start + cookieName.length + 1;
			c_end   = top.document.cookie.indexOf(";", c_start);
			if (c_end == -1) {
				c_end = top.document.cookie.length;
			}
			return unescape(top.document.cookie.substring(c_start, c_end)).replaceAll("+", " ");
		}
	}
	return "";
}
//------------------------------------
function ClearCookie(cookieName) { 
	var today = new Date(); 
	var expire = new Date(); 
	expire.setTime(today.getTime() -1); 
	top.document.cookie = cookieName+"=;expires="+expire.toGMTString()+";path=/;domain=bloedlijnen.nl;" ; 
}
//------------------------------------
function doKeyPress () {
    var key = window.event.keyCode
    if (key == '13') { //return
        doSearch ()
    }
    return false;
}
//------------------------------------
// Presentatie functies
//------------------------------------
function Loading() {
	document.getElementById('loading').style.display = 'none';
	document.getElementById('results').style.display = 'inline';
}
//------------------------------------
function SetLanguage(language) {
	SetCookie('Language' , language, 365);
	top.location.reload();
}
//------------------------------------
// Start functies
//------------------------------------
function News() {
	SelectMenuAndSubMenu('start','nieuws');
}
function Contact() {
	SelectMenuAndSubMenu('start','contact');
}
function AboutUs() {
	SelectMenuAndSubMenu('start','overdesite');
}
//------------------------------------
// Zoeken functies
//------------------------------------
function MyDog() {
	SelectMenuAndSubMenu('zoeken','mijnhond');
}
//------------------------------------
function MyDogs() {
	SelectMenuAndSubMenu('zoeken','mijnhonden');
}
//------------------------------------
function History() {
	SelectMenuAndSubMenu('zoeken','geschiedenis');
}
//------------------------------------
function Last50() {
	SelectMenuAndSubMenu('zoeken','laatste50');
}
//------------------------------------
function Last50Modified() {
	SelectMenuAndSubMenu('zoeken','laatste50gewijzigd');
}
//------------------------------------
function Last50Videos() {
    SelectMenuAndSubMenu('zoeken','laatste10videos');
}

//------------------------------------
// Stamboom functies
//------------------------------------
function ShowPedigree (brn) {
	SetCookie('BRN' , brn, 365);
	SetCookie('SelectedSubMenuOption' , 'stamboom', 365);
    SelectMenuAndSubMenu('stamboom','stamboom');
}
//------------------------------------
function Descendants(option) {
	SetCookie('Nakomelingen' , option, 365);
    SelectMenuAndSubMenu('stamboom','nakomelingen');
}
//------------------------------------
function Partners(option) {
	SetCookie('Combinaties' , option, 365);
    SelectMenuAndSubMenu('stamboom','combinaties');
}
//------------------------------------
function Siblings() {
    SelectMenuAndSubMenu('stamboom','broerzus');
}
//------------------------------------
function SiblingPhotos() {
    SelectMenuAndSubMenu('stamboom','broerzusfotos');
}
//------------------------------------
function DogLitters() {
    SelectMenuAndSubMenu('stamboom','nesten');
}
//------------------------------------
function DogPhotos() {
    SelectMenuAndSubMenu('stamboom','fotos');
}
//------------------------------------
function DogVideos() {
    SelectMenuAndSubMenu('stamboom','videos');
}
//------------------------------------
function AddDog() {
	SetCookie('BRN' , 0, 365);
	ClearCookie('CopyDog');
	SelectMenuAndSubMenu('stamboom','wijzigen');
}
//------------------------------------
function ModifyDog() {
	ClearCookie('CopyDog');
	SelectMenuAndSubMenu('stamboom','wijzigen');
}
//------------------------------------
function DeleteDog() {
	SelectMenuAndSubMenu('stamboom','verwijderen');
}
//------------------------------------
function PayedStud() {
    SelectMenuAndSubMenu('stamboom','betaald');
}
//------------------------------------
function AddPuppy() {
	SelectMenuAndSubMenu('stamboom', 'puptoevoegen');
}
//------------------------------------
function CopyDog() {
	SetCookie('CopyDog' , '1', 365);
    SelectMenuAndSubMenu('stamboom','wijzigen');
}
//------------------------------------
function UploadStandFoto () {
    SelectMenuAndSubMenu('stamboom','standfotoupload');
}
//------------------------------------
function PrintPedigree () {
    SelectMenuAndSubMenu('stamboom','pdfstamboom');
}
//------------------------------------
function UploadFoto () {
	SetCookie('SelectedSubMenuOption' , 'fotoupload', 365);
	top.location.reload();
}
//------------------------------------
function DeleteDogPicture(foto) {
    msg = "Deze foto verwijderen?";
    if (GetCookie('Language') == 'en') {
        msg = "Delete this picture?";
    } else if (GetCookie('LANGUAGE') == 'du') {
        msg = "Dieses Bild löschen?";
    }

    result = confirm(msg);
    if (result) {
        if (!foto) {
            SelectMenuAndSubMenu('stamboom','standfotoverwijderen');
        } else {
            SetCookie('DeletePicture' , foto, .01);
            SelectMenuAndSubMenu('stamboom','fotoverwijderen');            
        }
    }
}
//------------------------------------
function UploadVideo () {
	SetCookie('SelectedSubMenuOption' , 'videoupload', 365);
	top.location.reload();
}
//------------------------------------
function DeleteDogVideo(video) {
    msg = "Deze video verwijderen?";
    if (GetCookie('Language') == 'en') {
        msg = "Delete this video?";
    } else if (GetCookie('LANGUAGE') == 'du') {
        msg = "Dieses Video löschen?";
    }

    result = confirm(msg);
    if (result) {
        SetCookie('DeleteVideo' , video, .01);
        SelectMenuAndSubMenu('stamboom','videoverwijderen');
    }
}
//------------------------------------
function DescendentsPhotos() {
    SelectMenuAndSubMenu('stamboom','nakomelingenfotos');
}
//------------------------------------
function DescendentsVideos() {
    SelectMenuAndSubMenu('stamboom','nakomelingenvideos');
}

//------------------------------------
// Nesten functies
//------------------------------------
function Litters (option) {
	/*
	SetCookie('SelectedBreed' , '%', 365);
	SetCookie('SelectedMale' , '%', 365);
	SetCookie('SelectedFemale' , '%', 365);
	*/

	SetCookie('Nesten' , option, 365);
	SetCookie('SelectedSubMenuOption' , 'nesten', 365);
	top.location.reload();
}
function NewestLitters () {
    SetCookie('SelectedSubMenuOption' , 'nieuwste10', 365);
    top.location.reload();
}
//------------------------------------
function UploadLitterPicture () {
	SetCookie('SelectedSubMenuOption' , 'fotoupload', 365);
	top.location.reload();
}
//------------------------------------
function DeleteLitterPicture() {
	msg = "Deze foto verwijderen?";
	if (GetCookie('Language') == 'en') {
		msg = "Delete this picture?";
	} else if (GetCookie('LANGUAGE') == 'du') {
		msg = "Dieses Bild löschen?";
	}

	result = confirm(msg);
	if (result) {
		SelectMenuAndSubMenu('nesten','fotoverwijderen');
	}
	top.location.reload();
}
//------------------------------------
function UploadLitterPictures () {
	SetCookie('SelectedSubMenuOption' , 'fotosupload', 365);
	top.location.reload();
}
//------------------------------------
function DeleteLitterPictures($picture) {
	msg = "Deze foto verwijderen?";
	if (GetCookie('Language') == 'en') {
		msg = "Delete this picture?";
	} else if (GetCookie('LANGUAGE') == 'du') {
		msg = "Dieses Bild löschen?";
	}

	result = confirm(msg);
	if (result) {
		SetCookie("DeletePicture", $picture);
		SelectMenuAndSubMenu('nesten','fotosverwijderen');
	}
//	top.location.reload();
}
//------------------------------------
function AddLitter() {
	SetCookie('BNN' , 0, 365);
	ClearCookie('CopyLitter');
	SelectMenuAndSubMenu('nesten','wijzigen');
}
//------------------------------------
function ModifyLitter() {
	ClearCookie('CopyLitter');
	SelectMenuAndSubMenu('nesten','wijzigen');
}
//------------------------------------
function DeleteLitter() {
    msg = "Dit nest verwijderen?";
    if (GetCookie('Language') == 'en') {
        msg = "Delete this litter?";
    } else if (GetCookie('LANGUAGE') == 'du') {
        msg = "Dieses Wurf löschen?";
    }

    result = confirm(msg);
    if (result) {
	    SelectMenuAndSubMenu('nesten','verwijderen');
    }
}
//------------------------------------
function CopyLitter() {
	SetCookie('CopyLitter' , 1, 365);
	SelectMenuAndSubMenu('nesten','wijzigen');
}
//------------------------------------
function ShowLitterPedigree (bnn) {
	SetCookie('BNN' , bnn, 365);
	SelectMenuAndSubMenu('nesten','stamboom');
}
//------------------------------------
function ShowExamplePedigree() {
	SelectMenuAndSubMenu('nesten','stamboomvoorbeeld');
}
//------------------------------------
function LitterPictures() {
    SelectMenuAndSubMenu('nesten','fotos');
}
//------------------------------------
function PayedLitter() {
    SelectMenuAndSubMenu('nesten','betaald');
}
//------------------------------------
function SoldLitter() {
    SelectMenuAndSubMenu('nesten','uitverkocht');
}
//------------------------------------
function UndoSoldLitter() {
    SelectMenuAndSubMenu('nesten','uitverkocht');
}
//------------------------------------
function LitterVideos() {
    SelectMenuAndSubMenu('nesten','videos');
}
//------------------------------------
function DeleteLitterVideo(video) {
    msg = "Deze video verwijderen?";
    if (GetCookie('Language') == 'en') {
        msg = "Delete this video?";
    } else if (GetCookie('LANGUAGE') == 'du') {
        msg = "Dieses Video löschen?";
    }

    result = confirm(msg);
    if (result) {
        SetCookie('DeleteVideo' , video, .01);
        SelectMenuAndSubMenu('nesten','videoverwijderen');
    }
}
//------------------------------------
function PrintLitter() {
    SelectMenuAndSubMenu('nesten','pdfstamboom');
}
//------------------------------------
function ClearLitterFilters() {
    ClearCookie("LitterFilter");
    ClearCookie("SelectedBreed");
    ClearCookie("SelectedMale");
    ClearCookie("SelectedFemale");
    top.location.reload();
}
//------------------------------------
// Gebruiker functies
//------------------------------------
function Users() {
	SelectMenuAndSubMenu('login','gebruikers');
}
//------------------------------------
function LockedUsers() {
	SelectMenuAndSubMenu('login','deblokkeren');
}
//------------------------------------
function UnlockUser(id) {
	SetCookie('UnlockUser' , id, 365); 
	top.location.reload();
}
//------------------------------------
function ResetPassword(id) {
	SetCookie('ResetPassword' , id, 365); 
	SelectMenuAndSubMenu('login','resetwachtwoord');
}
//------------------------------------
function DeleteUser(id) {
	msg = "Deze gebruiker verwijderen?";
	if (GetCookie('Language') == 'en') {
		msg = "Delete this user?";
	} else if (GetCookie('LANGUAGE') == 'du') {
		msg = "Diese Benutzer löschen?";
	}

	result = confirm(msg);
	if (result) {
		SetCookie('DeleteUser' , id, 365); 
		SelectMenuAndSubMenu('login','delete');
	}
}

//------------------------------------
// Dekreuen functies
//------------------------------------
function Dekreuen (option) {
	SetCookie('DekreuRas' , '%', 365);
	SetCookie('Dekreuen' , option, 365);
	SetCookie('SelectedSubMenuOption' , 'dekreuen', 365);
	top.location.reload();
}
//------------------------------------
function switchDekreu(value) {
	if (value == 0) {
		document.getElementById('dekreu').style.display = 'inline';
	} else {
		document.getElementById('dekreu').style.display = 'none';
	}
}
//------------------------------------
// Multi-purpose functies
//------------------------------------
function Advertising(option) {
	if (option == "litter") {
		SelectMenuAndSubMenu('nesten','adverteren');
	} else if (option == "stud") {
		SelectMenuAndSubMenu('dekreuen','adverteren');
	} else if (option == "forsale") {
		SelectMenuAndSubMenu('tekoop','adverteren');
	}
}
//------------------------------------
// TeKoop functies
//------------------------------------
function ForSale(option) {
	SetCookie('ForSaleOption' , option, 365);
	top.location.reload();
}
//------------------------------------
function ShowAd(value) {
	SetCookie('BSN' , value, 365);
	SelectMenuAndSubMenu('tekoop','artikel');
}
//------------------------------------
function AddAd() {
	ClearCookie('CopyAd');
	SelectMenuAndSubMenu('tekoop','wijzigen');
}
//------------------------------------
function CopyAd() {
	SetCookie('CopyAd' , '1', 365);
	SelectMenuAndSubMenu('tekoop','wijzigen');
}
//------------------------------------
function ModifyAd() {
	ClearCookie('CopyAd');
	SelectMenuAndSubMenu('tekoop','wijzigen');
}
//------------------------------------
function DeleteAd() {
	msg = "Deze advertentie verwijderen?";
	if (GetCookie('Language') == 'en') {
		msg = "Delete this add?";
	} else if (GetCookie('LANGUAGE') == 'du') {
		msg = "Diese Anzeige löschen?";
	}

	result = confirm(msg);
	if (result) {
		SelectMenuAndSubMenu('tekoop','verwijderen');
  	}
}
//------------------------------------
function SoldAd() {
	SelectMenuAndSubMenu('tekoop','uitverkocht');
}
//------------------------------------
function NotSoldAd() {
	SelectMenuAndSubMenu('tekoop','nietuitverkocht');
}
//------------------------------------
function UploadForSalePicture () {
	SetCookie('SelectedSubMenuOption' , 'fotoupload', 365);
	top.location.reload();
}
//------------------------------------
function DeleteForSalePicture() {
	msg = "Deze foto verwijderen?";
	if (GetCookie('Language') == 'en') {
		msg = "Delete this picture?";
	} else if (GetCookie('LANGUAGE') == 'du') {
		msg = "Dieses Bild löschen?";
	}

	result = confirm(msg);
	if (result) {
		SelectMenuAndSubMenu('tekoop','fotoverwijderen');
	}
	top.location.reload();
}
//------------------------------------
// Login functies
//------------------------------------
function Information() {
	SelectMenuAndSubMenu('login','logininfo');
}
//------------------------------------
function Register() {
	SelectMenuAndSubMenu('login','wijzigen');
}
//------------------------------------
function ModifyUser() {
	SelectMenuAndSubMenu('login','wijzigen');
}
//------------------------------------
function Logout() {
    SetCookie('Logout' , '1', 365);
	SelectMenuAndSubMenu('login','uitloggen');
}	
//------------------------------------
// Generic functies
//------------------------------------
function Content() {
	document.write ('<IFRAME id="content" height="' + (document.documentElement.clientHeight - 195) + 'px" width="100%" frameborder="0" src="/content.php"></IFRAME>');
}
//------------------------------------
function Save() {
	var browser   = navigator.appName;
	var b_version = navigator.appVersion;
	var version   = parseFloat(b_version);
	var iframe    = document.getElementById('content');
	var form;

	if(iframe == null) alert("iframe not found");
	
    if(iframe.contentDocument)			// Firefox, Opera  
       form = iframe.contentDocument;  
    else if(iframe.contentWindow)		// Internet Explorer  
       form = iframe.contentWindow.document;  
    else if(iframe.document)  		    // Others?  
       form = iframe.document;  
   
    if(form == null) alert("form not found");

	form.getElementById('submit').click();
}
//------------------------------------     
function Copyright() {
	document.getElementById('content').src = 'copyright.php'
}
//------------------------------------
function doSearch () {
	SetCookie('zoekstring', document.forms[0].zoekstring.value, 365);
	var loc = 'pages/zoeken/selecteren.php?store=true';
	self.frames.resultFrame.document.location = loc;
    return false;
}
//------------------------------------
function reSearch (zarg) {
	SetCookie('zoekstring', zarg, 365);
	SelectMenuAndSubMenu('zoeken','zoeken');
}
//-------------------------------------------------------------
function validDate (toCheck_) {
    var dag  = toCheck_.substring(0,2)-0 ;
    var mnd  = toCheck_.substring(3,5)-0 ;
    var jaar = toCheck_.substring(6,10)-0 ;
    var sep1 = toCheck_.substring(2,3) ;
    var sep2 = toCheck_.substring(5,6) ;
    var retrn = true ;
    
    if (dag < 1 || dag > 31) {
        retrn = false;
    }
    if (mnd < 1 || mnd > 12) {
        retrn = false;
    }
    if (jaar < 2001 || jaar > 2010) {
        retrn = false;
    }
    if (sep1 != "-") {
        retrn = false;
    }
    if (sep2 != "-") {
        retrn = false;
    }
    if (!retrn) {
        alert ("Datum in incorrect formaat. Veranderd dit svp! Bijvoorbeeld: 25-10-2002") ;
    }
	return retrn;
}
//------------------------------------------------------------- 
function emptyDate () {
	return '00-00-0000';
}

//------------------------------------------------------------- 
function uitverkochtDate () {
	var myDate = new Date;
	myDate.setDate(myDate.getDate()+13);
	return formatDate(myDate, "dd-MM-yyyy");
}

//------------------------------------------------------------- 
function CheckNumeric(e) {
   // Get ASCII value of key that user pressed
   e = e || window.event;
   var key = e.keyCode || e.which;

   // Was key that was pressed a numeric character (0-9)?
   if ((key > 47 && key < 58) || key == 46) {
      return; // if so, do nothing
   } else {
      window.event.returnValue = null; // otherwise, discard character
   }
}

//------------------------------------------------------------- 
function dekreuDate () {
	var myDate = new Date;
	myDate.setYear(myDate.getYear()+1);
	return formatDate(myDate, "dd-MM-yyyy");
}

//------------------------------------------------------------- 
function nestDate (toCheck_) {
    var dag  = toCheck_.substring(0,2)-0 ;
    var mnd  = toCheck_.substring(3,5)-0 ;
    var jaar = toCheck_.substring(6,10)-0 ;
	var myDate = new Date();
	
	myDate.setDate(dag);
	myDate.setMonth(mnd-1);
	myDate.setYear(jaar);
	myDate.setDate(myDate.getDate()+63);
	return formatDate(myDate, "dd-MM-yyyy");
}

//------------------------ 
function displayDate (gebDate_, displayDate_) { 
	var retrn = false ; 
	if (top.validDate(displayDate_)) { 
	    var gebTest = gebDate_.substring(6,10) + gebDate_.substring(3,5) + gebDate_.substring(0,2) ;
		var disTest = displayDate_.substring(6,10) + displayDate_.substring(3,5) + displayDate_.substring(0,2) ;

		if (disTest > gebTest) { 
			retrn = true; 
        } 
    } 
    if (!retrn) {
        alert ("De display datum is eerder dan de geboorte datum. Kijk dit na s.v.p.!") ;
    }
	return retrn;
}
//------------------------ 
function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}
//------------------------------------
// Replaces all instances of the given substring.
String.prototype.replaceAll = function(
	strTarget, // The substring you want to replace
	strSubString // The string you want to replace in.
) {
	var strText = this;
	var intIndexOfMatch = strText.indexOf( strTarget );
	 

	// Keep looping while an instance of the target string
	// still exists in the string.
	while (intIndexOfMatch != -1) {
		// Relace out the current instance.
		strText = strText.replace( strTarget, strSubString )

		// Get the index of any next matching substring.
		intIndexOfMatch = strText.indexOf( strTarget );
	}
 
	// Return the updated string with ALL the target strings
	// replaced out with the new substring.
	return( strText );
}

