function submitLink(objForm)
{
     var objSelect = document.getElementById("linkSelect");

     if(objSelect.selectedIndex == 0)
     {
          return false;
     }

     var strURL = objSelect.options[objSelect.selectedIndex].value

     if(strURL!="")
     {
          objForm.action = strURL;
     }

     return true;
}

function BuildPrintButton()
{
	var printButton =document.createElement("A");
	
	printButton.href="javascript:window.print();";
	printButton.id = "PrintLink";
	printButton.appendChild(document.createTextNode("» Print"));
	var container = document.getElementById("PrintEmailFooter");
	container.appendChild(printButton);
}

function checkEnter(e, theForm){
var characterCode
if(e && e.which){
 characterCode = e.which;
}
else{
 e = event;
 characterCode = e.keyCode;
}

if(characterCode == 13){
 appendSearchTerm();
 theForm.submit();
 return false;
}
else{
 return true;
}
}

function acceptDownloadTerms(strContainer)
{
	objContainer = document.getElementById(strContainer);

	if(objContainer.className=="hide")
	{
		objContainer.className ="show";
	}
	else
	{
		objContainer.className ="hide";
	}
}

function SetCookie (cookieName, cookieValue, domain)
{

	document.cookie = cookieName + "=" + escape(cookieValue) + ";domain=" + domain;
  }
function dropdown(mySel)
{   
    
    mySel=document.getElementById(mySel);    
    var myWin, myVal;
    myVal = mySel.options[mySel.selectedIndex].value;    
    if(myVal)
    {
        if(this.target)myWin = parent[this.target];
        else myWin = window;
        if (! myWin) return true;
        myWin.location = myVal;
    }
    return false;
}

function validate()
{
document.getElementById("lblErrorName").innerHTML="";
document.getElementById("lblErrorEmail").innerHTML="";

if(document.getElementById("name").value=="")
    {
        document.getElementById("lblErrorName").innerHTML="This field is required";
        document.getElementById("name").focus();
        return false;
    }

    var objEmail = document.getElementById("email");
    if(objEmail != null){
        if(document.getElementById("email").value=="")
        {
           document.getElementById("lblErrorEmail").innerHTML="This field is required";
            document.getElementById("email").focus();
            return false;
        }
        if(document.getElementById("email").value!="")
        {
            if(!emailcheck1(document.getElementById("email")))
            {
           document.getElementById("lblErrorEmail").innerHTML="Invalid email address";
           document.getElementById("email").focus();
                return false;
            }
        }
    }
    return true;
}
    function emailcheck1(input)
    {
        if(input.value.length!=0)
        {
            var notAllowed="[]:;,\"<>";
            var str = input.value;
            for (var i=0;i<str.length;i++)
            {
                if (notAllowed.indexOf(str.charAt(i))!=-1)
                {
                    input.focus();
                    return false;
                }
            }
            
            var str=input.value.charAt(0);
            
            if(isNaN(str))
            {		
                if(str=='@' || str=='.')
                {
                    input.focus();
                    return false;
                }
            }
            
            if(input.value.indexOf("@@")>0 || input.value.substr(input.value.indexOf("@")).indexOf("..")>0 || input.value.indexOf("@.")>0)
            {
                input.focus();
                return false;
            }
            
            var x = 1;
            var i=1;
            var j = 0;
            var k =0;
            
            if(input.value.charAt(input.value.length-1)=='.' || input.value.charAt(input.value.length-1)=='@')
            {
                input.focus();
                return false;
            }
            
            if(input.value.indexOf(" ")>0)
            {
                input.focus();
                return false;
            }
            
            pos1=input.value.indexOf("@");
            pos2=input.value.indexOf(".");
            
            if((pos1+1)==pos2 || (pos1-1)==pos2)
            {
                input.focus();
                return false;
            }
            while(input.value.charAt(i))
            {
                if(input.value.charAt(i)=='@')
                {
                    j= i+1;
                    k= j;
                    while(input.value.charAt(j))
                    {
                        if(input.value.charAt(j)=='.')
                            x=0;
                        j++;
                    }
                    break;
                }
                i++;
            }
            if (j==0)
            {
                input.focus();
                return false;
            }
            if (x!=0)
            {
                input.focus();
                return false;
            }
            if (k==(j+1))
            {
                input.value="";
                input.focus();
                return false;
            } 
        }
        return true;
    }


/* Light Box Script */ 

$(document).ready(function() {
			/*
			*   Examples - images
			*/
if(jQuery.isFunction(jQuery.fn.fancybox))
{


$("a#example1").fancybox({
				'titleShow'		: false
			});

			$("a#example2").fancybox({
				'titleShow'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
			$("a.example2").fancybox({
				'titleShow'		: false,
'titleFromAlt': true ,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
	$("a#example6").fancybox({
				'titlePosition'	: 'over',
'titleFromAlt': true 
			});

$("a.example6").fancybox({
				'titlePosition'	: 'over',
'titleFromAlt': true 
			});
	$("#various1").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
'titleFromAlt': true ,
				'transitionOut'		: 'none'
			});



$('a[rel=example_group],a[rel=example_group1],a[rel=example_group2],a[rel=example_group3],a[rel=example_group4]').each(function(){  
		//alert($(this).attr('href'));
		//if($(this).attr('href').split(".")[1]=="swf"){
		if($(this).attr('href').substr(($(this).attr('href')).length-3,3)=="swf"){
			var dWidth=parseInt($(this).attr('class').split("x")[0]);
		var dHeight=parseInt($(this).attr('class').split("x")[1]);      
		  //  var dWidth  = parseInt($(this).attr('href').match(/width=[0-9]+/i)[0].replace('width=',''));  
		  //  var dHeight     =  parseInt($(this).attr('href').match(/height=[0-9]+/i)[0].replace('height=','')); 	  
	  	$(this).fancybox({
				'width':dWidth,  
    			'height':dHeight, 			
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
'titleFromAlt': true ,
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});

		}else {
		$('a[rel=example_group],a[rel=example_group1],a[rel=example_group2],a[rel=example_group3],a[rel=example_group4]').fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
'titleFromAlt': true ,
				'titlePosition' 	: 'over',				 
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
			}

			});
 


}
/*
*   Examples - various
*/

			 		});


/* Light Box Script */ 


// Hide-Show Navigation Tab on Content area

function ShowHideDiv(DivId,total)
    {
        for (i=1;i<=total;i++)
        {
        document.getElementById('div'+i).style.display = "none";
        } 
        document.getElementById('div' + DivId).style.display = "block";
        document.getElementById('li' + DivId).className = "active";
        for (i=1;i<=total;i++)
        {
        document.getElementById('li'+i).className = "";
        } 
       document.getElementById('li' + DivId).className = "active";
    }

// Hide-Show Navigation Tab on Right Side

function ShowHideDiv1(DivId,total)
    {
	
        for (i=1;i<=total;i++)
        {
        document.getElementById('tdiv'+i).style.display = "none";
        } 
        document.getElementById('tdiv' + DivId).style.display = "block";
        document.getElementById('tli' + DivId).className = "active";
        for (i=1;i<=total;i++)
        {
        document.getElementById('tli'+i).className = "";
        } 
       document.getElementById('tli' + DivId).className = "active";
	   return true;
    }

// Hide-Show Navigation Tab END



// Rolls-Royce find and replace

function findAndReplace(searchText, replacement, searchNode) {
    if (!searchText || typeof replacement === 'undefined') {
        // Throw error here if you want...
        return;
    }
    var regex = typeof searchText === 'string' ?
                new RegExp(searchText, 'g') : searchText,
        childNodes = (searchNode || document.body).childNodes,
        cnLength = childNodes.length,
        excludes = 'html,input,embed,select,object,head,style,script,link,iframe,title';
        //head,style,title,link,meta,script,object,iframe,input,select,embed
        var i=0;
    while (cnLength--) {
        
        var currentNode = childNodes[cnLength];
        if (currentNode.nodeType === 1 &&
            (excludes + ',').indexOf(currentNode.nodeName.toLowerCase() + ',') === -1) {
            arguments.callee(searchText, replacement, currentNode);
        }
        if (currentNode.nodeType !== 3 || !regex.test(currentNode.data) ) {
            continue;
        }
        var parent = currentNode.parentNode,
            frag = (function(){
                var html = currentNode.data.replace(regex, replacement),
                    wrap = document.createElement('div'),
                    frag = document.createDocumentFragment();
                wrap.innerHTML = html;
                while (wrap.firstChild) {
                    frag.appendChild(wrap.firstChild);
                }
                return frag;
            })();
        parent.insertBefore(frag, currentNode);
        parent.removeChild(currentNode);
    }
}

window.onload = function FindAndReplaceAll() {
findAndReplace('Rolls-Royce','<span class="new">Rolls-Royce</span>',document.getElementById('Content') );

}
