var winobj;
function getDepth()
{
	if (document.getElementById("ctl00_hidDepth")==null || document.getElementById("ctl00_hidDepth")=="null") return ("../");
	else return (document.getElementById("ctl00_hidDepth").value);
}
function OpenPopUpWin(obj)
{
	winobj = window.open(obj.href, "testimonial",
		"top=40,left=40,width=550,height=450,scrollbars=yes,resizable=yes,location=no,menubar=no,status=yes,toolbar=no");
	winobj.focus();
	return false;
}
function EmailPage(strPage)
{
	winobj = window.open(getDepth() + "Misc/EmailPage.aspx?Page="+escape(strPage), "Email",
		"top=10,left=10,width=570,height=401,scrollbars=no,resizable=no,location=no,menubar=no,status=yes,toolbar=no");
	winobj.focus();
}
function OpenTourWin(strWin,strContent)
{
	winobj = window.open(getDepth() + "Tour/Tour"+strWin+".aspx?utm_source=biscom&utm_medium=tour&utm_content="+strContent+"&utm_campaign=tour2Minute", "Tour",
		"top=20,left=20,width=750,height=525,scrollbars=no,resizable=no,location=no,menubar=no,status=yes,toolbar=no");
	winobj.focus();
}

//Email validation
function ValidateEmail(idEmail, NoEmpty, msg)
{
	var objEmail = document.getElementById(idEmail);
	if (NoEmpty == true && objEmail.value == "")
	{
		ShowErr(idEmail);
		alert("You did not enter an e-mail address!\n\n" + msg);
		return false;
	}
	var emailRegExp = new RegExp("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$");
	if ((NoEmpty == true || objEmail.value != "") && !objEmail.value.match(emailRegExp))
	{
		ShowErr(idEmail);
		alert("You did not enter a valid e-mail address!\n\n" + msg);
		return false;
	}
	if(NoEmpty == true && objEmail.value.substr(0,4).toLowerCase()=="www.")
	{
		ShowErr(idEmail);
		alert("You did not enter a valid e-mail address.\n\nE-mail addresses don't being with 'www.'!");
		return false;
	}
	return true;
}

function Check_TrialStep1(idFirstName,idLastName,idName,idEmail)
{
	var objFirstName = document.getElementById(idFirstName);
	if (objFirstName != null && objFirstName.value == "")
	{
		ShowErr(idFirstName);
		alert("You did not enter a first name! \n\nYou must do this before your information can be sent.");
		return false;
	}
	var objLastName = document.getElementById(idLastName);
	if (objLastName != null && objLastName.value == "")
	{
		ShowErr(idLastName);
		alert("You did not enter a last name! \n\nYou must do this before your information can be sent.");
		return false;
	}
	var objName = document.getElementById(idName);
	if (objName != null && objName.value == "")
	{
		ShowErr(idName);
		alert('You did not enter a name! \n\nYou must do this before your information can be sent.');
		return false;
	}
	var emailvalid = ValidateEmail(idEmail, true, "An e-mail address is required to create the test drive.\nImportant access instructions will be sent to this email address.");
	return emailvalid;
}

function ValidateLoginName(idLoginName)
{
	var objLoginName = document.getElementById(idLoginName);
	if(objLoginName.value == "")
	{
		ShowErr(idLoginName);
		alert("Please enter a Username.");
		return false;
	}
	var pattern = new RegExp("^[a-zA-Z]([\-\_\.]?[0-9a-zA-Z]+)*$"); //^[a-zA-Z][0-9a-zA-Z]{4,15}$
	if(objLoginName.value.match(pattern) == null)
	{
		ShowErr(idLoginName);
		alert("The Username must START with a letter,\nthen only letters, numbers, dashes, underlines, or periods.\nIt must END with a letter or number.\n\nYou cannot have more than dash, underline, or period in a row.");
		return false;
	}
	if(objLoginName.value.length > 18)
	{
		ShowErr(idLoginName);
		alert("The Username cannot be longer than 18 characters.");
		return false;
	}
	else if(objLoginName.value.length < 5)
	{
		ShowErr(idLoginName);
		alert("The Username must be at least 5 characters long.");
		return false;
	}
	return true;
}
function ValidatePassWord(idPassword)
{
	var objPassword = document.getElementById(idPassword);
	if(objPassword.value == "")
	{
		ShowErr(idPassword);
		alert("Please enter a Password.");
		return false;
	}
	var pattern = new RegExp("^[\\w\\-]{4,18}$");
	if(objPassword.value.match(pattern) == null)
	{
		ShowErr(idPassword);
		alert("The Password must use only letters, numbers, underlines,\nand dashes, and be at least 4 characters long.");
		return false;
	}
	return true;
}

function Check_TrialStep2(idCompanyName,idLoginName,idPassword,idAgreement,idRadio)
{
	var objCompanyName = document.getElementById(idCompanyName);
	if(objCompanyName != null && objCompanyName.value == "")
	{
		ShowErr(idCompanyName);
		alert("Please enter a Company/School Name.");
		return false;
	}
	if(!ValidateLoginName(idLoginName) || !ValidatePassWord(idPassword))
	{
		return false;
	}
	if(document.getElementById(idAgreement).checked == false)
	{
		ShowErr(idAgreement);
		alert("You cannot continue until you have clicked in the checkbox\rto indicate acceptance of the BuildIT Terms of Use Agreement.");
		return false;
	}
	if(GetCheckedValue(idRadio) == "")
	{
		document.getElementById("bxCat").style.border = "2px solid #F60";
		setTimeout("document.getElementById('bxCat').style.border='2px solid #EEE';",2000);
		alert("Please select the category that best describes you.");
		return false;
	}
	if(document.getElementById("ctl00_cphBody_chkUrgent").checked == true && document.getElementById("ctl00_cphBody_tbxBusTel").value == "")
	{
		ShowErr("ctl00_cphBody_tbxBusTel");
		alert("You have checked that you 'need to create a schedule fast'.\n\nPlease enter a telephone number so we can contact you.");
		return false;
	}
	return true;
}

function Check_ARSignUp(idName)
{
	var objName = document.getElementById(idName);
	if (objName.value == "")
	{
		ShowErr(objName);
		alert('You did not enter a name! \n\nYou must do this before your information can be sent.');
		return false;
	}
	return ValidateEmail(objName, true, "An e-mail address is required so we can send the requested information.");
}

function Check_Guide(idFirstName,idLastName,idName,idEmail)
{
	var objFirstName = document.getElementById(idFirstName);
	if (objFirstName != null && objFirstName.value == "")
	{
		ShowErr(idFirstName);
		alert("You did not enter a first name! \n\nYou must do this before your information can be sent.");
		return false;
	}
	var objLastName = document.getElementById(idLastName);
	if (objLastName != null && objLastName.value == "")
	{
		ShowErr(idLastName);
		alert("You did not enter a last name! \n\nYou must do this before your information can be sent.");
		return false;
	}
	var objName = document.getElementById(idEmail);
	if (objName != null && objName.value == "")
	{
		ShowErr(idEmail);
		alert('You did not enter a name! \n\nYou must do this before your information can be sent.');
		return false;
	}
	var emailvalid = ValidateEmail(idEmail, true, "An e-mail address is required.");
	return emailvalid;
}

function Check_EmailPage(idEmail, idRcvrEMail)
{
	return (ValidateEmail(idEmail, true, "\"Your E-mail\" is required before the message can be sent.")
		&& ValidateEmail(idRcvrEMail, true, "\"Friend's E-mail\" is required before the message can be sent."));
}
function Check_RemoveAR(idEmail)
{
	return ValidateEmail(idEmail, true, "You must do this before your address can be removed.");
}

function GoDDLPage(obj)
{
	if (obj.options[obj.options.selectedIndex].value != "")
	{
		document.location = obj.options[obj.options.selectedIndex].value;
	}
}
function OpenVideo(strPage)
{
	winobj = window.open(getDepth() + "Video/ComVidWin2.aspx?Vid="+strPage, "VidWin",
		"top=10,left=10,width=640,height=497,scrollbars=no,resizable=no,location=no,menubar=no,status=yes,toolbar=no");
	winobj.focus();
}
function OpenVideo2(strPage)
{
	winobj = window.open(getDepth() + "Video/ComVidWin2.aspx?Vid="+strPage, "VidWin",
		"top=10,left=10,width=640,height=497,scrollbars=no,resizable=no,location=no,menubar=no,status=yes,toolbar=no");
	winobj.focus();
}
function NavParent(strURL, blnClose)
{
	if (parent.opener == null || parent.opener.closed) { window.open("http://" + strURL); }
	else { parent.opener.location.href = "http://" + strURL; }
	if (blnClose && parent.opener != null) window.close();
}
function showItems(divID, imgID, imgID2, ordr)
{
	var msec = 1000;
	setTimeout("document.getElementById('"+divID+"').style.visibility = 'visible';", (ordr*msec));
	if(imgID != null) {
		setTimeout("document.getElementById('"+imgID+"').style.visibility = 'visible';", (ordr*msec));
		setTimeout("document.getElementById('"+imgID+"').style.visibility = 'hidden';", ((ordr+1)*msec));
	}
	if(imgID2 != null) {
		document.getElementById(imgID2).style.visibility = 'hidden';
		setTimeout("document.getElementById('"+imgID2+"').style.visibility = 'visible';", ((ordr+1)*msec));
	}
}
function framePage(depth,URL)
{
	if (false) //(top==self)
	{
		if(URL==null || URL=="")
		{
			top.location.replace(depth+"BuildIT.aspx");
		}
		else
		{
			top.location.replace(depth+"BuildIT.aspx?page="+URL);
		}
	}
	else
	{
		try
		{
			parent.document.title = document.title;
		}
		catch(err){}
	}
	return;
}
function frameUnload()
{
	if(top.document.getElementById("hidUnloadFrame").value != null)
	{
		if(top.document.getElementById("hidUnloadFrame").value != "false")
		{
			showModalDialog("ExitSurvey/?page="+escape(self.parent.frames[0].location.href),window,"status:no; help:no; dialogHeight:550px; dialogWidth:780px;");
		}
	}
}
function frameUnloadOff()
{
	if(top.document.getElementById("hidUnloadFrame") != null)
	{
		top.document.getElementById("hidUnloadFrame").value = "false";
	}
}
function frameRemove(newURL)
{
	frameUnloadOff();
	if (self.parent.frames.length != 0)
	{
		self.parent.location = newURL;
	}
}

function swap(obj)
{
	if(typeof(obj) == "string")
	{
		obj = document.getElementById(obj);
	}
	imHi = obj.getAttribute("src");
	imLo = obj.getAttribute("oversrc");
	if(imLo.indexOf("/") == -1)
	{
		//add the full path first
		imLo = imHi.substr(0, imHi.lastIndexOf("/") + 1) + imLo;
	}
	obj.setAttribute("src",imLo);
	obj.setAttribute("oversrc",imHi);
}

function Toggle(idDiv)
{
	var obj = document.getElementById(idDiv);
	if(obj.style.display == "none")
	{
		obj.style.display = "block";
	}
	else
	{
		obj.style.display = "none";
	}
}
function OpenBIScomContact()
{ /* used in BLOG */
	winobj = window.open("http://www.builditsystems.com/About/Contact.aspx", "contact",
		"top=10,left=10,width=1024,height=768,scrollbars=yes,resizable=yes,location=no,menubar=no,status=yes,toolbar=no");
	winobj.focus();
}
function GetCheckedValue(radioObj) {
	var ctlObj = document.getElementsByName(radioObj);
	if(!ctlObj) return "";
	var radioLength = ctlObj.length;
	if(radioLength == undefined)
		if(ctlObj.checked)
			return ctlObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(ctlObj[i].checked) {
			return ctlObj[i].value;
		}
	}
	return "";
}
function ShowErr(idObj)
{
	try
	{
		document.getElementById(idObj).style.backgroundColor='#FC6';
		setTimeout("document.getElementById('"+idObj+"').style.backgroundColor='white';",2000);
		document.getElementById(idObj).focus();
		document.getElementById(idObj).select();
	}
	catch (er){}
}

