
	/**
	Javascript Library for squirrel framework
	**/
	

var galleryCounter = 1;


function updateBanner( id ) {
	swapImage( id );	
	var obj =  document.getElementById('case_gallery').getElementsByTagName('a');
	if ( !obj ) return;
	for ( var i=0;i< obj.length ; i++ ) {
		obj[i].className = '';
	}
}	


function refreshGallery() {
	swapImage( galleryCounter++ );
	var imgs = document.getElementById('main_image').getElementsByTagName('img');
	if ( !imgs ) return;
	if ( galleryCounter >= imgs.length ) galleryCounter = 0; 
	setTimeout("refreshGallery()", 3000 );
	
}

function setOpacity( obj , opacity ) {
 	obj.style.opacity = opacity;
 	obj.style.filter =  'alpha(opacity=' + ( opacity * 100 ) + ')';
}

function fadeInImage( id , cont ) {			 	
	var imgObj = document.getElementById('image_content_'+id);
		
 	var level;
 	
 	if ( cont != true ) {
 			 	
	 	level = 0;
	 	
	 	setOpacity(imgObj , 0 );
					 	
 	} else {
	 	level = imgObj.style.opacity * 10;
 	}
 	imgObj.style.display = 'block';
 	level++;;

 	setOpacity ( imgObj , level / 10 );
 
 	if ( level >= 10 ) {	
 		imgObj.style.display = 'block';	 
	 	return;
 	}
 	setTimeout( 'fadeInImage('+id+' , true )' , 60 );
}


	
function fadeOutImage( id , cont ) {
 	var imgObj = document.getElementById('image_content_'+id);
 	var level;			 	

	if ( cont != true ) {	
		if ( imgObj.style.display == 'none' ) return;			 	
	 	level = 10;
	 	//imgObj.style.opacity = 1;
	 	setOpacity ( imgObj , 1 );
	 					 	
 	} else {
	 	level = imgObj.style.opacity * 10;
 	}
	imgObj.style.display = 'block';
	
 	level--;
 	//imgObj.style.opacity = level/10;
 	setOpacity ( imgObj , level / 10 ); 
 	if ( level <= 0 ) {		
 		imgObj.style.display = 'none';				 	
	 	return;
 	}
 	
 	setTimeout( 'fadeOutImage('+id+' , true )' , 60 );
}


function swapImage( id ) {	 	
		var imgs = document.getElementById('main_image').getElementsByTagName('img');
		if ( !document.getElementById('image_content_'+id) ) return;
		/*
		if ( document.getElementById('title_text').childNodes[0] )
		document.getElementById('title_text').childNodes[0].nodeValue = document.getElementById('image_content_'+id).getAttribute('alt');
		*/
		
		for ( var i=0; i < imgs.length; i++ ) {
			if ( document.getElementById('image_content_'+i) && document.getElementById('image_content_'+i).style.display == 'block' && i!=id ) { 			
				
				fadeOutImage( i );
				
			}
		}
			
		fadeInImage( id );		
}


	function isPopulated( obj ) {
		if ( obj && obj.value != '' && obj.value != 'Search' && obj.value != 'Szukaj' ) return true;
		return false;
	}
	
	function mouseX(evt) {
	if (evt.pageX) return evt.pageX;
	else if (evt.clientX)
	   return evt.clientX + (document.documentElement.scrollLeft ?
	   document.documentElement.scrollLeft :
	   document.body.scrollLeft);
	else return null;
	}
	function mouseY(evt) {
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY)
	   return evt.clientY + (document.documentElement.scrollTop ?
	   document.documentElement.scrollTop :
	   document.body.scrollTop);
	else return null;
	}
	/**
	Shows submenu in Navigation
	**/
	function sqShowSubmenu( obj , display ) {
		if ( obj ) {
			var ul = obj.getElementsByTagName('ul');
			if ( ul.length == 1 ) {
				ul = ul.item(0);
				ul.style.display = display;
			}				
		}			
	}
    
	/**
	Shows submenu in Navigation
	**/
	function sqShowSubmenu( obj , display ) {
		if ( obj ) {
			var ul = obj.getElementsByTagName('ul');
			if ( ul.length == 1 ) {
				ul = ul.item(0);
				ul.style.display = display;
			}				
		}			
	}
    
    
    /**
    * Function select/unselect given checkboxes 
    * id = html id of checkboxes
    * chilren string of indexes of checkboxes to select/unselect
    * select boolean - if true then children will be selected, otherwise unselected )
    */
   
    function selectCheckboxes( id , children , checked ) {
        var children = children.split(",");
        var obj;
        for ( var i = 0 ; i < children.length ; i++ ) {
            obj = document. getElementById( id + '[' + children[i] + ']' );
            if ( obj ) {
                obj.checked = checked;
            } 
        }
    }
    
    function hideCheckboxes( id , children , source ) {
   
        var hide;
		if ( source ) {
			hide = source.innerHTML == '-';
		} else {
			hide = true;
		}
        
        var children = children.split(",");
        var obj;
        
        for ( var i = 0 ; i < children.length ; i++ ) {
            obj = document. getElementById( 'div_' + id + '[' + children[i] + ']' );
            if ( obj ) {
                if ( hide ) {
                    obj.style.display = 'none';
					if ( source ) 
                    source.innerHTML = '+';
                    
                } else {
                    obj.style.display = 'block';
					if ( source )
                    source.innerHTML = '-';
                }
            } 
        }
    }
    
    
    function selectParent( id, parents , checked ) {
        var parents = parents.split(",");
        if ( checked == false ) {
            var obj;
            for ( var i = 0 ; i < parents.length ; i++ ) {
                obj = document.getElementById( id + '[' + parents[i] + ']' );
                if ( obj ) {
                    obj.checked = false;
                }
            }
        }
        
    }
    
	 function addHTextField( name , itemName , itemLabel , displayLabel , text , removeLabel ) {

        
        var ni = document.getElementById( name+'_div' );
        var num = document.getElementById( name+'_counter').value * 1;    
        var length = document.getElementById( name+'_length').value * 1; 
        var min = document.getElementById( name+'_min').value * 1;            
        var max = document.getElementById( name+'_max').value * 1;    
        
        var newdiv = document.createElement('div');                     
        var divIdName =  name+itemName+'_div_'+length;                
        var inputIdName = name+itemName+'_text['+length+']';                        
        var inputName = name+itemName+'_text['+length+']';                        
        
        if ( text == null ) text = '';
        var p_string = text;
        p_string = p_string.replace(/&/g, '&amp;');
        p_string = p_string.replace(/</g, '&lt;');
        p_string = p_string.replace(/>/g, '&gt;');
        p_string = p_string.replace(/"/g, '&quot;');

        newdiv.setAttribute('id',divIdName);                
                   
        if ( displayLabel )
        newdiv.innerHtml =  '<label for=\"'+inputIdName+'\">'+itemLabel+' :</label>'; 
        
        
        
        newdiv.innerHTML+= '<input type="text" name="'+inputIdName+'" id="'+inputIdName+'" style="margin:5px; width:80% ;display:inline" value="'+p_string+'">';                                
        newdiv.innerHTML+= ' <a href="javascript: " onclick="removeHTextField(\''+name+'\',\''+divIdName+'\');">'+removeLabel+'</a>';        
        
        ni.appendChild(newdiv);
        
        num++;
        length++;
        document.getElementById(name+'_counter').value =num;
        document.getElementById(name+'_length').value = length;
            
        // hidding add
        if ( max>0 && num >= max && document.getElementById( name+'_add') ) {
            document.getElementById( name+'_add').style.display='none';
        }
    }
                        
    function createXmlHttpRequestObject() {
    	var xmlHttp;
    	try {
            // Firefox, Opera 8.0+, Safari
            xmlHttp = new XMLHttpRequest();
        } catch (e) {
            // Internet Explorer
            try {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                    alert("Your browser does not support AJAX!");
                    return false;
                }
            }
        }
    	return xmlHttp;
    }
                         
    var xmlHttp = createXmlHttpRequestObject();
    var url;
    var feedFile;
    
    function dropdownmenu_filter_onkeyup( feed ,src , destId , data_source , field_names ) {
    
    	var dest = document.getElementById( destId ) ;
    	
    	var keywords = src.value;
      	feedFile = feed;
    	if ( dest ) {
    	
   			keywords = encodeURIComponent( keywords );    			
   			field_names = encodeURIComponent( field_names );  
   			data_source = encodeURIComponent( data_source ); 			
   			url = 'ds='+data_source+'&fn='+field_names+'&k='+keywords;
   			
   			/////////////////////////////////////////////////////////////////////
			// function to deal with data
	        xmlHttp.onreadystatechange=function() {
				var elOptNew; 
				var vals;
				var texts;
				var root;				
				dest.options.length = 0;
	            if( xmlHttp.readyState == 4 ) { 
	            	if ( xmlHttp.status == 200 ) {
	            						
						var xmlResponse = xmlHttp.responseXML;
						var root = xmlResponse.documentElement;
						
						var vals = root.getElementsByTagName("primary_key");
						var texts = root.getElementsByTagName("field");
					
						for ( var i=0 ; i < texts.length ; i++ ) {
							
							var elOptNew = document.createElement('option');
							elOptNew.text = texts.item(i).firstChild.data;
	  						elOptNew.value = vals.item(i).firstChild.data;
	  						
							 try {
							    dest.add(elOptNew, null); // standards compliant; doesn't work in IE
							  }
							  catch(ex) {
							    dest.add(elOptNew); // IE only
							  }
						
						}																									
					}					
	            }
	        }
	        ajaxSend();
	       
   		 		    	
    	} 
    }

	function checkboxgroup_filter_onkeyup( feed ,src , name , data_source , field_names ) {
  		var destId = name+"_div";
    	var dest = document.getElementById( destId ) ;    	
    	feedFile = feed;
    	var keywords = src.value;
      	
    	if ( dest ) {
    	
   			keywords = encodeURIComponent( keywords );    			
   			field_names = encodeURIComponent( field_names );  
   			data_source = encodeURIComponent( data_source ); 			
   			url = 'ds='+data_source+'&fn='+field_names+'&k='+keywords;
   			
   			/////////////////////////////////////////////////////////////////////
			// function to deal with data
	        xmlHttp.onreadystatechange=function() {
				var elOptNew; 
				var vals;
				var texts;
				
			
				dest.innerHTML = '';
	            if( xmlHttp.readyState == 4 ) { 
	            	if ( xmlHttp.status == 200 ) {
	            					
						var xmlResponse = xmlHttp.responseXML;
						var root = xmlResponse.documentElement;
					
						var vals = root.getElementsByTagName("primary_key");
						var texts = root.getElementsByTagName("field");
					
						for ( var i=0 ; i < texts.length ; i++ ) {
							var checked = '';
							
							var text = texts.item(i).firstChild.data;
							var val = vals.item(i).firstChild.data;
							if ( document.getElementById( name +'_item['+val+']') ) {
								checked = 'checked="checked" ';
							}
							dest.innerHTML += "<div>";
					 		dest.innerHTML += "<input "+checked+" style=\"margin-top: 10px; width: auto;\" class=\"checkbox\" name=\""+name+"["+val+"]\" id=\""+name+"["+val+"]\" value=\""+val+"\" type=\"checkbox\" onclick=\"checkboxgroup_update_item( this, '"+name+"', '"+text+"' )\" /> ";
							dest.innerHTML += "<label for=\""+name+"["+val+"]\" style=\"display: inline;\">"+text+"</label>";	            
							dest.innerHTML += "</div>";														
						}																									
					}					
	            }
	        }
	        
   			ajaxSend();
   		 		    	
    	} 
    }
        
   
        
    function checkboxgroup_update_item( obj , name , label ) {
    	
    	if ( !obj ) return;
    	
    	var val = obj.value;
    	
    	if ( obj.checked ) {    	
    		var dest = document.getElementById( name+'_dest' );
    		if ( dest ) {
    	
    	
    			var item = name+'_item['+val+']';
    			var elm = document.getElementById(item);
    			if ( !elm ) {
	    		    var nname = name+'_selected['+val+']';
		            var item = name+'_item['+val+']';
	    			dest.innerHTML += '<li id="'+item+'" >'+label;
					dest.innerHTML += "<input type=\"hidden\" name=\""+nname+"\" value=\""+val+"\" /></li>";
				}     
    		}
    	} else {
    		var item = name+'_item['+val+']';
    		var elm = document.getElementById(item);
    		if ( elm ) {
				elm.parentNode.removeChild( elm );
			}
    	}
    }
    
    function extendedcheckboxgroup_filter_onkeyup( feed ,src , name , data_source , field_names , ex_options ) {
  		var destId = name+"_div";
    	var dest = document.getElementById( destId ) ;    	
    	feedFile = feed;
    	var keywords = src.value;
      	
    	if ( dest ) {
    	
   			keywords = encodeURIComponent( keywords );    			
   			field_names = encodeURIComponent( field_names );  
   			data_source = encodeURIComponent( data_source ); 			
   			url = 'ds='+data_source+'&fn='+field_names+'&k='+keywords;
   			
   			/////////////////////////////////////////////////////////////////////
			// function to deal with data
	        xmlHttp.onreadystatechange=function() {
				var elOptNew; 
				var vals;
				var texts;
				
			
				dest.innerHTML = '';
	            if( xmlHttp.readyState == 4 ) { 
	            	if ( xmlHttp.status == 200 ) {
	            					
						var xmlResponse = xmlHttp.responseXML;
						var root = xmlResponse.documentElement;
					
						var vals = root.getElementsByTagName("primary_key");
						var texts = root.getElementsByTagName("field");
					
						for ( var i=0 ; i < texts.length ; i++ ) {
							var checked = '';
							
							var text = texts.item(i).firstChild.data;
							var val = vals.item(i).firstChild.data;
							if ( document.getElementById( name +'_item['+val+']') ) {
								checked = 'checked="checked" ';
							}
							dest.innerHTML += "<div>";
					 		dest.innerHTML += "<input "+checked+" style=\"margin-top: 10px; width: auto;\" class=\"checkbox\" name=\""+name+"["+val+"]\" id=\""+name+"["+val+"]\" value=\""+val+"\" type=\"checkbox\" onclick=\"extendedcheckboxgroup_update_item( this, '"+name+"', '"+text+"' , '"+ex_options+"' )\" /> ";
							dest.innerHTML += "<label for=\""+name+"["+val+"]\" style=\"display: inline;\">"+text+"</label>";	            
							dest.innerHTML += "</div>";														
						}																									
					}					
	            }
	        }
	        
   			ajaxSend();
   		 		    	
    	} 
    }
    
    function extendedcheckboxgroup_update_item( obj , name , label ,ex_options ) {
    	
    	if ( !obj ) return;
    	var options = ex_options.split(';');
    	var values = new Array();
    	var labels = new Array();
 		
 		var j=0;
 		for (var i=0;  i < options.length ; i+=2 ) {
 			if ( options[i+1] ) {
	 			values[j] = options[i];
	 			labels[j] = options[i+1];
	 			j++;		 		
 			}
 		}
 		 		
    	var val = obj.value;
    	
    	if ( obj.checked ) {    	
    		var dest = document.getElementById( name+'_dest' );
    		if ( dest ) {
    	
    	
    			var item = name+'_item['+val+']';
    			var elm = document.getElementById(item);
    			if ( !elm ) {
    				var select = '';
	    		    var nname = name+'_selected['+val+']';
		            var item = name+'_item['+val+']';
		            var select_name = name+'_select['+val+']';
		            
	    			//select += '<li id="'+item+'" > ";
	    			
	    			select += '<div style="float:left;width:100px;height:25px">'+label+'</div>';
	    			
	    			// adding extended options
	    			
	    			if ( values.length > 0 ) {	    			
	    				select += '<select name="'+select_name+'" style="height:25px;font-size:80%">';	    				
	    				for ( var i = 0 ; i < values.length ; i++ ) {
	    					select += "<option value=\""+values[i]+"\">"+labels[i]+"</option>";
	    				}
	    				select += '</select>';
	    			}
	    			
	    			
					select += "<input type=\"hidden\" name=\""+nname+"\" value=\""+val+"\" /><div style=\"clear:both\"></div>";
					//select += "</li>";
					//dest.innerHTML += select;
					
					// DOM version
					var li = document.createElement('li');
					li.setAttribute('id' , item );
					li.innerHTML = select;
					dest.appendChild( li );
				}   
				  
    		}
    	} else {
    		// deleting li element
    		var item = name+'_item['+val+']';
    		var elm = document.getElementById(item);
    		if ( elm ) {
				elm.parentNode.removeChild( elm );
			}
    	}
    }
    
    
    function ajaxSend( obj ) {
        if ( obj ) {
            xmlHttp = obj;
        }
    	if ( xmlHttp.readyState == 4 ||  xmlHttp.readyState == 0 ) {   				
	   			xmlHttp.open('POST', feedFile+'?'+url , true );
	   			xmlHttp.send(url);
   		} else {
   			setTimeout('ajaxSend()',400);
   		} 
    }
	
	
	
    function removeHTextField( name , divNum ) {
                        
        var d = document.getElementById(name+'_div');
        var min = document.getElementById( name+'_min').value * 1;            
        var max = document.getElementById( name+'_max').value * 1;    
        var num = document.getElementById( name+'_counter').value * 1;   
        
        if ( num <= min ) return false;
        
        var olddiv = document.getElementById(divNum);
        d.removeChild(olddiv);
        
        num--;
        document.getElementById(name+'_counter').value = num;   
        // showing  add
        if ( num < max && document.getElementById( name+'_add' ) ) {
            document.getElementById( name+'_add').style.display = 'block';          
        }        
    }
	

    function addHImageField( name , itemName , itemLabel,  removeLabel, displayLabel ,  imageUrl  ) {

        if ( name == null ) return; 
        var ni = document.getElementById( name+'_div' );
        var num = document.getElementById( name+'_counter').value * 1;    
        var length = document.getElementById( name+'_length').value * 1;     
        var min = document.getElementById( name+'_min').value * 1;            
        var max = document.getElementById( name+'_max').value * 1;    
		var attributes = document.getElementById( name+'_attributes').value ;
		var attributesLabels = document.getElementById( name+'_attributes_labels').value ;
		
		attributes = attributes.split(",");
		attributesLabels = attributesLabels.split(",");
		
        var newdiv = document.createElement('div');                     
        var divIdName =  name+itemName+'_div_'+length;                
        var inputIdName = name+itemName+'_file_'+length;
        var delIdName = name+itemName+'_del['+length+']';
        var inputName = name+itemName+'_file['+length+']';  
                    
        
        newdiv.setAttribute('id',divIdName);                

        if ( displayLabel )
        newdiv.innerHtml =  '<label for=\"'+inputIdName+'\">'+itemLabel+' :</label>'; 

        

        if ( imageUrl != null ){

        	newdiv.innerHTML+= "<img style=\"margin: 5px\" src=\""+imageUrl+"\" />";

        	newdiv.innerHTML+= "<br/>";          

			newdiv.innerHTML+= "<input class=\"checkbox\" style=\"display:inline;float: left\" type=\"checkbox\" name=\""+delIdName+"\" id=\""+delIdName+"\" value=\"true\" />";

			newdiv.innerHTML+= "<label  for=\""+delIdName+"\" title=\"Delete\">Delete</label> <br/>";

        }			        

        

        newdiv.innerHTML+= '<input type="file" name="'+inputIdName+'" id="'+inputIdName+'" style="width:80%">';                                

		for ( var i=0 ; i < attributes.length ; i++ ) {
			newdiv.innerHTML+= '<br /><label>'+ attributesLabels[i] + '</label>';
			newdiv.innerHTML+= '<input type="text" name="'+inputIdName+'_'+attributes[i]+'" id="'+inputIdName+'_'+attributes[i]+'" /><br /><br />'; 
		}
        newdiv.innerHTML+= '<a href="javascript:" onclick="removeHImageField(\''+name+'\',\''+divIdName+'\');">'+removeLabel+'</a>';                

        

        ni.appendChild(newdiv);

        

        num++;

        length++;

        document.getElementById(name+'_counter').value =num;

        document.getElementById(name+'_length').value = length;

            

        // hidding add

        if ( max>0 && num >= max && document.getElementById( name+'_add') ) {

            document.getElementById( name+'_add').style.display='none';

        }

    }

    

    function removeHImageField( name , divNum ) {

            

            

        var d = document.getElementById(name+'_div');

        var min = document.getElementById( name+'_min').value * 1;            

        var max = document.getElementById( name+'_max').value * 1;    

        var num = document.getElementById( name+'_counter').value * 1;   

        

        if ( num <= min ) return false;

        

        var olddiv = document.getElementById(divNum);

        d.removeChild(olddiv);

        

        num--;

        document.getElementById(name+'_counter').value = num;   

        // showing  add

        if ( num < max && document.getElementById( name+'_add') ) {

            document.getElementById( name+'_add').style.display = 'block';          

        }

        

    }

    
	

    function addHFileField( name , itemName , itemLabel , removeLabel , displayLabel , fileUrl , fileName ) {
            
        var ni = document.getElementById( name+'_div' );
        var num = document.getElementById( name+'_counter').value * 1;    
        var length = document.getElementById( name+'_length').value * 1;   
        var min = document.getElementById( name+'_min').value * 1;            
        var max = document.getElementById( name+'_max').value * 1;    
		
        var attributes = document.getElementById( name+'_attributes').value ;
		var attributesLabels = document.getElementById( name+'_attributes_labels').value ;
		
		attributes = attributes.split(",");
		attributesLabels = attributesLabels.split(",");		
		
        var newdiv = document.createElement('div');                     
        var divIdName =  name+itemName+'_div_'+length;                
        var delIdName = name+itemName+'_del['+length+']';      
        var inputIdName = name+itemName+'_file_'+length;
        var inputName = name+itemName+'_file['+length+']';                        
        newdiv.setAttribute('id',divIdName);                
                   
        if ( displayLabel )
        newdiv.innerHtml =  '<label for=\"'+inputIdName+'\">'+itemLabel+' :</label>'; 
        
        if ( fileUrl != null ){
            newdiv.innerHTML+= "<a href=\""+fileUrl+"\" style=\"display: inline;float:left\" />"+fileName+"</a> ";                 
            newdiv.innerHTML+= "<input class=\"checkbox\" style=\"display:inline;float: left\" type=\"checkbox\" name=\""+delIdName+"\" id=\""+delIdName+"\" value=\"true\" />";
            newdiv.innerHTML+= "<label  for=\""+delIdName+"\" title=\"Delete\">Delete</label>";
        }        

        newdiv.innerHTML+= '<input type="file" name="'+inputIdName+'" id="'+inputIdName+'" style="width:80%">';
		for ( var i=0 ; i < attributes.length ; i++ ) {
			newdiv.innerHTML+= '<br /><label>'+ attributesLabels[i] + '</label>';
			newdiv.innerHTML+= '<input type="text" name="'+inputIdName+'_'+attributes[i]+'" id="'+inputIdName+'_'+attributes[i]+'" /><br /><br />'; 
		}
		                                
        newdiv.innerHTML+= ' <a href="javascript:" onclick="removeHFileField(\''+name+'\',\''+divIdName+'\');">'+removeLabel+'</a>';
       
        ni.appendChild(newdiv);        
        num++;
        length++;
        document.getElementById(name+'_counter').value =num;
        document.getElementById(name+'_length').value =length;
            
        // hidding add

        if ( max>0 && num >= max && document.getElementById( name+'_add') ) {
            document.getElementById( name+'_add').style.display='none';
        }

    }

    

    function removeHFileField( name , divNum ) {
            
            
        var d = document.getElementById(name+'_div');
        var min = document.getElementById( name+'_min').value * 1;            
        var max = document.getElementById( name+'_max').value * 1;    
        var num = document.getElementById( name+'_counter').value * 1;   
        
        if ( num <= min ) return false;
      
        var olddiv = document.getElementById(divNum);
        d.removeChild(olddiv);        
        num--;

        document.getElementById(name+'_counter').value = num;   
        // showing  add
        if ( num < max && document.getElementById( name+'_add') ) {
            document.getElementById( name+'_add').style.display = 'block';          
        }        
    }

    
		
	var scwDateNow = new Date(Date.parse(new Date().toDateString()));
	var scwBaseYear        = scwDateNow.getFullYear() - 60;
	var scwDropDownYears   = 110;
	var scwLanguage;

	function scwSetDefaultLanguage() {
		try
			{scwSetLanguage();}

		 catch (exception)
			{// English
			 scwToday               = 'Today:';
			 scwDrag                = 'click here to drag';
			 scwArrMonthNames       = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
			 scwArrWeekInits        = ['S','M','T','W','T','F','S'];
			 scwInvalidDateMsg      = 'The entered date is invalid.';
			 scwOutOfRangeMsg       = 'The entered date is out of range.';
			 scwDoesNotExistMsg     = 'The entered date does not exist.';
			 scwInvalidAlert        = ['Invalid date (',') ignored.'];
			 scwDateDisablingError  = ['Error ',' is not a Date object.'];
			 scwRangeDisablingError = ['Error ',' should consist of two elements.'];
			}
		};

	var scwWeekStart       =    1;
	var scwWeekNumberDisplay    = false;
	var scwWeekNumberBaseDay    = 4;
	var scwShowInvalidDateMsg       = true,
		scwShowOutOfRangeMsg        = true,
		scwShowDoesNotExistMsg      = true,
		scwShowInvalidAlert         = true,
		scwShowDateDisablingError   = true,
		scwShowRangeDisablingError  = true;
	var scwArrDelimiters   = ['/','-','.',',',' '];
	var scwDateDisplayFormat = 'dd/mmm/yyyy';     // e.g. 'MMM-DD-YYYY' for the US
	var scwDateOutputFormat  = 'DD/MM/YYYY'; // e.g. 'MMM-DD-YYYY' for the US
	var scwZindex          = 1;
	var scwBlnStrict       = false;
	var scwEnabledDay      = [true, true, true, true, true, true, true,
							  true, true, true, true, true, true, true,
							  true, true, true, true, true, true, true,
							  true, true, true, true, true, true, true,
							  true, true, true, true, true, true, true,
							  true, true, true, true, true, true, true];

	var scwDisabledDates   = new Array();
	var scwActiveToday = true;
	var scwOutOfMonthDisable = false;
	var scwOutOfMonthHide    = false;
	var scwOutOfRangeDisable = true;
	var scwFormatTodayCell = true;
	var scwTodayCellBorderColour = 'red';
	var scwAllowDrag = false;
	var scwClickToHide = false;
	document.writeln(
		'<style type="text/css">'                                       +
			'.scw           {padding:1px;vertical-align:middle;width:200px}'       +
			'iframe.scw     {position:absolute;z-index:' + scwZindex    +
							';top:0px;left:0px;visibility:hidden;'      +
							'width:1px;height:1px;}'                    +
			'table.scw      {padding:0px;visibility:hidden;'            +
							'position:absolute;cursor:default;'         +

							'width:200px;top:-500px;left:0px;'             +

							'z-index:' + (scwZindex+1)                  +

							';text-align:center;}'                      +

		'</style>'  );

	document.writeln(

		'<style type="text/css">'                                       +

			'/* IMPORTANT:  The SCW calendar script requires all '      +

			'               the classes defined here.'                  +

			'*/'                                                        +

			'table.scw      {padding:       1px;'                       +
							
							'vertical-align:middle;'                    +

							'border:        ridge 2px;'                 +

							'font-size:     10pt;'                      +

							'font-family:   ' +

								   'Verdana,Arial,Helvetica,Sans-Serif;'+

							'font-weight:   bold;}'                     +

			'td.scwDrag,'                                               +

			'td.scwHead                 {padding:       0px 0px;'       +

										'text-align:    center;}'       +

			'td.scwDrag                 {font-size:     8pt;}'          +

			'select.scwHead             {margin:        3px 1px;'       +

										'text-align:    center;}'       +

			'input.scwHead              {height:        22px;'          +

										'width:         22px;'          +

										'vertical-align:middle;'        +

										'text-align:    center;'        +

										'margin:        2px 1px;'       +

										'font-weight:   bold;'          +

										'font-size:     10pt;'          +

										'font-family:   fixedSys;}'     +

			'td.scwWeekNumberHead,'                                     +

			'td.scwWeek                 {padding:       0px;'           +

										'text-align:    center;'        +

										'font-weight:   bold;}'         +

			'td.scwFoot,'                                               +

			'td.scwFootHover,'                                          +

			'td.scwFoot:hover,'                                         +

			'td.scwFootDisabled         {padding:       0px;'           +

										'text-align:    center;'        +

										'font-weight:   normal;}'       +

			'table.scwCells             {text-align:    right;'         +

										'font-size:     8pt;'           +

										'width:         96%;}'          +

			'td.scwCells,'                  +

			'td.scwCellsHover,'             +

			'td.scwCells:hover,'            +

			'td.scwCellsDisabled,'          +

			'td.scwCellsExMonth,'           +

			'td.scwCellsExMonthHover,'      +

			'td.scwCellsExMonth:hover,'     +

			'td.scwCellsExMonthDisabled,'   +

			'td.scwCellsWeekend,'           +

			'td.scwCellsWeekendHover,'      +

			'td.scwCellsWeekend:hover,'     +

			'td.scwCellsWeekendDisabled,'   +

			'td.scwInputDate,'              +

			'td.scwInputDateHover,'         +

			'td.scwInputDate:hover,'        +

			'td.scwInputDateDisabled,'      +

			'td.scwWeekNo,'                 +

			'td.scwWeeks                {padding:           3px;'       +

										'width:             16px;'      +

										'height:            16px;'      +

										'border-width:      1px;'       +

										'border-style:      solid;'     +

										'font-weight:       bold;'      +

										'vertical-align:    middle;}'   +

			'/* Blend the colours into your page here...    */'         +

			'/* Calendar background */'                                 +

			'table.scw                  {background-color:  #666666;}'  +

			'/* Drag Handle */'                                         +

			'td.scwDrag                 {background-color:  #9999CC;'   +

										'color:             #CCCCFF;}'  +

			'/* Week number heading */'                                 +

			'td.scwWeekNumberHead       {color:             #6666CC;}'  +

			'/* Week day headings */'                                   +

			'td.scwWeek                 {color:             #CCCCCC;}'  +

			'/* Week numbers */'                                        +

			'td.scwWeekNo               {background-color:  #776677;'   +

										'color:             #CCCCCC;}'  +

			'/* Enabled Days */'                                        +

			'/* Week Day */'                                            +

			'td.scwCells                {background-color:  #CCCCCC;'   +

										'color:             #000000;}'  +

			'/* Day matching the input date */'                         +

			'td.scwInputDate            {background-color:  #CC9999;'   +

										'color:             #FF0000;}'  +

			'/* Weekend Day */'                                         +

			'td.scwCellsWeekend         {background-color:  #CCCCCC;'   +

										'color:             #CC6666;}'  +

			'/* Day outside the current month */'                       +

			'td.scwCellsExMonth         {background-color:  #CCCCCC;'   +

										'color:             #666666;}'  +

			'/* Today selector */'                                      +

			'td.scwFoot                 {background-color:  #000000;'   +

										'color:             #CCCCCC;'   +

										'padding: 4px 0px 4px 0px;}'    +

			'/* MouseOver/Hover formatting '                            +

			'       If you want to "turn off" any of the formatting '   +

			'       then just set to the same as the standard format'   +

			'       above.'                                             +

			' '                                                         +

			'       Note: The reason that the following are'            +

			'       implemented using both a class and a :hover'        +

			'       pseudoclass is because Opera handles the rendering' +

			'       involved in the class swap very poorly and IE6 '    +

			'       (and below) only implements pseudoclasses on the'   +

			'       anchor tag.'                                        +

			'*/'                                                        +

			'/* Active cells */'                                        +

			'td.scwCells:hover,'                                        +

			'td.scwCellsHover           {background-color:  #FFFFFF;'   +

										'cursor:            pointer;'   +

										'color:             #000000;}'  +

			'/* Day matching the input date */'                         +

			'td.scwInputDate:hover,'                                    +

			'td.scwInputDateHover       {background-color:  #FFFFFF;'   +

										'cursor:            pointer;'   +

										'color:             #000000;}'  +

			'/* Weekend cells */'                                       +

			'td.scwCellsWeekend:hover,'                                 +

			'td.scwCellsWeekendHover    {background-color:  #FFFFFF;'   +

										'cursor:            pointer;'   +

										'color:             #000000;}'  +

			'/* Day outside the current month */'                       +

			'td.scwCellsExMonth:hover,'                                 +

			'td.scwCellsExMonthHover    {background-color:  #FFFFFF;'   +

										'cursor:            pointer;'   +

										'color:             #000000;}'  +

			'/* Today selector */'                                      +

			'td.scwFoot:hover,'                                         +

			'td.scwFootHover            {color:             #FFFFFF;'   +

										'cursor:            pointer;'   +

										'font-weight:       normal;'    +

										'padding: 4px 0px 4px 0px;}'    +

			'/* Disabled cells */'                                      +

			'/* Week Day */'                                            +

			'/* Day matching the input date */'                         +

			'td.scwInputDateDisabled    {background-color:  #999999;'   +

										'color:             #000000;}'  +

			'td.scwCellsDisabled        {background-color:  #999999;'   +

										'color:             #000000;}'  +

			'/* Weekend Day */'                                         +

			'td.scwCellsWeekendDisabled {background-color:  #999999;'   +

										'color:             #CC6666;}'  +

			'/* Day outside the current month */'                       +

			'td.scwCellsExMonthDisabled {background-color:  #999999;'   +

										'color:             #666666;}'  +

			'td.scwFootDisabled         {background-color:  #6666CC;'   +

										'color:             #FFFFFF;}'  +

		'</style>'

					);

	var scwTargetEle,

		scwTriggerEle,

		scwMonthSum            = 0,

		scwBlnFullInputDate    = false,

		scwPassEnabledDay      = new Array(),

		scwSeedDate            = new Date(),

		scwParmActiveToday     = true,

		scwWeekStart           = scwWeekStart%7,

		scwToday,

		scwDrag,

		scwArrMonthNames,

		scwArrWeekInits,

		scwInvalidDateMsg,

		scwOutOfRangeMsg,

		scwDoesNotExistMsg,

		scwInvalidAlert,

		scwDateDisablingError,

		scwRangeDisablingError;



	// Add a method to format a date into the required pattern



	Date.prototype.scwFormat =

		function(scwFormat)

			{var charCount = 0,

				 codeChar  = '',

				 result    = '';



			 for (var i=0;i<=scwFormat.length;i++)

				{if (i<scwFormat.length && scwFormat.charAt(i)==codeChar)

						{// If we haven't hit the end of the string and

						 // the format string character is the same as

						 // the previous one, just clock up one to the

						 // length of the current element definition

						 charCount++;

						}

				 else   {switch (codeChar)

							{case 'y': case 'Y':

								result += (this.getFullYear()%Math.

											pow(10,charCount)).toString().

											scwPadLeft(charCount);

								break;

							 case 'm': case 'M':

								// If we find an M, check the number of them to

								// determine whether to get the month number or

								// the month name.

								result += (charCount<3)

											?(this.getMonth()+1).

												toString().scwPadLeft(charCount)

											:scwArrMonthNames[this.getMonth()];

								break;

							 case 'd': case 'D':

								// If we find a D, get the date and format it

								result += this.getDate().toString().

											scwPadLeft(charCount);

								break;

							 default:

								// Copy any unrecognised characters across

								while (charCount-- > 0) {result += codeChar;}

							}



						 if (i<scwFormat.length)

							{// Store the character we have just worked on

							 codeChar  = scwFormat.charAt(i);

							 charCount = 1;

							}

						}

				}

			 return result;

			};



	// Add a method to left pad zeroes



	String.prototype.scwPadLeft =

		function(padToLength)

			{var result = '';

			 for (var i=0;i<(padToLength - this.length);i++) {result += '0';}

			 return (result + this);

			};



	// Set up a closure so that any next function can be triggered

	// after the calendar has been closed AND that function can take

	// arguments.



	Function.prototype.runsAfterSCW =

		function()  {var func = this,

						 args = new Array(arguments.length);



					 for (var i=0;i<args.length;++i) {args[i] = arguments[i];}



					 return function()

						{// concat/join the two argument arrays

						 for (var i=0;i<arguments.length;++i) {args[args.length] = arguments[i];}

						 return (args.shift()==scwTriggerEle)?func.apply(this, args):null;

						};

					};



	// Set up some shortcuts



	function scwID(id)  {return document.getElementById(id);};



	var scwNextActionReturn, scwNextAction;





	function showCal(aCurrent,scwSource) {scwShow(aCurrent, scwSource);};




    var scwTime = '';
    
	function scwShow(aCurrent , scwSource , years , time ) {
        if ( time && time.length > 0 ) {
                scwTime = time;
        }
        
        if ( years ) {
            scwBaseYear        = scwDateNow.getFullYear() + years  ; 
        }

		scwEle = aCurrent.parentNode.getElementsByTagName('input')[0];

		if (!scwSource) scwSource = window.event;



		// getting the close Text element









		 if (scwSource.tagName) // Second parameter isn't an event it's an element

			{var scwSourceEle = scwSource;



			 if (scwID('scwIE'))  {window.event.cancelBubble = true;}

			 else {scwSourceEle.parentNode.addEventListener('click',scwStopPropagation,false);}

			}

		 else   // Second parameter is an event

			{var scwSourceEle = (scwSource.target)

									?scwSource.target

									:scwSource.srcElement;



			 // Stop the click event that opens the calendar from bubbling up to

			 // the document-level event handler that hides it!

			 if (scwSource.stopPropagation) {scwSource.stopPropagation();}

			 else                           {scwSource.cancelBubble = true;}

			}



		 scwTriggerEle = scwSourceEle;



		 // Take any parameters that there might be from the third onwards as

		 // day numbers to be disabled 0 = Sunday through to 6 = Saturday.



		 scwParmActiveToday = true;



		 for (var i=0;i<7;i++)

			{scwPassEnabledDay[(i+7-scwWeekStart)%7] = true;

			 for (var j=2;j<arguments.length;j++)

				{if (arguments[j]==i)

					{scwPassEnabledDay[(i+7-scwWeekStart)%7] = false;

					 if (scwDateNow.getDay()==i) {scwParmActiveToday = false;}

					}

				}

			}





		 scwSeedDate = scwDateNow;



		 var scwDateValue = '';



		 if (scwEle.value) {
            scwDateValue = scwEle.value.replace(/^\s+/,'').replace(/\s+$/,'');
            scwTime = ' '+ scwEle.value.substr(11,8);
         }

		 else   {if (typeof scwEle.value == 'undefined')

					{var scwChildNodes = scwEle.childNodes;

					 for (var i=0;i<scwChildNodes.length;i++)

						{if (scwChildNodes[i].nodeType == 3)

							{scwDateValue = scwChildNodes[i].nodeValue.replace(/^\s+/,'').replace(/\s+$/,'');

							 if (scwDateValue.length > 0)

								{scwTriggerEle.scwTextNode = scwChildNodes[i];

								 scwTriggerEle.scwLength   = scwChildNodes[i].nodeValue.length;

								 break;

								}

							}

						}

					}

				}



		 // Set the language-dependent elements



		 scwSetDefaultLanguage();



		 scwID('scwDragText').innerHTML = scwDrag;



		 scwID('scwMonths').options.length = 0;

		 for (var i=0;i<scwArrMonthNames.length;i++)

			{scwID('scwMonths').options[i] = new Option(scwArrMonthNames[i],scwArrMonthNames[i]);}



		 scwID('scwYears').options.length = 0;

		 for (var i=0;i<scwDropDownYears;i++)

			{scwID('scwYears').options[i] =  new Option((scwBaseYear+i),(scwBaseYear+i));}



		 for (var i=0;i<scwArrWeekInits.length;i++)

			{scwID('scwWeekInit' + i).innerHTML = scwArrWeekInits[(i+scwWeekStart)%scwArrWeekInits.length];}



		 if (scwID('scwFoot'))

			{scwID('scwFoot').innerHTML = scwToday + ' ' + scwDateNow.scwFormat(scwDateDisplayFormat);}



		 if (scwDateValue.length==0)

			{// If no value is entered and today is within the range,

			 // use today's date, otherwise use the middle of the valid range.



			 scwBlnFullInputDate=false;



			 if ((new Date(scwBaseYear+scwDropDownYears,0,0))<scwSeedDate ||

				 (new Date(scwBaseYear,0,1))                 >scwSeedDate

				)

				{scwSeedDate = new Date(scwBaseYear + Math.floor(scwDropDownYears / 2), 5, 1);}

			}

		 else

			{function scwInputFormat()

				{var scwArrSeed = new Array(),

					 scwArrInput = scwDateValue.split(new RegExp('\\\\'+scwArrDelimiters.join('\\\\')+']+','g'));





				 if (scwArrInput[0]!=null)

					{if (scwArrInput[0].length==0)                      {scwArrInput.splice(0,1);}

					 if (scwArrInput[scwArrInput.length-1].length==0)   {scwArrInput.splice(scwArrInput.length-1,1);}

					}



				 scwBlnFullInputDate = false;



				 scwDateOutputFormat = scwDateOutputFormat.toUpperCase();



				 // List all the allowed letters in the date format

				 var template = ['D','M','Y'];



				 // Prepare the sequence of date input elements

				 var result = new Array();



				 for (var i=0;i<template.length;i++)

					{if (scwDateOutputFormat.search(template[i])>-1)

						{result[scwDateOutputFormat.search(template[i])] = template[i];}

					}



				 var scwDateSequence = result.join('');



				 // Separate the elements of the date input

				 switch (scwArrInput.length)

					{case 1:

						{if (scwDateOutputFormat.indexOf('Y')>-1 &&

							 scwArrInput[0].length>scwDateOutputFormat.lastIndexOf('Y'))

							{scwArrSeed[0] = parseInt(scwArrInput[0].substring(scwDateOutputFormat.indexOf('Y'),

																			   scwDateOutputFormat.lastIndexOf('Y')+1),10);

							}

						 else   {scwArrSeed[0] = 0;}



						 if (scwDateOutputFormat.indexOf('M')>-1 &&

							 scwArrInput[0].length>scwDateOutputFormat.lastIndexOf('M'))

							{scwArrSeed[1] = scwArrInput[0].substring(scwDateOutputFormat.indexOf('M'),

																	  scwDateOutputFormat.lastIndexOf('M')+1);

							}

						 else   {scwArrSeed[1] = '6';}



						 if (scwDateOutputFormat.indexOf('D')>-1 &&

							 scwArrInput[0].length>scwDateOutputFormat.lastIndexOf('D'))

							{scwArrSeed[2] = parseInt(scwArrInput[0].substring(scwDateOutputFormat.indexOf('D'),

																			   scwDateOutputFormat.lastIndexOf('D')+1),10);

							}

						 else   {scwArrSeed[2] = 1;}



						 if (scwArrInput[0].length==scwDateOutputFormat.length) {scwBlnFullInputDate = true;}

						 break;

						}

					 case 2:

						{// Year and Month entry

						 scwArrSeed[0] =

							 parseInt(scwArrInput[scwDateSequence.

													replace(/D/i,'').

													search(/Y/i)],10);  // Year

						 scwArrSeed[1] = scwArrInput[scwDateSequence.

													replace(/D/i,'').

													search(/M/i)];      // Month

						 scwArrSeed[2] = 1;                             // Day

						 break;

						}

					 case 3:

						{// Day Month and Year entry



						 scwArrSeed[0] =

							 parseInt(scwArrInput[scwDateSequence.

													search(/Y/i)],10);  // Year

						 scwArrSeed[1] = scwArrInput[scwDateSequence.

													search(/M/i)];      // Month

						 scwArrSeed[2] =

							 parseInt(scwArrInput[scwDateSequence.

													search(/D/i)],10);  // Day



						 scwBlnFullInputDate = true;

						 break;

						}

					 default:

						{// A stuff-up has led to more than three elements in

						 // the date.

						 scwArrSeed[0] = 0;     // Year

						 scwArrSeed[1] = 0;     // Month

						 scwArrSeed[2] = 0;     // Day

						}

					}





				 var scwExpValDay    = new RegExp('^(0?[1-9]|[1-2][0-9]|3[0-1])$'),

					 scwExpValMonth  = new RegExp('^(0?[1-9]|1[0-2]|'        +

												  scwArrMonthNames.join('|') +

												  ')$','i'),

					 scwExpValYear   = new RegExp('^([0-9]{1,2}|[0-9]{4})$');



				 // Apply validation and report failures



				 if (scwExpValYear.exec(scwArrSeed[0])  == null ||

					 scwExpValMonth.exec(scwArrSeed[1]) == null ||

					 scwExpValDay.exec(scwArrSeed[2])   == null

					)

					{if (scwShowInvalidDateMsg)

						{alert(scwInvalidDateMsg  +

							   scwInvalidAlert[0] + scwDateValue +

							   scwInvalidAlert[1]);}

					 scwBlnFullInputDate = false;

					 scwArrSeed[0] = scwBaseYear +

									 Math.floor(scwDropDownYears/2); // Year

					 scwArrSeed[1] = '6';                            // Month

					 scwArrSeed[2] = 1;                              // Day

					}



				 // Return the  Year    in scwArrSeed[0]

				 //             Month   in scwArrSeed[1]

				 //             Day     in scwArrSeed[2]



				 return scwArrSeed;

				};



			 // Parse the string into an array using the allowed delimiters



			 scwArrSeedDate = scwInputFormat();



			 // in which case it assumes the 20th Century is intended.



			 if (scwArrSeedDate[0]<100) {scwArrSeedDate[0] += (scwArrSeedDate[0]>50)?1900:2000;}



			 // Check whether the month is in digits or an abbreviation



			/* if (scwArrSeedDate[1].search(/\\d+/)!=0)

				{month = scwArrMonthNames.join('|').toUpperCase().

							search(scwArrSeedDate[1].substr(0,3).

													toUpperCase());

				 scwArrSeedDate[1] = Math.floor(month/4)+1;

				}

                 */

			 scwSeedDate = new Date(scwArrSeedDate[0],scwArrSeedDate[1]-1,scwArrSeedDate[2]);

			}



			// Test that we have arrived at a valid date



		 if (isNaN(scwSeedDate))

			{if (scwShowInvalidDateMsg) {alert(scwInvalidDateMsg + scwInvalidAlert[0] + scwDateValue + scwInvalidAlert[1]);}

			 scwSeedDate = new Date(scwBaseYear + Math.floor(scwDropDownYears/2),5,1);

			 scwBlnFullInputDate=false;

			}

		 else

			{// Test that the date is within range,

			 // if not then set date to a sensible date in range.



			 if ((new Date(scwBaseYear,0,1)) > scwSeedDate)

				{if (scwBlnStrict && scwShowOutOfRangeMsg) {alert(scwOutOfRangeMsg);}

				 scwSeedDate = new Date(scwBaseYear,0,1);

				 scwBlnFullInputDate=false;

				}

			 else

				{if ((new Date(scwBaseYear+scwDropDownYears,0,0))<scwSeedDate)

					{if (scwBlnStrict && scwShowOutOfRangeMsg) {alert(scwOutOfRangeMsg);}

					 scwSeedDate = new Date(scwBaseYear + Math.floor(scwDropDownYears)-1,11,1);

					 scwBlnFullInputDate=false;

					}

				 else

					{if (scwBlnStrict && scwBlnFullInputDate &&

						  (scwSeedDate.getDate()      != scwArrSeedDate[2] ||

						   (scwSeedDate.getMonth()+1) != scwArrSeedDate[1] ||

						   scwSeedDate.getFullYear()  != scwArrSeedDate[0]

						  )

						)

						{if (scwShowDoesNotExistMsg) alert(scwDoesNotExistMsg);

						 scwSeedDate = new Date(scwSeedDate.getFullYear(),scwSeedDate.getMonth()-1,1);

						 scwBlnFullInputDate=false;

						}

					}

				}

			}



		 // Test the disabled dates for validity

		 // Give error message if not valid.



		 for (var i=0;i<scwDisabledDates.length;i++)

			{if (!((typeof scwDisabledDates[i] == 'object') && (scwDisabledDates[i].constructor == Date)))

				{if ((typeof scwDisabledDates[i] == 'object') && (scwDisabledDates[i].constructor == Array))

					{var scwPass = true;



					 if (scwDisabledDates[i].length !=2)

						{if (scwShowRangeDisablingError)

							{alert(scwRangeDisablingError[0] + scwDisabledDates[i] + scwRangeDisablingError[1]);}

						 scwPass = false;

						}

					 else

						{for (var j=0;j<scwDisabledDates[i].length;j++)

							{if (!((typeof scwDisabledDates[i][j] == 'object') && (scwDisabledDates[i][j].constructor == Date)))

								{if (scwShowRangeDisablingError)

									{alert(  scwDateDisablingError[0] + scwDisabledDates[i][j] + scwDateDisablingError[1]);}

								 scwPass = false;

								}

							}

						}



					 if (scwPass && (scwDisabledDates[i][0] > scwDisabledDates[i][1])) {scwDisabledDates[i].reverse();}

					}

				 else

					{if (scwShowRangeDisablingError) {alert(scwDateDisablingError[0] + scwDisabledDates[i] + scwDateDisablingError[1]);}}

				}

			}



		 // Calculate the number of months that the entered (or

		 // defaulted) month is after the start of the allowed

		 // date range.



		 scwMonthSum =  12*(scwSeedDate.getFullYear()-scwBaseYear)+scwSeedDate.getMonth();



		 scwID('scwYears' ).options.selectedIndex = Math.floor(scwMonthSum/12);

		 scwID('scwMonths').options.selectedIndex = (scwMonthSum%12);



		 // Check whether or not dragging is allowed and display drag handle if necessary



		 scwID('scwDrag').style.display=(scwAllowDrag)?'':'none';



		 // Display the month



		 scwShowMonth(0);



		 // Position the calendar box



		 scwTargetEle=scwEle;



		 var offsetTop =parseInt(scwEle.offsetTop ,10) + parseInt(scwEle.offsetHeight,10),

			 offsetLeft=parseInt(scwEle.offsetLeft,10);



		 if (!window.opera)

			 {while (scwEle.tagName!='BODY' && scwEle.tagName!='HTML')

				 {offsetTop -=parseInt(scwEle.scrollTop, 10);

				  offsetLeft-=parseInt(scwEle.scrollLeft,10);

				  scwEle=scwEle.parentNode;

				 }

			  scwEle=scwTargetEle;

			 }



		 do {scwEle=scwEle.offsetParent;

			 offsetTop +=parseInt(scwEle.offsetTop, 10);

			 offsetLeft+=parseInt(scwEle.offsetLeft,10);

			}

		 while (scwEle.tagName!='BODY' && scwEle.tagName!='HTML');



		 scwID('scw').style.top =offsetTop +'px';

		 scwID('scw').style.left=offsetLeft+'px';



		 scwID('scwIframe').style.top=offsetTop +'px';

		 scwID('scwIframe').style.left=offsetLeft+'px';

		 scwID('scwIframe').style.width=(scwID('scw').offsetWidth-(scwID('scwIE')?2:4))+'px';

		 scwID('scwIframe').style.height=(scwID('scw').offsetHeight-(scwID('scwIE')?2:4))+'px';

		 scwID('scwIframe').style.visibility='inherit';



		 // Show it on the page

		 scwID('scw').style.visibility='inherit';

		};



	function scwHide()

		{scwID('scw').style.visibility='hidden';

		 scwID('scwIframe').style.visibility='hidden';

		 if (typeof scwNextAction!='undefined' && scwNextAction!=null)

			 {scwNextActionReturn = scwNextAction();

			  // Explicit null set to prevent closure causing memory leak

			  scwNextAction = null;

			 }

		};



	function scwCancel(scwEvt)

		{if (scwClickToHide) {scwHide();}

		 scwStopPropagation(scwEvt);

		};



	function scwStopPropagation(scwEvt)

		{if (scwEvt.stopPropagation)

				{scwEvt.stopPropagation();}     // Capture phase

		 else   {scwEvt.cancelBubble = true;}   // Bubbling phase

		};



	function scwBeginDrag(event)

		{var elementToDrag = scwID('scw');



		 var deltaX    = event.clientX,

			 deltaY    = event.clientY,

			 offsetEle = elementToDrag;



		 do {deltaX   -= parseInt(offsetEle.offsetLeft,10);

			 deltaY   -= parseInt(offsetEle.offsetTop ,10);

			 offsetEle = offsetEle.offsetParent;

			}

		 while (offsetEle.tagName!='BODY' &&

				offsetEle.tagName!='HTML');



		 if (document.addEventListener)

				{document.addEventListener('mousemove',moveHandler,true);        // Capture phase

				 document.addEventListener('mouseup',  upHandler,  true);        // Capture phase

				}

		 else   {elementToDrag.attachEvent('onmousemove',moveHandler); // Bubbling phase

				 elementToDrag.attachEvent('onmouseup',  upHandler);   // Bubbling phase

				 elementToDrag.setCapture();

				}



		 scwStopPropagation(event);



		 function moveHandler(scwEvt)

			{if (!scwEvt) scwEvt = window.event;



			 elementToDrag.style.left = (scwEvt.clientX - deltaX) + 'px';

			 elementToDrag.style.top  = (scwEvt.clientY - deltaY) + 'px';



			 scwID('scwIframe').style.left = (scwEvt.clientX - deltaX) + 'px';

			 scwID('scwIframe').style.top  = (scwEvt.clientY - deltaY) + 'px';



			 scwStopPropagation(scwEvt);

			};



		 function upHandler(scwEvt)

			{if (!scwEvt) scwEvt = window.event;



			 if (document.removeEventListener)

					{document.removeEventListener('mousemove',moveHandler,true);     // Capture phase

					 document.removeEventListener('mouseup',  upHandler,  true);     // Capture phase

					}

			 else   {elementToDrag.detachEvent('onmouseup',  upHandler);   // Bubbling phase

					 elementToDrag.detachEvent('onmousemove',moveHandler); // Bubbling phase

					 elementToDrag.releaseCapture();

					}



			 scwStopPropagation(scwEvt);

			};

		};



	function scwShowMonth(scwBias)

		{// Set the selectable Month and Year

		 // May be called: from the left and right arrows

		 //                  (shift month -1 and +1 respectively)

		 //                from the month selection list

		 //                from the year selection list

		 //                from the showCal routine

		 //                  (which initiates the display).



		 var scwShowDate  = new Date(Date.parse(new Date().toDateString())),

			 scwStartDate = new Date();



		 // Set the time to the middle of the day so that the handful of

		 // regions that have daylight saving shifts that change the day

		 // of the month (i.e. turn the clock back at midnight or forward

		 // at 23:00) do not mess up the date display in the calendar.



		 scwShowDate.setHours(12);



		 scwSelYears  = scwID('scwYears');

		 scwSelMonths = scwID('scwMonths');



		 if (scwSelYears.options.selectedIndex>-1)

			{scwMonthSum=12*(scwSelYears.options.selectedIndex)+scwBias;

			 if (scwSelMonths.options.selectedIndex>-1) {scwMonthSum+=scwSelMonths.options.selectedIndex;}

			}

		 else

			{if (scwSelMonths.options.selectedIndex>-1) {scwMonthSum+=scwSelMonths.options.selectedIndex;}}



		 scwShowDate.setFullYear(scwBaseYear + Math.floor(scwMonthSum/12),(scwMonthSum%12),1);



		 // If the Week numbers are displayed, shift the week day names to the right.

		 scwID('scwWeek_').style.display=(scwWeekNumberDisplay)?'':'none';



		 // Opera has a bug with setting the selected index.

		 // It requires the following work-around to force SELECTs to display correctly.

		 if (window.opera)

			{scwID('scwMonths').style.display = 'inherit';

			 scwID('scwYears' ).style.display = 'inherit';

		   }



		 // Set the drop down boxes.

		 scwTemp = (12*parseInt((scwShowDate.getFullYear()-scwBaseYear),10)) + parseInt(scwShowDate.getMonth(),10);



		 if (scwTemp > -1 && scwTemp < (12*scwDropDownYears))

			{scwSelYears.options.selectedIndex=Math.floor(scwMonthSum/12);

			 scwSelMonths.options.selectedIndex=(scwMonthSum%12);



			 scwCurMonth = scwShowDate.getMonth();



			 scwShowDate.setDate((((scwShowDate.

									getDay()-scwWeekStart)<0)?-6:1)+

								 scwWeekStart-scwShowDate.getDay());



			 // This statement moved by Michael Cerveny to make version 3.55

			 var scwCompareDateValue = new Date(scwShowDate.getFullYear(),

												scwShowDate.getMonth(),

												scwShowDate.getDate()).valueOf();



			 scwStartDate = new Date(scwShowDate);



			 if (scwID('scwFoot'))

				{var scwFoot = scwID('scwFoot');



				 function scwFootOutput() {scwSetOutput(scwDateNow);};



				 if (scwDisabledDates.length==0)

					{if (scwActiveToday && scwParmActiveToday)

						{scwFoot.onclick     = scwFootOutput;

						 scwFoot.className   = 'scwFoot';



						 if (scwID('scwIE'))

							{scwFoot.onmouseover  = scwChangeClass;

							 scwFoot.onmouseout   = scwChangeClass;

							}



						}

					 else

						{scwFoot.onclick     = null;

						 scwFoot.className   = 'scwFootDisabled';



						 if (scwID('scwIE'))

							{scwFoot.onmouseover  = null;

							 scwFoot.onmouseout   = null;

							}



						 if (document.addEventListener)

								{scwFoot.addEventListener('click',scwStopPropagation,false);}

						 else   {scwFoot.attachEvent('onclick',scwStopPropagation);}

						}

					}

				 else

					{for (var k=0;k<scwDisabledDates.length;k++)

						{if (!scwActiveToday || !scwParmActiveToday ||

							 ((typeof scwDisabledDates[k] == 'object')                   &&

								 (((scwDisabledDates[k].constructor == Date)             &&

								   scwDateNow.valueOf() == scwDisabledDates[k].valueOf()

								  ) ||

								  ((scwDisabledDates[k].constructor == Array)               &&

								   scwDateNow.valueOf() >= scwDisabledDates[k][0].valueOf() &&

								   scwDateNow.valueOf() <= scwDisabledDates[k][1].valueOf()

								  )

								 )

							 )

							)

							{scwFoot.onclick     = null;

							 scwFoot.className   = 'scwFootDisabled';



							 if (scwID('scwIE'))

								{scwFoot.onmouseover  = null;

								 scwFoot.onmouseout   = null;

								}



							 if (document.addEventListener)

									{scwFoot.addEventListener('click',scwStopPropagation,false);}

							 else   {scwFoot.attachEvent('onclick',scwStopPropagation);}

							 break;

							}

						 else

							{scwFoot.onclick=scwFootOutput;

							 scwFoot.className='scwFoot';



							 if (scwID('scwIE'))

								{scwFoot.onmouseover  = scwChangeClass;

								 scwFoot.onmouseout   = scwChangeClass;

								}

							}

						}

					}

				}



			 function scwSetOutput(scwOutputDate)

				{if (typeof scwTargetEle.value == 'undefined')

					  {scwTriggerEle.scwTextNode.replaceData(0,scwTriggerEle.scwLength,scwOutputDate.scwFormat(scwDateOutputFormat));}

				 else {scwTargetEle.value = scwOutputDate.scwFormat(scwDateOutputFormat) + scwTime;
                 scwTime = '';
                 }

				 scwHide();

				};



			 function scwCellOutput(scwEvt,time)

				{var scwEle = scwEventTrigger(scwEvt),

					 scwOutputDate = new Date(scwStartDate);



				 if (scwEle.nodeType==3) scwEle=scwEle.parentNode;



				 scwOutputDate.setDate(scwStartDate.getDate() + parseInt(scwEle.id.substr(8),10));



				 scwSetOutput(scwOutputDate,time);

				};



			 function scwChangeClass(scwEvt)

				{var scwEle = scwEventTrigger(scwEvt);



				 if (scwEle.nodeType==3) {scwEle=scwEle.parentNode;}



				 switch (scwEle.className)

					{case 'scwCells':

						scwEle.className = 'scwCellsHover';

						break;

					 case 'scwCellsHover':

						scwEle.className = 'scwCells';

						break;

					 case 'scwCellsExMonth':

						scwEle.className = 'scwCellsExMonthHover';

						break;

					 case 'scwCellsExMonthHover':

						scwEle.className = 'scwCellsExMonth';

						break;

					 case 'scwCellsWeekend':

						scwEle.className = 'scwCellsWeekendHover';

						break;

					 case 'scwCellsWeekendHover':

						scwEle.className = 'scwCellsWeekend';

						break;

					 case 'scwFoot':

						scwEle.className = 'scwFootHover';

						break;

					 case 'scwFootHover':

						scwEle.className = 'scwFoot';

						break;

					 case 'scwInputDate':

						scwEle.className = 'scwInputDateHover';

						break;

					 case 'scwInputDateHover':

						scwEle.className = 'scwInputDate';

					}



				 return true;

				}



			 function scwEventTrigger(scwEvt)

				{if (!scwEvt) {scwEvt = event;}

				 return scwEvt.target||scwEvt.srcElement;

				};



			 function scwWeekNumber(scwInDate)

				{// The base day in the week of the input date

				 var scwInDateWeekBase = new Date(scwInDate);



				 scwInDateWeekBase.setDate(scwInDateWeekBase.getDate()

											- scwInDateWeekBase.getDay()

											+ scwWeekNumberBaseDay

											+ ((scwInDate.getDay()>

												scwWeekNumberBaseDay)?7:0));



				 // The first Base Day in the year

				 var scwFirstBaseDay = new Date(scwInDateWeekBase.getFullYear(),0,1);



				 scwFirstBaseDay.setDate(scwFirstBaseDay.getDate()

											- scwFirstBaseDay.getDay()

											+ scwWeekNumberBaseDay

										);



				 if (scwFirstBaseDay < new Date(scwInDateWeekBase.getFullYear(),0,1))

					{scwFirstBaseDay.setDate(scwFirstBaseDay.getDate()+7);}



				 // Start of Week 01

				 var scwStartWeekOne = new Date(scwFirstBaseDay

												- scwWeekNumberBaseDay

												+ scwInDate.getDay());



				 if (scwStartWeekOne > scwFirstBaseDay)

					{scwStartWeekOne.setDate(scwStartWeekOne.getDate()-7);}



				 // Subtract the date of the current week from the date of the

				 // first week of the year to get the number of weeks in

				 // milliseconds.  Divide by the number of milliseconds

				 // in a week then round to no decimals in order to remove

				 // the effect of daylight saving.  Add one to make the first

				 // week, week 1.  Place a string zero on the front so that

				 // week numbers are zero filled.



				 var scwWeekNo = '0' + (Math.round((scwInDateWeekBase - scwFirstBaseDay)/604800000,0) + 1);



				 // Return the last two characters in the week number string



				 return scwWeekNo.substring(scwWeekNo.length-2, scwWeekNo.length);

				};



			 // Treewalk to display the dates.

			 // I tried to use getElementsByName but IE refused to cooperate

			 // so I resorted to this method which works for all tested

			 // browsers.



			 var scwCells = scwID('scwCells');



			 for (i=0;i<scwCells.childNodes.length;i++)

				{var scwRows = scwCells.childNodes[i];

				 if (scwRows.nodeType==1 && scwRows.tagName=='TR')

					{if (scwWeekNumberDisplay)

						{//Calculate the week number using scwShowDate

						 scwTmpEl = scwRows.childNodes[0];

						 scwTmpEl.innerHTML = scwWeekNumber(scwShowDate);

						 scwTmpEl.style.borderColor =

							 (scwTmpEl.currentStyle)

								?scwTmpEl.currentStyle['backgroundColor']

								:(window.getComputedStyle)

									?document.defaultView.getComputedStyle(scwTmpEl,null).getPropertyValue('background-color')

									:'';

						 scwTmpEl.style.display='';

						}

					 else

						{scwRows.childNodes[0].style.display='none';}



					 for (j=1;j<scwRows.childNodes.length;j++)

						{var scwCols = scwRows.childNodes[j];

						 if (scwCols.nodeType==1 && scwCols.tagName=='TD')

							{scwRows.childNodes[j].innerHTML=

								scwShowDate.getDate();

							 var scwCell=scwRows.childNodes[j],

								 scwDisabled =

									((scwOutOfRangeDisable &&

										(scwShowDate <

											(new Date(scwBaseYear,0,1,

													  scwShowDate.getHours()))

										 ||

										 scwShowDate >

											(new Date(scwBaseYear+

													  scwDropDownYears,0,0,

													  scwShowDate.getHours()))

										)

									 ) ||

									 (scwOutOfMonthDisable &&

										(scwShowDate <

											(new Date(scwShowDate.getFullYear(),

													  scwCurMonth,1,

													  scwShowDate.getHours()))

										 ||

										 scwShowDate >

											(new Date(scwShowDate.getFullYear(),

													  scwCurMonth+1,0,

													  scwShowDate.getHours()))

										)

									 )

									)?true:false;



							 scwCell.style.visibility =

								(scwOutOfMonthHide &&

									(scwShowDate <

										(new Date(scwShowDate.getFullYear(),

												  scwCurMonth,1,

												  scwShowDate.getHours()))

									 ||

									 scwShowDate >

										(new Date(scwShowDate.getFullYear(),

												  scwCurMonth+1,0,

												  scwShowDate.getHours()))

									)

								)?'hidden':'inherit';



							 for (var k=0;k<scwDisabledDates.length;k++)

								{if ((typeof scwDisabledDates[k]=='object') &&

									 (scwDisabledDates[k].constructor == Date) &&

									 scwCompareDateValue == scwDisabledDates[k].valueOf()

									)

									{scwDisabled = true;}

								 else

									{if ((typeof scwDisabledDates[k]=='object') &&

										 (scwDisabledDates[k].constructor == Array) &&

										 scwCompareDateValue >= scwDisabledDates[k][0].valueOf() &&

										 scwCompareDateValue <= scwDisabledDates[k][1].valueOf()

										)

										{scwDisabled = true;}

									}

								}



							 if (scwDisabled ||

								 !scwEnabledDay[j-1+(7*((i*scwCells.childNodes.length)/6))] ||

								 !scwPassEnabledDay[(j-1+(7*(i*scwCells.childNodes.length/6)))%7]

								)

								{scwRows.childNodes[j].onclick = null;



								 if (scwID('scwIE'))

									{scwRows.childNodes[j].onmouseover  = null;

									 scwRows.childNodes[j].onmouseout   = null;

									}



								 scwCell.className=

									(scwShowDate.getMonth()!=scwCurMonth)

										?'scwCellsExMonthDisabled'

										:(scwBlnFullInputDate &&

										  scwShowDate.toDateString()==

										  scwSeedDate.toDateString())

											?'scwInputDateDisabled'

											:(scwShowDate.getDay()%6==0)

												?'scwCellsWeekendDisabled'

												:'scwCellsDisabled';



								 scwCell.style.borderColor =

									 (scwFormatTodayCell && scwShowDate.toDateString()==scwDateNow.toDateString())

										?scwTodayCellBorderColour

										:(scwCell.currentStyle)

											?scwCell.currentStyle['backgroundColor']

											:(window.getComputedStyle)

												?document.defaultView.getComputedStyle(scwCell,null).getPropertyValue('background-color')

												:'';

								}

							 else

								{scwRows.childNodes[j].onclick=scwCellOutput;



								 if (scwID('scwIE'))

									{scwRows.childNodes[j].onmouseover  = scwChangeClass;

									 scwRows.childNodes[j].onmouseout   = scwChangeClass;

									}



								 scwCell.className=

									 (scwShowDate.getMonth()!=scwCurMonth)

										?'scwCellsExMonth'

										:(scwBlnFullInputDate &&

										  scwShowDate.toDateString()==

										  scwSeedDate.toDateString())

											?'scwInputDate'

											:(scwShowDate.getDay()%6==0)

												?'scwCellsWeekend'

												:'scwCells';



								 scwCell.style.borderColor =

									 (scwFormatTodayCell && scwShowDate.toDateString() == scwDateNow.toDateString())

										?scwTodayCellBorderColour

										:(scwCell.currentStyle)

											?scwCell.currentStyle['backgroundColor']

											:(window.getComputedStyle)

												?document.defaultView.getComputedStyle(scwCell,null).getPropertyValue('background-color')

												:'';

							   }



							 scwShowDate.setDate(scwShowDate.getDate()+1);

							 scwCompareDateValue = new Date(scwShowDate.getFullYear(),scwShowDate.getMonth(),scwShowDate.getDate()).valueOf();

							}

						}

					}

				}

			}



		 // Opera has a bug with setting the selected index.

		 // It requires the following work-around to force SELECTs to display correctly.

		 // Also Opera's poor dynamic rendering prior to 9.5 requires

		 // the visibility to be reset to prevent garbage in the calendar

		 // when the displayed month is changed.



		 if (window.opera)

			{scwID('scwMonths').style.display = 'inline';

			 scwID('scwYears' ).style.display = 'inline';

			 scwID('scw').style.visibility='hidden';

			 scwID('scw').style.visibility='inherit';

		   }

		};



// *************************

//  End of Function Library

// *************************

// ***************************

// Start of Calendar structure

// ***************************



	document.writeln("<!--[if IE]><div id='scwIE'></div><![endif]-->");

	document.writeln("<!--[if lt IE 7]><div id='scwIElt7'></div><![endif]-->");

	document.write(

	 "<iframe class='scw' " + (scwID('scwIElt7')?"src='/scwblank.html '":'') +

			 "id='scwIframe' name='scwIframe' frameborder='0'>" +

	 "</iframe>" +

	 "<table id='scw' class='scw'>" +

	   "<tr class='scw'>" +

		 "<td class='scw'>" +

		   "<table class='scwHead' id='scwHead' width='100%' " +

					"cellspacing='0' cellpadding='0'>" +

			"<tr id='scwDrag' style='display:none;'>" +

				"<td colspan='4' class='scwDrag' " +

					"onmousedown='scwBeginDrag(event);'>" +

					"<div id='scwDragText'></div>" +

				"</td>" +

			"</tr>" +

			"<tr class='scwHead' >" +

				 "<td class='scwHead'>" +

					"<input class='scwHead' id='scwHeadLeft' type='button' value='<' " +

							"onclick='scwShowMonth(-1);'  /></td>" +

				 "<td class='scwHead'>" +

					"<select id='scwMonths' class='scwHead' " +

							"onchange='scwShowMonth(0);'>" +

					"</select>" +

				 "</td>" +

				 "<td class='scwHead'>" +

					"<select id='scwYears' class='scwHead' " +

							"onchange='scwShowMonth(0);'>" +

					"</select>" +

				 "</td>" +

				 "<td class='scwHead'>" +

					"<input class='scwHead' id='scwHeadRight' type='button' value='>' " +

							"onclick='scwShowMonth(1);' /></td>" +

				"</tr>" +

			  "</table>" +

			"</td>" +

		  "</tr>" +

		  "<tr class='scw'>" +

			"<td class='scw'>" +

			  "<table class='scwCells' align='center'>" +

				"<thead>" +

				  "<tr><td class='scwWeekNumberHead' id='scwWeek_' ></td>");



	for (i=0;i<7;i++)

		{document.write(

					  "<td class='scwWeek' id='scwWeekInit" + i + "'></td>");

		}



	document.write("</tr>" +

				"</thead>" +

				"<tbody id='scwCells' " +

						"onClick='scwStopPropagation(event);'>");



	for (i=0;i<6;i++)

		{document.write(

					"<tr>" +

					  "<td class='scwWeekNo' id='scwWeek_" + i + "'></td>");

		 for (j=0;j<7;j++)

			{document.write(

						"<td class='scwCells' id='scwCell_" + (j+(i*7)) +

						"'></td>");

			}



		 document.write(

					"</tr>");

		}



	document.write(

				"</tbody>");



	if ((new Date(scwBaseYear + scwDropDownYears, 0, 0)) > scwDateNow &&

		(new Date(scwBaseYear, 0, 0))                    < scwDateNow)

		{document.write(

				  "<tfoot class='scwFoot'>" +

					"<tr class='scwFoot'>" +

					  "<td class='scwFoot' id='scwFoot' colspan='8'>" +

					  "</td>" +

					"</tr>" +

				  "</tfoot>");

		}



	document.write(

			  "</table>" +

			"</td>" +

		  "</tr>" +

		"</table>");



	if (document.addEventListener)

			{scwID('scw'         ).addEventListener('click',scwCancel,false);

			 scwID('scwHeadLeft' ).addEventListener('click',scwStopPropagation,false);

			 scwID('scwMonths'   ).addEventListener('click',scwStopPropagation,false);

			 scwID('scwMonths'   ).addEventListener('change',scwStopPropagation,false);

			 scwID('scwYears'    ).addEventListener('click',scwStopPropagation,false);

			 scwID('scwYears'    ).addEventListener('change',scwStopPropagation,false);

			 scwID('scwHeadRight').addEventListener('click',scwStopPropagation,false);

			}

	else    {scwID('scw'         ).attachEvent('onclick',scwCancel);

			 scwID('scwHeadLeft' ).attachEvent('onclick',scwStopPropagation);

			 scwID('scwMonths'   ).attachEvent('onclick',scwStopPropagation);

			 scwID('scwMonths'   ).attachEvent('onchange',scwStopPropagation);

			 scwID('scwYears'    ).attachEvent('onclick',scwStopPropagation);

			 scwID('scwYears'    ).attachEvent('onchange',scwStopPropagation);

			 scwID('scwHeadRight').attachEvent('onclick',scwStopPropagation);

			}



// ***************************

//  End of Calendar structure

// ***************************

// ****************************************

// Start of document level event definition

// ****************************************



	if (document.addEventListener)

			{document.addEventListener('click',scwHide, false);}

	else    {document.attachEvent('onclick',scwHide);}



// ****************************************

//  End of document level event definition

// ****************************************

// ************************************

//  End of Simple Calendar Widget Code

// ************************************


	function get_html_translation_table(table, quote_style) {
	    // Returns the internal translation table used by htmlspecialchars and htmlentities  
	    // 
	    // version: 906.401
	    // discuss at: http://phpjs.org/functions/get_html_translation_table
	    // +   original by: Philip Peterson
	    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	    // +   bugfixed by: noname
	    // +   bugfixed by: Alex
	    // +   bugfixed by: Marco
	    // +   bugfixed by: madipta
	    // +   improved by: KELAN
	    // +   improved by: Brett Zamir (http://brett-zamir.me)
	    // +    bugfixed by: Brett Zamir (http://brett-zamir.me)
	    // %          note: It has been decided that we're not going to add global
	    // %          note: dependencies to php.js. Meaning the constants are not
	    // %          note: real constants, but strings instead. integers are also supported if someone
	    // %          note: chooses to create the constants themselves.
	    // *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
	    // *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}
	    
	    var entities = {}, histogram = {}, decimal = 0, symbol = '';
	    var constMappingTable = {}, constMappingQuoteStyle = {};
	    var useTable = {}, useQuoteStyle = {};
	    
	    // Translate arguments
	    constMappingTable[0]      = 'HTML_SPECIALCHARS';
	    constMappingTable[1]      = 'HTML_ENTITIES';
	    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
	    constMappingQuoteStyle[2] = 'ENT_COMPAT';
	    constMappingQuoteStyle[3] = 'ENT_QUOTES';

	    useTable       = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
	    useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';

	    if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
	        throw new Error("Table: "+useTable+' not supported');
	        // return false;
	    }

	    if (useTable === 'HTML_ENTITIES') {
	        entities['160'] = '&nbsp;';
	        entities['161'] = '&iexcl;';
	        entities['162'] = '&cent;';
	        entities['163'] = '&pound;';
	        entities['164'] = '&curren;';
	        entities['165'] = '&yen;';
	        entities['166'] = '&brvbar;';
	        entities['167'] = '&sect;';
	        entities['168'] = '&uml;';
	        entities['169'] = '&copy;';
	        entities['170'] = '&ordf;';
	        entities['171'] = '&laquo;';
	        entities['172'] = '&not;';
	        entities['173'] = '&shy;';
	        entities['174'] = '&reg;';
	        entities['175'] = '&macr;';
	        entities['176'] = '&deg;';
	        entities['177'] = '&plusmn;';
	        entities['178'] = '&sup2;';
	        entities['179'] = '&sup3;';
	        entities['180'] = '&acute;';
	        entities['181'] = '&micro;';
	        entities['182'] = '&para;';
	        entities['183'] = '&middot;';
	        entities['184'] = '&cedil;';
	        entities['185'] = '&sup1;';
	        entities['186'] = '&ordm;';
	        entities['187'] = '&raquo;';
	        entities['188'] = '&frac14;';
	        entities['189'] = '&frac12;';
	        entities['190'] = '&frac34;';
	        entities['191'] = '&iquest;';
	        entities['192'] = '&Agrave;';
	        entities['193'] = '&Aacute;';
	        entities['194'] = '&Acirc;';
	        entities['195'] = '&Atilde;';
	        entities['196'] = '&Auml;';
	        entities['197'] = '&Aring;';
	        entities['198'] = '&AElig;';
	        entities['199'] = '&Ccedil;';
	        entities['200'] = '&Egrave;';
	        entities['201'] = '&Eacute;';
	        entities['202'] = '&Ecirc;';
	        entities['203'] = '&Euml;';
	        entities['204'] = '&Igrave;';
	        entities['205'] = '&Iacute;';
	        entities['206'] = '&Icirc;';
	        entities['207'] = '&Iuml;';
	        entities['208'] = '&ETH;';
	        entities['209'] = '&Ntilde;';
	        entities['210'] = '&Ograve;';
	        entities['211'] = '&Oacute;';
	        entities['212'] = '&Ocirc;';
	        entities['213'] = '&Otilde;';
	        entities['214'] = '&Ouml;';
	        entities['215'] = '&times;';
	        entities['216'] = '&Oslash;';
	        entities['217'] = '&Ugrave;';
	        entities['218'] = '&Uacute;';
	        entities['219'] = '&Ucirc;';
	        entities['220'] = '&Uuml;';
	        entities['221'] = '&Yacute;';
	        entities['222'] = '&THORN;';
	        entities['223'] = '&szlig;';
	        entities['224'] = '&agrave;';
	        entities['225'] = '&aacute;';
	        entities['226'] = '&acirc;';
	        entities['227'] = '&atilde;';
	        entities['228'] = '&auml;';
	        entities['229'] = '&aring;';
	        entities['230'] = '&aelig;';
	        entities['231'] = '&ccedil;';
	        entities['232'] = '&egrave;';
	        entities['233'] = '&eacute;';
	        entities['234'] = '&ecirc;';
	        entities['235'] = '&euml;';
	        entities['236'] = '&igrave;';
	        entities['237'] = '&iacute;';
	        entities['238'] = '&icirc;';
	        entities['239'] = '&iuml;';
	        entities['240'] = '&eth;';
	        entities['241'] = '&ntilde;';
	        entities['242'] = '&ograve;';
	        entities['243'] = '&oacute;';
	        entities['244'] = '&ocirc;';
	        entities['245'] = '&otilde;';
	        entities['246'] = '&ouml;';
	        entities['247'] = '&divide;';
	        entities['248'] = '&oslash;';
	        entities['249'] = '&ugrave;';
	        entities['250'] = '&uacute;';
	        entities['251'] = '&ucirc;';
	        entities['252'] = '&uuml;';
	        entities['253'] = '&yacute;';
	        entities['254'] = '&thorn;';
	        entities['255'] = '&yuml;';
	    }

	    if (useQuoteStyle !== 'ENT_NOQUOTES') {
	        entities['34'] = '&quot;';
	    }
	    if (useQuoteStyle === 'ENT_QUOTES') {
	        entities['39'] = '&#39;';
	    }
	    entities['60'] = '&lt;';
	    entities['62'] = '&gt;';

	    // ascii decimals for better compatibility
	    entities['38'] = '&amp;';

	    // ascii decimals to real symbols
	    for (decimal in entities) {
	        symbol = String.fromCharCode(decimal);
	        histogram[symbol] = entities[decimal];
	    }
	    
	    return histogram;
	}

	
	function htmlspecialchars (string, quote_style) {
	    // Convert special characters to HTML entities  
	    // 
	    // version: 906.401
	    // discuss at: http://phpjs.org/functions/htmlspecialchars
	    // +   original by: Mirek Slugen
	    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	    // +   bugfixed by: Nathan
	    // +   bugfixed by: Arno
	    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	    // +    bugfixed by: Brett Zamir (http://brett-zamir.me)
	    // -    depends on: get_html_translation_table
	    // *     example 1: htmlspecialchars("<a href='test'>Test</a>", 'ENT_QUOTES');
	    // *     returns 1: '&lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;'
	    var histogram = {}, symbol = '', tmp_str = '', entity = '';
	    tmp_str = string.toString();
	    
	    if (false === (histogram = this.get_html_translation_table('HTML_SPECIALCHARS', quote_style))) {
	        return false;
	    }
	    
	    histogram["'"] = '&#039;';
	    for (symbol in histogram) {
	        entity = histogram[symbol];
	        tmp_str = tmp_str.split(symbol).join(entity);
	    }
	    
	    return tmp_str;
	}





