﻿//string prototypes goe here
String.prototype.Trim = function()  {return this.LTrim().RTrim();};
String.prototype.LTrim = function() {var re = /\s*((\S+\s*)*)/; return this.replace(re, "$1"); }
String.prototype.RTrim = function() { var re = /((\s*\S+)*)\s*/; return this.replace(re, "$1");	}


// JScript File

function goSearch( format, keyword)
{

    sFormat = new String(format);

    sKeyword = new String (keyword);
    url = format.replace("{0}", sKeyword);
    
    if (url != "") {
        if ((parseInt(navigator.appVersion) == 2) && (navigator.appName == "Microsoft Internet Explorer"))
                top.location = url;
        else top.document.location = url;
    }
}


function goSearchEncyclopedia( format, keyword)
{

    sFormat = new String(format);
    sKeyword = new String (keyword);
    
    // replacing spaces with +
    sKeyword = sKeyword.replace(" ", "+");
    
    // add query string parameter value keyword in url
    url = sFormat.replace("{0}", sKeyword);
    
 
    if (url != "") {
        if ((parseInt(navigator.appVersion) == 2) && (navigator.appName == "Microsoft Internet Explorer"))
                top.location = url;
        else top.document.location = url;
    }
}


// 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 gradeLeadershipQuiz()
{ 
    var score = 0
    for(i=1; i <21; i++)//16
    {
        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.getElementsByName('q'+i).item(4).checked)
        {
            alert ('Please answer question ' + i +'.')  
            return false; 
        }
        for(j=0; j<5; j++)
        {
            if(document.getElementsByName('q'+i).item(j).checked)
            {
                score =  parseInt(score, 10) +  parseInt(document.getElementsByName('q'+i).item(j).value, 10);
                break;
            }
        }   
    }
    document.getElementById("score").value = score; 
    return true;
}

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;
    return true;
}  

function gradeYourOfficeQuiz() 
{
    var ans="";
    var scoreStr=""; // = 0; 
//    int numQ;
//    numQ = parseInt(document.getElementById("numQ").value, 10);
    for(i=1; i <= 10; i++)
    { 
        if(!document.getElementsByName('q'+i).item(0).checked && !document.getElementsByName('q'+i).item(1).checked && !document.getElementsByName('q'+i).item(2).checked)
        { 
            alert ('Please complete all questions!');  
            return false; 
        }  
        for(j=0; j<3; j++)
        {
            if(document.getElementsByName('q'+i).item(j).checked) 
            {  
               // score = parseInt(score, 10) + parseInt(document.getElementsByName('q'+i).item(j).value, 10);
                scoreStr =scoreStr + document.getElementsByName('q'+i).item(j).value;
            }               
        } 
    } 
    document.getElementById("ansStr").value= scoreStr;   
    return true;
}   

function gradeEinsteinQuiz() 
{

    var ans="";
    var scoreStr; // = 0; 
    scoreStr=0;
//    int numQ;
//    numQ = parseInt(document.getElementById("numQ").value, 10);
    for(i=1; i <= 22; i++)
    { 
        if(!document.getElementsByName('q'+i).item(0).checked && !document.getElementsByName('q'+i).item(1).checked )
        { 
            alert ('Please complete all questions!');  
            return false; 
        }  
        for(j=0; j<2; j++)
        {
            if(document.getElementsByName('q'+i).item(j).checked) 
            {  
               // score = parseInt(score, 10) + parseInt(document.getElementsByName('q'+i).item(j).value, 10);
                scoreStr +=parseInt(document.getElementsByName('q'+i).item(j).value);
            }                       
        } 
    } 
  
    document.getElementById("score").value= scoreStr;   
    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="";
}

function region()
{
 document.getElementById('region').style.display="";
 document.getElementById('rank').style.display="none";
 document.getElementById('industry').style.display="none";
}
function rank()
{
 document.getElementById('region').style.display="none";
 document.getElementById('rank').style.display="";
 document.getElementById('industry').style.display="none";
}
function industry()
{
 document.getElementById('region').style.display="none";
 document.getElementById('rank').style.display="none";
 document.getElementById('industry').style.display="";
}
function closeregion()
{
    document.getElementById('region').style.display = "none"; 
	document.getElementById('rank').style.display = "none"; 
	document.getElementById('industry').style.display = "none"; 
    return false;
}


// 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;
}




//added 12/21 for sub categories boxes
function ShowMenu(ulDiv)
{ 
    HideAllMenus();
    var ulElem = document.getElementById(ulDiv);
	document.getElementById(ulDiv).style.display ="";
	ulElem.style.zIndex = "100";
}
function HideMenu(ulDiv){
    document.getElementById(ulDiv).style.display="none";
} 

function HideAllMenus(){
 var i;
    for( i= 1; i < 14; i++)
    {
        var s= "Div" + i.toString();
        HideMenu(s); 
    }
}
function DeselectAll()
{
    for( var i= 1; i < 14; i++)
    {
        var s2="img" + i.toString();
        document.getElementById(s2).src ="/i/images/ch/franchises/button_default.gif";
        document.getElementById(s2).setAttribute("rel","close");
    }
}
function Toggle(img, div)
{
    var ulElem = document.getElementById(div);    
    HideAllMenus();  
    if(img.getAttribute("rel")=="open" ){
        img.setAttribute("rel", "close");
        ulElem.style.display="none";
        img.src="/i/images/ch/franchises/button_default.gif";
    }
    else if(img.getAttribute("rel")=="close")
    {
        DeselectAll();
        img.setAttribute("rel", "open");
        ulElem.style.display="block";
        img.src="/i/images/ch/franchises/button_selected.gif";    
    }
}

function mouseOver(img)
{
    if(img.getAttribute("rel")!="open") 
        img.src='/i/images/ch/franchises/button_hover.gif';
}
function mouseOut()
{  
    for( var i= 1; i < 14; i++)
    {
        var s2="img" + i.toString();
        if(document.getElementById(s2).getAttribute("rel")=="open")
        {    
            document.getElementById(s2).src='/i/images/ch/franchises/button_selected.gif';
        }
        else
        document.getElementById(s2).src='/i/images/ch/franchises/button_default.gif';
    }
}



function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}



/* Text Sizer */
var tgs = new Array( 'div','td','tr');

var szs = new Array( '14px','16px' );
//var szs = new Array( 'small','medium' );
var startSz = 1;

function textsizer( trgt,inc ) {
	if (!document.getElementById) return
	var doc = document,text = null,sz = startSz,i,j,cTags;
	
	sz += inc;
	if ( sz < 0 ) sz = 0;
	if ( sz > 1 ) sz = 1;
	startSz = sz;
		
	if ( !( text = doc.getElementById( trgt ) ) ) text = doc.getElementsByTagName( trgt )[ 0 ];

	text.style.fontSize = szs[ sz ];

	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = text.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
	}
}

function GSearch3(q) //google search text box.  
{
//?cx=013574105172325703311%3Axhkof7qpqpa&cof=FORID%3A9&q=money&_btnSearch.x=0&_btnSearch.y=0#963
    var srchStr="q="+UrlEnc(q) + "&cx=013574105172325703311%3Axhkof7qpqpa&cof=FORID%3A9";    
    goSearch('http://search.entrepreneur.com/GoogleSearchResults.php?{0}',srchStr);     
}

function GSearch2(q ,site) //google search text box.  Dependency: UrlEnc
{
    var srchStr="q="+UrlEnc(q) + "&client=pub-1914278930181225&cof="+UrlEnc("GALT:#009900;GL:1;DIV:#C0C0C0;VLC:003399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:003399;LC:003399;T:000000;GFNT:666666;GIMP:003399;FORID:9")+ "&sitesearch="+ site;    
    goSearch('http://search.entrepreneur.com/GoogleSearchResults.php?{0}',srchStr);     
}

function GSearch() //google search text box.  Dependency: UrlEnc
{
    var site= (document.getElementsByName('site').item(1).checked)?"":"www.entrepreneur.com";
    var srchStr="q="+UrlEnc( document.getElementById('q').value) + "&client=" + UrlEnc(document.getElementById('cx').value) + "&cof="+UrlEnc(document.getElementById('cof').value )+ "&sitesearch="+ site;
    goSearch('http://search.entrepreneur.com/GoogleSearchResults.php?{0}',srchStr);      
}


function UrlEnc(str) //url encode a string for google search
{ 
	var SAFECHARS = "0123456789" +
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";
	var HEX = "0123456789ABCDEF";

	var plaintext = str;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} 
	return encoded;
}

//toggle and toggle images for various controls. 
imgminus = new Image(); 
imgminus.src = "/graphics/minus.gif"; 
imgplus = new Image(); 
imgplus.src = "/graphics/plus.gif";
function toggle(divId, imgname) {
	var d = document.getElementById(divId);
	
	if (d.style.display != 'block') {
		 document [imgname].src = imgminus.src; 
		 d.style.display = 'block';
		 
	} else {
		document [imgname].src = imgplus.src;
		d.style.display = 'none';
	}
}

function toggle2(divId, imgname) {
	var d = document.getElementById(divId);
	
	if (d.style.display != 'block') {
		 document [imgname].src = imgplus.src;
		 d.style.display = 'block';
		 
	} else {
		document [imgname].src = imgminus.src; 
		d.style.display = 'none';
	}
}

function toggle_noimg(divId) {
	var d = document.getElementById(divId);
	if (d.style.display != 'block') {
		 d.style.display = 'block';
		 
	} else {
		 d.style.display = 'none';
	}
}

function toggle_layer(szDivID)
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = (document.layers[szDivID].visibility=="hide") ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = (obj.style.visibility=="hidden") ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = (document.all[szDivID].style.visibility=="hidden") ? "visible" : "hidden";
    }
}



function getmetaContents(mn){ 
  var m = document.getElementsByTagName('meta'); 
  for(var i in m){ 
   if(m[i].name == mn){ 
     return m[i].content; 
   } 
  } 
}


var Url = {

	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},

	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}
