//::pop-up window (complete settings)
//ex -> onClick="CiPopWin('./pageurl.asp','WindowName','500','300','no','no','no','no','no','no');return false"
var win = null;
function CiPopWin(mypage,myname,w,h,scroll,resize,toolbar,loc,status,menubar){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+resize+',toolbar='+toolbar+',location='+loc+',status='+status+',menubar='+menubar;
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}

//::Build URL string for project search options
function ProjectSearch(sType,sPage) {
	var objForm		= document.forms[0];
	var strProject  = objForm.projecttype.value;
	var strCustomer	= objForm.customer.value;
	var strItems	= objForm.items.value;
	if (sPage == "") { sPage = "1" };
	document.location.href = "?type=" + sType +
							 "&project=" + strProject +
							 "&customer=" + strCustomer +
							 "&items=" + strItems +
							 "&pg=1";
}

//::Send Page Window
function SendPage(){
	var url = escape(location.href);
	//CiPopWin('../sendpage.asp?url='+url,'SendPageWin','450','350','no','no','no','no','no','no');
	document.location.href = 'mailto:?subject=Check out this page from GirardOnline.com!&body=' + url;
}

//::Quotes Window
function OpenQuotes(){
	CiPopWin('print_quotes.asp','QuotesWindow','610','410','yes','yes','no','no','no','yes');
}

//::Delay Video Start
function DelayedVideoStart(){
	setTimeout("document.MediaPlayer.controls.Play();", 3*1000);
}

//::Attach onLoad Event (Crossbrowser)
//ex.	 onLoadEvent("alert('sample')");
function onLoadEvent(strFunc) {
	if (window.addEventListener)
		window.addEventListener("load", eval(strFunc), false)
	else if (window.attachEvent)
		window.attachEvent("onload", function(){eval(strFunc)})
	else if (ie4||dom||document.layers)
		window.onload = eval(strFunc)
}

//::Limit TextArea Length
//ex.	 onKeyPress="LimitTextarea(this,500);"
function LimitTextarea(fld,lmt) {
	if (fld.value.length > lmt) {
		fld.value = fld.value.substring(0, lmt);
	}
}

function ToggleResumeOption(val) {
	switch (val) {
		case "Upload":
			document.getElementById('resume_upload').style.display = "";
			document.getElementById('resume_paste').style.display = "none";
			break;

		case "Paste":
			document.getElementById('resume_upload').style.display = "none";
			document.getElementById('resume_paste').style.display = "";
			break;
	}
}

//::Swap Client Type
function SwapClientType(val){
	switch (val) {
		case "residential":
			document.getElementById('tblResidential1').style.display = "block";
			document.getElementById('tblResidential2').style.display = "block";
			document.getElementById('tblResidential3').style.display = "block";

			document.getElementById('tblCommercial1').style.display = "none";
			document.getElementById('tblCommercial2').style.display = "none";
			document.getElementById('tblCommercial3').style.display = "none";
			break;

		case "commercial":
			document.getElementById('tblResidential1').style.display = "none";
			document.getElementById('tblResidential2').style.display = "none";
			document.getElementById('tblResidential3').style.display = "none";

			document.getElementById('tblCommercial1').style.display = "block";
			document.getElementById('tblCommercial2').style.display = "block";
			document.getElementById('tblCommercial3').style.display = "block";
			break;
	}
}

//::Swap How Hear
function SwapHowHear(val){
	switch (val) {
		case "tr_howhear1":
			document.getElementById('tr_howhear1').style.display = "";
			document.getElementById('tr_howhear2').style.display = "none";
			document.getElementById('tr_howhear5').style.display = "none";
			break;

		case "tr_howhear2":
			document.getElementById('tr_howhear1').style.display = "none";
			document.getElementById('tr_howhear2').style.display = "";
			document.getElementById('tr_howhear5').style.display = "none";
			break;

		case "tr_howhear3":
			document.getElementById('tr_howhear1').style.display = "none";
			document.getElementById('tr_howhear2').style.display = "none";
			document.getElementById('tr_howhear5').style.display = "none";
			break;

		case "tr_howhear4":
			document.getElementById('tr_howhear1').style.display = "none";
			document.getElementById('tr_howhear2').style.display = "none";
			document.getElementById('tr_howhear5').style.display = "none";
			break;

		case "tr_howhear5":
			document.getElementById('tr_howhear1').style.display = "none";
			document.getElementById('tr_howhear2').style.display = "none";
			document.getElementById('tr_howhear5').style.display = "";
			break;
	}
	//clear more fields
	document.forms[0].howhear_more[0].value = "";
	document.forms[0].howhear_more[1].value = "";
	document.forms[0].howhear_more[2].value = "";
}

//::Preload Rollover Images
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

MM_preloadImages('images/TopMenu_Home_H.gif','images/TopMenu_MyGirard_H.gif','images/TopMenu_SiteMap_H.gif');


//::Vertical Scroller
var delayb4scroll = 2	//Initial Delay in Seconds
var marqueespeed = 1	//Pixels
var pauseit = 1			//Pause on Rollover
var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var actualheight=''
function scrollmarquee(){
	if (parseInt(cross_marquee.style.top)>(actualheight*(-1)+8))
		cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px"
	else
		cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
}
function initializemarquee(){
	cross_marquee=document.getElementById("vmarquee")
	cross_marquee.style.top=0
	marqueeheight=document.getElementById("marqueecontainer").offsetHeight
	actualheight=cross_marquee.offsetHeight
	if (window.opera || navigator.userAgent.indexOf("Netscape/7")!=-1){ //if Opera or Netscape 7x, add scrollbars to scroll and exit
		cross_marquee.style.height=marqueeheight+"px"
		cross_marquee.style.overflow="scroll"
		return
	}
	setTimeout('lefttime=setInterval("scrollmarquee()",30)', delayb4scroll*3000)
}

//::Right Substring
function Right(str, n){
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else {
		var iLen = String(str).length;
		return String(str).substring(iLen, iLen - n);
	}
}

//::Trim String Function
function Trim(str){
	str = str.replace(/\s+/,'');
	str = str.replace(/\s+$/,'');
	return str;
}

//::IsNumeric Function
function IsNumeric(val){
	for (i=0; i<val.length; i++){
		if (isNaN(val.charAt(i))){
			return false;
		}
	}
	return true;
}

//::Valid E-Mail
function ValidEmail(str){
	AccPos = str.indexOf('@');
	AccStr = str.substr(0,AccPos);
	AccLen = AccStr.length;
	DomPos = str.lastIndexOf('.');
	DomStr = str.substr(AccPos+1,(DomPos-AccPos)-1);
	DomLen = DomStr.length;
	ExtPos = DomPos + 1;
	ExtLen = str.length - ExtPos;
	ExtStr = str.substr(ExtPos,ExtLen);
	if(	   (AccPos != -1)
		&& (DomPos != -1)
		&& (AccLen >= 2)
		&& (DomLen >= 2)
		&& (ExtLen >= 2)
		&& (ExtLen <= 3)){
		return true;
	}
	else{return false}
}

//::Valid E-Mail List
function ValidEmailList(str){
	var booStatus = true;
	if (str == "") {
		booStatus = false;
	}
	else if (str != "") {
		var emailStr = "";
		for (var i = 0; i < str.length; i++) {
			if (str.charAt(i) != " ") emailStr += str.charAt(i);
		}
		if (emailStr.indexOf(",") > 0) {
			emailArr = emailStr.split(",");
			for (i=0; i<emailArr.length; i++) {
				if (!ValidEmail(emailArr[i])) {
					booStatus = false;
					break;
				}
			}
		}
		else if (emailStr.indexOf(";") > 0) {
			emailArr = emailStr.split(";");
			for (i=0; i<emailArr.length; i++) {
				if (!ValidEmail(emailArr[i])) {
					booStatus = false;
					break;
				}
			}
		}
		else {
			if (!ValidEmail(str)) {
				booStatus = false;
			}
		}
	}
	return booStatus;
}

//::Valid Phone
function ValidPhone(PhoneArea,PhonePre,PhoneSuf){
	if ((Trim(PhoneArea) == "") ||
		(Trim(PhonePre) == "") ||
		(Trim(PhoneSuf) == "") ||
		(PhoneArea.length != 3) ||
		(PhonePre.length != 3) ||
		(PhoneSuf.length != 4)){
		return false;
	}else{
		if (IsNumeric(PhoneArea) &&
			IsNumeric(PhonePre) &&
			IsNumeric(PhoneSuf) &&
			(PhoneArea.length == 3) &&
			(PhonePre.length == 3) &&
			(PhoneSuf.length == 4)){
			return true;
		}
	}
}

//::Valid Telephone
function ValidTelephone(str){
	str = Trim(str);
	str = str.replace("(","");
	str = str.replace(")","");
	str = str.replace(".","");
	str = str.replace(".","");
	str = str.replace("-","");
	str = str.replace("-","");
	str = str.replace(" ","");
	strLen = str.length;
	if((strLen == 10 || strLen == 7) && IsNumeric(str)){
		return true;
	}
	else{
		return false;
	}
}

//::Valid Extensions
//ex.	 ValidExtension("c:\sample.txt","txt,pdf,doc")
function ValidExtension(str,lst){
	str = str.toLowerCase();
	lst = lst.toLowerCase();
	booValid = false;
	arrExt = lst.split(",")
	for (i=0; i<arrExt.length; i++) {
		lstExt = arrExt[i];
		curExt = Right(str,lstExt.length);
		if (lstExt == curExt) {
			booValid = true;
			break;
		}
	}
	return booValid;
}

//::Validate Feedback
function ValidateFeedback() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (objForm.company.value == "") {
	missinginfo += "\n     »  Attention: 'Company'";
	}
	if (objForm.firstname.value == "") {
	missinginfo += "\n     »  First Name";
	}
	if (objForm.lastname.value == "") {
	missinginfo += "\n     »  Last Name";
	}
	if (!ValidEmail(objForm.email.value)) {
	missinginfo += "\n     »  E-Mail";
	}
	if (objForm.comments.value == "") {
	missinginfo += "\n     »  Comments";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Service Request
function ValidateServiceRequest(srType) {
	missinginfo = "";
	var objForm = document.forms[0];

	switch (srType) {
		case 1:	//Construction
			switch (objForm.clienttype.value) {
				case "residential":
					if (objForm.buildername.value == "") {
					missinginfo += "\n     »  Builder Name";
					}
					if (objForm.subdivisionname.value == "") {
					missinginfo += "\n     »  Subdivision Name";
					}
					if (objForm.lot.value == "") {
					missinginfo += "\n     »  Lot #";
					}
					break;
				case "commercial":
					if (objForm.projectname.value == "") {
					missinginfo += "\n     »  Project Name";
					}
					if (objForm.generalcontractor.value == "") {
					missinginfo += "\n     »  General Contractor";
					}
					break;
			}
			if (objForm.requestedby.value == "") {
			missinginfo += "\n     »  Requested by";
			}
			if (!ValidEmail(objForm.emailaddress.value)) {
			missinginfo += "\n     »  E-Mail Address";
			}
			if (objForm.servicerequest.value == "") {
			missinginfo += "\n     »  Service Request";
			}
			break;

		case 2:	//Management
			if (objForm.propertyname.value == "") {
			missinginfo += "\n     »  Property Name";
			}
			if (objForm.requestedby.value == "") {
			missinginfo += "\n     »  Requested by";
			}
			if (!ValidEmail(objForm.emailaddress.value)) {
			missinginfo += "\n     »  E-Mail Address";
			}
			if (objForm.servicerequest.value == "") {
			missinginfo += "\n     »  Service Request";
			}
			break;

		case 3:	//Residential
			if (objForm.firstname.value == "") {
			missinginfo += "\n     »  First Name";
			}
			if (objForm.lastname.value == "") {
			missinginfo += "\n     »  Last Name";
			}
			if (objForm.address.value == "") {
			missinginfo += "\n     »  Service Address";
			}
			if (objForm.city.value == "") {
			missinginfo += "\n     »  City";
			}
			if (objForm.state.value == "") {
			missinginfo += "\n     »  State";
			}
			if (objForm.zip.value == "") {
			missinginfo += "\n     »  Zip Code";
			}
			if (!ValidEmail(objForm.emailaddress.value)) {
			missinginfo += "\n     »  E-Mail Address";
			}
			if (objForm.servicerequest.value == "") {
			missinginfo += "\n     »  Service Request";
			}
			break;
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}


//::Validate Request For Quote
function ValidateRequestForQuote(srType) {
	missinginfo = "";
	var objForm = document.forms[0];

	switch (srType) {
		case 1:	//Construction
			switch (objForm.clienttype.value) {
				case "residential":
					if (objForm.buildername.value == "") {
					missinginfo += "\n     »  Builder Name";
					}
					if (objForm.subdivisionname.value == "") {
					missinginfo += "\n     »  Subdivision Name";
					}
					if (objForm.lot.value == "") {
					missinginfo += "\n     »  Lot #";
					}
					break;
				case "commercial":
					if (objForm.projectname.value == "") {
					missinginfo += "\n     »  Project Name";
					}
					if (objForm.generalcontractor.value == "") {
					missinginfo += "\n     »  General Contractor";
					}
					break;
			}
			if (objForm.requestedby.value == "") {
			missinginfo += "\n     »  Requested by";
			}
			if (!ValidEmail(objForm.emailaddress.value)) {
			missinginfo += "\n     »  E-Mail Address";
			}
			if (objForm.servicerequest.value == "") {
			missinginfo += "\n     »  Service Request";
			}
			break;

		case 2:	//Management
			if (objForm.propertyname.value == "") {
			missinginfo += "\n     »  Property Name";
			}
			if (objForm.requestedby.value == "") {
			missinginfo += "\n     »  Requested by";
			}
			if (!ValidEmail(objForm.emailaddress.value)) {
			missinginfo += "\n     »  E-Mail Address";
			}
			if (objForm.servicerequest.value == "") {
			missinginfo += "\n     »  Service Request";
			}
			break;

		case 3:	//Residential
			if (objForm.firstname.value == "") {
			missinginfo += "\n     »  First Name";
			}
			if (objForm.lastname.value == "") {
			missinginfo += "\n     »  Last Name";
			}
			if (objForm.address.value == "") {
			missinginfo += "\n     »  Service Address";
			}
			if (objForm.city.value == "") {
			missinginfo += "\n     »  City";
			}
			if (objForm.state.value == "") {
			missinginfo += "\n     »  State";
			}
			if (objForm.zip.value == "") {
			missinginfo += "\n     »  Zip Code";
			}
			if (!ValidEmail(objForm.emailaddress.value)) {
			missinginfo += "\n     »  E-Mail Address";
			}
			if (!CheckSelected(objForm.howhear)) {
			missinginfo += "\n     »  How did you learn about us?";
			}
			if (!CheckSelected(objForm.service)) {
			missinginfo += "\n     »  What services are you interested in?";
			}
			//if (objForm.comments.value == "") {
			//missinginfo += "\n     »  Questions and/or Comments";
			//}
			break;
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Service Request
function ValidateSR() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (objForm.propertyname.value == "") {
	missinginfo += "\n     »  Property Name";
	}
	if (objForm.accountmanager.value == "") {
	missinginfo += "\n     »  Account Manager Name";
	}
	if (objForm.name.value == "") {
	missinginfo += "\n     »  Requested By";
	}
	if (!ValidEmail(objForm.emailaddress.value)) {
	missinginfo += "\n     »  E-Mail Address";
	}
	if (objForm.servicerequest.value == "") {
	missinginfo += "\n     »  Service Request";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Request a Proposal
function ValidateRequestProposal() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (objForm.service.value == "") {
	missinginfo += "\n     »  Type of Service";
	}
	if (objForm.name.value == "") {
	missinginfo += "\n     »  Requested By";
	}
	if (!ValidEmail(objForm.emailaddress.value)) {
	missinginfo += "\n     »  E-Mail Address";
	}
	if (objForm.comments.value == "") {
	missinginfo += "\n     »  Questions/Comments";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Request An Article
function ValidateRequestArticle() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (objForm.name.value == "") {
	missinginfo += "\n     »  Requested By";
	}
	if (!ValidEmail(objForm.emailaddress.value)) {
	missinginfo += "\n     »  E-Mail Address";
	}
	if (objForm.use.value == "") {
	missinginfo += "\n     »  Intended Use";
	}
	if (objForm.comments.value == "") {
	missinginfo += "\n     »  Subject Matter";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Warranty Request
function ValidateRequestWarranty() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (objForm.address.value == "") {
	missinginfo += "\n     »  Service Address";
	}
	if (objForm.city.value == "") {
	missinginfo += "\n     »  City";
	}
	if (objForm.state.value == "") {
	missinginfo += "\n     »  State";
	}
	if (objForm.zip.value == "") {
	missinginfo += "\n     »  Zip";
	}
	if (objForm.name.value == "") {
	missinginfo += "\n     »  Requested By";
	}
	if (!ValidEmail(objForm.emailaddress.value)) {
	missinginfo += "\n     »  E-Mail Address";
	}
	if (objForm.comments.value == "") {
	missinginfo += "\n     »  Description of Problem";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Employment Application
function ValidateEmploymentApplication() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (objForm.position.value == "") {
	missinginfo += "\n     »  Positions Available";
	}
	if (objForm.firstname.value == "") {
	missinginfo += "\n     »  First Name";
	}
	if (objForm.lastname.value == "") {
	missinginfo += "\n     »  Last Name";
	}
	if (objForm.homephone.value == "") {
	missinginfo += "\n     »  Home Telephone";
	}
	if (!ValidEmail(objForm.emailaddress.value)) {
	missinginfo += "\n     »  E-Mail Address";
	}
	if (objForm.resumeoption.value == "Upload") {
		if (objForm.file.value == "") {
		missinginfo += "\n     »  Upload Resume";
		}
		else if(!ValidExtension(objForm.file.value,"txt,pdf,doc,docx,rtf")) {
		missinginfo += "\n     »  Upload Resume: *** Invalid File Type! ***";
		}
	}
	else {
		if (objForm.resume.value == "") {
		missinginfo += "\n     »  Paste Resume";
		}
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Send Page
function ValidateSendPage() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (objForm.yourname.value == "") {
	missinginfo += "\n     »  Your Name";
	}
	if (!ValidEmail(objForm.youremail.value)) {
	missinginfo += "\n     »  Your E-Mail";
	}
	if (!ValidEmailList(objForm.recipientemail.value)) {
	missinginfo += "\n     »  Recipient E-Mail";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Email List
function ValidateEmailList() {
	missinginfo = "";
	var objForm = document.forms[0];

	if (!ValidEmail(objForm.email.value)) {
	missinginfo += "\n     »  E-Mail Address";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}