// JavaScript Document

function nowYear() {
	// Output current year in YYYY format
    var now = new Date();

    function YYYYyear(number)	{
        return (number < 1000) ? number + 1900 : number;}

    thisyear =  (YYYYyear(now.getYear()));

    return thisyear;  }

function winPopup3(popurl)
    {
	var secPop = (("https:" == document.location.protocol) ?
"https://" : "http://");	
	var secPopurl = secPop + popurl;
	
    var newwindow;
	
	newwindow=window.open(secPopurl,'name','left=30, top=30, toolbar=no, location=yes, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=700, height=500');
	
	if (window.focus) {newwindow.focus()}
	}

function winPopup800(popurl)
    {
	var secPop = (("https:" == document.location.protocol) ?
"https://" : "http://");	
	var secPopurl = secPop + popurl;
	
    var newwindow;
	
	newwindow=window.open(secPopurl,'name','left=30, top=30, toolbar=no, location=yes, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=800, height=500');
	
	if (window.focus) {newwindow.focus()}
	}
	
function winPopup(popurl)
    {
    var newwindow;
	
	newwindow=window.open(popurl,'name','left=30, top=30, toolbar=no, location=yes, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=700, height=500');
	
	if (window.focus) {newwindow.focus()}
	}

function addToFavs()
   {
   if (document.all)
      {
      window.external.AddFavorite("http://www.Irish-Certificates.ie","Irish Certificates")
      }
   }
   
function CreateBookmarkLink() { 
    title = "Irish Certificates";
    // Blogger - Replace with <$BlogItemTitle$>   
	// MovableType - Replace with <$MTEntryTitle$> 
	url = "http://www.Irish-Certificates.ie/";  
	// Blogger - Replace with <$BlogItemPermalinkURL$>   
	// MovableType - Replace with <$MTEntryPermalink$>  
	// WordPress - <?php bloginfo('url'); ?>	
	
	if (window.sidebar) { 
	    // Mozilla Firefox Bookmark		
		window.sidebar.addPanel(title, url,"");	
		} 
	else if ( window.external ) { 
	    // IE Favorite		
		window.external.AddFavorite( url, title); 
		}	
	else if(window.opera && window.print) { 
	    // Opera Hotlist		
		return true; 
		} 
	} 
	

function removeRadioOpts(){
if(!document.getElementById("the_new")){return}//checks whether the element exists
var the_row = document.getElementById("the_new");
the_row.parentNode.removeChild(the_row);
}

function replaceNode(element){
    alert('Check for child nodes...' + element);
	//checks whether the element exists
	if(!document.getElementById(element)){return}

	//the element exists
    alert('Child nodes found...' + element);

    var el = document.getElementById(element);
	el.parentNode.removeChild(el);

    alert('Check for child nodes...' + element);
	//checks whether the element exists
	if(!document.getElementById(element)){return}

	//the element exists
    alert('Child nodes found...' + element);

    var el = document.getElementById(element);
	el.parentNode.removeChild(el);

    alert('Check for child nodes...' + element);
	//checks whether the element exists
	if(!document.getElementById(element)){return}

	//the element exists
    alert('Child nodes found...' + element);

    var el = document.getElementById(element);
	el.parentNode.removeChild(el);

    // var label=document.getElementById(element);	
    // while( label.hasChildNodes() ) { 
    //     alert('Removing child nodes...');
    //     label.removeChild( label.lastChild ); 
	// }
}

function removeNode() {
    // alert('Ready to remove nodes...');
    var holder = document.getElementById("radioGender");
	//the holder div. 
	while(holder.hasChildNodes()){
        // alert('Removing nodes...');
		holder.removeChild(holder.lastChild);
		}
}

function addNode() {
    // alert('Ready to add nodes...');
    var holder = document.getElementById("radioGender");
	//the holder div. 
	while(holder.hasChildNodes()){
        // alert('Removing nodes...');
		holder.removeChild(holder.lastChild);
		}
}

function checktheform(theForm) {
// alert('Checking form...');
	
if (Spry) { 
    // checks if Spry is used in your page
	// alert('Spry is on page...');

	var whatform = document.getElementById("formtype").value
	
    // validates the form Spry fields
    var retSpry = Spry.Widget.Form.validate(theForm);
	
    if (retSpry) {
		// Spry fields are validated
		
		// have to check the calendar field
		// different field name on different forms
		if ( whatform == "birth") {
			// =====================
			// = BIRTH             =
			// =====================
            // alert('Checking BIRTH form...');

            // check calendar field first
			if ((theForm.itemname4.value == null) ||
			   (theForm.itemname4.value == '')  ) {
				alert( "Childs date of birth is required." );
			    return false;
			} 
			
            // check calendar field first
			if ((theForm.itemname4.value.length < 11)  ||
			   (theForm.itemname4.value.length > 11)  ) {
				alert( "Childs date of birth must be in dd-mmm-yyyy format." );
			    return false;
			} 
			
			// calendar field appears to be valid as far as we can tell

			<!-- Childs Full Name -->
			// itemname2
			var tmpfld = theForm.itemname2.value;
			theForm.itemname2.value = "CHILD: " + tmpfld;
			// itemname3

			<!-- Childs Birth Date -->
			// itemname4
			var tmpfld = theForm.itemname4.value;
			theForm.itemname4.value = "DATE: " + tmpfld;

			<!-- Childs Birth Place -->
			// itemname5
			var tmpfld = theForm.itemname5.value;
			theForm.itemname5.value = "LOCATION: " + tmpfld;
			// itemname6

			// Fathers name
			// itemname7
			var tmpfld = theForm.itemname7.value;
			theForm.itemname7.value = "FATHER: " + tmpfld;
			// itemname8
  
			// Mothers name
			// itemname9
			var tmpfld = theForm.itemname9.value;
			theForm.itemname9.value = "MOTHER: " + tmpfld;
			// itemname10
			
			// alert("pause to look at fields");

            // =====================
			// =  END - BIRTH      =
			// =====================
		} else if ( whatform == "birth2") {
			// =====================
			// = BIRTH             =
			// =====================
            // alert('Checking BIRTH v2 form...');

			<!-- Childs Full Name -->
			// itemname2
			theForm.itemname2.value = "CHILD: " + theForm.childfirst.value + ", " + theForm.childlast.value;;

			<!-- Childs Birth Date -->
			// itemname3
			theForm.itemname3.value = "DATE: " + theForm.datedd.value + "-" + theForm.datemmm.value + "-" + theForm.dateyyyy.value;

			<!-- Childs Birth Place -->
			// itemname4
			if ((theForm.location.value == null) ||
			   (theForm.location.value == '')  ) {
			    theForm.itemname4.value = "LOCATION: " + "Co. " + theForm.countyname.value;
			} else {
    			theForm.itemname4.value = "LOCATION: " + theForm.location.value + ", Co. " + theForm.countyname.value;
			}
			
			// Fathers name
			// itemname5
			if (
				((theForm.fatherfirst.value == null) || (theForm.fatherfirst.value == ''))
				&&
				((theForm.fatherlast.value == null) || (theForm.fatherlast.value == ''))
				) {
			    theForm.itemname5.value = "FATHER: * not given *";
			} else if (
				((theForm.fatherfirst.value == null) || (theForm.fatherfirst.value == ''))
				) {
			    theForm.itemname5.value = "FATHER: ---, " + theForm.fatherlast.value;
			} else if (
				((theForm.fatherlast.value == null) || (theForm.fatherlast.value == ''))
				) {
			    theForm.itemname5.value = "FATHER: " + theForm.fatherfirst.value + ", ---";
			} else {
    			theForm.itemname5.value = "FATHER: " + theForm.fatherfirst.value + ", " + theForm.fatherlast.value;
			}
  
			// Mothers name
			// itemname6
			if (
				((theForm.motherfirst.value == null) || (theForm.motherfirst.value == ''))
				&&
				((theForm.motherlast.value == null) || (theForm.motherlast.value == ''))
				) {
			    theForm.itemname6.value = "MOTHER: * not given *";
			} else if (
				((theForm.motherfirst.value == null) || (theForm.motherfirst.value == ''))
				) {
			    theForm.itemname6.value = "MOTHER: ---, " + theForm.motherlast.value;
			} else {
    			theForm.itemname6.value = "MOTHER: " + theForm.motherfirst.value + ", " + theForm.motherlast.value;
			}
			
			// alert("pause to look at fields");

            // =====================
			// =  END - BIRTH      =
			// =====================
		} else if ( whatform == "adoption") {
			// =====================
			// = ADOPTION          =
			// =====================
            // alert('Checking ADOPTION form...');

            // check calendar field first
			if ((theForm.itemname4.value == null) ||
			   (theForm.itemname4.value == '')  ) {
				alert( "Childs date of birth is required." );
			    return false;
			} 
			
            // check calendar field first
			if ((theForm.itemname4.value.length < 11)  ||
			   (theForm.itemname4.value.length > 11)  ) {
				alert( "Childs date of birth must be in dd-mmm-yyyy format." );
			    return false;
			} 
			
			// calendar field appears to be valid as far as we can tell

			<!-- Childs Full Name -->
			// itemname2
			var tmpfld = theForm.itemname2.value;
			theForm.itemname2.value = "CHILD: " + tmpfld;
			// itemname3

			<!-- Childs Birth Date -->
			// itemname4
			var tmpfld = theForm.itemname4.value;
			theForm.itemname4.value = "DATE: " + tmpfld;

			// Fathers name
			// itemname5
			var tmpfld = theForm.itemname5.value;
			theForm.itemname5.value = "FATHER: " + tmpfld;
			// itemname6
  
			// Mothers name
			// itemname7
			var tmpfld = theForm.itemname7.value;
			theForm.itemname7.value = "MOTHER: " + tmpfld;
			// itemname8
			
			// alert("pause to look at fields");

			// =====================
			// = END - ADOPTION    =
			// =====================
	    } else if ( whatform == "marriage" ) {
			// =====================
			// = MARRIAGE          =
			// =====================
				
            // alert('Checking MARRIAGE form...');
				
            // check calendar field first
			if ((theForm.itemname6.value == null) ||
			   (theForm.itemname6.value == '')  ) {
				alert( "Date of marriage is required." );
			    return false;
			} 
			
            // check calendar field first
			if ((theForm.itemname6.value.length < 11)  ||
			   (theForm.itemname6.value.length > 11)  ) {
				alert( "Date of marriage must be in dd-mmm-yyyy format." );
			    return false;
			} 
			
			// calendar field appears to be valid as far as we can tell

			<!-- Grooms Full Name -->
			// itemname2
			var tmpfld = theForm.itemname2.value;
			theForm.itemname2.value = "GROOM: " + tmpfld;
			// itemname3

			<!-- Brides Full Name -->
			// itemname4
			var tmpfld = theForm.itemname4.value;
			theForm.itemname4.value = "BRIDE: " + tmpfld;
			// itemname5


			<!-- Marriage Date -->
			// itemname6
			var tmpfld = theForm.itemname6.value;
			theForm.itemname6.value = "DATE: " + tmpfld;

			<!-- Location & County of Marriage -->
			// itemname7
			var tmpfld = theForm.itemname7.value;
			theForm.itemname7.value = "LOCATION: " + tmpfld;
			// itemname8
				
			// alert("pause to look at fields");

			// =====================
			// = END - MARRIAGE    =
			// =====================
	    } else if ( whatform == "marriage2" ) {
			// =====================
			// = MARRIAGE          =
			// =====================
				
            // alert('Checking MARRIAGE v2 form...');
				
			<!-- Grooms Full Name -->
			// itemname2
			theForm.itemname2.value = "GROOM: " + theForm.groomfirst.value + ", " + theForm.groomlast.value;

			<!-- Brides Full Name -->
			// itemname3
			theForm.itemname3.value = "BRIDE: " + theForm.bridefirst.value + ", " +  theForm.bridelast.value;

			<!-- Marriage Date -->
			// itemname4
			theForm.itemname4.value = "DATE: " + theForm.marrdd.value + "-" + theForm.marrmmm.value + "-" + theForm.marryyyy.value;

			<!-- Location & County of Marriage -->
			// itemname5
			if ((theForm.location.value == null) ||
			   (theForm.location.value == '')  ) {
			    theForm.itemname5.value = "LOCATION: " + "Co. " + theForm.countyname.value;
			} else {
    			theForm.itemname5.value = "LOCATION: " + theForm.location.value + ", Co. " + theForm.countyname.value;
			}
			
			// alert("pause to look at fields");

			// =====================
			// = END - MARRIAGE    =
			// =====================
        } else if ( whatform == "death" ) {
			// =====================
			// = DEATH             =
			// =====================
				
            // alert('Checking DEATH form...');
				
            // check calendar field first
			if ((theForm.itemname4.value == null) ||
			   (theForm.itemname4.value == '')  ) {
				alert( "Persons date of death is required." );
			    return false;
			} 
			
            // check calendar field first
			if ((theForm.itemname4.value.length < 11)  ||
			   (theForm.itemname4.value.length > 11)  ) {
				alert( "Persons date of death must be in dd-mmm-yyyy format." );
			    return false;
			} 
			
			// calendar field appears to be valid as far as we can tell

			<!-- Persons Full Name -->
			// itemname2
			var tmpfld = theForm.itemname2.value;
			theForm.itemname2.value = "NAME: " + tmpfld;
			// itemname3

			<!-- Persons Death Date -->
			// itemname4
			var tmpfld = theForm.itemname4.value;
			theForm.itemname4.value = "DATE: " + tmpfld;

			<!-- Persons Death Place -->
			// itemname5
			var tmpfld = theForm.itemname5.value;
			theForm.itemname5.value = "LOCATION: " + tmpfld;
			// itemname6

			<!-- Occupation at Death -->
			// itemname7
			var tmpfld = theForm.itemname7.value;
			theForm.itemname7.value = "OCCUPATION: " + tmpfld;

			<!-- Age at Death -->
			// itemname8
			var tmpfld = theForm.itemname8.value;
			theForm.itemname8.value = "AGE: " + tmpfld;

            <!-- Address at Death -->
			// itemname9
			var tmpfld = theForm.itemname9.value;
			theForm.itemname9.value = "ADDRESS: " + tmpfld;

			// =====================
			// =  END - DEATH      =
			// =====================
        } else if ( whatform == "death2" ) {
			// =====================
			// = DEATH             =
			// =====================
				
            // alert('Checking DEATH v2 form...');
				
			<!-- Persons Full Name -->
			// itemname2
			theForm.itemname2.value = "NAME: " + theForm.deceasedfirst.value + ", " + theForm.deceasedlast.value;

			<!-- Date of Death -->
			// itemname3
			theForm.itemname3.value = "DATE: " + theForm.datedd.value + "-" + theForm.datemmm.value + "-" + theForm.dateyyyy.value;

			<!-- Location & County of Death -->
			// itemname4
			if ((theForm.location.value == null) ||
			   (theForm.location.value == '')  ) {
			    theForm.itemname4.value = "LOCATION: Co. " + theForm.countyname.value;
			} else {
    			theForm.itemname4.value = "LOCATION: " + theForm.location.value + ", Co. " + theForm.countyname.value;
			}

			<!-- Occupation at Death -->
			// itemname5
			if ((theForm.occupation.value == null) ||
			   (theForm.occupation.value == '')  ) {
			    theForm.itemname5.value = "OCCUPATION: * not given *";
			} else {
    			theForm.itemname5.value = "OCCUPATION: " + theForm.occupation.value;
			}
			
			<!-- Age at Death -->
			// itemname6
			theForm.itemname6.value = "AGE: " + theForm.age.value;

            <!-- Address at Death -->
			// itemname7
			if ((theForm.homeaddress.value == null) ||
			   (theForm.homeaddress.value == '')  ) {
			    theForm.itemname7.value = "ADDRESS: * not given *";
			} else {
    			theForm.itemname7.value = "ADDRESS: " + theForm.homeaddress.value;
			}

			// =====================
			// =  END - DEATH      =
			// =====================
		} else if ( whatform == "birth-record") {
			// =====================
			// = BIRTH-RECORD      =
			// =====================
            // alert('Checking BIRTH RECORD form...');

			<!-- Childs Full Name -->
			// itemname2
			var tmpfld = theForm.itemname2.value;
			theForm.itemname2.value = "CHILD: " + tmpfld;
			// itemname3

			<!-- Mothers Maiden Name -->
			// itemname4
			var tmpfld = theForm.itemname4.value;
			theForm.itemname4.value = "MOTHER: " + tmpfld;

			<!-- Registration District -->
			// itemname5

			<!-- Registration Year -->
			// itemname6
  
			<!-- Registration Quarter -->
			// itemname7
			
			<!-- Registration Volume -->
			// itemname8
  
			<!-- Registration Page -->
			// itemname9
			var tmpfld = theForm.itemname9.value;
			theForm.itemname9.value = "PAGE: " + tmpfld;
  
			// alert("pause to look at fields");

            // ========================
			// =  END - BIRTH-RECORD  =
			// ========================
		} else if ( whatform == "marriage-record") {
			// =====================
			// = MARRIAGE-RECORD   =
			// =====================
            // alert('Checking MARRIAGE RECORD form...');

			<!-- Persons Full Name -->
			// itemname2
			var tmpfld = theForm.itemname2.value;
			theForm.itemname2.value = "NAME: " + tmpfld;
			// itemname3

			<!-- Registration District -->
			// itemname4

			<!-- Registration Year -->
			// itemname5
  
			<!-- Registration Quarter -->
			// itemname6
			
			<!-- Registration Volume -->
			// itemname7
  
			<!-- Registration Page -->
			// itemname8
			var tmpfld = theForm.itemname8.value;
			theForm.itemname8.value = "PAGE: " + tmpfld;
  
			// alert("pause to look at fields");

            // ===========================
			// =  END - MARRIAGE-RECORD  =
			// ===========================
		} else if ( whatform == "death-record") {
			// ==================
			// = DEATH-RECORD   =
			// ==================
            // alert('Checking DEATH RECORD form...');

			<!-- Persons Full Name -->
			// itemname2
			var tmpfld = theForm.itemname2.value;
			theForm.itemname2.value = "NAME: " + tmpfld;
			// itemname3

			<!-- Registration District -->
			// itemname4

			<!-- Registration Year -->
			// itemname5
  
			<!-- Registration Quarter -->
			// itemname6
			
			<!-- Registration Volume -->
			// itemname7
  
			<!-- Registration Page -->
			// itemname8
			var tmpfld = theForm.itemname8.value;
			theForm.itemname8.value = "PAGE: " + tmpfld;
  
			// alert("pause to look at fields");

            // ========================
			// =  END - DEATH-RECORD  =
			// ========================
		}
	    // Spry and calendarDate form fields are valid
		// one of the forms has been validated and processed
		// All fields are validated
		// release it for submitting
		return true;
	} else {
		// Spry validation failed or date validation failed
		return false;
	}}}
	   


function autoYear() {
  var time = new Date();
  var curr_year = time.getYear();
 
  if (curr_year < 1900) {
    curr_year = curr_year + 1900;
  }

  var past = 2005; /*change the year value to the years in the past you want to show */

  document.writeln ("<form><select><option value=\"\">Select Year");
  do {
    date++;
    document.write ("<option value=\"" +date+"\">" +date+ "");
  }
  while (date < future)
  document.write ("</select></form>");
}
