function isEmail(string) 
{
	regExp0 = /^\w+([-+.&]\w+)*@\w+([-.]\w+)*\.[A-Za-z][A-Za-z]+$/;
    return regExp0.test(string);
}

function isPhone(string)
{
	regExp0 = /^[0-9]+([-\ ][0-9]+)*$/;
    return regExp0.test(string);
}

function debug(expression){
	alert(expression + " = (" + eval(expression)+")");
}

function debugParents(element){
	var i = 1;
	while(element != null && element.nodeName!="BODY"){
		var s = i+++"> "+element.nodeName+"."+element.className+"#"+element.id;
		if(element.style){
			var bg = element.style.backgroundColor;
			element.style.backgroundColor="cyan";
			s += "\n styleDimensions("+element.style.width+", " + element.style.height+")";
			s += "\n clientDimensions("+element.clientWidth+", " + element.clientHeight+")";
			s += "\n overflow("+element.style.overflow+")";
			if(!window.confirm(s)){
				return;
			}
			element.style.backgroundColor = bg;
		}
		else{
			if(!window.confirm(s)){
				return;
			}
		}
		element = element.parentNode;
	}
}

// javascript:void(document.body.onclick=clickDebug);
function clickDebug(){
	if(event.altKey)
		debugParents(event.srcElement);
	return true;
}


function isClickInRadEditor(element){	
	while(element != null){
		if(element.nodeName=="DIV"){
			if(element.className=="RadEContent"){
				return true;
			}
		}
		element = element.parentNode;
	}
	return false;
}



function showMenu() {
	//debugParents(event.srcElement);
	
	if(isClickInRadEditor(event.srcElement)){
		return false;
	}
	var m = document.getElementById( "RightClickConsoleDiv" );

	if (event.ctrlKey) {
		//don't show the menu...
		m.style.display='none';
		return true;
	} 
	else  {

		//this function will position and display a nested div that acts like a menu
		whichDoc = event.srcElement;
		m.style.posLeft = event.clientX+window.document[getDocElName()].scrollLeft;
		m.style.posTop = event.clientY+window.document[getDocElName()].scrollTop;
		m.style.display = "";
		document.body.onclick=clickedMenu;
		return false;
	}
}
/**
If we are in "standards mode" we must use document.documentElement, not body (-roberte)
*/
function getDocElName(){
	if(document.compatMode && (document.compatMode == "CSS1Compat")){
		return "documentElement";
	}
	else{
		return "body";
	}
}

function clickedMenu() {
	//when the custom menu is visible (and capturing events),
	//this handler runs after a click event.  if one of the
	//menu items is clicked, it takes appropriate action.
	//otherwise, it just hides the menu.
	var m = document.getElementById( "RightClickConsoleDiv" );
	
	m.style.display="none";
	m.releaseCapture();
	document.body.onclick = function(){return true;};
	return true;
}


function contextTwice() {
	//this handles the case in div#5 when you might right-click, and then you ctrl-right-click in the same div.
	if (event.srcElement==whichDoc){
		showMenu();
	}
}

function init(){

	
	/**/
	if(document.getElementById( "RightClickConsoleDiv" )){
		document.body.oncontextmenu = showMenu;
		//window.onscroll = clickedMenu;
	}
	/**/
	
	//the following peice of code makes all current links in the headerBarNav have a 
	// class of "current"
	if(document.getElementById("headerBarNav")){
		var headerLinks = document.getElementById("headerBarNav").getElementsByTagName("A");
		for(var i = 0; i < headerLinks.length; i++){	
			if(headerLinks[i].href == window.location){
				headerLinks[i].className += " current";
			}
		}
	}
	
	
	//debug("document.getElementById(\"Search1_headerBarSearchKeywords\").clientWidth");
	
}




function showPrintPreview(){	
	//var popup = window.open(window.location, "printPreview", "scrollbars=yes, toolbar=no, menubar=yes, location=no, directories=no, status=no"); 
	SystemPrintPreview(7); 
}

function RadSpellCheck(){
	if(this.spellCheckedIds){
		for(var i = 0; i < spellCheckedIds.length; i++){ 
			var o = document.getElementById(spellCheckedIds[i]);
			if(o.spellCheck){
				o.spellCheck();
			}
		}
	}
}

function SystemPrintPreview(OLECMDID) 
{ 
	//var OLECMDID = 10; 
	/* OLECMDID values: 
	* 6 - print 
	* 7 - print preview 
	* 8 - page setup (for printing) 
	* 1 - open window 
	* 4 - Save As 
	* 10 - properties 
	*/ 
	try
	{
		var PROMPT = 1; // 1 PROMPT & 2 DONT PROMPT USER 
		var oWebBrowser = document.getElementById("WebBrowser1");
		if(oWebBrowser == null)
		{
			var sWebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>'; 
			document.body.insertAdjacentHTML('beforeEnd', sWebBrowser); 
			oWebBrowser = document.getElementById("WebBrowser1");
		}
		oWebBrowser.ExecWB(OLECMDID,PROMPT);
	}
	catch(e){
		window.print()
	}
} 

/*
function showPrintPreview(){	
	var popup = window.open("about:blank", "printPreview", "scrollbars=yes, toolbar=no, menubar=yes, location=no, directories=no, status=no"); 
	popup.document.body.innerHTML = document.body.innerHTML;
}*/

function hide(b, ids){
	var display = b?"none":"";
	for(var i = 0; i < ids.length; i++){		
		document.getElementById(ids[i]).style.display = display;
	}
}

/*Rad Editor Control Spell Check Invoke for Premium Version*/
function MultipleTextSource(sources)
{
    this.sources = sources;
    this.getText = function()
    {
        var texts = [];
        for (var i = 0; i < this.sources.length; i++)
        {
            texts[texts.length] = this.sources[i].getText();
        }
        return texts.join("<controlSeparator><hr></controlSeparator>");
    }
       
    this.setText = function(text)
    {
        var texts = text.split("<controlSeparator><hr></controlSeparator>");
        for (var i = 0; i < this.sources.length; i++)
        {
            this.sources[i].setText(texts[i]);
        }
    }
}

function Editor5Source(editor)
{
    this.editor = editor;
    this.getText = function()
    {
        return this.editor.GetHtml();
    }
       
    this.setText = function(text)
    {
        this.editor.SetHtml(text);
    }
    
}

function PlaceHolderSource(placeHolder)
{
	this.placeHolder = placeHolder;
	this.getText = function()
	{
		return this.placeHolder.innerHtml();
	}
}

function startSpellCheck(radspellId)
{
	var arraysources = new Array();
	if(this.spellCheckedIds){
		for(var i = 0; i < spellCheckedIds.length; i++){ 
			arraysources.push(new Editor5Source(spellCheckedIds[i]));
		}
	}    
    var spell = RadSpell.getSpellChecker(radspellId);
    spell.setTextSource(new MultipleTextSource(arraysources));
    spell.startSpellCheck();
}

function startSpellCheck()
{
	if(this.spellCheckedIds){
		for(var i = 0; i < spellCheckedIds.length; i++){ 
			var theEditor = eval(spellCheckedIds[i]);
			if (theEditor != null)
			{
				/*var temp;
				for (prop in theEditor)
					temp += prop + "\n";
				document.write(temp + "\n");*/
				theEditor.Fire("SpellCheck");
			}
			else
			{
				alert("The Editor Was Null");
			}
		}
	}
}
/*End of Premium Spell Check Inovke*/

/*Javascript to change RadEditor FormatBlock behaviour*/
var selValue = null;
var doNotCheck = false;
 
function CleanFormat(editor, commandName, oTool)
{
	if ("FormatBlock" == commandName)
	{ 
		if (doNotCheck)
			return;   
		if ("body" != oTool.GetSelectedValue())
		{ 
			selValue = oTool.GetSelectedValue();
			var newTool = { GetSelectedValue: function(){return "body";} };
			editor.Fire (commandName, newTool);    
		}   
	}
}
 
function CleanFormat2(editor, commandName, oTool)
{  
	if ("FormatBlock" == commandName)
	{   
		if ("body" != oTool.GetSelectedValue())
		{ 
			if (doNotCheck) 
			{
				doNotCheck = false;
				return;
			}   
			var newTool = { GetSelectedValue: function(){return selValue;} };   
			doNotCheck = true;     
			editor.Fire (commandName, newTool);    
		}   
	}
}

/*End of JS*/
