 function call_Refresh_Preview(elementName,element) {
        var elementValue =element.value;
              var a = new Array('phoneNumber','adTitle','promotionalText','displayUrl','eMail','adName','adGroup','globalBid');
             if ((elementName=='phoneNumber') ||(elementName=='adTitle')||(elementName=='promotionalText')||(elementName=='displayUrl')||(elementName=='eMail')||(elementName=='adNamessss')||(elementName=='adGroup'))
                    elementValue =","+elementValue;            
             // remove the -- your ad here -- text from the preview section
             document.getElementById('yourAdHere').style.display='none';
             if (document.getElementById(elementName))
             {    
                if (elementName == 'globalBid')
                 {
                    document.getElementById(elementName).innerHTML = "$" + element.value;
                 }
                 else if ( elementName == 'street' || elementName == 'suite' || elementName == 'city') 
                 {
                    if ( element.value != '')
                    {
                        document.getElementById(elementName).innerHTML = element.value + ", ";
                    }
                    else
                    {
                        document.getElementById(elementName).innerHTML = element.value
                    }
                 }
                 else if ( elementName == 'state' ) 
                 {
                    if ( element.value != '')
                    {
                        document.getElementById(elementName).innerHTML = element.value + " ";
                    }
                    else
                    {
                        document.getElementById(elementName).innerHTML = element.value
                    }
                 }
                 else if ( elementName == 'eMail' )
                 {
                    document.getElementById(elementName).innerHTML = '<u>'+element.value+'</u>';
                 }
                 else if ( elementName == 'phoneNumber' )
                 {
                    document.getElementById(elementName).innerHTML = element.value+'<br/>';
                 }
                 else
                 {                                        
                        document.getElementById(elementName).innerHTML = element.value;                    
                 }
            }
        }
    
        function refresh_Addrress_InPreview(addSelOption)
        {
      
            if (addSelOption!=null && addSelOption.value == '4')
            {
            
                document.getElementById('street').style.display="none";
                document.getElementById('suite').style.display="none";
                document.getElementById('city').style.display="none";
                document.getElementById('state').style.display="none";
                document.getElementById('zip').style.display="none";
            }
            else if (addSelOption!=null && addSelOption.value == '1')
            {
               
                document.getElementById('street').style.display="inline";
                document.getElementById('suite').style.display="inline";
                document.getElementById('city').style.display="inline";
                document.getElementById('state').style.display="inline";
                document.getElementById('zip').style.display="inline";
            }
            else if (addSelOption!=null && addSelOption.value == '2')
            {
              
                document.getElementById('street').style.display="none";
                document.getElementById('suite').style.display="none";
                document.getElementById('city').style.display="inline";
                document.getElementById('state').style.display="inline";
                document.getElementById('zip').style.display="inline";
            }
           
            return true;
        }
  
    
    // to display the icon when the user starts typing in website txt box.
    function showIcon( website, setting, elementName )
    {
        // remove the -- your ad here -- text from the preview section
        document.getElementById('yourAdHere').style.display='none';
        // if ( website.value.length > 7 && website.value.substring(0,7) == 'http://')
        if ( website.value.length > 0 ) 
        {                              
            document.getElementById('displayUrl').innerHTML = "<a href='"+website.value+"' target='_blank'>" + website.value + "</a>";                                     
            return true;
        }      
        else
        {            
            document.getElementById('displayUrl').innerHTML = '';            
        }  
    }
    
   
    
    //          Validation for Bid by category page ::
    
    function validateBid( amount )
        {
            var validBid = 0.20;
            var maxBid = 999.99;
            var bid = amount.value;
            
            var amountLength = amount.value.length;
            var numDots = 0;
            var i;
            
            if ( bid < validBid  && bid != 0  )
            {
               alert ('A minimum bid of 20 cents is required');
               amount.focus();
               return false;
            }
            else if ( bid > maxBid )
            {
               alert ('Your bid has surpassed the maximum allowed');
               amount.focus();
               return false;
            }
            
            for (i=0;i<amountLength;i++)
            {
                var x = amount.value.substr(i, 1);
                if (isNaN (x))
                {
                    if (x == ".")
                    {
                        numDots++;
                        if (numDots > 1)
                        {
                            alert ("Please enter exactly one decimal point.");
                            amount.focus();
                            return false;
                        }
                    }
                    else
                    {
                        alert ("Plese enter amount in decimal digits.");
                        amount.focus();
                        return false;
                    }
                }
                if (x == ".")
                {
                    var decimalDigits = (amountLength - 1) - i;
                    if (decimalDigits > 2)
                    {
                        
                        alert ("Please enter maximum two decimal digits.");
                        amount.focus();
                        return false;
                    } 
                }
            }
            return true;
        }
        
        
        function validateBidAmountLength(amount)
        {
            var amountLength = amount.length;
            var numDots = 0;
            var i;
            var decimalflag = false;
            var decimalDigits = 0;
            for (i=0;i<amountLength;i++)
            {
                var x = amount.substr(i, 1);
                if (isNaN (x))
                {
                    if (x == ".")  
                    {
                        numDots++;
                        decimalflag = true;
                        if (numDots > 1)
                        {
                            alert ("Please enter exactly one decimal point.");                            
                            return false;
                        }
                    }
                    else
                    {
                        alert ("Plese enter amount in decimal digits.");
                        return false;
                    }
                }
                if ( decimalflag == true && x != "." )
                {
                    
                    if (decimalDigits > 2)
                    {
                        
                        alert ("Please enter maximum two decimal digits.");
                        return false;
                    } 
                    decimalDigits++;
                }
            }
            return true;    
        }
  

     function expandKeyWords(str)
     {
      var a = new Array('0','1','2','3','4','5');                
         if(document.getElementById('keymore'+a[str]))
            document.getElementById('keymore'+a[str]).style.display = "inline";
         if(document.getElementById('key'+a[str]))
            document.getElementById('key'+a[str]).style.display = "none";
         
         
        return false; 
     }
     
     
     // PPC FULL SERVICE
     
      var proTxt = ""
    function checkChars(){
            var n = 0;
            n = 150 - document.forms[getNetuiTagName("adInfo")][getNetuiTagName("promotionalText")].value.length;
        if (n >=0){
            document.getElementById("charsRem").innerHTML=n + " Characters Remaining";                                           
        }
        else
        {              
            proTxt = document.forms[getNetuiTagName("adInfo")][getNetuiTagName("promotionalText",this)].value;
            proTxt = proTxt.substr(0,150);
            document.forms[getNetuiTagName("adInfo")][getNetuiTagName("promotionalText")].value = proTxt;            
            document.getElementById("charsRem").innerHTML="0 Characters Remaining";
        }
        return true;
    }
    
    function hide(flag)
    {        
        document.getElementById("displayurl1").style.visibility= flag;
        document.getElementById("displayurl2").style.visibility= flag;
        document.getElementById("displayurl3").style.visibility= flag;
    }
    
 function dateSetup()
     {
        var month = document.forms.signup.month.value;
        var year = document.forms.signup.year.value;
        var days = document.forms.signup.days.options.length;
        if(month == "January" || month == "March" || month == "May" || month == "July" ||
           month == "August" || month == "October" || month == "December")
           {
                days=31;
           }
        else if(month == "April" || month == "June" || month == "September" || month == "November")
        {
            days=30;
        }
        else if(month == "February")
        {
            if((year%4 == 0))
            {
                days = 29;
            }
            else 
            {
                days = 28;
            }
        }
        
        document.forms.signup.days.options.length = days;
        for(i = 28 ;i<=days; i++)
        {
            var option = new Option(i,i);
            document.forms.signup.days.options[i-1] = option;
        }
        document.forms.signup.days.options[days-1].selected = true;
     }      
     
     
     
//************** Bidgrid functions ******************

//using AJAX to open geo lists
function openGeoList(header, cell, catId) {        

    //make sure AJAX function is only called once
    if(clicked == false)
    {
        clicked = true;
    
        //get the geolist container
        var theader = document.getElementById(header);
        var color;
        var bid;                                 

        //get the color of the current row
        if(cell.parentNode.parentNode.parentNode.parentNode.parentNode.className.indexOf('white') >= 0)
        {
            color = "white";
        }
        else
        {
            color = "grey";
        }   

        if(theader.className == 'collapse')
        {
        
            if(theader.getElementsByTagName('tr').length == 0)
            {                  
                bid = document.getElementById('category'+catId).value;
                
                var url = '/spportal/locations.do?categoryId='+catId+'&bid='+bid+'&datehack=' + new Date().getTime();          
                        
                var req = null;
                if(header.indexOf('metro') >= 0)
                {
                    url = url + '&location=METR';
                }
                            
                //native XMLHttpRequest object
                if (window.XMLHttpRequest) {                  
                   req = new XMLHttpRequest();
                    if (req.overrideMimeType) {
                        req.overrideMimeType('text/xml');
                    }
                }
                //IE ActiveX object
                else if (window.ActiveXObject) {                    
                   req = new ActiveXObject("Microsoft.XMLHTTP");
                }                                       
                
                req.onreadystatechange = function(){
                    if (req.readyState == 4) {
                            if (req.status == 200) {                                                                                     
                                generateList(header, theader, cell, req, color);                                                                                                   
                            }
                    }
                };
                req.open("GET", url, true); 
                req.send(null);                                                    
                cell.innerHTML = 'loading ...';
            }
            else
            {
                cell.parentNode.parentNode.parentNode.parentNode.parentNode.className = 'firstCellTop'+color;   
                theader.className = 'show';
                clicked = false;                
                displayLink(header, cell, 'hide');                            
            }                                                         
        }
        else
        {
            theader.className = 'collapse';
                              
            displayLink(header, cell, 'show');
            
            cell.parentNode.parentNode.parentNode.parentNode.parentNode.className = 'firstCellCollapse'+color;
            clicked = false;
        } 
    }
}

//toggle between states and metros locations for a nationwide ppc campaign
function toggleLocation(header, cell) {        
    
    //make sure AJAX function is only called once
    if(clicked == false)
    {                         
        var theader = document.getElementById(header);    
        var color;                                      
    
        //get the color of the current row
        if(cell.parentNode.parentNode.parentNode.parentNode.parentNode.className.indexOf('white') >= 0)
        {
            color = "white";
        }
        else
        {
            color = "grey";
        } 
                  
        if(theader.className != 'collapse') 
        {
            theader.className = 'collapse';
                              
            displayLink(header, cell, 'show');
            
            cell.parentNode.parentNode.parentNode.parentNode.parentNode.className = 'firstCellCollapse'+color;
            clicked = false;
        } 
    }
    
}

//displays the correct text for the location links
function displayLink(header, cell, flag)
{
    if(header.indexOf('metro') >= 0)
    {
        cell.innerHTML = flag + ' metros';
    }
    else if(header.indexOf('states') >= 0)
    {
        cell.innerHTML = flag + ' states';
    }
    else
    {        
        cell.innerHTML = flag + ' locations';            
    }
}

//parse the responseXML and generate elements for the geo lists
function generateList(header, theader, cell, req, color)
{	      
    var row;
    var col;    
    var bidfield;    
	var custDetailDoc = req.responseXML;                 
    var geos = custDetailDoc.getElementsByTagName('geo');  
    var catName;    
        
    
    for(var j=0; j<geos.length; ++j)
    {                                                                               
        row = theader.appendChild(document.createElement('tr'));
       
        //create indent column
        col = row.appendChild(document.createElement('td'));            
        if(j < geos.length-1)
            col.className = 'firstCellMiddle'+color;
        else
            col.className = 'firstCellBottom'+color;
        col.innerHTML = "&nbsp;";
        
        //create category column
        col = row.appendChild(document.createElement('td'));
        col.className = color+'Row';
        col.colSpan = 2;
        
        catName = new String(geos[j].childNodes[1].firstChild.nodeValue);        
        while(catName.match("amp;") != null)
        {
            catName = catName.replace("amp;", "");
        }
        
        col.innerHTML = catName;        
        col.style.textAlign = 'left';        
        col.style.paddingLeft = '5px';                         
        
        //create max price column
        col = row.appendChild(document.createElement('td'));
        col.className = color+'Row';                 
        col.innerHTML = '$'+parseFloat(geos[j].childNodes[3].firstChild.nodeValue).toFixed(2);                
        
        //create min price column
        col = row.appendChild(document.createElement('td'));
        col.className = color+'Row';                 
        col.innerHTML = '$'+parseFloat(geos[j].childNodes[9].firstChild.nodeValue).toFixed(2);   
        
        //create the bid field for max price column
        col = row.appendChild(document.createElement('td'));
        col.className = color+'Row';
        col.innerHTML = '$';
        bidfield = col.appendChild(document.createElement('input'));
        bidfield.setAttribute("type", "text");        
        bidfield.setAttribute("id", geos[j].childNodes[0].firstChild.nodeValue);
        bidfield.setAttribute("name", geos[j].childNodes[0].firstChild.nodeValue);
        bidfield.setAttribute("value", parseFloat(geos[j].childNodes[4].firstChild.nodeValue).toFixed(2));                                           
        
        //check for zerobid validation to see if input needs to be highlighted
        if(parseFloat(bidfield.value) == 0)
        {
            bidfield.className = 'zerobid'; 
        }
        
        if(navigator.userAgent.indexOf( "MSIE" ) < 0)
        {                        
            bidfield.setAttribute("onblur", "validateGridBid(this, getCatId(this.name));");              
        }
        else
        {            
            bidfield.setAttribute("onblur", function() {validateGridBid(this, getCatId(this.name));});   
        }
        
        //create ctr column
        col = row.appendChild(document.createElement('td'));
        col.className = color+'Row';        
        col.innerHTML = geos[j].childNodes[5].firstChild.nodeValue+'%';
        
        //create clicks column
        col = row.appendChild(document.createElement('td'));
        col.className = color+'Row';
        col.innerHTML = geos[j].childNodes[6].firstChild.nodeValue;
        
        //create avg cpc column
        col = row.appendChild(document.createElement('td'));
        col.className = color+'Row';
        col.innerHTML = '$'+parseFloat(geos[j].childNodes[7].firstChild.nodeValue).toFixed(2);
        
        //create cost
        col = row.appendChild(document.createElement('td'));
        col.className = color+'Row';
        col.innerHTML = '$'+parseFloat(geos[j].childNodes[8].firstChild.nodeValue).toFixed(2);                                      
    }
    if(navigator.userAgent.indexOf( "MSIE" ) < 0)
    {
        theader.innerHTML = theader.innerHTML;
    }
    
    displayLink(header, cell, 'hide');
    
    cell.parentNode.parentNode.parentNode.parentNode.parentNode.className = 'firstCellTop'+color;                                   
    theader.className = 'show';        
    clicked = false;
}

//submit grid form
function submitBidGrid()
{
    if(clicked == false)
    {
        clicked = true;
        document.bidGridForm.submit();
    }    
}

//clear global bid when category or geo bids are entered
function clearGlobalBid(box)
{
    if(box.value != document.bidGridForm.global.value)
        document.bidGridForm.global.value = '';
}

//apply globe bid to all bid fields
function setGlobalBid(globalBid)
{
    var inputlist = document.getElementById('grid').getElementsByTagName('input');    
    for(var i=0; i<inputlist.length; ++i)
    {
        inputlist[i].value = globalBid.value;
    }
}

//formats bid value
function formatBidAmount( bid )
{        
    var amt = bid.value/1;
    var formattedAmt = 0;
    if (amt.toFixed)
        formattedAmt = amt.toFixed(2);
    if (formattedAmt != 'NaN')
    {
        bid.value = formattedAmt;
    }
}

//bid validation used on ppc global set price and budget page
        function validatePPCBid(val)
        {
            var validBid = 0.20;
            var maxBid = 999.99;
            
            var txtGlobalbid = val;
            var globalbid = txtGlobalbid.value;
            var amountLength = txtGlobalbid.value.length;
            var numDots = 0;
            var i;
            
            
                 if ( globalbid < validBid && globalbid >= 0)
                {
                   alert ('A minimum bid of 20 cents is required');
                   txtGlobalbid.focus();
                   return false;
                }
                else if ( globalbid > maxBid )
                {
                   alert ('Your bid has surpassed the maximum alloweds');
                   txtGlobalbid.focus();
                   return false;
                }
                else
                {
                    var result = validateBidAmountLength( globalbid );
                   
                }
            } 

 function validatePPCFulBudget(val)
        {
            var validBid = 15.00;  
            var txtGlobalbid = val;
            var globalbid = txtGlobalbid.value;
            var amountLength = txtGlobalbid.value.length;
            var numDots = 0;
            var i;
            
            
                 if ( globalbid < validBid && globalbid >= 0)
                {
                   alert ('A minimum budget of 15$ is required');
                   txtGlobalbid.focus();
                   return false;
                }                
                else
                {
                    var result = validateBidAmountLength( globalbid );
                   
                }
            } 


//clear category bid when it's geo bid is entered
function clearCatetoryBid(box, catid)
{        
    var categoryBid = document.getElementById(catid+'td').getElementsByTagName('input')[0];
    if(box.value != categoryBid.value)
    {
        categoryBid.value = '';
    }
}

//get the category id from the geoid
function getCatId(geoName)
{
    geoName = geoName.substring(0, geoName.indexOf('#'));
    return geoName
}

//apply category bid to all geo level bids
function applyCategoryBid(box)
{
    var categoryId = box.parentNode.id.replace('td', '');
    var cbody;
    var inputs;
    var i;        
    
    for(var j=0; j<3; ++j)
    {
        if(j==0)
            cbody = document.getElementById(categoryId+'body');
        else if(j==1)
            cbody = document.getElementById(categoryId+'states');
        else
            cbody = document.getElementById(categoryId+'metros');        
            
        if(cbody != null && cbody.getElementsByTagName('input').length != 0)
        {                    
            inputs = cbody.getElementsByTagName('input');
            for(i=0; i<inputs.length; ++i)
            {
                inputs[i].value = box.value;
            }
        }
    }
}


function submitMainPPCBidGridForm(pageNo,recordsPerPage) 
{
	document.forms["bidGridForm"]["currentPageNo"].value = pageNo;            
    document.forms["bidGridForm"]["recordsPerPage"].value = recordsPerPage;        
    document.forms["bidGridForm"]["_eventId_findMore"].name="_eventId_pagination";    
    document.forms["bidGridForm"].submit();            
}


function deleteCategoryFromBidGrid(){    
    alert( "You must have at least one category for your Pay Per Click ad." );    
}

//validate the bid value entered
function validateGridBid(box, catid)
{
    //var validBid = 0.20;
    var maxBid = 999.99;    
    
    var bidamt = box.value;  
    if(isNaN(bidamt))
    {
        alert ('Please enter a valid number.');  
        box.value = '';         
        setTimeout("document.getElementById('"+box.id+"').focus()",0);
        return false;
    }
    
    if (bidamt != 0 && bidamt < validBidgetBid )
    { 
       alert ('Your price per click must be at least $' +validBidgetBid+'.');              
       box.value = '';
       setTimeout("document.getElementById('"+box.id+"').focus()",0);
       return false;
    }
    else if (bidamt != 0 && bidamt > maxBid )
    {       
       alert ('Your price per click exceeds the maximum amount allowed');       
       box.value = '';
       setTimeout("document.getElementById('"+box.id+"').focus()",0);
       return false;
    }                                                
        
    if(box.value != '')
        formatBidAmount(box);    
    
    //check to see if this bid field is global bid field
    if(box.id.indexOf('global') >= 0)
    {
        if(box.value != '')
            setGlobalBid(box);
    }
    else
    {
        clearGlobalBid(box);  
        //get to see if the bid field is geo level - it is if catid = ''
        if(catid != '')      
            clearCatetoryBid(box, catid);
        else
        {
            if(box.value != 'bidGridForm')
                applyCategoryBid(box);
        }
    }
         
    return true;
}


//end Bid Grid


//tooltip function for bidgrid to avoid selectbox issue
function popup1(element,tag,xOffset)
{
    clearInterval(timer);
    findPosition(element);
    
    document.getElementById("tooltip").style.top = (absY-250) + "px";
        
    document.getElementById("tooltip").style.left = (absX+xOffset) + "px";
    document.getElementById("tooltext").innerHTML = document.getElementById(tag).innerHTML;
    
    //IE
    if(navigator.userAgent.indexOf( "MSIE" ) >= 0)
    {
        document.getElementById("tooltip").style.filter='alpha(style=0,opacity=0)';
    }
    //Firefox
    else
    {
        document.getElementById("tooltip").style.MozOpacity = 0;
    }
    
    document.getElementById('tooltip').style.display = 'block'
    fadeIn(0);
}



//  fix for firefox .. function to  submit the form to superpages.com and close the current popup..

 function search(searchForm)
{
     window.open('http://yellowpages.superpages.com/listings.jsp?C=' + searchForm.C.value + '&L=' + searchForm.L.value);
     window.close();
}

//added for ppc summary page

function showform(nr) {
    if (document.getElementById(nr) != null)
    {
        document.getElementById(nr).style.display = 'block';
    }
}

function hideform(nr) {
    if (document.getElementById(nr) != null)
    {
         document.getElementById(nr).style.display = 'none';
    }
}

//google keywords page
   function clearGlobalKeywords() {
          document.forms[getNetuiTagName("goglkwbidding")][getNetuiTagName("globalBidId")].value='';
      }
  
   
 //end google keywords
 
 
 function showPrice()
{
    if(document.getElementById('priceMore').className == 'collapse')
    {
        document.getElementById('priceMore').className = 'show';      
        document.getElementById('showMoreLink').className = 'collapse';  
    }
    else
    {
        document.getElementById('priceMore').className = 'collapse';  
        document.getElementById('showMoreLink').className = 'show';      
    }

}

    
// This function is used in PPC ad summary edit process 
function showEmail()
{
    document.getElementById('eMail').style.display='inline';
    document.getElementById('emailLink').className = 'clicked';
}

// This function is used in PPC ad summary edit brocess 
function showPhone()
{
    document.getElementById('phoneNumber').style.display='inline';
    document.getElementById('phoneNumberLink').className = 'clicked';
}

   
function calcAmt() 
{
    var avgsale;
    var avgpr;
    var conver;
    avgsale = document.frm.average_sale_amount.value;
    avgpr = document.frm.average_profit_margin.value;
    conver = document.frm.click_conversion_rate.value;
    var anumber = avgsale*(avgpr/100)*(conver/100);
    anumber = round(anumber);
    document.frm.maximum_bid_amount.value = anumber;
}

function round(value) 
{
    var r = "" + (Math.round(value*100)/100);
    return r;
}

function clearAmt()
{
    document.frm.maximum_bid_amount.value = "";
    document.frm.click_conversion_rate.value = "";
    document.frm.average_profit_margin.value = "";
    document.frm.average_sale_amount.value = "";
}


function roicalcAmt()
{
     clicks = document.frm.total_monthly_clicks.value;
     avgcost = document.frm.average_price_per_click.value;
     conver = document.frm.click_conversion_rate.value;
     profit = document.frm.average_profit_per_conversion.value;
     document.results.monthly_ppc_cost.value = Math.round(clicks*avgcost);
     document.results.number_of_sales.value = Math.round(clicks*conver)/100;
     document.results.profit_less_ppc_cost.value = Math.round(((clicks*conver)/100*profit)-(clicks*avgcost));
     document.results.roi.value = Math.round(((((clicks*conver)/100*profit)-(clicks*avgcost))/(clicks*avgcost))*100);
}

 function roiclearAmt() 
{
         document.frm.total_monthly_clicks.value = "";
         document.frm.average_price_per_click.value = ""
         document.frm.click_conversion_rate.value = "";
         document.frm.average_profit_per_conversion.value = "";
         document.results.monthly_ppc_cost.value = "";
         document.results.number_of_sales.value = "";
         document.results.profit_less_ppc_cost.value = "";
         document.results.roi.value = "";
}

//           
function formatAllFields()
{
    var inputs = document.getElementsByTagName('input');
    
    for(var i=0; i<inputs.length; ++i)
    {
        formatBidAmount(inputs[i]);
    }
}
   
 

 
//functions on enhance Ad page
function showLogo(box)
{   
    if (box.checked)
    {
        //document.getElementById('logo-info').style.display = 'inline';
        //document.getElementById('logo-divider').style.display='inline';
                
        $('#logo-info').slideDown(300);	
        $('#logo-divider').show();
        $('#previewLogo').show(300);	
        $('#ppclogo').show();
      
    }
	else
    {
        resetErrorMsg();
       	$('#logo-info').slideUp(300);	
        $('#logo-divider').hide();
        $('#logoErr').hide();
       	$('#previewLogo').hide(300);	
        $('#ppclogo').hide();
    }
    
}

function showVid(box)
{
	if (box.attr('checked'))
		$('#vidicon').show(300);	
	else
	{
		$('#vidicon').hide(300);	
	}
}

function resetErrorMsg(){
    if(document.getElementById('errormsg')){
      document.getElementById('errormsg').style.display='none';
    }  
}

//function to change display of business header

function changeBusinessName(element,isError) {
	if(element){
        var elementValue =element.value;
                     
              
             var StrCol="";
             var StrFont="";
             var StrSize="";
             var StrDisp="";
             
             
             if (element.alt=='Red')
             {
                    if (element.checked)
                        StrCol ="red";
                       document.getElementById('adTitle').style.color=StrCol;
             }       
             else if(element.alt=='Italic')
             
             {
                     if (element.checked)
                         StrFont ="italic";
                         document.getElementById('adTitle').style.fontStyle  = StrFont; 
             } 
                   
             else if(element.alt=='Bold')
             {
                    if(element.checked) 
                       StrSize ="bold";
                      document.getElementById('adTitle').style.fontWeight = StrSize; 
                    
             }               
                                      

          }
     }


	function setElpPreview()
	{
		changeBusinessName(document.enhanceAdForm.bold,false);
		changeBusinessName(document.enhanceAdForm.italics,false);
		changeBusinessName(document.enhanceAdForm.red,false);
		showVid($('#video'));
		return true;
	}
	

 
//functions on create your pay per click  Ad page
    function showMoreAdOptions()
    {
       document.getElementById('moreAdOptions').style.display ='inline';
       document.getElementById('moreButton').style.display='none';
       
       if (document.getElementById("addrOpt")!=null)
       {
           var name = document.forms["adInfo",this].elements["addrOpt"].value;
           if (name == 'Display my full Address')
            {
                 if (document.getElementById('link_to_map')!=null)
                 {
                    document.getElementById('link_to_map').style.display='inline';
                    showMapLink(document.getElementById("mapLinkBox"));
                 }
            }
            else
            {
                if (document.getElementById('link_to_map')!=null)
                {
                    document.getElementById('link_to_map').style.display='none';
                    showMapLink(document.getElementById("mapLinkBox"));
                }
            }
        }
       
    }




     var proTxt="";
  
    function checkHeadlineChars(headline){
            var n = 0;
            n = 50 - headline.value.length;
        if (n >=0){
            document.getElementById("HeadCharsRem").innerHTML=n;                                           
        }
        else
        {              
            proTxt = headline.value;
            proTxt = proTxt.substr(0,50);
            headline.value = proTxt;            
            document.getElementById("HeadCharsRem").innerHTML=0;
        }
        return true;
    }
    
    
    
    function checkSeventyChars(field){
            var n = 0;
            n = 70 - field.value.length;
        if (n >=0){
            document.getElementById("charsRem").innerHTML=n;                                           
        }
        else
        {              
            proTxt = field.value;
            proTxt = proTxt.substr(0,70);
            field.value = proTxt;            
            document.getElementById("charsRem").innerHTML=0;
        }
        return true;
    }
    
    function seventyChars(){
            var n = 0;
            n = 70 - document.forms[getNetuiTagName("adInfo")][getNetuiTagName("promotionalText")].value.length;
        if (n >=0){
            document.getElementById("charsRem").innerHTML=n;                                           
        }
        else
        {              
            proTxt = document.forms[getNetuiTagName("adInfo")][getNetuiTagName("promotionalText",this)].value;
            proTxt = proTxt.substr(0,70);
            document.getElementById("charsRem").innerHTML=0;
        }
        return true;
    }


//  functions to validate ad description text

 
/* function validateAdTitle(field)
 {
   // function to restrict pipe char from the ad title text field
    var value = field.value;
          if (value.indexOf("|")==-1)
             {
                return true;
             }
                 return false;
 } 
                        
 function validateText(field)
 {
    if (validateAdTitle(document.getElementById('headline')))
    {

            var value =field.value;
           //var chk=/[a-zA-Z_ _0-9@#$%^&*()_+-[]{}:;'?.,<>(TM) (C) (R)áÁéÉíÍóÓúÚñÑüÜ¿¡]/ ;
            var chk=/[a-zA-Z_ _0-9!@#$%^&*()_+-=\[\]{}:;\'?.,<>™© ®áÁéÉíÍóÓúÚñÑüÜ¿¡]/ ;
            var namechk=new RegExp(chk);
            var flag = false;
                      
             var char1 = "";
          for (var i=0; i<value.length; i++) {
          
              indVal = "" + value.substring(i, i+1);
              if(!(namechk.exec(indVal)))
              {								
                  if( indVal == '\r')
                  {
                      char1 +=  '<enter>' +',';
                  }
                  else if( indVal == '\n' )
                  {

                  }
                  else if( i != value.length )
                  {								
                      char1 +=  indVal + ',';
                      
                  }
                  flag = true;
              }
          }
          
          char1 = char1.substring(0,char1.length-1);
          
          if( flag == true )
          {
              alert( "The following characters are not supported for the Ad Description text of an ad: \r\n" + char1 + "\r\n Please revise your Promotional Text to continue."); 
              return false;
          }
      }
      else
      {
            alert(" The following character is not supported for the title of an ad: | "+ "\r\n Please revise your Headline Text to continue.");
            return false;
      } 
} */
   

      
        // this function is used in PPC buy process in ad summarry page for formating 
        // ad headline when add on products are selected and in elp page during buy process edit flow
        function formatAdTitle(addOn, elementId)
        {
            if (addOn == 'bold')
                {
                    document.getElementById(elementId).style.fontSize = "larger";
                }
              else if (addOn == 'color')
                {
                    document.getElementById(elementId).style.color="red";
                }
                    else if (addOn == 'italics')
                    {
                        document.getElementById(elementId).style.fontStyle  = "italic";
                    }
        }
                    
                    
//handles website url link in the preview box
function checkUrl(box)
{
    if(box.checked)
    {        
        document.getElementById('businessprofilelink').style.display = 'inline';
        $('#businessprofilediv').show();
        document.getElementById('adTitle').style.textDecoration = 'underline';
    }
    else
    {        
        document.getElementById('businessprofilelink').style.display = 'none';    
        $('#businessprofilediv').hide();
        document.getElementById('adTitle').style.textDecoration = 'none';    
    }    
}

//handles phone number link in the preview box
function showPhoneNumberLink(box)
{
    if(box.checked == true)
    {                       
        document.getElementById('phoneNumberLink').style.display = 'inline';        
         document.getElementById('phoneNumber').style.display = 'none';
         $('#phoneNumberdiv').show();
    }
    else
    {                
        document.getElementById('phoneNumberLink').style.display = 'none';
        document.getElementById('phoneNumber').style.display = 'none';
        $('#phoneNumberdiv').hide();
    }
}

//handles email link in the preview box
function showEmailLink(box)
{   
    if(box.checked == true)
    {             
        document.getElementById('emailLink').style.display = 'inline';
         document.getElementById('eMail').style.display = 'inline';
         $('#emaildiv').show();        
    }
    else
    {      
        document.getElementById('emailLink').style.display = 'none';
        document.getElementById('eMail').style.display = 'none';
        $('#emaildiv').hide();    
    }    
}


//handles map link in the preview box
function showMapLink(box)
{
    if(box.checked == true)
    {        
        document.getElementById('mapPreviewLink').style.display = 'inline';
        $('#mapPreviewdiv').show();  
    }
    else
    {        
        document.getElementById('mapPreviewLink').style.display = 'none';
        $('#mapPreviewdiv').hide();
    }
}

// refreshes map link in design ad and edit ad pages based on addr options
function refreshMapLink(addrbox)
{
    if (addrbox.value == 'Do not display my address')
    {
        document.getElementById('mapLinkSpan').style.display = 'inline';
        document.forms[getNetuiTagName("adInfo")][getNetuiTagName("mapLinkBox")].checked = false;
    }
}



//handles send link in the preview box
function showSendLink(box)
{
    if(box.checked == true)
    {        
        document.getElementById('sendPreviewLink').style.display = 'inline';
    }
    else
    {        
        document.getElementById('sendPreviewLink').style.display = 'none';
    }
}

//functions used on maintenece audience pages

function maintSelectAllStates(field,form)
{

     var i;
    if (eval(document.forms[getNetuiTagName(form)][getNetuiTagName('selectAllOption')].checked))
    {
             for (i=0;i<field.length;i++){
             if(field[i].checked==false){
             field[i].checked=true;
             maintAddStates(field[i], document.forms[getNetuiTagName(form)][getNetuiTagName('selectedBox')],form);
             }
          }
     }
   else
    { 
       for(i=0;i<field.length;i++){
       field[i].checked=false;
       maintAddStates(field[i], document.forms[getNetuiTagName(form)][getNetuiTagName('selectedBox')],form);
      
       }
    } 
}

function maintSelectAllCheck(field,form)
{
     var i;
  if(field.length!=null)
     { 
         if (eval(document.forms[form].selectAllOption.checked))
        {
             for (i=0;i<field.length;i++){
                if(field[i].checked==false){
                   field[i].checked=true;
                   maintAddAudience(field[i], document.getElementById('selectedBox'),form);
                }
             }
         }
         else
        {  
           for(i=0;i<field.length;i++){
              field[i].checked=false;
              maintAddAudience(field[i], document.getElementById('selectedBox'),form);
      
            }
         } 
   }
   else{
     
        if (eval(document.forms[form].selectAllOption.checked))
        {
             
             if(field.checked==false){
                field.checked=true;
                maintAddAudience(field[i], document.getElementById('selectedBox'),form);
             
            }
        }
        else
         { 
             field.checked=false;
             maintAddAudience(field[i], document.getElementById('selectedBox'),form);
         }
     }
   
}
function maintAddStates(val, sel, form){   
      
        //add category to selectbox
        if(val.checked == true)              
        {        
            if((val.value != "") && (val.value.length != 0)){
                var newOption = new Option(val.value);                      
                sel.options[sel.options.length] = newOption; 
            }
        }
        //remove category from selectbox
        else
        {
            for( var i = 0; i < sel.options.length; i++ )  
            {
                if(sel.options[i].value != "")
                {
                    if(val.value == sel.options[i].value)
                    {
                        sel.options[i].value = ""; 
                        sel.options[i].text = ""; 
                    }
                }
            }
            bumpUp( sel );   
        }
        addStatesDisplay(form, val);
    }
  
function addStatesDisplay(formName, box)
{
    var tableObj = document.getElementById('new-categories');						
    var row, cell, catid;
    catid = box.value;

    if(box.checked == true)
    {
        catText = box.value;
        appendCategoryToDisplay(formName, catid, catText, row, cell, tableObj);			
    }
    else
    {
        removeAudience(formName, catid);
    }        
}
function maintAddAudience(val, sel, form){   
      
        //add category to selectbox
        if(val.checked == true)              
        {        

            if((val.alt != "") && (val.alt.length != 0)){
                var newOption = new Option(val.alt, val.value);                      
                sel.options[sel.options.length] = newOption; 
            }

        }
        //remove category from selectbox
        else
        {
            for( var i = 0; i < sel.options.length; i++ )  
            {
                if(sel.options[i].value != "")
                {
                    if(val.value == sel.options[i].value)
                    {
                        sel.options[i].value = ""; 
                        sel.options[i].text = ""; 
                    }
                }
            }
            bumpUp( sel );   
        }
        addCategoryDisplay(form, val);
    }
    



//locations for buy and maintenance flows

function selectAllCheck(field,selectedCities,selectBox)
{
    if(selectedCities.length!=null)
    { 
        if( field.checked ){
        
            for (i=0;i<selectedCities.length;i++){
            
                selectedCities[i].checked = true;
                
                updateIteminSelectBox( selectBox, selectedCities[i], 'add' );
            
            }
        
        }else{
        
            for (i=0;i<selectedCities.length;i++){
            
                selectedCities[i].checked = false;
                
                updateIteminSelectBox( selectBox, selectedCities[i], 'delete' );
            
            }
        
        }
        
    }else{
    
        if( field.checked ){
                          
                selectedCities.checked = true;
                
                updateIteminSelectBox( selectBox, selectedCities, 'add' );

            }else{

                selectedCities.checked = false;
                
                updateIteminSelectBox( selectBox, selectedCities, 'delete' );

            }
    
    }
    
}

function updateIteminSelectBox(selectBox, geooption, option ){//private method


    for( var i = 0; i < selectBox.options.length; i++ ){
    
        if( selectBox.options[i].value == geooption.name ){
        
            if( option == 'delete' ){
        
                selectBox.remove(i);
                
            }
            
            return;
        
        }
    
    }
    
    if( option == 'add' ){
    
        var newOption = new Option(geooption.value,geooption.name); 

        selectBox.options[ selectBox.options.length ] = newOption;
    
    }

}


function addordeleteitem( chkboxoption,selectBox,selectAllOption ){

    if( chkboxoption.checked ){
    
        updateIteminSelectBox( selectBox, chkboxoption, 'add' );
    
    }else{
    
        updateIteminSelectBox( selectBox, chkboxoption, 'delete' ); 
        
        selectAllOption.checked = false;
    
    }

}

function removeItemFromSelectBox( selectBoxOption, checkBoxOptions, selectAllOption ){
if(checkBoxOptions.length!=undefined){
    for( var i = selectBoxOption.options.length-1; i >=0; i-- ){
        if( selectBoxOption.options[i].selected ){  
            for( var j = 0; j < checkBoxOptions.length; j++ ){    
                if( checkBoxOptions[j].name == selectBoxOption.options[i].value ){               
                    checkBoxOptions[j].checked = false;
                    selectAllOption.checked = false;
                }
            }
            
            selectBoxOption.remove(i);
        }
    }
    }
 else 
 {
  checkBoxOptions.checked = false;
  selectAllOption.checked = false;
   selectBoxOption.remove(0);
 }
}

function submitLocalPagFrm(pageNo,recordsPerPage) 
{    
    document.forms["chooseGeosForm"]["currentPageNo"].value = pageNo;            
    document.forms["chooseGeosForm"]["recordsPerPage"].value = recordsPerPage;    
    var selectBox = document.forms["chooseGeosForm"]["selectedBox"];
    for( var i = 0; i < selectBox.options.length; i++ ){  
        selectBox.options[i].selected = true;
    } 
    document.forms["chooseGeosForm"]["_eventId_key"].name="_eventId_pagination";
    
    document.forms["chooseGeosForm"].submit();         
}

function submitGeos(state) {
    var selectBox = document.forms["chooseGeosForm"].elements["selectedBox"];    
    if( selectBox != null ){        
        if( state == 'continue' && selectBox.options.length == 0  )
        {
            alert("Please make a selection from the cities listed");            
            
        }else{        
            if( state != 'back' ){
                for( var i = 0; i < selectBox.options.length; i++ ){  
                    selectBox.options[i].selected = true;
                }  
            } 
            document.forms["chooseGeosForm"]["_eventId_key"].name="_eventId_" + state;                   
            document.forms["chooseGeosForm"].submit();                 
        }     
        
    }else{
		document.forms["chooseGeosForm"]["_eventId_key"].name="_eventId_" + state;                   
        document.forms["chooseGeosForm"].submit();  
    }
    
}

function submitAudience(currentForm, audienceList) {
	for(var i=0; i< audienceList.length; i++)
	{
		if(audienceList[i].checked == true)
		{
		    currentForm._eventId.value = audienceList[i].value;   
		    break;           	
		}
	}
}

// javascript function for categories

function submitCategoriesPagFrm(pageNo,recordsPerPage) 
{    
    document.forms["catResultForm"]["currentPageNo"].value = pageNo;            
    document.forms["catResultForm"]["recordsPerPage"].value = recordsPerPage;    
    var selectBox = document.forms["catResultForm"]["selectedBox"];
    for( var i = 0; i < selectBox.options.length; i++ ){  
        selectBox.options[i].selected = true;
    } 
    document.forms["catResultForm"]["_eventId_findMore"].name="_eventId_pagination";
    
    document.forms["catResultForm"].submit();         
}

function submitPpcQuickSetupForm(pageNo,recordsPerPage) 
{    
    document.forms["ppcQuickSetupForm"]["currentPageNo"].value = pageNo;              
    document.forms["ppcQuickSetupForm"]["_eventId_searchBCats"].name="_eventId_pagination";
    document.forms["ppcQuickSetupForm"].submit();         
}

function submitPpcQuickSetupFormForSelectedCategories(pageNo,recordsPerPage) 
{    
	//select full list options
	var fullSelOpt= document.getElementById('toList-full').options;
	for(var i=0;i<fullSelOpt.length;i++)
		fullSelOpt[i].selected= true;
    document.forms["ppcQuickSetupForm"]["currentPageNoForSelectedCategories"].value = pageNo;              
    document.forms["ppcQuickSetupForm"]["_eventId_searchBCats"].name="_eventId_paginationForSelectedCategories";
    document.forms["ppcQuickSetupForm"].submit();         
}

function formsubmitForCategories(formState)
{

	document.forms["catResultForm"]["_eventId_findMore"].name="_eventId_"+formState;
	var list = document.catResultForm.selectedBox;
	
	
	if( list != null && list.options.length > 0 ){
		for (i=0;i<list.options.length;i++)
        {
            current = list.options[i];
            current.selected = true;
        }
        document.catResultForm.submit();
    }else{
    	if( formState == 'continue' || formState == 'finished' ){
    		alert("Please make a selection from the categories listed");
    	}else{
    		document.catResultForm.submit();
    	}
    }
	
}

function formsubmitForPaidCategories(formState,status)
{

	document.forms["catResultForm"]["_eventId_findMore"].name="_eventId_"+formState;
	var list = document.catResultForm.selectedBox;
	
	
	if( list != null && list.options.length > 0 ){
		for (i=0;i<list.options.length;i++)
        {
            current = list.options[i];
            current.selected = true;
        }
        document.catResultForm.submit();
    }else{
   		document.catResultForm.submit();
    }
	
}
function validateBrowse()
{
	 var list = document.catResultForm.selectedBox;		
     if( document.catResultForm.topic.value == 'Select a Topic' ){

         alert("Please select a Topic and Sub-Topic");

     }else if( document.catResultForm.subtopic.value == 'Select a Sub-topic' ){

         alert("Please select a Sub-Topic");

     }else{
     	if( list != null ){
			for (i=0;i<list.options.length;i++)
	        {
	            current = list.options[i];
	            current.selected = true;
	        }
    	}
        document.forms["catResultForm"]["_eventId_findMore"].name="_eventId_go";
        document.catResultForm.submit();
     }

}

function validateBrowseAll()
{
	 var list = document.catResultForm.selectedBox;		
     if( document.catResultForm.topic.value == 'Select a Topic' ){

         alert("Please select a Topic and Sub-Topic");
         return false;

     }
     if( document.catResultForm.subtopic.value == 'Select a Sub-topic' ){

          alert("Please select a Sub-Topic");
          return false;
     }
     
     	if( list != null ){
			for (i=0;i<list.options.length;i++)
	        {
	            current = list.options[i];
	            current.selected = true;
	        }
    	}
        document.forms["catResultForm"]["_eventId_findMore"].name="_eventId_go";
        document.catResultForm.submit();
    

}

function validateSearch(formState)
{
    var val = formState.value;
    if( val == null || val.length <= 0 )
    {
        alert('Please enter a keyword to search for categories.');
    }else{
		document.forms["catResultForm"]["_eventId_findMore"].name="_eventId_findMore";
		var list = document.catResultForm.selectedBox;
		if( list != null ){
			for (i=0;i<list.options.length;i++)
	        {
	            current = list.options[i];
	            current.selected = true;
	        }
	    }
        document.catResultForm.submit();
    }
}

function validateAjaxSearch(formState)
{
    var val = formState.value;
    if( val == null || val.length <= 0 )
    {
        alert('Please enter a keyword to search for categories.');
        return false;
    }else{
		document.forms["catResultForm"]["_eventId_findMore"].name="_eventId_findMore";
		var formElement = document.catResultForm;
		var url = formElement.action;
		var params = '_flowExecutionKey=' + document.forms["catResultForm"]["_flowExecutionKey"].value + '&' + document.forms["catResultForm"]["_eventId_findMore"].name + '=pagination&searchCriteria=' + document.forms["catResultForm"]["searchCriteria"].value ;
		var http = null;
   		if (window.XMLHttpRequest) {                  
   			http = new XMLHttpRequest();	                 
         }
         //IE ActiveX object
         else if (window.ActiveXObject) {                    
        	 http = new ActiveXObject("Microsoft.XMLHTTP");
         }    
		
		http.open("POST", url, true);

		//Send the proper header information along with the request
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");

		http.onreadystatechange = function() {//Call a function when the state changes.
			if(http.readyState == 4 && http.status == 200) {
				var ajaxRespRE= /####([\w\d\"\n\s><\/=\'\-:;&\(\)\,|%#\.\?\{\}\*\[\]\+\_\^\!@$~`]*)####/;
				var match= ajaxRespRE.exec(http.responseText);
				//document.getElementById('testout').innerHTML= match[1];
				if(typeof validateAjaxSearch_clbk =='function')
					validateAjaxSearch_clbk(match[1]);
				if(match[1]!='error'){
					$('#ajax-div').html(match[1]);
					$('#ajax-div').show();
					$('#back-category').hide();
					$('#error-div').hide();
				}else{
					$('#error-div').show();
					$('#searchCats-ajax-loading').hide();
				}
			}
		}
		http.send(params);
    }
    return true;
}

function submitAjaxCategoriesPagFrm(pageNo,recordsPerPage) 
{    
    document.forms["catResultForm"]["currentPageNo"].value = pageNo;            
    document.forms["catResultForm"]["recordsPerPage"].value = recordsPerPage;    
    document.forms["catResultForm"]["_eventId_findMore"].name="_eventId_pagination";
    var formElement = document.catResultForm;
    var url = formElement.action;
	var params = '_flowExecutionKey=' + document.forms["catResultForm"]["_flowExecutionKey"].value + '&' + document.forms["catResultForm"]["_eventId_findMore"].name + '=pagination&currentPageNo=' + pageNo +'&recordsPerPage='+ recordsPerPage;
	var http = null;
		if (window.XMLHttpRequest) {                  
			http = new XMLHttpRequest();	                 
     }
     //IE ActiveX object
     else if (window.ActiveXObject) {                    
    	 http = new ActiveXObject("Microsoft.XMLHTTP");
     }    
	
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			var ajaxRespRE= /####([\w\d\"\n\s><\/=\'\-:;&\(\)\,|%#\.\?\{\}\*\[\]\+\_\^\!@$~`]*)####/;
			var match= ajaxRespRE.exec(http.responseText);
			//document.getElementById('testout').innerHTML= match[1];
			$('#ajax-div').html(match[1]);
			//alert(match);
		}
	}
	http.send(params);    
    
    //document.forms["catResultForm"].submit();         
}



function validateAjaxBrowse()
{
	 var list = document.catResultForm.selectedBox;		
     if( document.catResultForm.topic.value == 'Select a Topic' ){

         alert("Please select a Topic and Sub-Topic");

     }else if( document.catResultForm.subtopic.value == 'Select a Sub-topic' ){

         alert("Please select a Sub-Topic");

     }else{
	     document.forms["catResultForm"]["_eventId_findMore"].name="_eventId_go";
	     var formElement = document.catResultForm;
	     var url = formElement.action;
		 var params = '_flowExecutionKey=' + document.forms["catResultForm"]["_flowExecutionKey"].value + '&' + document.forms["catResultForm"]["_eventId_go"].name + '=go&parentCategoryId=' + document.catResultForm.topic.value + '&childCategoryId=' + document.catResultForm.subtopic.value;
	 	 var http = null;
	 	 if (window.XMLHttpRequest) {                  
	 			http = new XMLHttpRequest();	                 
	      }
	      //IE ActiveX object
	      else if (window.ActiveXObject) {                    
	     	 http = new ActiveXObject("Microsoft.XMLHTTP");
	      }    
	 	
	 	http.open("POST", url, true);
	
	 	//Send the proper header information along with the request
	 	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	 	http.setRequestHeader("Content-length", params.length);
	 	http.setRequestHeader("Connection", "close");
	
	 	http.onreadystatechange = function() {//Call a function when the state changes.
	 		if(http.readyState == 4 && http.status == 200) {
				var ajaxRespRE= /####([\w\d\"\n\s><\/=\'\-:;&\(\)\,|%#\.\?\{\}\*\[\]\+\_\^\!@$~`]*)####/;
				var match= ajaxRespRE.exec(http.responseText);
				if(match[1]!='error'){
					$('#ajax-div').html(match[1]);
					$('#back-category').hide();
					$('#error-div').hide();
				}else{
					$('#error-div').show();
					$('#searchCats-ajax-loading').hide();
				}				
			}
	 	}
	 	http.send(params);    
     }

}

function submitPPCEvent(formId,event){
		document.forms[formId]["_eventId_findMore"].name="_eventId_" + event;
		document.forms[formId].submit(); 
	}
	

//end categories

function closePopup()
{
    if (popWin && !popWin.closed)
        popWin.close();
    return true;
}

/******** maintCreateAd.jsp *********/

// for BP pop up window
function submiteDesignForm(bpbox)
{
    if (bpbox.checked)
    {
        //var companyboid = document.getElementById("compboid").value;        
        //var targetUrl = '/spportal/jsp/popups/payperclick/showProfiles.jsp';
        var targetUrl = 'showBPListings.do';
        
        
        if (bpbox!=null
            && bpbox.checked
            && document.getElementById('diffProfileLink')!=null )
                document.getElementById('diffProfileLink').style.display='inline';
     
        popWin = window.open(targetUrl, "", "width=390, height=600, toolbar=0, scrollbars=1 ");
        initPopUpBlockerTimer();                       
    }
    else
    {
        saveListId(bpbox);
        checkUrl(bpbox);
    }
}

function saveListId(bpbox)
{
    if (bpbox.checked)
    {
        var listId = document.forms["adDesignForm"]["oneBPlistingId"].value;
        document.forms["adDesignForm"]["pfpCampaign.listingId"].value = listId;
        if (document.getElementById('diffProfileLink')!=null )
            document.getElementById('diffProfileLink').style.display='inline';
        document.getElementById('adTitle').style.textDecoration = 'underline'; 
    }
    else
    {
        document.forms["adDesignForm"]["pfpCampaign.listingId"].value = "";
        if (document.getElementById('diffProfileLink')!=null )
            document.getElementById('diffProfileLink').style.display='none';
        document.getElementById('adTitle').style.textDecoration = 'none';
    }
}

function refocus()
{          
    if(popWin != null)
        popWin.focus();
}

function showMapLinkOption()
{
   var name = document.forms[getNetuiTagName("adInfo",this)][getNetuiTagName("addrOpt")].value;
   if (name == 'Display my full Address')
    {
         document.getElementById('link_to_map').style.display='inline';
    }
    else
    {
        document.getElementById('link_to_map').style.display='none';
    }
}

function showHideMapLink(selectbox)
{
    if (selectbox !=null)
    {
        var name = selectbox.value;
        if (name == '1')
         {
             document.getElementById('link_to_map').style.display='inline';   
             document.getElementById('mapPreviewLink').style.display='inline';              
             document.getElementById('mapLink').checked = true;                       
         }
         else
         {
	         document.getElementById('link_to_map').style.display='none';   
             document.getElementById('mapPreviewLink').style.display='none';   
             document.getElementById('mapLink').checked = false;                                
         }
     }
       
}

    function addItem1(val, sel, flag){


            if( flag == 'false' ){
            if(val.checked == true)
            {
                if( sel.options.length == 5 ){

                    alert("You have reached the maximum limit of 5 categories.  You must remove/deselect a category before adding more.");
                    val.checked = false;
                    return false;

                }
            }
        }
        //add category to selectbox
        if(val.checked == true)
        {
            if((val.alt != "") && (val.alt.length != 0)){
                var newOption = new Option(val.alt, val.value);
                sel.options[sel.options.length] = newOption;
            }
        }
        //remove category from selectbox
        else
        {
            for( var i = 0; i < sel.options.length; i++ )
            {
                if(sel.options[i].value != "")
                {
                    if(val.value == sel.options[i].value)
                    {
                        sel.options[i].value = "";
                        sel.options[i].text = "";
                    }
                }
            }
            bumpUp( sel );
        }
    }
    //PPC POP UPS
// how to write a great ad
function greatAd() {
     var targetUrl =  '/spportal/jsp/popups/payperclick/greatAd/greatAd1.jsp'
     popWin = window.open(targetUrl, "greatAd", "width=385,height=470,toolbar=0,status=0");
     initPopUpBlockerTimer();
}  
         
// improving your ads ranking  
function ranking() {
     var targetUrl = '/spportal/jsp/popups/payperclick/ranking/improve.jsp'
     popWin = window.open(targetUrl, "Ranking", "width=385,height=460,toolbar=0,status=0");
     initPopUpBlockerTimer();
}     
// popup for  Learn more about setting your price-maintanence
function maintainBidding() {
        popWin = window.open('/spportal/jsp/popups/payperclick/maintenanceBidding/maint_bidding1.jsp', "maintainbidding", "width=382,height=490,toolbar=0,status=0");
        popWin.resizeTo(392, 520);
        initPopUpBlockerTimer();
     }
function setBudget() {
        popWin = window.open('/spportal/jsp/popups/payperclick/bidding/bidding4.jsp', "bidding4", "width=382,height=490,toolbar=0,status=0");
}
// popup for Click here for logo requirements        
 function showLogoSpecs() {
       popWin = window.open('/spportal/jsp/popups/payperclick/logoSpec.jsp', "logospecification", "width=382,height=470,toolbar=0,status=0");
       initPopUpBlockerTimer();
}
// popup for Choosing the right audience
 function rightAudience() {
      popWin = window.open('/spportal/jsp/popups/payperclick/rightAudience.jsp', "rightAudience", "width=382,height=525,toolbar=0,status=0");
      initPopUpBlockerTimer();       
}
//popup for View my competition
function showCompetition() {
    popWin = window.open("/spportal/jsp/popups/showCompetition.jsp", "show", "width=315, height=295, toolbar=0, status=0");
    initPopUpBlockerTimer();
}
//maintenance categories how popup
function showHow()
{
    popWin = window.open("/spportal/jsp/popups/payperclick/howCatKey.jsp", "", "width=320, height=400, toolbar=0, status=0");
    popWin.resizeTo(395, 460);
    initPopUpBlockerTimer();
}
//Popup for ppc.Preview the sign up steps
function ppcSteps() {
     var targetUrl =  '/spportal/jsp/popups/payperclick/ppcSignupPop/gettingStarted.jsp'
     popWin = window.open(targetUrl, "roi", "width=385,height=470,toolbar=0,status=0");
     initPopUpBlockerTimer();
}

//Learn more about your price per click
 function bidding(){

    popWin = window.open("/spportal/jsp/popups/payperclick/bidding/bidding1.jsp", "bid", "width=382,height=490,toolbar=0,status=0");
    popWin.resizeTo(392, 520);
    initPopUpBlockerTimer();
 }
                
function roiHelp() {
    popWin = window.open("/spportal/jsp/popups/payperclick/roicalculator.jsp", "roi", "width=320, height=430,toolbar=0, status=0");            
    popWin.resizeTo(327, 490);
    initPopUpBlockerTimer();                                   
}

function max() {
    popWin = window.open("/spportal/jsp/popups/payperclick/maxbidcalculator.jsp", "max", "width=335, height=430, toolbar=0, status=0");
    popWin.resizeTo(347, 490);
    initPopUpBlockerTimer();
}     
function showSGPopup(){

    popWin = window.open("/spportal/jsp/popups/payperclick/aboutSGProgram.jsp", "SGPrgm", "width=382,height=490,toolbar=0,status=0");
    popWin.resizeTo(372, 470);
    initPopUpBlockerTimer();
 }

// Javascript for Ad groups page : Start and End Dates:


    function showDatePicker(setting)
    {
        // remove the calender (if open) also when the start asap is chosen
        if (setting == 'none')
        {
            hideall(1);
        }
        if(document.getElementById('dtSpana'))
            document.getElementById('dtSpana').style.display=setting;
        document.getElementById('dtSpan1').style.display=setting;
        document.getElementById('dtSpan2').style.display=setting;
        document.getElementById('dtSpan3').style.display=setting;
        document.getElementById('dtSpan4').style.display=setting;
        document.getElementById('dtSpan4b').style.display=setting;
        return true;
    }
    function showEndDate(setting)
    {
        // remove the second calendar when the no end date is chosen.
        if (setting == 'none')
        {
            hideall(2);
        }
        if(document.getElementById('dtSpanb'))
            document.getElementById('dtSpanb').style.display=setting;
        document.getElementById('dtSpan5').style.display=setting;
        document.getElementById('dtSpan6').style.display=setting;
        document.getElementById('dtSpan7').style.display=setting;
        document.getElementById('dtSpan8').style.display=setting;
        document.getElementById('dtSpan8b').style.display=setting;
        return true;
    }

    function loadDays(date)
    {
    var len_new =0;
    if (date == 'sdate') {
        var mth = document.forms["adGroupForm"]["startMonth"].value;
        var day = document.forms["adGroupForm"]["startDay"];
        var len_old = day.length;
        var yr = document.forms["adGroupForm"]["startYear"].value;
    }
    else if (date =='edate') {
            var mth = document.forms["adGroupForm"]["endMonth"].value;
            var day = document.forms["adGroupForm"]["endDay"];
            var len_old = day.length;
            var yr = document.forms["adGroupForm"]["endYear"].value;
        }

    if (mth == "1" || mth == "3" || mth == "5" || mth == "7" || mth == "8" || mth == "10" || mth == "12"){
        len_new = 31;
    }
    else if (mth == "4" || mth == "6" || mth == "9" || mth == "11"){
            len_new = 30;
        }
        else{
             if ((yr % 4 )== 0){  len_new = 29; }
            else { len_new = 28; }
        }
    if (len_old != len_new){
        day.length=len_new;
        for (i = 28; i<=len_new; i++)
            {
                var option = new Option(i,i);
                day.options[i-1] = option;
            }
        day.options[len_new-1].selected = true;
    }

    return true;
    }

     function showhideDatePicker()
    {
        var name = document.forms["adGroupForm"]["startDateOption"][1].checked;
        //when start date is selected, show calendar
        if ( name == true )
        {
            var sday = document.forms["adGroupForm"]["startDay"].value;
            loadDays('sdate');
            document.forms["adGroupForm"]["startDay"].value = sday;
            showDatePicker('inline');
        }
        name = document.forms["adGroupForm"]["endDateOption"][1].checked;
        //when end date is selected, show calendar        
        if (name == true)
        {
            var eday = document.forms["adGroupForm"]["endDay"].value;
            loadDays('edate');
            document.forms["adGroupForm"]["endDay"].value = eday;
            showEndDate('inline');
        }

        return true;
    }
    
    //PPC Advanced Search
    
	function formSubmitAdvSearch(key){	
		if( key == 'go' ){
			if( document.forms["adSummaryActionForm"]["ppcadvancedsearchbox"].value == 'Search Criteria' ){
				alert('Please select a Search Criteria');
			}else{
				document.forms["adSummaryActionForm"]["_eventId_findMore"].name="_eventId_" + key;    
				document.forms["adSummaryActionForm"]["currentPageNo"].value=1;			
		    	document.forms["adSummaryActionForm"].submit();            
			}
		}else if( key == 'allAds' ){
			document.forms["adSummaryActionForm"]["_eventId_findMore"].name="_eventId_" + key;    
			document.forms["adSummaryActionForm"]["currentPageNo"].value=1;			
			document.forms["adSummaryActionForm"]["searchCriteria"].value='';				
	    	document.forms["adSummaryActionForm"].submit();            		
		}else{
			document.forms["adSummaryActionForm"]["_eventId_findMore"].name="_eventId_" + key;    
			document.forms["adSummaryActionForm"]["currentPageNo"].value=1;
		    document.forms["adSummaryActionForm"].submit();            
		}
	}
	
	function formSubmitAdSummary(campaignId){
		document.forms["adSummaryActionForm"]["_eventId_findMore"].name="_eventId_edit";    
		document.forms["adSummaryActionForm"]["campaignId"].value=campaignId;
	    document.forms["adSummaryActionForm"].submit();            
	}
	
	function sortAdvSearch(key){
		var header = document.forms["adSummaryActionForm"]["orderBy"].value;
		var sort = document.forms["adSummaryActionForm"]["sortId"].value;
		if( key == 'Ad Title'){
			if( header == 'Ad Title' ){
				if( sort == 'desc' ){
					document.forms["adSummaryActionForm"]["sortId"].value = 'asc';
				}else{
					document.forms["adSummaryActionForm"]["sortId"].value = 'desc';
				}
			}else{
				document.forms["adSummaryActionForm"]["sortId"].value = 'asc';
			}
		}else if( key == 'Campaign ID'){
			if( header == 'Campaign ID' ){
				if( sort == 'desc' ){
					document.forms["adSummaryActionForm"]["sortId"].value = 'asc';
				}else{
					document.forms["adSummaryActionForm"]["sortId"].value = 'desc';
				}
			}else{
				document.forms["adSummaryActionForm"]["sortId"].value = 'asc';
			}
		}else{
			if( header == 'Ad Name' ){
				if( sort == 'desc' ){
					document.forms["adSummaryActionForm"]["sortId"].value = 'asc';
				}else{
					document.forms["adSummaryActionForm"]["sortId"].value = 'desc';
				}
			}else{
				document.forms["adSummaryActionForm"]["sortId"].value = 'desc';
			}
		}
		document.forms["adSummaryActionForm"]["orderBy"].value = key;	
		document.forms["adSummaryActionForm"]["_eventId_findMore"].name="_eventId_sort";    
		document.forms["adSummaryActionForm"]["currentPageNo"].value=1;
	    document.forms["adSummaryActionForm"].submit();            
	}
	
	function toggleAdvSearch( key, campaignId ){
		document.forms["adSummaryActionForm"]["_eventId_findMore"].name="_eventId_toggle";    
		document.forms["adSummaryActionForm"]["campaignId"].value=campaignId;
	    document.forms["adSummaryActionForm"].submit();            
	}
	
	function advSearchPPCPagination(pageNo,recordsPerPage){
		document.forms["adSummaryActionForm"]["currentPageNo"].value = pageNo;            
	    document.forms["adSummaryActionForm"]["recordsPerPage"].value = recordsPerPage;        
	    document.forms["adSummaryActionForm"]["_eventId_findMore"].name="_eventId_pagination";    
	    document.forms["adSummaryActionForm"].submit();            
	}

//PPC Fulservice End
function CheckFullServiceValidator(formObj, requiredFields) 
{

	if(formObj != null)
	{
		var flag = true;
		var index = 0;
		for(var i=0; i<requiredFields.length; i++)
		{
		   
			if(formObj[requiredFields[i]] !=null)
			{  
				if(formObj[requiredFields[i]].type == 'text' || formObj[requiredFields[i]].type == 'password' || formObj[requiredFields[i]].type == 'textarea')
				{
					if(formObj[requiredFields[i]].value == '')					    
					{    					    
						if(document.getElementById(requiredFields[i]+'-error') != null)
						{						      
							document.getElementById(requiredFields[i]+'-error').style.display = 'block';
							index = i;
						}						
						/*else
						{
							alert('error message ['+requiredFields[i]+'-error] not found');
						}*/
						flag = false;
					}					
				}
				else if(formObj[requiredFields[i]].type == 'checkbox')
				{
					if(!formObj[requiredFields[i]].checked)
					{
						if(document.getElementById(requiredFields[i]+'-error') != null)
						{
							document.getElementById(requiredFields[i]+'-error').style.display = 'block';
						}	
						flag = false;
					}					
				}				
				else if(formObj[requiredFields[i]].type == 'select-one')
				{
					if(formObj[requiredFields[i]].value == 'Select'|| formObj[requiredFields[i]].value=="") 
					{
						if(document.getElementById(requiredFields[i]+'-error') != null)
						{
							document.getElementById(requiredFields[i]+'-error').style.display = 'block';
						}	
						flag = false;
					}					
				}else if(formObj[requiredFields[i]][0].type == 'radio')				
				{			
					var radioButtons=formObj[requiredFields[i]];
					var radioCheck= false;
					for(var j=0; j<radioButtons.length; j++){
						if(radioButtons[j].checked) { 
							radioCheck= true;
							break;
						}
					}
					if(radioCheck==false) {
						if(document.getElementById(requiredFields[i]+'-error') != null)
							{
								document.getElementById(requiredFields[i]+'-error').style.display = 'block';
							}
						flag=false;
					}												
				}
			}
			else
			{
				if(requiredFields[i])
				{
					alert('required field ['+requiredFields[i]+'] not found');
					flag = false;
				}
			}
		}
		if(flag == false && document.getElementById('global-error-message') != null)
		{
			document.getElementById('global-error-message').style.display = 'block';
			scroll(0,0);
		}		
		return flag;
	}
	else
	{
		alert('form object not found');
		return false;
	}
}

function ppcDisplay(key)
{
	var contentIds= new Array('advantages-table','how-table','addisplay-table','customer-table','cost-table');
	var navIds= new Array("advantagesdiv","howdiv","addiv","customerdiv","costdiv");
	tabbedNavigationShow(key,contentIds,'','highlight-anchor',navIds);
}

function newppcDisplay(key)
{	
	var contentIds= new Array('advantages-table','how-table','addisplay-table','sem-table','customer-table','cost-table');
	var navIds= new Array("advantagesdiv","howdiv","adoptsdiv","semdiv","customerdiv","costdiv");
	tabbedNavigationShow(key,contentIds,'sml-tab-button-navoff','sml-tab-button-navon',navIds);
	changeBusinessName(document.getElementById('boldCheckBox'));
	changeBusinessName(document.getElementById('italicCheckBox'));
	changeBusinessName(document.getElementById('redCheckBox'));
	showLogoinPreview(document.getElementById('logoCheckBox'));
	showVid($('#video'));
}
function showLogoinPreview(box)
{   
	if(box)
	{
	    if (box.checked)
	        $('#Logosample').show(300);
	     else   
	        $('#Logosample').hide(300);
	}
}
function onPPCVertsterLoad(vswapid)
{
	if(document.getElementById(vswapid) == null)
	{
		newppcDisplay('how-table');
		updatePrimaryNav('online');
	}
	else
	{
		setTimeout('onPPCVertsterLoad("'+vswapid+'")',100);
	}
}

//changes how the ad will look
function Changer(theid, prop, oneclick, twoclick)
{				
	if (document.getElementById(theid).style[prop] != oneclick)
	{
		document.getElementById(theid).style[prop] = oneclick;	
	}
	else
	{
		document.getElementById(theid).style[prop] = twoclick;
	}
}
function greatAdHowToPopup()
{
	var w= window.open('','How to write a great Ad','width=320,height=240');
}
function searchEngineMarketingPopup()
{
	var w;
	if($.browser.msie)
		w= window.open('/spportal/jsp/popups/payperclick/smlocal/sml_popup.jsp','Search_Engine_Marketing','width=350, height=460');
	else	
		w= window.open('/spportal/jsp/popups/payperclick/smlocal/sml_popup.jsp','Search_Engine_Marketing','width=390, height=460');
}
function showComparePackages()
{ 
	var w;
	if($.browser.msie)
		w= window.open('/spportal/jsp/popups/payperclick/comparePackages.jsp','compare_packages','width=350, height=423');
	else
		w= window.open('/spportal/jsp/popups/payperclick/comparePackages.jsp','compare_packages','width=380, height=423');
}
//builds category display list from hidden selectbox
//defSel default select status of added elements
function ppcbuildList(selectId, displayId,defSel)
{	
	$('#load-icon').hide();
    var tableObj = document.getElementById(displayId);
   $('#'+displayId).html('');
    var sel = document.getElementById(selectId);
    var row, cell, catId, catText;
	if(sel){
	    for( var i = 0; i < sel.options.length; i++ )  
	    {
	        catId = sel.options[i].value;
	        catText = sel.options[i].text;
	        ppcloadCategoriesToDisplay(catId, catText, row, cell, tableObj,defSel);								
	    }    
	    bpalternateColor(displayId);
	}
	$('#CategoryDisplay').show();  
}
//load selected categories to display list
function ppcloadCategoriesToDisplay(catId, catText, row, cell, tableObj,defSel)
{	
	row = document.createElement("tr");    
    cell = document.createElement("td");
    cell.setAttribute("height", '20px');    
    cell.setAttribute("id", catId + 'Item');
    cell.style.verticalAlign = 'middle';
    cell.style.paddingLeft = '5px';
    cell.innerHTML = catText;
    row.appendChild(cell);
    cell = document.createElement("td");
    cell.setAttribute("align", "right");
    cell.setAttribute("nowrap", "true");
    cell.style.verticalAlign = 'middle';
    cell.style.paddingRight = '5px';    
    if (tableObj!=null && tableObj.id=='fromDisplay')
       {
        cell.innerHTML = "<a href=\"#test\" onclick=\"ppcmaintAddItem('"+getJSString(catText)+"','"+getJSString(catId)+"', true"+(defSel?",true);":");")+"ppcAddCallback('"+getJSString(catId)+"');\">Add ></a>";
       }
       else
       {
        cell.innerHTML = "<a href=\"#test\" onclick=\"ppcmaintAddItem('"+getJSString(catText)+"','"+getJSString(catId)+"', false);ppcRemoveCallback('"+getJSString(catId)+"')\">Remove</a>";
       }
    row.appendChild(cell);
    tableObj.appendChild(row);	
}
//for PPC Maintenace Category pages
function ppcmaintAddItem(catName, catId, flag,defSel){           
	ppcaddCategoryItem(catName, catId, flag,defSel);
	bpalternateColor('toDisplay');              
}
function ppcaddCategoryItem(catName, catId, flag,defSel){
        var sel = document.getElementById('toList');
         
        //add category to selectbox      
        if(flag)
        {
	        if((catName != "") && (catName.length != 0) && !bpitemExist(sel,catId)){
	                var newOption = new Option(catName, catId,null,defSel);                      
	                sel.options[sel.options.length] = newOption; 
	                ppcaddCategoryDisplay(catName,catId, flag);
	        }
        }
        //remove category from selectbox
        else
        {
            for( var i = 0; i < sel.options.length; i++ )  
            {
                if(sel.options[i].value != "")
                {
                    if(catId == sel.options[i].value)
                    {
                        sel.options[i].value = ""; 
                        sel.options[i].text = ""; 
                    }
                }
            }
            bpbumpUp( sel );   
            ppcaddCategoryDisplay(catName,catId, flag);
        }

}
//update list from user selection
function ppcaddCategoryDisplay(catName,catId, flag)
{    			
	var tableObj = document.getElementById('toDisplay');
    var row, cell;
    var sel = document.getElementById('toList');

	//add category to display 
    if(flag)
    {       
    	ppcloadCategoriesToDisplay(catId, catName, row, cell, tableObj);		
    }
    //remove category to display
    else
    {
        var sel = document.getElementById('toList');
	    var tableRows = tableObj.getElementsByTagName('tr');
	
	    for( var i = 0; i < sel.options.length; i++ )  
	    {
	        if(sel.options[i].value == catId)
	        {
	            sel.remove(i);
	        }
	
	    }
	
	    for( var i = 0; i < tableRows.length; i++ )  
	    {
	        if( tableRows[i].firstChild.id == (catId+"Item"))
	        {
	            tableRows[0].parentNode.removeChild(tableRows[i]);
	        }
	    }
    }        
}

function calculateBudget() 
{
	var obj =document.getElementById('toList');
	if ( obj!= null && obj.options.length > 0 ){
		for(var i=0;i<obj.options.length;i++){
			obj.options[i].selected = true;
			
		}
		document.forms["ppcQuickSetupForm"]["_eventId_calculateBudget"].name="_eventId_calculateBudget";
		document.forms["ppcQuickSetupForm"].submit(); 	
	}else{
		alert('please select aleast one category');
		return false;
	}	
}

function photoGuidelinesPopup() 
{	var w;
	if($.browser.msie)
		w= window.open('/spportal/jsp/popups/photos/photoGuidelines.jsp', "Photo_Guidelines", "width=385,height=520,toolbar=0,status=0");
	else
		w= window.open('/spportal/jsp/popups/photos/photoGuidelines.jsp', "Photo_Guidelines", "width=385,height=490,toolbar=0,status=0");
}
function businessReplyGuidlinesPopup() 
{
	var w;
	if($.browser.msie)
		w= window.open('/spportal/jsp/popups/businessprofile/businessReplyGuidelines.jsp', "Business_Guidelines", "width=385,height=450,toolbar=0,status=0,scrollbars=1");
	else
		w= window.open('/spportal/jsp/popups/businessprofile/businessReplyGuidelines.jsp', "Business_Guidelines", "width=395,height=450,toolbar=0,status=0,scrollbars=1");
} 
function businessReviewGuidlinesPopup() 
{
	var w;
	if($.browser.msie)
		w= window.open('/spportal/jsp/popups/businessprofile/reviewGuidelines.jsp', "Review_Guidelines", "width=385,height=450,toolbar=0,status=0,scrollbars=1");
	else
		w= window.open('/spportal/jsp/popups/businessprofile/reviewGuidelines.jsp', "Review_Guidelines", "width=395,height=450,toolbar=0,status=0,scrollbars=1");
} 