//*************************************************************************
//***	DOM LIBRARY
//*************************************************************************

//*** GLOBAL VARIABEL
	var blnDOM = false;
	
//*** FUNCTIONS	
	//Advanced dthml check
	if (document.getElementById && document.createElement){
		blnDOM = true;
	}		
	// TIP 
	function fjsTip(onoff)
	{
		if(onoff == 1){
			if(document.getElementById("TipArea")){
				document.getElementById("TipArea").className = "Visible";
			}			
		}
		if(onoff == 0){
			if(document.getElementById("TipArea")){
				document.getElementById("TipArea").className = "Hidden";
			}			
		}		
	}
	function fjsSendTip(){
		if(document.getElementById("TipTitle") && document.getElementById("TipUrl")){
			if(document.getElementById("TipToEmail").value != "" && document.getElementById("TipFromEmail").value != ""){
				if(!echeck(document.getElementById("TipFromEmail").value)){
					alert("Feil format i senders e-post!");
					return;
				}
				if(!echeck(document.getElementById("TipToEmail").value)){
					alert("Feil format i mottaker e-post!");
					return;
				}
				var title = document.getElementById("TipTitle").value;
				var url = document.getElementById("TipUrl").value;
				var to = document.getElementById("TipToEmail").value;
				var from = document.getElementById("TipFromEmail").value;
				var source = "../../modules/module_123/include/tip_proc.asp?title=" + title + "&url=" + escape(url) + "&to=" + to + "&from=" + from;
				//alert(source);
				document.getElementById("TipFrame").src= source; 
			}
			else{
				alert("Sett inn e-post");				
			}			
		}	
	}
	
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
function echeck(str) {
	var at = "@";
	var dot = ".";
	var lat = str.indexOf(at);
	var lstr  = str.length;
	var ldot = str.indexOf(dot);
	if (str.indexOf(at)==-1){
		return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){		   
		return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){		    
		return false;
	}
	if (str.indexOf(at,(lat+1))!=-1){
		return false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	}
	if (str.indexOf(dot,(lat+2))==-1){
		return false;
	}
	if (str.indexOf(" ")!=-1){		    
		return false;
	}
	return true;				
}
	function checkEmail(email) {		
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(email.value)) {
			return false;
		}
		return true;
	}
	//default image switch
	function fjsImgSwitch(id, imgsrc){
		if (blnDOM == true){		
			if (document.getElementById(item)){		
				//Switch image	
				document.getElementById(item).src = imgsrc;			
			}
		}
	}
	
	//Tool, strips away all path info
	function fjsGetFileName(varName) {
		var re = /^.*\/(\S*\.\S*)$/;
		var tmp = new String(varName);
		tmp = tmp.match(re)[1];
			
		return tmp;
	}
	
	//Swap classes for any item
	function fjsSwapClass(strId, class1, class2){
		if (blnDOM == true){			
			//Check if element exists
			if (document.getElementById(strId)){
				//Switch class
				if (document.getElementById(strId).className == class1){
					document.getElementById(strId).className = class2;
				}
				else if(document.getElementById(strId).className == class2){
					document.getElementById(strId).className = class1;
				}
			}
		}
	}
		
	//Change class for any item
	function fjsChangeClass(strId, class1){
		if (blnDOM == true){
			//Check if element exists
			if (document.getElementById(strId)){
				//Change class
				document.getElementById(strId).className = class1;
			}
		}
	}
	
	//Clear input boxes for default data 
	function fjsClearBox(e){			
		e.value = "";
		e.focus();			
	}	
	
	//When IE creates a new element it gives the new element about 84 attributes inherited from IE's default DTD. Oh what fun.
	//And when you try to change an attribute like "class", it actually creates a new attribute so you end up with 2 "class" attributes.
	//So, this function checks your node for a given attribute, if it exists then it changes the attribute value with the one given.
	//If the attribute doesnt exist, it creates a new one and sets its value.
	function fjsToolBox_setAttribute(oNode, strAttribute, strValue) 
	{
		if (oNode.getAttributeNode(strAttribute)) 
		{
			for (var i = 0; i < oNode.attributes.length; i++) {
				var attrName = oNode.attributes[i].name.toUpperCase();
				if (attrName == strAttribute.toUpperCase()) 
				{
					oNode.attributes[i].value = strValue;
				}
			}				
		}
		else {
			//create a new attribute 
			oNode.setAttribute(strAttribute, strValue);
		}
	}

	
	//retrieves content from text nodes
	function fjsToolBox_GetTextNodeContent(n) 
	{			
		var s = '';
		var children = n.childNodes;
		for(var i = 0; i < children.length; i++) 
		{
			var child = children[i];
			if (child.nodeType == 3 /*Node.TEXT_NODE*/) 
			{
				s += child.data;
			}
			else{ 
				s += getTextContent(child);
			}
		}
		return s;
	}	
	
	
	//Removes all content from a Node
	function fjsToolBox_RemoveNodes(oNode)
	{
	    while(oNode.firstChild) 
	    {
	        oNode.removeChild(oNode.firstChild);
        }
	}
	
	if(!document.importNode)
	{
	    document._importNode = function(oNode, bImportChildren)
	    {
		    var oNew;
            var attr;
            
		    if(oNode.nodeType == 1){
			    oNew = document.createElement(oNode.nodeName);
			    /*
			    for(var i = 0; i < oNode.attributes.length; i++){
				    oNew.setAttribute(oNode.attributes[i].name, oNode.attributes[i].value);
			    }
			    */
			    for (var i = 0; i < oNode.attributes.length; i++)
                {
                    attr = oNode.attributes[i];
                    if (attr.nodeValue != null && attr.nodeValue != '')
                    {
                        //oNew.setAttribute(attr.name, attr.nodeValue);
                        fjsToolBox_setAttribute(oNew, attr.name, attr.nodeValue);
                    }
                }
			    oNew.style.cssText = oNode.style.cssText;
		    } else if(oNode.nodeType == 3){
			    oNew = document.createTextNode(oNode.nodeValue);
		    }
    		
		    if(bImportChildren && oNode.hasChildNodes()){
			    for(var oChild = oNode.firstChild; oChild; oChild = oChild.nextSibling){
				    oNew.appendChild(document._importNode(oChild, true));
			    }
		    }
		        		
		    return oNew;
	    }
    }
