﻿// email this window opener
function openEmailThis(sURL)
{
    newwindow=open(sURL, "emailthis", "scrollbars=no,toolbar=no,directories=no,location=no,menubar=no,resizable=no,status=no,width=432,height=615");
}

function isValidZip (strZip)
{
    reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/); 
    if(!reZip.test(strZip)) 
        return false;
    return true;
}

function isValidEmail(strAddress)
{
    var exclude = /[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@] \1/;
	var check = /@[\w\-]+\./;
	var checkend = /\.[a-zA-Z]{2,5}$/;
	if (((strAddress.search(exclude) != -1) || (strAddress.search(check)) == -1) || (strAddress.search(checkend) == -1)){
        return false;
    } 
    return true;
} 

// this function fill the given div element by id
function FillDivById(id, data)
{
    //alert('id: ' + id + ', data: ' + data);
    if (document.getElementById(id)) {
        //alert('id found');
        document.getElementById(id).innerHTML = data;
    }
}

// this function shows or hides the given div element by id
function ShowDivById(id, show)
{
    var showOption = "none";
    if (show) {
        showOption = "block";
    }

    //alert('id: ' + id + ', show: ' + showOption);
    document.getElementById(id).style.display = showOption;
}

function DbAppsGotoURL(urlFormat, listControl) {

  // get the state from the listControl value
  var State = document.getElementById(listControl).value;


  // Create url by replacing placeholder with state value
  sUrlFormat = new String(urlFormat);
  var url= sUrlFormat.replace("{0}", State);
 
 // go To Url!
 if (url != "") {
        if ((parseInt(navigator.appVersion) == 2) && (navigator.appName == "Microsoft Internet Explorer"))
                top.location = url;
        else top.document.location = url;
        }
}

// this function is used to open a new window using the given args
function windowOpener(url, name, args)
{
    if (typeof(popupWin) != "object") {
        popupWin = window.open(url, name, args);
    } else {
        if (!popupWin.closed) {
            popupWin.location.href = url;
        } else {
            popupWin = window.open(url, name,args);
        }
    }

    popupWin.focus();
}
 
function goToThunderstoneSearch(keywordId, prId)

{   

    if(document.getElementById(keywordId).value.replace(/^\s+|\s+$/g, '')=='')

    {

        alert("Please enter what you want to search.");

        return false;

     }

    window.document.location = 'http://websearch.entrepreneur.com/cgi-bin/texis/webinator/search/?query=' + document.getElementById(keywordId).value + '&pr=' +document.getElementById(prId).value; return false;

}

function goToAOLSearch(keywordId, invocationTypeId)
{
    window.document.location = 'http://aolsearch.aol.com/aol/search?query=' + document.getElementById(keywordId).value + '&invocationType=' +document.getElementById(invocationTypeId).value; return true;
}


/*******************************************
BEGIN CODE FOR QUIZZES added 07/25/06
*******************************************/

function gradeBadBossQuiz()

{ 

    var score = 0

            for(i=1; i < 16; i++)//16

            {

                if(!document.getElementsByName('q'+i).item(0).checked && !document.getElementsByName('q'+i).item(1).checked && !document.getElementsByName('q'+i).item(2).checked)

               {  

                                                alert ('Please answer question ' + i +'.')  

                                                return false; 

                                    }

        if(document.getElementsByName('q'+i).item(0).checked)

            score =  parseInt(score, 10) +  parseInt(document.getElementsByName('q'+i).item(0).value, 10)

        if(document.getElementsByName('q'+i).item(1).checked)

            score = parseInt(score, 10) + parseInt(document.getElementsByName('q'+i).item(1).value, 10)

        if(document.getElementsByName('q'+i).item(2).checked)

            score =  parseInt(score, 10) + parseInt(document.getElementsByName('q'+i).item(2).value, 10)

    }                   

    document.getElementById("score").value = score; 

   

    return true;

}

 

function gradeMarketingIQ() 

{

            var ans="";

            var score = 0;

            

            for(i=1; i < 11; i++)

    { 

        

                        if(!document.getElementsByName('q'+i).item(0).checked && !document.getElementsByName('q'+i).item(1).checked && !document.getElementsByName('q'+i).item(2).checked && !document.getElementsByName('q'+i).item(3).checked)

                        { 

                                    document.getElementById("complete").value="f";

                                    alert ('Please complete all questions!');  

                                    return false; 

                        }  

              

                for(j=0; j<4; j++)

                {

                    if(document.getElementsByName('q'+i).item(j).checked) 

                            {  

                                      score = parseInt(score, 10) + parseInt(document.getElementsByName('q'+i).item(j).value, 10); 

                    }               

                } 

             

                        if(document.getElementsByName('q'+i).item(0).checked) 

                                    document.getElementById("answer"+i).value = 'A';  

                        if(document.getElementsByName('q'+i).item(1).checked) 

                                    document.getElementById("answer"+i).value = 'B';

                        if(document.getElementsByName('q'+i).item(2).checked) 

                                    document.getElementById("answer"+i).value = 'C';

                        if(document.getElementsByName('q'+i).item(3).checked) 

                                    document.getElementById("answer"+i).value = 'D';            

            } 

    document.getElementById("score").value= score;

//    alert('var score = ' +score + '    score=' + document.getElementById("score").value);

            return true;

}  

 



/*******************************************
BEGIN CODE FOR NEWSLETTERS
*******************************************/

function newsLettersFormCheck(){	
	var status = false;
	document.getElementById("listname").value = '';

	for( var i = 0; i < document.getElementsByName("listname").length; i++){
		if(document.getElementsByName("listname").item(i).checked){
		   document.getElementById("listname").value +=  'listname='+ document.getElementsByName("listname").item(i).value + '&';
		   status = true;
		}
	}

	if(status)
	    return true;
	else 
	{
            alert("Please select at least one interest area.");
	    return false;
	}	
}

/******************************************
MODIFIED gotoUrl() added gotoUrl2()
******************************************/
function gotoUrl(url)
{
    if(url =="" || url==null || url.toLowerCase() == 'select state'){
	return false;
    }
    if (url != "") {
        if ((parseInt(navigator.appVersion) == 2) && (navigator.appName == "Microsoft Internet Explorer")) {
            top.location = url;
        } else {
            top.document.location = url;
        }
    }
}

function gotoUrl2(url, opt)
{
    if(url =="" || url==null || opt.selectedIndex==0){
	return false;
    }
    gotoUrl(url);
}

/*******************************************
BEGIN CODE FOR CONFERENCE REGISTRATION
*******************************************/
/*
function onload(){
   if( document.getElementsByName("fax").item(0).checked)
        document.getElementById("q5Text").style.display="";
	else
		document.getElementById("contry").value ="";
   if( document.getElementsByName("title").item(0).checked)
        document.getElementById("q6Text").style.display="";
	else
		document.getElementById("address2").value ="";
}   
*/


function show5(){ 
	document.getElementById("q5Text").style.display="";
	return true; 
}
function hide5(){ 
	document.getElementById("country").value ="";
	document.getElementById("q5Text").style.display="none"; 
	return true; 
}

function show6(){
	document.getElementById("q6Text").style.display="";
	return true; 
}
function hide6(){
	document.getElementById("address2").value ="";
	document.getElementById("q6Text").style.display="none"; 
	return true;  
}
function isEmpty(strng) {
	if (strng.length == 0) {
		return true;
	}
	return false;  
}

function isEmail (strng) {
	if (strng == "") {
	   return false;
	}
    var emailFilter=/^.+@.+..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       return false;
    }
   
	return true;   
}
function isZipcode (zip)
{
    reZip = new RegExp(/(^d{5}$)|(^d{5}-d{4}$)/); 
    if(!reZip.test(document.getElementById("zip").value)) 
        return false;
    return true;
} 
 
function validateConference()
{  
 	if (isEmpty(document.getElementById("fName").value))
	{
		alert('Please tell us your first name.');
		return false;
	}
	if (isEmpty(document.getElementById("lName").value))
	{
		alert('Please tell us your last name.');
		return false;
	} 
	if (isEmpty(document.getElementById("companyName").value))
	{
		alert('Please tell us your company name.');
		return false;
	}
	if (isEmpty(document.getElementById("address1").value))
	{
		alert('Please tell us your company address.');
		return false;
	}
	if (isEmpty(document.getElementById("city").value))
	{
		alert('Please enter city.');
		return false;
	}
	if (isEmpty(document.getElementById("state").value))
	{
		alert('Please select state.');
		return false;
	} 
	if (isEmpty(document.getElementById("zip").value))
	{
		alert('Please enter a valid zip code.');
		return false;
	} 
	if ( isEmpty (document.getElementById("email").value)) 
	{
		alert('Please provide us with your email address.')
		return false;
	}
	if ( isEmpty (document.getElementById("phone").value)) 
	{
		alert('Please provide us with your telephone number.')
		return false;
	}	


	var myOption = -1;
	for (i=0; i<document.getElementsByName("businessOwner").length; i++) {
		if (document.getElementsByName("businessOwner").item(i).checked) {
			myOption = i;
		}
	}
	if (myOption == -1) {
		alert("Please tell us whether or not you own a business.");
		return false;
	}
	myOption = -1;
	for (i=0; i<document.getElementsByName("fax").length; i++) {
		if (document.getElementsByName("fax").item(i).checked) {
			myOption = i;
		}
	}
	if (myOption == -1) {
		alert("Please tell us if you have a State Farm agent.");
		return false;
	}
	
	if(document.getElementsByName("fax").item(0).checked && isEmpty(document.getElementById("country").value)) {
		alert ("Please tell us your State Farm agent's name.");
		return false;
	}

	myOption = -1;
	for (i=0; i<document.getElementsByName("title").length; i++) {
		if (document.getElementsByName("title").item(i).checked) {
			myOption = i;
		}
	}
	if (myOption == -1) {
		alert("Please tell us if you were invited to the seminar by a State Farm agent.");
		return false;
	}
	if(document.getElementsByName("title").item(0).checked && isEmpty(document.getElementById("address2").value)) {
		alert ("Please tell us the State Farm agent who invited you.");
		return false;
	}
		myOption = -1;
	for (i=0; i<document.getElementsByName("grossSales").length; i++) {
		if (document.getElementsByName("grossSales").item(i).checked) { 
			myOption=i; 
		}
	}
	if (myOption == -1) {
		alert("Please tell us if your business is primarily located in your home.");
		return false;
	}	
			
	
	if (document.getElementById("age").selectedIndex == 0){  
  		alert("Please indicate how many years you've been in business");
		return false;
	}
	if (document.getElementById("purchaseDecisions").selectedIndex == 0){  
  		alert("Please indicate how many employees you have");
		return false;
	} 
	if (document.getElementById("gender").selectedIndex == 0){  
  		alert("Please tell us what industry best describes your business");
		return false;
	}    
	if (document.getElementById("promoCode").selectedIndex == 0) 
	{
		alert('Please tell us how you heard about these seminars.')
		return false;
	}   
 	return true;
} 
/*******************************************
END CODE FOR CONFERENCE REGISTRATION
*******************************************/

 /******************************************
Comercial vehicle center popup
******************************************/
function openit(sURL)
{
    newwindow=open(sURL,"newwin","scrollbars=yes,toolbar=no,directories=no,menubar=no,resizable=yes,left=300,top=154,status=yes,width=615,height=550");
}

function openFeaturePopup(sURL)
{
    newwindow=open(sURL,"","status=no,resizable=no,scrollbars=no,location=no,directories=no,menubar=no,width=742,height=550");
}
 
/*****************************************
NEWSLETTERS SIGNUP
*****************************************/
function gotoNewsletterForm(urlFormat)
{
    
    var selValue = getNewslettersSelection(); 
    
    gotoUrl(urlFormat +selValue);
}
 
function getNewslettersSelection()
{
    var selection = 0;
    
    if (getCheckboxSelection("chkLeftSAB"))
        selection +=1;
    
    if (getCheckboxSelection("chkLeftSAM"))
        selection +=2;
        
    if (getCheckboxSelection("chkLeftGAB"))
        selection +=4;
        
    if (getCheckboxSelection("chkLeftEBZ"))
        selection +=8;
        
    if (getCheckboxSelection("chkLeftFZN"))
        selection +=16;
        
    if (getCheckboxSelection("chkLeftBKS"))
        selection +=32;
        
    return selection;
        
}
 
function getCheckboxSelection(id)
{
    var checkbox = document.getElementById(id);
    
    if (checkbox != null && checkbox.checked)
    {
        return true;
    }
    else
        return false;
    
}

function fran1()
{
 document.getElementById('list').style.display="";
 document.getElementById('opps').style.display="none";
}
function fran2()
{
 document.getElementById('list').style.display="none";
 document.getElementById('opps').style.display="";
}

// open popup for setting preview date taken from value of give input control
function setPreviewDate(textBoxId)
{
    var date = document.getElementById(textBoxId);
    
    if(date != null)
    {
        ecmPopUpWindow("/admin/setPreviewDate.aspx?preview_date=" +date.value, "SetPreviewDate", 1, 1, 1, 1);return false;
    }
}


 function showFeatured()
{
	document.getElementById('featuredBox').style.display="";
	document.getElementById('oppBox').style.display="none";
	document.getElementById('catBox').style.display="none";
}
function showOpp()
{
	document.getElementById('featuredBox').style.display="none";
	document.getElementById('oppBox').style.display="";
}
function openCatBox()
{
    document.getElementById('catBox').style.display = ""; 
    return false;
}
function closeCatBox()
{
    document.getElementById('catBox').style.display = "none"; 
    return false;
}

// function that takes the windows event and if it is an enter key
// will fire the default given button
function fireDefaultButton(e, button)
{
    var keychar = '';
    
    if(window.event) // IE
    {
        keychar = e.keyCode
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
        keychar = e.which
    }

    if (e == null)
        e = windows.event;
        
    if (keychar == '13')
    {
        var ctl = document.getElementById(button);
        if (ctl != null)
        {
            ctl.focus();
            ctl.click();
            
            return false;
        }
    }
}

function validateAlias(e)
{
    var keychar = '';
    
    if(window.event) // IE
    {
        keychar = e.keyCode
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
        keychar = e.which
    }
    
    //alert( keychar );
    
    if (e == null)
        e = window.event;
        
    /*if (keychar == '46' || keychar == '32' || keychar == '47' || keychar == '63' || keychar == '38' || keychar == '58' ) //period, space, /, ?, 
    {
        alert( 'The alias can only contain A through Z, 0 through 9, and a hyphen (-). If you are entering an extension, stop and please use the menu on the right.' );
        return false;
    }*/

    var keyint = parseInt(keychar);
    
    if( (keyint >= 48 && keyint <= 57) ||   //0-9
        (keyint >= 97 && keyint <= 122)||   //a-z
        (keyint >= 65 && keyint <= 90) ||   //a-z
        keyint == 47 ||                     // /
        keyint == 45 ||                     // -
        keyint <= 27 ||                       // any control character is allowed
        keyint == 127  ||                     // DEL
        keyint > 255                       // any other non visual character is allowed
        ){                      
        //do nothing for valid characters    
        
        return true;
    }
    else{
        alert( 'The alias can only contain A through Z, 0 through 9, and a hyphen (-). If you are entering an extension, stop and please use the menu on the right.' );
        return false;
    }
    
}

function checkAliasSelectedForDeletion()
{
    var table  = document.getElementById("tableResults");
    
    var foundCheck = false;
    if (table != null)
    {
        var inputControls = table.getElementsByTagName("input");
        
        if (inputControls != null && inputControls.length >0)
        {    
            var i;
            for(i=0; i< inputControls.length; i++)
            {
                if (inputControls[i].type == "checkbox" && inputControls[i].checked)
                {
                    foundCheck = true;
                }
            }
            
        }
    }
    
    if (!foundCheck)
    {
        alert("No alias has been marked for deletion. Please select one.");
    }
    return foundCheck;
}
