if (document.getElementById && document.createElement && document.createTextNode && document.getElementsByTagName) {

var vetgen = {

	// reference to the div holding the layout
	container : document.getElementById('container'),
	
	//reference to the body tag
	body : document.getElementsByTagName('body')[0],
	
	init : function() {
		
		// metaprogramming to rewrite event and XHR handling
		this.util.configEvents();
		this.util.configXHR();

		this.fontSize.setup	();	//inserts the images that will be used for resizing the text on the screen
		this.clock.updateClock(); // sets the copyright year for VetGen on bottom of pages as the current year
		this.scripts.insertJavascripts(); //Inserts the JavaScripts that are needed for the page.
		this.retrieveStoredSettings(); //retrieves any stored settings via cookies
		this.faq.setup();//runs the setup for the FAQ page
		this.tables.setup();//runs the setup to find the table on the page with the class name 'coatColorTable';
		this.allBreeds.setup();//runs the setup to find the AllBreeds page
		this.specials.setup(); // runs the setup to make sure you are on the Specials page
		
		// add the buttons for creating students and grade items, as well as the fields for that data
		//this.help.setupLightBoxContent();
		
		this.util.addEvent(this.fontSize.fontDiv, 'click', this.fontSize.resize, false);//sets an event listener for the resizing of the fontsize
		this.util.addEvent(this.body, 'click', this.faq.showHide,false);//sets an event listener for the showing & hiding all of the FAQ answers
		this.util.addEvent(this.body, 'click', this.faq.displayAnswer,false);//sets an event listener for display an answer on the FAQ Page
		this.util.addEvent(this.body, 'click', this.help.displayHelp,false);//sets an event listener for displaying a lightbox with the Ordering Instructions information on certain pages
		this.util.addEvent(this.body, 'click', this.help.printDiv,false);//sets an event listener for printing out the just current div of information
		
		// assign listener to helpLink
		//this.util.addEvent(this.help.helpLink, 'click', this.help.showLightBox, false);
		
		    // assign listener to lightbox divs
		//this.util.addEvent(this.help.lightBoxDiv, 'click', this.help.closeLightBox, false);
	
			
	},
	//Help for Ordering steps, creates a lightbox with the step by step instructions on it.
	help : {
			
		// layer behind lightbox
		boxBg : document.createElement('div'),
		
		// tabindex value for use in lightboxes
		tabNum : 100,

		// timer for fading in    
		timer : null,
		
		// counter for degree of opacity
		fadeCounter : 0,
		
		
		setupLightBoxContent : function() {
		
			var helpLink = document.getElementById('help');
			
			if(!helpLink){return};
			
			vetgen.help.helpLink = helpLink;

			//Set up a link to close the light box
			var delAnchor = document.createElement('a');
			delAnchor.href = '#';
			var xImg = vetgen.util.generateImg();
			xImg.alt = xImg.title = 'Close';
			delAnchor.appendChild(xImg);
			
			//set up a lightbox div
			vetgen.help.lightBoxDiv = document.createElement('div');
			vetgen.help.lightBoxDiv.id = 'printMe';
			vetgen.help.lightBoxDiv.className = 'lightBox hideBox';
			
			vetgen.help.boxBg.id = 'bgLayer';
			vetgen.help.boxBg.className = 'rem';
				
			//set up a link to print the contents of the lightbox
			var printAnchor = document.createElement('a');
				printAnchor.href = '#'
				printAnchor.className = 'printMe';
			var printAnchorText = document.createTextNode('Print Instructions');
				printAnchor.appendChild(printAnchorText);
				
			//set up the header info
			var hdr = document.createElement('h2');        
			hdr.appendChild(document.createTextNode('How to place a secure order online (Canine Only)'));

			//set up the ol for the ordering steps
			var orderOL = document.createElement('ol');
				orderOL.id = "orderSteps";
			
			//current amount of steps
			var steps = 12;
			
			//creates an empty string for the li text
			var string = '';
			
			//create the li steps and append to OL
			for(var i =1; i<=steps; i++){
				
				var li = document.createElement('li');
				
				
				switch(i){
				
					case 1 :	string = 'Click on "Place a secure order ONLINE for Canine now" link at bottom of list.';
					
					case 2 :	string = 'Select and click on your breed to open a Breed Specific shopping cart.';
					
					case 3 :	string = 'Select one test at a time to add to your shopping cart.';
								
					case 4 :	string = 'Identify dog by clicking on "Animal #1" for a single dog. '

					case 5 :	string = 'Repeat to add more tests for "Animal #1".';
					
					case 6 :	string = 'Select tests and repeat for additional dogs, "Animal #2", "Animal #3", etc. ';
					
					case 7 :	string = 'When shopping is complete, click on CHECKOUT icon.';
					
					case 8 :	string = 'Review cart items and then click on CONTINUE button.';
					
					case 9 :	string = 'Provide CUSTOMER INFORMATION and SHIP-TO INFORMATION and then click on CONTINUE.';
					
					case 10 :	string = 'Select SHIPPING METHOD and review ORDER SUMMARY and then click on CONTINUE.';
					
					case 11 :	string = 'Provide PAYMENT INFORMATION for VISA or MASTERCARD and then click on CONTINUE.';
					
					case 12 :	string = 'Print your completed order and exit.';
				}
				
					var liText = document.createTextNode(string);
					
					li.appendChild(liText);
					
					orderOL.appendChild(li);		
				
			}
			
			//create p tag with the more information about test text
			var moreInfoP = document.createElement('p');
			var strongInfo = document.createElement('strong');
			var moreInfoText = document.createTextNode('*Click on test name for more information. Hit GO BACK button to return to shopping cart. ');
			strongInfo.appendChild(moreInfoText);
			moreInfoP.appendChild(strongInfo);
			
			//create header for DNA Sampling Kit
			var dnaHdr = document.createElement('h3');
			var dnaText = document.createTextNode('A DNA sampling kit will arrive shortly from VetGen');
			dnaHdr.appendChild(dnaText);
			
			var dnaP1 = document.createElement('p');
			var dnaP1Text = document.createTextNode('Once your order is complete, you will receive a pre-paid testing kit from VetGen that may be used at any time. It will not expire. Your DNA sampling kit contains 3 bar-coded cytology (cheek) swabs for each dog in your order, sampling instructions and an Order Submission form.');
			dnaP1.appendChild(dnaP1Text);
			
			var dnaP2 = document.createElement('p');
			var dnaP2Text = document.createTextNode('When you are ready to test, swab your dog according to the instructions provided, complete all available information on the order forms and swab cases and return to VetGen in the envelope provided.');
			dnaP2.appendChild(dnaP2Text);
			
			vetgen.help.lightBoxDiv.appendChild(delAnchor);
			//vetgen.help.lightBoxDiv.appendChild(printAnchor);
			vetgen.help.lightBoxDiv.appendChild(hdr);
			vetgen.help.lightBoxDiv.appendChild(orderOL);
			vetgen.help.lightBoxDiv.appendChild(moreInfoP);
			vetgen.help.lightBoxDiv.appendChild(dnaHdr);
			vetgen.help.lightBoxDiv.appendChild(dnaP1);
			vetgen.help.lightBoxDiv.appendChild(dnaP2);
			

			vetgen.body.appendChild(vetgen.help.lightBoxDiv);
			vetgen.body.appendChild(vetgen.help.boxBg);
							
		},
		
		showLightBox : function(evt) {
   		
			// display the black layer behind the lightbox
			vetgen.help.boxBg.className = '';

			vetgen.help.lightBoxDiv.className = 'lightBox op0';
			vetgen.help.timer = setInterval("vetgen.help.fadeIn()", 50);

		},
    
    fadeIn : function() {
    
      vetgen.help.fadeCounter += 1;
      
      vetgen.help.lightBoxDiv.className = 'lightBox op' + vetgen.help.fadeCounter;

      // once the full fade-in has happened clear the timer and reset the counter      
      if (vetgen.help.fadeCounter === 11) { 
      
        clearInterval(vetgen.help.timer); 
        vetgen.help.fadeCounter = 0;
      
      }
     
    },
    
    closeLightBox : function(evt) {
    
      var closeImg = vetgen.util.findTarget(evt, 'a', this);
      
      // make sure to only respond to clicks on the image
      if (closeImg) {
      
        // hide the lightbox
		vetgen.help.lightBoxDiv.className = 'lightBox hideBox';
        
        // hide the black background layer
        vetgen.help.boxBg.className = 'rem';
            
        // disable the href
        vetgen.util.stopDefault(evt);
      
      }
    
    },
		printDiv : function(evt){
		
			var v = vetgen.help;
			
			// locate the link being clicked on
			var a = vetgen.util.findTarget(evt, 'a', this);
						
			//stop if no link was found & it is not in the FAQ Definition List & allow links inside of Definition Terms to work
			if (!a) { return; }
			if(a.parentNode.id !== 'printMe'){return};
			if (a.className !== 'printMe'){return};
						
			//stops default action of the anchor tag
			vetgen.util.stopDefault(evt);
			
			var printContents = a.parentNode.innerHTML;
			var originalContents = document.body.innerHTML;
			
			document.body.innerHTML = printContents;
			document.body.style.textAlign = "left";
			document.body.style.background ="white";
			document.body.style.color = "black";

			window.print();

			document.body.innerHTML = originalContents;
			document.body.style.background ="#DDE1D2";
			document.body.style.color = "#666666";
		}
		
	
	},
	//Showing and Hiding on specials Page
	specials : { 
		
		setup :function(){
			var currentPage = document.getElementById('secondaryPageContent');
			if(currentPage){
				var pattern = /specialsPage/;
				
					if(pattern.test(currentPage.className)){
					
						var specialsPage = currentPage;
					
					}
			
					if(specialsPage){
						
						vetgen.specials.configureExpandCollapse(specialsPage);
						vetgen.util.addEvent(specialsPage, 'click', vetgen.specials.collapseExpand, false);    
					}
				
			
			}
		
		
		},
		// node list of h4 elements 
		collapsibleHeaders : null,

		// node list or array of areas associated with h3's and h4's
		collapsibleAreas : null,

		configureExpandCollapse : function(specialsPage) {
			
		  vetgen.specials.collapsibleHeaders = specialsPage.getElementsByTagName('h4');
			  
		  vetgen.specials.collapsibleAreas = vetgen.util.getByClass('collapsible', specialsPage);
		
		  // synchronize headers and their associated content
		  for (var i=0, allHdrs=this.collapsibleHeaders.length; i<allHdrs; i++) {
		  
			vetgen.specials.collapsibleHeaders[i].number = vetgen.specials.collapsibleAreas[i].number = i;
			vetgen.specials.collapsibleHeaders[i].title = 'Click to expand or collapse this area';
		  
		  }
		
		},

		// implement the expand/collapse functionality when heading is clicked
		collapseExpand : function(evt) {
		
		
		  var hdr = vetgen.util.findTarget(evt, 'h4', this);
		  
		  if (!hdr) { return; }
		  if (/collapsed/.test(hdr.className)) {
		  
			hdr.className = hdr.className.replace('collapsedHeader','');
			vetgen.specials.collapsibleAreas[hdr.number].className = vetgen.specials.collapsibleAreas[hdr.number].className.replace('collapsedNow','');
		  
		  }
		  
		  else {
		  
			hdr.className += ' collapsedHeader';
			vetgen.specials.collapsibleAreas[hdr.number].className += ' collapsedNow';
			
		  
		  }
		
		}
	},
	//STILL WORKING ON.  WILL ALLOW SEARCHING FOR BREED QUICKLY ON ALL BREEDS LIST PAGE
	allBreeds : {
		alphaArr : [
			"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"
		],
			
		setup : function(){
		
			var breedTable = document.getElementById('gvBreeds');
			
			var locPattern = /vetgen.com\/AllBreedsList.aspx/;
			
			var loc = locPattern.test(document.location.href);
			
			if(breedTable && loc){
							
				//var links = breedTable.getElementsByTagName('a');
				//var len = links.length;
				var p = document.getElementById('alphaLinks');
				var len = vetgen.allBreeds.alphaArr.length;
				
				for(var i=0; i<len;i++){
				
					var a = document.createElement('a');
					var text = document.createTextNode(vetgen.allBreeds.alphaArr[i]);
					a.href = '#' + vetgen.allBreeds.alphaArr[i];
					
					a.appendChild(text);
					p.appendChild(a);
										
				}
				var form = document.getElementById('form1');
					form.style.height="350px";
					form.style.overflow="auto";
				vetgen.allBreeds.createPageLinks();
			}
			
			
		},
		
		createPageLinks : function(){
		
			var breedTable = document.getElementById('gvBreeds');
			
			var links = breedTable.getElementsByTagName('a');
			
			var len = links.length;
			
			var alphaLoc = 0;
			
			var i = 0;
			
			while (i<len){
			
				var newLen = links.length;
				
				if(newLen != len){
					len = newLen;
				}
				
				len = links.length;
			
				var linkString = links[i].firstChild.data;
				
				var letter = linkString[0].toLowerCase();
					
				if (linkString[0] === ' '){
					letter = linkString[1].toLowerCase();
				}
				if(letter === vetgen.allBreeds.alphaArr[alphaLoc].toLowerCase()){
					
					var inpageLink = document.createElement('a');
						inpageLink.name = vetgen.allBreeds.alphaArr[alphaLoc];
						inpageLink.href = '#';
						inpageLink.style.visibility = 'hidden';
						inpageLink.style.display= 'block';
						inpageLink.style.width = inpageLink.style.height = '0';
						
					var inpageTest = document.createTextNode(vetgen.allBreeds.alphaArr[alphaLoc]);
					
						inpageLink.appendChild(inpageTest);
							
					var parent = links[i].parentNode;
					parent.insertBefore(inpageLink, links[i]);
				
					alphaLoc++;
					
				}
				switch(alphaLoc) {
				
					case 16 : alphaLoc++; break;
					case 20 : alphaLoc++; break;
					case 23 : alphaLoc++; break;
					default : break;
				
				
				
				}
					
				i++	
			}	
		
		}
	
	
	
	},
	//Sets up the table script to highlight table rows and headers the correspond with the highlighted cell
	tables : {
	
		// reference to the data table
		tableArray : document.getElementsByTagName('table'),
		
		theTable : [],
		setup : function(evt) {
		
			
			var len = vetgen.tables.tableArray.length;
			
			for(var i=0; i<len; i++){
			
				if(vetgen.tables.tableArray[i].className ==='coatColorTable'){
					
					vetgen.tables.theTable[i] = vetgen.tables.tableArray[i];
				
							//assign mouse events to the coatColorTable if it exists
					if(vetgen.tables.theTable){
						vetgen.util.addEvent(vetgen.tables.theTable[i], 'mouseover', vetgen.tables.showHighlight, false);   
						vetgen.util.addEvent(vetgen.tables.theTable[i], 'mouseout', vetgen.tables.removeHighlight, false);    
					}
				}
			
			}

			
		
		
		},
				
		showHighlight : function(evt) {
			
			// reference to the first row of the table (holding header cells)
			var headerRow = this.rows[0];

			var targetCell = vetgen.util.findTarget(evt, 'td', this);

			if (targetCell) {

			   vetgen.tables.findCellsRow(targetCell);
			   
			   // add highlight on cell, row header cell, and column header cell
			   targetCell.className = vetgen.tables.rowHeader.cells[0].className = headerRow.cells[vetgen.tables.currentCellNumber].className = 'highlight';

			   // highlight the td's to the left of the current td
			   for (var i=1; i<vetgen.tables.currentCellNumber; i++) {
				  vetgen.tables.rowHeader.cells[i].className = 'path';   
			   }
			   
			   // highlight the td's in the same column, above the current td
			   for (var i=1; i<vetgen.tables.rowNumber; i++) {
				   this.rows[i].cells[vetgen.tables.currentCellNumber].className = 'path';   
			   }    

			}

		},

		removeHighlight : function(evt) {
		
			// reference to the first row of the table (holding header cells)
			var headerRow = this.rows[0];

			var targetCell = vetgen.util.findTarget(evt, 'td', this);

			if (targetCell) {
				
			   vetgen.tables.findCellsRow(targetCell);
			   
			   // remove highlight on cell, row header cell, and column header cell
			   targetCell.className =vetgen.tables.rowHeader.cells[0].className = headerRow.cells[vetgen.tables.currentCellNumber].className = '';
			   
			   // remove highlight for the td's to the left of the current td
			   for (var i=1; i<vetgen.tables.currentCellNumber; i++) {
				  vetgen.tables.rowHeader.cells[i].className = '';   
			   }
			   
			   // remove highlight for the td's in the same column, above the current td
			   for (var i=1; i<vetgen.tables.rowNumber; i++) {
					this.rows[i].cells[vetgen.tables.currentCellNumber].className = '';   
			   }    

			}  

		},

		// method to track down cells and rows involved in highlights
		findCellsRow : function(theCell) {

			// store the cell number for the td moused over or moused away from
			this.currentCellNumber = theCell.cellIndex;

			// pinpoint the row holding the cell moused over or moused away from
			this.rowHeader = theCell.parentNode;

			// store the row number for the row moused over or moused away from
			this.rowNumber = this.rowHeader.rowIndex;

		}
	
	
	
	
	},
	//Sets up the faq page to show/hide answers
	faq : {
		dt : document.getElementsByTagName('dt'),
		dd : document.getElementsByTagName('dd'),
		len1 : 0,
		len2 : 0,
		hideA : document.getElementById('hideall'),
		showA : document.getElementById('showall'),
		
		setup : function(){
			var v = vetgen.faq;
			v.len1 = vetgen.faq.dt.length;
			v.len2 = vetgen.faq.dd.length;
			
			if(v.len1 != v.len2){
				alert("Please contact webmaster at vetgen.com and alert them that there is an error on the FAQ page.");
			}
			else{
								
				for(var i =0; i<v.len1;i++){
				
					v.dd[i].style.display = 'none';		
				
				}
			}
		},
		
		showHide : function(evt){
			var v = vetgen.faq;
			
			// locate the link being clicked on
			var a = vetgen.util.findTarget(evt, 'a', this);
						
			//stop if no link was found & it is not in the FAQ Definition List & allow links inside of Definition Terms to work
			if (!a) { return; }
			if (a.className !== 'showhide'){return};

			//stops default action of the anchor tag
			vetgen.util.stopDefault(evt);
			if(a.id === 'showall'){
				for(var i=0;i<v.len1;i++){
					v.dd[i].style.display = 'block';				
				
				}
				
				a.style.display = 'none';
				v.hideA.style.display ='block';
				
			
			}
			else{
				for(var i=0;i<v.len1;i++){
					v.dd[i].style.display = 'none';				
				
				}
				
				a.style.display = 'none';
				v.showA.style.display ='block';
			
			}		
		},	
		displayAnswer :function(evt){
			var v = vetgen.faq;
			var show = false;
			
			// locate the link being clicked on
			var a = vetgen.util.findTarget(evt, 'a', this);
						
			//stop if no link was found & it is not in the FAQ Definition List & allow links inside of Definition Terms to work
			if (!a) { return; }
			if (a.className === 'links'){return};
			if (a.parentNode.parentNode.id !== 'faq'){return};

			//stops default action of the anchor tag
			vetgen.util.stopDefault(evt);

			for(var i=0; i<v.len1;i++){
							
				if(a.parentNode === v.dt[i]){
					if(v.dd[i].style.display ==='none'){
						v.dd[i].style.display = 'block';
					
					}
					else{
						v.dd[i].style.display = 'none';
				
					}
				}
			}
		}
	},
	//Retrieves the Font Size Cookie
	retrieveStoredSettings : function() {
        
		// restore font size
		var fontSize = vetgen.util.findCookie('fontSize');

			if (fontSize !== null) {

			fontSize= parseInt(fontSize);
				   
			vetgen.body.style.fontSize = fontSize + '%';

			};
		          
    },
	//Sets the Copyright date on the bottom of the page
	clock : {
	
		copyright : document.getElementById('year'),  //looks for the span on the page for the copyright information
	
		updateClock : function(){
		
			var currentTime = new Date ( );	//Sets currentTime as a date object		
			var currentHours = currentTime.getHours ( ); //Sets currentHours as the current hour
			var currentMinutes = currentTime.getMinutes ( );  //Sets currentMinutes as the current minutes
			var currentSeconds = currentTime.getSeconds ( );  //Sets currentSeconds as the current seconds
			var currentDay = currentTime.getDay();	//Sets currentDay as the current day
			var currentMonth = currentTime.getMonth();	//Sets currentMonth as the current month
			var currentDate = currentTime.getDate();	//Sets currentDate as the current date
			this.currentYear = currentTime.getFullYear();  //Sets currentYear as the current year			
			vetgen.clock.setCopyrightYear();  //Calls functions to set the current year as the copyright on the bottom of the pages


		},
		
		setCopyrightYear : function(){
			
			var year = document.createTextNode(vetgen.clock.currentYear);  //Creates a text node for the currentYear information
			vetgen.clock.copyright.appendChild(year); //appends the currentYear text node onto the page in the span that was created for it
		
		}


	},
	//Lets users resize the font-size on the page
	fontSize : {
			
		setup : function(){
			
			this.fontDiv = document.createElement('div');
			this.fontDiv.id ="fontDiv";
			
			this.container = document.getElementById('container');
		
			for (var i =0; i<3; i++){
				
				var img = document.createElement('img');
				img.src ="i/fontsize" + i + ".png"
				var a = document.createElement('a');
				a.href ='#';
				a.appendChild(img);
				this.fontDiv.appendChild(a);
										
			}
			
			this.container.appendChild(this.fontDiv);
		},
		
		resize : function(evt){

			// locate the text input field
			var a = vetgen.util.findTarget(evt, 'a', this);
		
			//stop if no button was found
			if (!a) { return; }
			if (a.parentNode.id !== 'fontDiv' ){return;}
			
			//stops default action of the anchor tag
			vetgen.util.stopDefault(evt);
			
			var string = a.firstChild.src;
			
			var pattern0 = /fontsize0/;
			
			var pattern1 = /fontsize1/;
			
			var pattern2 = /fontsize2/;
			
			var test0 = pattern0.test(string);
			
			var test1 = pattern1.test(string);
			
			var test2 = pattern2.test(string);
			
			if (test0){
							
				var value =	vetgen.body.style.fontSize = '71%';
				
			}			
			
			else if (test1){
				
				var value = vetgen.body.style.fontSize = '80%';
			
			}
			
			else if (test2){
			
				var value =	vetgen.body.style.fontSize = '90%';
			
			}
			
			var name = 'fontSize';
				
			var data = name + "=" + escape(value);
			
			document.cookie = data;
		}
			
	},
	//Loads all other scripts onto the page
	scripts : {
	
		src : [
			'scripts/common.js',
			'scripts/swfobject.js',
			'scripts/sifr.js',
			'scripts/api.js',
			'scripts/uistrings.js',
			'scripts/uds_compiled.js',
			'scripts/search.js'
		 ],
		
		insertJavascripts : function(){
		
			type = 'text/javascript';
			var x = vetgen.scripts.src.length;
			
				for (var i=0; i<x; i++){
					var scriptTag = document.createElement('script');
					scriptTag.type = type;
					scriptTag.src = vetgen.scripts.src[i];
					
					vetgen.body.appendChild(scriptTag);
				
				}
				
		}
			
	},
	//Utility functions
	util : {
	
		insertAfter : function(parent, nodeToInsert, previousNode) {

			parent.insertBefore(nodeToInsert, previousNode.nextSibling);
	
		},
		createCookie : function(name,value,expiration,path,domain,secure) {
		  var data = name + "=" + escape(value);
		  if (expiration) { 
			  var expiresAt = new Date();
			  expiresAt.setTime(expiration);
			  data += "; expires=" + expiresAt.toGMTString();
		  }
		  if (path) { data += "; path=" + path; }
		  if (domain) { data += "; domain=" + domain; }
		  if (secure) { data += "; secure"; }
		  document.cookie = data;
		},
	  
		findCookie : function(name) {  
		  var query = name + "=";
		  var queryLength = query.length;
		  var cookieLength = document.cookie.length;
		  var i=0;
		  while (i<cookieLength) {
			var position = i + queryLength;
			if (document.cookie.substring(i,position) === query) {
			   return this.findCookieValue(position);
			}
			i = document.cookie.indexOf(" ", i) + 1;
			if (i === 0) { break; }  
		  }
		  return null;  
		},

		findCookieValue : function(position) {
			var endsAt = document.cookie.indexOf(";", position);
			if (endsAt === -1) { endsAt = document.cookie.length; }
			return unescape(document.cookie.substring(position,endsAt));
		},
		
		eraseCookie : function(name) {
			
			if (proj.util.findCookie(name)) {
				
				var data = name + "=";
				
				data += "; expires=Thu, 01-Jan-70 00:00:01 GMT";
				
				document.cookie = data;
				
			}
	
		},

	

		configEvents : function() {

			if (document.addEventListener) {
			
				this.addEvent = function(el, type, func, capture) {
				
					el.addEventListener(type, func, capture);
					
				};
				
				this.stopBubble = function(evt) { evt.stopPropagation(); };
				
				this.stopDefault = function(evt) { evt.preventDefault(); };
				
				this.findTarget = function(evt, targetNode, container) {
				
					var currentNode = evt.target;
					
					while (currentNode && currentNode !== container) {
					
						if (currentNode.nodeName.toLowerCase() === targetNode) {
						
							return currentNode; break;
							
						}
						
						else { currentNode = currentNode.parentNode; }
						
					};
					
				return false;
				
				};
			}
			
			else if (document.attachEvent) {

				this.addEvent = function(el, type, func) {
				
					el["e" + type + func] = func;
					
					el[type + func] = function() { el["e" + type + func] (window.event); };
					
					el.attachEvent("on" + type, el[type + func]);
					
				};
				
				this.stopBubble = function(evt) { evt.cancelBubble = true; };
				
				this.stopDefault = function(evt) { evt.returnValue = false; };
				
				this.findTarget = function(evt, targetNode, container) {
				
					var currentNode = evt.srcElement;
					
					while (currentNode && currentNode !== container) {
					
						if (currentNode.nodeName.toLowerCase() === targetNode) {
						
							return currentNode; break;
						}
						
						else { currentNode = currentNode.parentNode; }
					};
					
					return false;
					
				};
			}
		},

		sendRequest : function(url, func, postData) {

			var xhr = this.createXHR();
				
				if (!xhr) { return; }
				
			var method = (postData) ? "POST" : "GET";
			
			xhr.open(method, url, true);
			
			xhr.setRequestHeader('User-Agent','XHR');
			
			if (postData) {xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');}
			
			xhr.onreadystatechange = function() {
			
				if (xhr.readyState !== 4) { return; }
				
				if (xhr.status !== 200 && xhr.status !== 304) {
				
					alert('HTTP error ' + xhr.status);
				
					return;
				}
				
				func(xhr);
			
			};
			
			if (xhr.readyState === 4) { return; }
		
				xhr.send(postData);
		},

		XHRoptions : [
		
			function () {return new XMLHttpRequest()},
		
			function () {return new ActiveXObject("Msxml2.XMLHTTP")},
		
			function () {return new ActiveXObject("Msxml3.XMLHTTP")},
		
			function () {return new ActiveXObject("Microsoft.XMLHTTP")}
		
		],

		XHRmethod : null,

		configXHR : function() {
		
			var xmlhttp = false;
			
			for (var i=0, allOptions=this.XHRoptions.length; i<allOptions; i++) {
				
				try { xmlhttp = this.XHRoptions[i](); }
			
				catch (e) { continue; }
				
				break;
			}

			this.XHRmethod = i;

			this.createXHR = function() {
			
				var xmlhttp = this.XHRoptions[this.XHRmethod]();
				
				return xmlhttp;
			
			}

		},
		getByClass : function(theClass, container, tag) {
				
				var classNodes = [];
				if (!container) { container = document; }
				if (!tag) { tag = '*'; }
				var theElements = container.getElementsByTagName(tag);
				var allTheElements = theElements.length;
				var pattern = new RegExp("(\s*)"+theClass+"(\s*)");
				for (var i=0, j=0; i<allTheElements; i++) {
					if (pattern.test(theElements[i].className)) { classNodes[j] = theElements[i]; j++; }
					
				}
			  return classNodes;			
		},
		generateImg : function() {
			var delImg = document.createElement('img');
			delImg.src = 'i/remove.gif';
			delImg.width = delImg.height = '9';
			return delImg;
		}
		

	}


};

vetgen.init();

}



