function toggle_title_tips()
{
    var title_span = document.getElementById('title_tips');
    if (title_span.innerHTML == "&nbsp;")
    {
        title_span.innerHTML = "very important for ranking. put keywords first. keep the total number of characters under 80. 10 character minimum. be sure that every page has a unique title tag. <a href=\"javascript:void(0);\" onClick=\"MM_openBrWindow('seo_title_tags.htm','','scrollbars=yes,resizable=yes,width=600,height=500')\">more info...</a>";
    }
    else
    {
        title_span.innerHTML = "&nbsp;"
    }
}

function toggle_desc_tips()
{
    var desc_span = document.getElementById('desc_tips');
    if (desc_span.innerHTML == "&nbsp;")
    {
        desc_span.innerHTML = "200 characters maximum. 10 charactes minimum. minor effect on ranking. be sure that every page has a unique description tag.  write good descriptions that entice people to click. <a href=\"javascript:void(0);\" onClick=\"MM_openBrWindow('seo_description_tags.htm','','scrollbars=yes,resizable=yes,width=700,height=670')\">more info...</a>";
    }
    else
    {
        desc_span.innerHTML = "&nbsp;"
    }
}
function toggle_alt_tips()
{
    var desc_span = document.getElementById('alt_tips');
    if (desc_span.innerHTML == "&nbsp;")
    {
        desc_span.innerHTML = "<br />In image filenames, words must be separated with dashes. No underscores, no spaces. For example, a good filename would be: \"lamy-safari-charcoal-pen\". The ALT text should describe the picture, and should include good keywords that people might search for, so always include the word pen if it's a pen. For example, \"Lamy Safari Charcoal Pen\". Make sure each image has a unique filename and ALT text.";
    }
    else
    {
        desc_span.innerHTML = "&nbsp;"
    }
}
function toggle_url_tips()
{
    var url_span = document.getElementById('url_tips');
    if (url_span.innerHTML == "&nbsp;")
    {
        url_span.innerHTML = "Once a page has been indexed in the search engines, it starts gaining rank and trust. If you change the filename of the page, then the search engines will see it as a new page, and it will have to start from scratch. There is really only one time that a filename can be changed, and that is shortly after a page was first created, and before any SEO work has been done on the page - so, within a day or two of creating a new page. If you must change the page filename, here are the naming guidelines:<br>Example: beauty-salon-services.php<br> Try to incorporate keywords. Use lowercase alphabetic characters and dashes only - NO SPACES. NO SPECIAL CHARACTERS. 3 WORD MAXIMUM. The filename Must be unique for each page."
    }
    else
    {
        url_span.innerHTML = "&nbsp;"
    }
}   

function changeURL()
{
    var agree = confirm("PLEASE NOTE\nIT IS A VERY RARE SITUATION WHERE YOU SHOULD CHANGE AN EXISTING PAGE'S FILENAME.\nOnce a page has been indexed in the search engines, it starts gaining rank and trust. If you change the URL of the page, then the search engines will see it as a new page, and it will have to start from scratch. There is really only one time that a filename can be changed, and that is shortly after a page was first created, and before any SEO work has been done on the page - so, within a day or two of creating a new page. Are you sure you want to change this filename? Click ok if yes, cancel if no.");
    if (agree)
    {
        document.forms[1].url.disabled = false;
    }
}


if(document.getElementById("google_title") != null)
    var ori_title = document.getElementById("google_title").innerHTML;
if(document.getElementById("google_text") != null)
    var ori_text = document.getElementById("google_text").innerHTML;
if(document.getElementById("urlout") != null)
    var ori_link = document.getElementById("urlout").innerHTML;
var short_title = "";
var short_text = "";
function blurTitle()
{
    if (document.getElementById("meta_title").value == "")
        document.getElementById("google_title").innerHTML = ori_title;
}
function changeTitle()
{
    if(document.getElementById("meta_title").value.length <=70)   
        document.getElementById("google_title").innerHTML = document.getElementById("meta_title").value;
    else
    {
        short_title = document.getElementById("meta_title").value.substring(0,70);
        document.getElementById("google_title").innerHTML = document.getElementById("meta_title").value.substring(0,short_title.lastIndexOf(" ")) + "...";
    }
    
    
    if(document.getElementById("meta_title").value =="")
        document.getElementById("google_title").innerHTML = ori_title;
}
function blurText()
{
    if (document.getElementById("meta_description").value == "")
        document.getElementById("google_text").innerHTML = ori_text;
}
function changeText()
{
    
    if(document.getElementById("meta_description").value.length <=200)   
        document.getElementById("google_text").innerHTML = document.getElementById("meta_description").value;
    else
    {
        short_title = document.getElementById("meta_description").value.substring(0,200);
        document.getElementById("google_text").innerHTML = document.getElementById("meta_description").value.substring(0,short_title.lastIndexOf(" ")) + "...";
    }    
    
    
    if(document.getElementById("meta_description").value == "")
        document.getElementById("google_text").innerHTML = ori_text;
        
        
}

function blurLink()
{

    if(document.getElementById("url").value.substring(document.getElementById("url").value.length-1, document.getElementById("url").value.length) == "-")
        document.getElementById("url").value = document.getElementById("url").value.substring(0, document.getElementById("url").value.length-1);
        
    if (document.getElementById("url").value == "")
        document.getElementById("urlout").innerHTML = ori_link;
}
function changeLink()
{
    var link = document.getElementById("url").value.replace(/[^a-z\/A-Z0-9]+/g,"-");
    
    
    if(link.substring(link.length-1, link.length) == "-")
        link = link.substring(0, link.length-1);
    if(link.substring(0,1) == "-")
        link = link.substring(1,link.length);          
    document.getElementById("link").innerHTML = link.toLowerCase() + "/";
    if(document.getElementById("url").value == "")
        document.getElementById("link").innerHTML = "";
}
function changeBrand(brand)
{
    var section = brand.options[brand.selectedIndex].text;

    var link = section.replace(/[^a-zA-Z0-9]+/g,"-");
    
    
    if(link.substring(link.length-1, link.length) == "-")
        link = link.substring(0, link.length-1);
    if(link.substring(0,1) == "-")
        link = link.substring(1,link.length);          
    
    document.getElementById("brand").innerHTML = link.toLowerCase();
    if(brand == "")
        document.getElementById("brand").innerHTML = "brand";    
}
function textCounter(field,cntfield,maxlimit)
{
    var cntDiv = document.getElementById(cntfield);
    var totalchars = field.value.length;
    var remaining = maxlimit - field.value.length;

    if ((remaining < 0) && (totalchars >= 10))
        cntDiv.innerHTML = "Total characters: "+totalchars+" | <font color=\"red\">Remaining characters: "+remaining+"</font>";

    else
        cntDiv.innerHTML = "Total characters: "+totalchars+" | Remaining characters: "+remaining;
}


function urlMask(value)
{
    if(value.substring(value.length-1, value.length) == "-")
        return;

    value = value.replace(/[^a-z\/A-Z0-9]+/g,"-");
    

    if(value.substring(0,1) == "-")
        value = value.substring(1,value.length);          
    value = value.toLowerCase();

    document.getElementById('url').value = value;
}

function userMask(value)
{
    value = value.replace(/[^a-z_\-@.A-Z0-9]+/g,"");
    document.getElementById('email').value = value;
}
function nameCommentsMask(value)
{
        value = value.replace(/[^a-z_ \-@.A-Z0-9]+/g,"");
    document.getElementById('comment_name').value = value;
}

function emailCommentsMask(value)
{
        value = value.replace(/[^a-z_\-@.A-Z0-9]+/g,"");
    document.getElementById('comment_email').value = value;
}

function secondsMask(value)
{
    value = value.replace(/[^0-9]+/g,"");
    document.getElementById('interval').value = value;
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function searchBlog(type,id){
    
    var url = "/search_blog.php?";
    
    switch(type){
        case 'a':{
                    url += "&author=" + id;
                    break;
        }
        case 'c':{
                    url += "&category=" + id; 
                    break;
        }
        case 'k':{
                    url += "keyword=" + document.getElementById("keyword").value; 
                    break;
        }
        case 'n':{
                    url += "post_id=" + id; 
                    break;
        }
        case 'd':{
                    var date_arr = id.split("-");
                    url += "date_filter=date_format(date(date_post),'%Y')='"+date_arr[0]+"' AND date_format(date(date_post),'%b')='" +date_arr[1]+"'"; 
                    break;
        }
    }

    execAJAXSearchBlog(0,url,"content-blog");
    document.getElementById("content-blog").style.marginBottom='170px';

}
function signUp()
{
    var user = document.getElementById('user').value.replace("&"," and ");
    var phone = document.getElementById('phone').value.replace("&"," and ");
    var area_code = document.getElementById('area_code').value.replace("&"," and ");
    var company = document.getElementById('company').value.replace("&"," and ");
    var city = document.getElementById('city').value.replace("&"," and ");
    var province = document.getElementById('province').value.replace("&"," and ");
    var postal_code = document.getElementById('postal_code').value.replace("&"," and ");
    var country = document.getElementById('country').value.replace("&"," and ");
    var address = document.getElementById('address').value.replace("&"," and ");
    var hear_about = document.getElementById('hear-about').value.replace("&"," and ");
    var email = document.getElementById('email').value.replace(/[^a-z.@_A-Z0-9]+/g,"");;

    var identifier = document.getElementById('identifier').value;
    
    document.getElementById('user_validator').innerHTML = "";
    document.getElementById('phone_validator').innerHTML = "";
    document.getElementById('company_validator').innerHTML = "";
    document.getElementById('city_validator').innerHTML = "";
    document.getElementById('province_validator').innerHTML = "";
    document.getElementById('postal_code_validator').innerHTML = "";
    document.getElementById('country_validator').innerHTML = "";
    document.getElementById('email_validator').innerHTML = "";
    
    var error = 0;
    if(user == "")
    {
        document.getElementById('user_validator').innerHTML += "* Please enter your name<br />";
        error++;
    }
    else
    {
        document.getElementById('user_validator').innerHTML = "";
    }
    
    if(phone == "")
    {
        document.getElementById('phone_validator').innerHTML += "* Please enter your phone number and area code";
        error++;
    }
    else
    {
        document.getElementById('phone_validator').innerHTML = "";
    }


    if(phone == "")
    {
        document.getElementById('area_code').innerHTML += "* Please enter your phone number and area code";
        error++;
    }
    else
    {
        document.getElementById('area_code').innerHTML = "";
    }
    
    if(company == "")
    {
        document.getElementById('company_validator').innerHTML += "* Please enter your company<br />";
        error++;
    }
    else
    {
        document.getElementById('company_validator').innerHTML = "";
    }
    if(city == "")
    {
        document.getElementById('city_validator').innerHTML += "* Please enter your city<br />";
        error++;
    }
    else
    {
        document.getElementById('city_validator').innerHTML = "";
    }
    if(province == "")
    {
        document.getElementById('province_validator').innerHTML += "* Please enter your province<br />";
        error++;
    }
    else
    {
        document.getElementById('province_validator').innerHTML = "";
    }

    if(postal_code == "")
    {
        document.getElementById('postal_code_validator').innerHTML += "* Please enter your postal code<br />";
        error++;
    }
    else
    {
        document.getElementById('postal_code_validator').innerHTML = "";
    }

    if(country == "")
    {
        document.getElementById('country_validator').innerHTML += "* Please enter your country<br />";
        error++;
    }
    else
    {
        document.getElementById('country_validator').innerHTML = "";
    }

    if (!(document.getElementById('email').value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.biz)|(\.coop)|(\.info)|(\.name)|(\.pro)|(\.int)|(\.aero)|(\..{2,2}))$)\b/gi)))
    {
        document.getElementById('email_validator').innerHTML += "* Your Email Address does not appear to be valid<br />";
        error++;
    }
    else
    {
        var email_check = execAJAXEmail('/check_user.php?email=' + email); // The E-mail is the user name, hence the filename check_user
        
        if(email_check != "0")
        {

            document.getElementById('email_validator').innerHTML += "* The E-mail address " + email + " is already subscribed to our email list.<br />";
            error++;
        }
        else
        {
            document.getElementById('email_validator').innerHTML = "";
        }        
    }    
    
    if(error > 0)
    {
        //document.getElementById('sign-up-result').innerHTML = "<br />The following problems were encountered:<br /><strong>" + document.getElementById('sign-up-result').innerHTML + "</strong>";
        return false;
    }
    else
    {
        var url = "/sign_up_user.php?user=" + user + "&email=" + email + "&company=" + company + "&phone=" + phone + "&area_code=" + area_code + "&city=" + city + "&province=" + province + "&postal_code=" + postal_code + "&country=" + country + "&address=" + address + "&hear_about=" + hear_about + "&identifier=" + identifier;
        execAJAXSignUpUser(0,url,"sign-up-result");
        
        document.getElementById('sign-up-table').style.display = 'none';
        document.getElementById('sign-up-result').innerHTML = "<br />Success! You are now signed up to our mailing list.";
    }
    document.getElementById('sign-up-result').style.display = 'block';
}




function update(email_ori){
    
    var user = document.getElementById('user').value;
    var password = document.getElementById('password').value;
    var password2 = document.getElementById('password2').value;
    var email = document.getElementById('email').value.replace(/[^a-z.@_A-Z0-9]+/g,"");;
    document.getElementById('user_validator').innerHTML = "";
    document.getElementById('password_validator').innerHTML = "";
    document.getElementById('password2_validator').innerHTML = "";
    document.getElementById('email_validator').innerHTML = "";
    
    var error = 0;
    if(user == "")
    {
        document.getElementById('user_validator').innerHTML += "* You must inform your name<br />";
        error++;
    }
    else
    {
        document.getElementById('user_validator').innerHTML = "";
    }
    
    /*
    if(password.length == "0" )
    {
        document.getElementById('password_validator').innerHTML += "* You must inform a password<br />";
        error++;
    }    
    else
    {
        document.getElementById('password_validator').innerHTML = "";
    }

    if(password2.length == "0" )
    {
        document.getElementById('password2_validator').innerHTML += "* You must re-type your password.<br />";
        error++;
    }     
    else
    {
        document.getElementById('password2_validator').innerHTML = "";
    }
    */
    
    if(password != password2 && (password.length != 0 && password2.length != 0))
    {
        document.getElementById('password_validator').innerHTML += "* The informed passwords does not match. Please verify<br />";
        error++;
    }
    if (!(document.getElementById('email').value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.biz)|(\.coop)|(\.info)|(\.name)|(\.pro)|(\.int)|(\.aero)|(\..{2,2}))$)\b/gi)))
    {
        document.getElementById('email_validator').innerHTML += "* Your Email Address does not appear to be valid<br />";
        error++;
    }
    else
    {
        var email_check = execAJAXEmail('check_user.php?email=' + email); // The E-mail is the user name, hence the filename check_user
        
        if(email_check != "0" && email != email_ori)
        {
            document.getElementById('email_validator').innerHTML += "* The informed E-mail is already in use. Please try another one.<br />";
            error++;
        }
        else
        {
            document.getElementById('email_validator').innerHTML = "";
        }        
    }    
    
    if(error > 0)
    {
        //document.getElementById('sign-up-result').innerHTML = "<br />The following problems were encountered:<br /><strong>" + document.getElementById('sign-up-result').innerHTML + "</strong>";
        return false;
    }
    else
    {
        var url = "update_user.php?user=" + user + "&password=" + password + "&email=" + email;
        var resp = execAJAXSignUpUser(0,url,"sign-up-result");
        
        document.getElementById('sign-up-table').style.display = 'none';
        document.getElementById('sign-up-result').innerHTML = "<br />Your profile has been updated.";
    }
document.getElementById('sign-up-result').style.display = 'block';
}




function userLogin()
{
var ASDFASEYR = document.getElementById('ASDFASEYR').value;
var XPOCBVWERN = document.getElementById('XPOCBVWERN').value;
var login = execAJAXLogin('/user_login.php?ASDFASEYR=' + ASDFASEYR + "&XPOCBVWERN=" + XPOCBVWERN);

if (login == "NS")
{
    window.location = "/sign-up.php?email="+XPOCBVWERN;
    return false;
}


if(login == 0)
    document.getElementById('login-error').innerHTML = "Invalid Login";
else
    if(login.substring(0,1)==1)
    {
        login = login.substring(1);
        document.getElementById('fieldset').innerHTML = "<span id='login-welcome'><p style='font-size:80%'>Welcome <strong>" + login + "</strong> - <a href='/manage_account.php'>Manage my account</a> - <a href='/logoff.php'>Logout</a>.</p></span>";
    }
return false;
}

function changeVideo()
{
    var video_url = document.getElementById('video_url').value;
    var url_start = parseInt(video_url.lastIndexOf('/'))+1;
    var video_id = video_url.substr(url_start,8);

    var new_video = "";
    
    new_video +="<object width=\"400\" height=\"300\">";
    new_video +="<param name=\"allowfullscreen\" value=\"true\" />";
    new_video +="<param name=\"allowscriptaccess\" value=\"always\" />";
    new_video +="<param name=\"movie\" value=\"http://vimeo.com/moogaloop.swf?clip_id=" + video_id + "&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1\" />";
    new_video +="<embed src=\"http://vimeo.com/moogaloop.swf?clip_id=" + video_id + "&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" width=\"400\" height=\"300\">";
    new_video +="</embed>";
    new_video +="</object>";
    
    document.getElementById('video').innerHTML = new_video;
    
}

function rssExpand(value)
{
var display = "";
    if(!bw.ieX)
        display  = 'table-row';
    else
        display = 'block';
    
    if(value ==1)
    {
        document.getElementById('rss_title_row').style.display = display;
        document.getElementById('rss_description_row').style.display = display;
    }
    else
    {
        document.getElementById('rss_title_row').style.display = 'none';
        document.getElementById('rss_description_row').style.display = 'none';
    }
    
}

function js_newline_replace(text){
    text = escape(text);
    if(text.indexOf('%0D%0A') > -1){
        re_nlchar = /%0D%0A/g ;
    }else if(text.indexOf('%0A') > -1){
        re_nlchar = /%0A/g ;
    }else if(text.indexOf('%0D') > -1){
        re_nlchar = /%0D/g ;
    }
    return unescape( text.replace(re_nlchar,'^^THISISANEWLINECHARACTER^^') );
}



function addComment(id,moderator_id)
{
    var problems = "";

    if (document.getElementById('comment_name').value == "")
    {
        problems = problems+"\n- name is required";
    }
    if (document.getElementById('comment_email').value == "")
    {
        problems = problems+"\n- email is required";
    }
    if (!(document.getElementById('comment_email').value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.biz)|(\.coop)|(\.info)|(\.name)|(\.pro)|(\.int)|(\.aero)|(\..{2,2}))$)\b/gi)))
    {
        problems = problems+"\n- your email address does not appear to be valid";
    }  
    if (document.getElementById('comment').value == "")
    {
        problems = problems+"\n- comment is required";
    }
    if (problems != "")
    {
        alert ("The following errors were encountered:\n"+problems+"\n\nPlease fix these problems and try again.");
    }          
    else
    {    
        var name = document.getElementById('comment_name').value.replace("&"," and ");
        var email = document.getElementById('comment_email').value.replace("&"," and ");
        var comment = document.getElementById('comment').value.replace("&"," and ");
        var website = document.getElementById('website').value.replace("&"," and ");
        document.getElementById('pancake').value = "Yummy!!!";
        var pancake = document.getElementById('pancake').value;

        // newlines are getting stripped out of comments, so replace them with something before passing
        comment = js_newline_replace(comment);
        //alert(comment);

        if(website == "" && pancake == "Yummy!!!" && name != "" && email != "" && comment != "")
            var resp = execAJAXEmail('/add_comments.php?moderator_id=' + moderator_id + '&id=' + id + '&name=' + name + "&email=" + email + "&comment=" + comment + "&website=" + website + "&pancake=" + pancake);
            
        if(resp =="")
        {
            document.getElementById('comment_name').value = "";
            document.getElementById('comment_email').value = "";
            document.getElementById('comment').value = "";
            if(moderator_id == 0)
                alert("Your comment has been posted");
            else
                alert("Your comment was received, but is subject to moderation");
        }
        document.getElementById('comments').innerHTML= execAJAXEmail('/list_comments.php?id='+id);    
    }
}



function searchSphinx(){

    var text = document.getElementById('text').value;
    var date_start = document.getElementById('date_start').value;
    var date_end = document.getElementById('date_end').value;
    var number = document.getElementById('number').value;
    
    var url = "search_sphinx.php?text=" + text + "&date_start=" + date_start + "&date_end=" + date_end + "&number=" + number;
    
    execAJAXSearchBlog(0,url,"results");

}

function mySubmit(newStart)
{
    document.form1.start.value = newStart;
    document.form1.submit();
}

function changeYear(year)
{
    document.form1.year.value = year;
    document.form1.start.value = 0;
    document.form1.submit();
}

function updateAddressList(id,value)
{
    var resp = execAJAXLogin("update_address_list.php?id=" + id + "&add_list=" + value);
    if(resp=="OK")
        alert("Saved!");
    else
        alert("Not Saved!");    
}


function updateArchive(id,value)
{
    var resp = execAJAXLogin("update_archive.php?id=" + id + "&archive=" + value);
    if(resp=="OK")
        alert("Saved!");
    else
        alert("Not Saved!");    
}

function updatePostDate(id)
{
    eval("var value = document.getElementById('post_date_" + id + "').value");
    var resp = execAJAXLogin("update_postdate.php?id=" + id + "&post_date=" + value);
    if(resp=="OK")
        alert("Saved!");
    else
        alert("Not Saved!");    
    location.reload(true);
}


function saveItems(id,count)
{
    document.getElementById('id').value = id+"|"+count;
    eval("document.getElementById('title').value = document.form1.rss_title_"+count+".value;");
    eval("document.getElementById('description').value = document.form1.rss_description_"+count+".value;");
    eval("document.getElementById('category').value = document.form1.rss_category_"+count+".value;");
    document.getElementById('form1').submit();
}
function deleteItem(id,desc,count)
{
    var check = confirm("Are you sure that you want to delete the item '" + desc + "'?");
    
    if(check)
    {
        document.getElementById('form_action').value = "delete";
        document.getElementById('id').value = id+"|"+count;
        document.getElementById('form1').submit();
    }
}
/*

function initPage()
{
    var inputs = document.getElementsByTagName("input");
    if (inputs){
        for (var i=0; i<inputs.length; i++)
        {
            if (inputs[i].value!=""&&inputs[i].parentNode) inputs[i].parentNode.className += " focus";
            inputs[i].onfocus = function (){if (this.parentNode&&this.parentNode.className.indexOf("focus")==-1) this.parentNode.className += " focus";}
            inputs[i].onblur = function (){if (this.parentNode&&this.value=="") this.parentNode.className = this.parentNode.className.replace("focus","");}
        }
    }
}



if (window.addEventListener)
{
    window.addEventListener("load", initPage, false);
}
else if (window.attachEvent){
    window.attachEvent("onload", initPage);
}


*/
