// Initialize browser detection variables
var HM_DOM, HM_NS4, HM_IE, HM_IE4, HM_Mac, HM_IE4M;
HM_DOM = (document.getElementById) ? true : false;
HM_NS4 = (document.layers) ? true : false;
HM_IE = (document.all) ? true : false;
HM_IE4 = HM_IE && !HM_DOM;
HM_Mac = (navigator.appVersion.indexOf("Mac") != -1);
HM_IE4M = HM_IE4 && HM_Mac;

// Set default window status
window.defaultStatus = 'CorasWorks - Workplace Software for SharePoint';

// Set child windows to null
winSHOWROOM = null;
winCENTRAL = null;

// Initialize global variables
var blnHomepage = false;

//RW Not required for community DevV1
/*
// Image cache
var SpacerCache = new Image();
SpacerCache.src = "/graphics/spacer.gif";
//	Tabs
var t;
for (t=0; t<=totalSections; t++) {
	eval["tabOn" + t + "Cache"] = new Image();
	eval["tabOn" + t + "Cache"].src = "/graphics/Template/Navigation/bg_tab" + t + "_on.gif";
}

*/

// Include JS Date function
function MakeArray(n) {
	this.length = n;
	return this;
}

function customDateString(oneDate) {
	var theDay = dayNames[oneDate.getDay() + 1];
	var theMonth = monthNames[oneDate.getMonth() + 1];
	var theYear = oneDate.getFullYear();
	return theDay + ", " + theMonth + " " + oneDate.getDate() + ", " + theYear;
}

var monthNames = new MakeArray(12);
monthNames[1] = "January";
monthNames[2] = "February";
monthNames[3] = "March";
monthNames[4] = "April";
monthNames[5] = "May";
monthNames[6] = "June";
monthNames[7] = "July";
monthNames[8] = "August";
monthNames[9] = "September";
monthNames[10] = "October";
monthNames[11] = "November";
monthNames[12] = "December";

var dayNames = new MakeArray(7);
dayNames[1] = "Sunday";
dayNames[2] = "Monday";
dayNames[3] = "Tuesday";
dayNames[4] = "Wednesday";
dayNames[5] = "Thursday";
dayNames[6] = "Friday";
dayNames[7] = "Saturday";

// Begin Global JS Functions
function DropdownChooser(Product) {
if (Product != "") {
window.location = Product;
	}
}

function SpawnWin(wURL,wName) {
Spawned = window.open(wURL,wName);
// Refocus window
setTimeout("Spawned.focus()",500);
}

function openShowroom() {
	if (winSHOWROOM == null) {
		winSHOWROOM = window.open('http://solutions.corasworks.net/','SHOWROOMWIN');
	}
	// Refocus window
	setTimeout("winSHOWROOM.focus()",500);
}

function openCentral() {
	if (winCENTRAL == null) {
		winCENTRAL = window.open('http://central.corasworks.net/','CENTRALWIN');
	}
	// Refocus window
	setTimeout("winCENTRAL.focus()",500);
}

function imgHilite(imgID) {
	// Replaces the terminus of an image "_off.gif" with "_on.gif" only
	thisSrc = eval(GetDIVStyleID(imgID)).src;
	newSrc =  thisSrc.substring(0,thisSrc.lastIndexOf('_off.gif')) + "_on.gif";
	eval(GetDIVStyleID(imgID)).src = newSrc;
}

function imgUnHilite(imgID) {
	// Replaces the terminus of an image "_on.gif" with "_off.gif" only
	thisSrc = eval(GetDIVStyleID(imgID)).src;
	newSrc =  thisSrc.substring(0,thisSrc.lastIndexOf('_on.gif')) + "_off.gif";
	eval(GetDIVStyleID(imgID)).src = newSrc;
}

function ctPageHilite(imgName) {
	// Amended 4/24/07 to generalize for PNG or GIF
	if (document.images[imgName]) {
		var img = document.images[imgName];
		var patt = /^(https?:\/\/[^\/]+)(.*?)(off)(\.(gif|png))$/;
		if (img.src.match(patt)) {
			img.src = RegExp.$2 + 'on' + RegExp.$4;
		}
	}
}

function ctPageUnHilite(imgName) {
	// Amended 4/24/07 to generalize for PNG or GIF
	if (document.images[imgName]) {
		var img = document.images[imgName];
		var patt = /^(https?:\/\/[^\/]+)(.*?)(on)(\.(gif|png))$/;
		if (img.src.match(patt)) {
			img.src = RegExp.$2 + 'off' + RegExp.$4;
		}
	}
}

function ToggleMenuVisibility(myid){
	if (eval(GetDIVStyleID('div_Nav_' + myid)).style.display == "none") {
		imgHilite('img_NavExp_' + myid);
		ShowItem('div_Nav_' + myid,"block");
	}
	else {
		imgUnHilite('img_NavExp_' + myid);
		ShowItem('div_Nav_' + myid,"none");
	}
}

function TriggerFlash() {
var args = TriggerFlash.arguments;
	for (x = 0; x < args.length; x++) {
		Root = eval("window." + args[x]);
		if (Root) {
			Root.Play();
		}
	}
}

function clrSearch(thisBox) {
	if (thisBox.value == "Search") {
		thisBox.value = "";
	}
}

function fillSearch(thisBox) {
	if (thisBox.value == "") {
		thisBox.value = "Search";
	}
}

function GetDIVStyleID(myid) {
	if ((HM_IE) || (HM_DOM)) {
		// Explorer
		if (HM_IE){
			ThisDIV = document.all[myid];
		}
		// DOM Browsers
		else if (HM_DOM) {
			ThisDIV = document.getElementById(myid);
		}
		return (ThisDIV);
	}
	else {
		return false;
	}
}

function ShowItem(myid,mydisplay) {
	if (mydisplay == "none") {
		eval(GetDIVStyleID(myid)).style.display = "none";
	}
	else if (mydisplay == "block") {
		eval(GetDIVStyleID(myid)).style.display = "block";
	}
}

function validateSearch(frm) {
	if ((frm.keys.value == "") || (frm.keys.value == "Search")) {
		return false;
	}
	else {
		return true;
	}
}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	if (obj.filters) {obj.filters.alpha.opacity=opacity;}
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
} 

function obfusc(box,subj) {
	obfusced = ("mail" + "to" + ":" + box + unescape("%40") + "idefense" + ".com");
	if (subj) { obfusced += ("?" + "subject" + "=" + escape(subj)); }
	this.location.href=obfusced;
}

function setFullHeight(elem) {
	var elm = document.getElementById(elem);
	elm.style.height = "auto";
	var x = elm.offsetHeight;
	elm.style.height = x + "px";
}

function ShowTabContent(TabID,TabLimit,TabSet) {
	for (u=1; u<=TabLimit; u++) {
		ShowItem('TabBox_'+TabSet+'_Content' + u,"none");
		eval(GetDIVStyleID('TabBox_'+TabSet+'_Tab' + u)).className = "TabBox_Tab";
	}
	ShowItem('TabBox_'+TabSet+'_Content' + TabID,"block");
	eval(GetDIVStyleID('TabBox_'+TabSet+'_Tab' + TabID)).className = "TabBox_TabOn";
}

// Form validation declarations
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz";
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var whitespace = " \t\n\r";
var defaultEmptyOK = false;

function isEmpty(s) {
   return ((s == null) || (s.length == 0))
}

function isWhitespace (s) {
   var i;
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}


function launchCT(tour,pgThis) {
	// Set initial slide to view
	if ( (pgThis + '' == 'undefined') || (isNaN(pgThis)) ) {
		pgThis = 1;	
	}
	else {
		pgThis = parseInt(pgThis);	
	}
	
	// Add new tour specs here
	if (tour == 'solutions') {
		openWindow('/ClickTours/?tour=solutions&pgThis='+pgThis+'&pgTotal=12','TOURWIN',855,500,null,null,true,true);	
	}
}

function openWindow(URL,Name,W,H,L,T,Scrolls,Resize) {
	// Used to control params of pop-ups
	var defProps = 'copyhistory=0,directories=0,fullscreen=0,location=1,menubar=0,status=1,titlebar=1,toolbar=0';
	var poppedProps = '';

	if (W != null) {
		if (Scrolls == true) { W += 16; } // Allow for chrome in IE
		poppedProps += ('width='+W+',');
	}
	if (H != null) { poppedProps += ('height='+H+','); }
	if (L != null) { poppedProps += ('left='+L+','); }
	if (T != null) { poppedProps += ('top='+T+','); }
	poppedProps += 'scrollbars=' + ((Scrolls == true) ? 1 : 0) + ',' ;
	poppedProps += 'resizable=' + ((Resize == true) ? 1 : 0) + ',' ;
	poppedProps += defProps;

//	alert(poppedProps);
	poppedUp = window.open(URL,Name,poppedProps);
	setTimeout("poppedUp.window.focus();",100);
	return poppedUp;
}