//SCOTTY'S JAVASCRIPT TRICKS

//SURVEY SCRIPTS:

// forward from survey 1 (or2) to question1
function startQ(){
window.location="question1.asp"
}

//Check Survey Email
function emailCheck(emailStr) {
// checks if the e-mail address is valid
	var emailPat = /^(\".*\"|^[A-Za-z][A-Za-z\-_\.]+)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z\-_\.]+(\.[A-Za-z]\w*)+)$/;
	var matchArray = emailStr.match(emailPat);
	if (matchArray == null) {
		alert("Your email address is empty or seems incorrect.  Please try again (if you entered an address, check the '@' and '.'s in the email address)");
		return false;
	}
// make sure the IP address domain is valid
	var IPArray = matchArray[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
	if (IPArray != null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!")
				return false;
      		}
   		}
	}
	return true;
}
//Check Survey Email & make sure one of the radio buttons is checked
function newsLetterCheck(inForm) {
// checks if the e-mail address is valid
	var emailStr = inForm.nltr_email.value;
//      var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
	var emailPat = /^(\".*\"|^[A-Za-z][A-Za-z\.\-_]+)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z\-_\.]+(\.[A-Za-z]\w*)+)$/;
	var matchArray = emailStr.match(emailPat);
	if (matchArray == null) {
		alert("Your email address is empty or seems incorrect.  Please try again (if you entered an address, check the '@' and '.'s in the email address)");
		return false;
	}
// make sure the IP address domain is valid
	var IPArray = matchArray[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
	if (IPArray != null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!")
				return false;
      		}
   		}
	}
// make sure user selected a type of user
	var aCheck = false;
	var radioChecked = inForm.clientType;
	for(var i=0;i<radioChecked.length;i++) {
		if(radioChecked[i].checked == true) {
			aCheck = true;
		}
	}
	if(aCheck == false) {
		alert("Please tell us if you are an agent, contractor or other");
		return false;
	}
	if(radioChecked[2].checked && (inForm.otherType.value == "")) {
		alert("Please tell us more in the 'other' text box");
		return false;
	}
return true;
}
//"other" focus change for survey page2
function other1(form){
	if(form.qwho.options[form.qwho.selectedIndex].text=="other"){
  	form.qwhoB.focus()}
   	else {
    	form.qwhy.focus()}
     }

//another "other" focus change for survey page2
function other2(form){
	if(form.qwhy.options[form.qwhy.selectedIndex].text=="other"){
  	form.qwhyB.focus()}
   	else {
    	form.qfind.focus()}
     }

//open survey from front page icon
function openSurvey(){ window.open("../surveys/survey1.asp","survey","width=400,height=300,screenX=100,screenY=100,top=200,left=100,scrollbars=0,resizable=1,toolbar=0,status=0")}

//OTHER SCRIPTS:

//open newsletter signup from front page icon
function openNews(){ window.open("../newsletter/newsletter1.asp","signup","width=250,height=200,screenX=100,screenY=100,top=200,left=100,scrollbars=0,resizable=1,toolbar=0,status=0")}


//show and hide financial graphs
function show(object) {
	if (document.getElementById && document.getElementById(object) != null)
	node = document.getElementById(object).style.visibility = 'visible';
	else if (document.layers && document.layers[object] != null)
	document.layers[object].visibility = 'visible';
	else if (document.all)
		document.all[object].style.visibility = 'visible';
}
function hide(object) {
	if (document.getElementById && document.getElementById(object) != null)
	node = document.getElementById(object).style.visibility ='hidden';
	else if (document.layers && document.layers[object] != null)
	document.layers[object].visibility = 'hidden';
	else if (document.all)
	document.all[object].style.visibility = 'hidden';
}

//start article email a friend
function emailWin(url,windowname){
window.open('',windowname,"width=300,height=300,screenX=100,screenY=100,top=200,left=100,scrollbars=0,resizable=1,toolbar=0,status=0");
document.forms[0].submit()
}


//change header if necessary
function myHeader(section){
// PPR - Use relative addressing for header
var path = "../../images/nav_images/"
var stop = null
if(parent.frames['headframe'].location.href.indexOf(section) != -1){stop = 1}
else if(parent.location.href.indexOf('Nv4.htm') > 0)
//{parent.frames['headframe'].location.href = 'http://www.gocbic.com/cbic/pages/nav/head/' + section + '_head_n.asp'}
//{parent.frames['headframe'].location.href = '../../pages/nav/head/' + section + '_head_n.asp'}
{parent.frames['headframe'].location.href = '/cbic/pages/nav/head/' + section + '_head_n.asp'}
else if(document.all)
{parent.frames['headframe'].document.all['header'].src = path + section + '_ctr_header.jpg'}
}
//change header if necessary
function myHomeHeader(){
//PPR - Use relative addressing for header
var path = "../../images/nav_images/"
if(parent.location.href.indexOf('Nv4.htm') > 0)
//{parent.frames['headframe'].location.href = 'http://www.gocbic.com/cbic/pages/nav/head/home_head_n.asp'}
//{parent.frames['headframe'].location.href = '../../pages/nav/head/home_head_n.asp'}
{parent.frames['headframe'].location.href = '/cbic/pages/nav/head/home_head_n.asp'}
else if(document.all)
{parent.frames['headframe'].document.all['header'].src = path + 'header.jpg'}
}


//tour slide show
var timerID = null
function changeArama(num){
	if(document.all){
	tourImage.filters[0].Apply();
	tourImage.style.visibility="visible";
	tourImage.filters[0].Play();
	timerID = setTimeout("document.location.href='corp_tour_" + num + ".htm'",10000)
	}
	else{
	timerID = setTimeout("document.location.href='corp_tour_" + num + ".htm'",10000)
		}
	}
	function stopTimer(){
	clearTimeout(timerID)
	}

//finish tour slide show
var timerID = null
function finishTour(){
	if(document.all){
	tourImage.filters[0].Apply();
	tourImage.style.visibility="visible";
	tourImage.filters[0].Play();}
	}

//modify submit button
function modSubmit(string){
document.forms[0].action = string;
document.forms[0].submit()
}

//reset button
function resetForm(myForm,numItems){
for(var i=1; i<=numItems; i++){
if(myForm.elements[i].type=="radio" || myForm.elements[i].type=="checkbox"){myForm.elements[i].checked = false}
else{if(myForm.elements[i].value.length>=1){
myForm.elements[i].value=""}
}
}
}

//submit menu
function mySubmit() {
    document.forms[0].submit()
}


//simple, generic form validation
function validateThis(myForm,numItems,msg){
for(var i=0; i<numItems; i++){
if(myForm.elements[i].value.length<1){
alert(msg);
myForm.elements[i].focus();
break;
return false;
}
}
}

//simple, generic form validation - select menus
function validateThisSelect(myForm,elmNum,msg){
if(myForm.elements[elmNum].selectedIndex==-1){
alert(msg);
return false;
}
}

//general alert

function UCalert(){
alert("this section is currently under construction.")
}

//mouseover
function swap(myimg,newsource){
document.images[myimg].src=newsource;
}

//legal disclaimer for applications
function agentlegal(){
var msg="By selecting the 'OK' box below the agent submitting this application "   
var msg=msg + "represents and warrants that the following is true and correct: "  
var msg=msg + "This submission is an on-line application for business insurance "
var msg=msg + "and is not intended primarily for personal, family, or household purposes. "
var msg=msg + "The agent submitting this application represents and warrants that the agent "
var msg=msg + "has been authorized by the business owner to submit applications for insurance on behalf of the business "
var msg=msg + "and that the business owner has authorized release of their business and personal credit reports "
var msg=msg + "in connection with the underwriting of this insurance."
alert(msg)
}

function custlegal(){
var msg="By selecting the 'OK' box below, the persons submitting "   
var msg=msg + "this application acknowledge their full and complete "  
var msg=msg + "agreement with the following: "
var msg=msg + "This is an on-line application for business insurance "   
var msg=msg + "submitted jointly by the business owners and spouses "   
var msg=msg + "entered herein.  This insurance is not for "
var msg=msg + "personal, family, or household purposes. All business owners "  
var msg=msg + "and spouses applying in this application hereby authorize "   
var msg=msg + "the release of their business and personal credit reports "   
var msg=msg + "in connection with the underwriting of this insurance. " 
var msg=msg + "Selecting the 'OK' box below is the electronic "  
var msg=msg + "equivalent of each business owner and spouse "   
var msg=msg + "entered herein signing this on-line application "
var msg=msg + "and attesting to its accuracy and completeness. "
alert(msg)
}

