var comment_post_enabled = true;

function showBookMarkLink(imgUrl)
{
  linkUrl = document.location;
  linkName = document.title;
  if (navigator.userAgent.indexOf('Safari') < 0)
      {document.write("<a onclick=\"bookmark('" + linkUrl + "','" + linkName + "')\"><img style='margin-right: 8px; cursor: pointer' src='" + imgUrl + "' /></a>");}
}

function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

function grey_sort_link(link_name)
{
    document.getElementById(link_name).style.color='#999999';
    document.getElementById(link_name).style.font_weight='normal';
}

function validate_comment_form()
{
    if (comment_post_enabled)
    {
        error_message = "";
        comment_form = document.forms['commentform'];

        author = strip(comment_form.author.value);
        email = strip(comment_form.email.value);
        comment = strip(comment_form.comment.value);

        if (author == "")
        {
            error_message += "Please enter your name\r\n"
        }

        if (email == "")
        {
            error_message += "Please enter your email address\r\n"
        }
        else if (!echeck(email))
        {
            error_message += "Your email address is not valid\r\n"
        }

        if (comment == "")
        {
            error_message += "Please enter a comment"
        }

        if (error_message == "")
        {
            //setTimeout('showSendingEmailMessage()', 100)
            disable_post_comment_button();
            return true;
        }
        else
        {
            alert(error_message);
            return false;
        }
    }
        else
    {
        return false;
    }
    
}

function disable_post_comment_button(){
    comment_post_enabled = false;
    post_button = document.getElementById('post-comment-button');
    post_link = document.getElementById('post-comment-button-link');
    if (post_button){
        post_button.style.color = '#CCCCCC';
    }
    if (post_link){
        post_link.display = 'none';
    }
}

function strip(string){
    return string.replace(/^\s*|\s*$/,"")
}

function echeck(str) {
    str = strip(str)
    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at)==-1){
       //alert("Invalid E-mail ID")
       return false
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
       //alert("Invalid E-mail ID")
       return false
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        //alert("Invalid E-mail ID")
        return false
    }

     if (str.indexOf(at,(lat+1))!=-1){
        //alert("Invalid E-mail ID")
        return false
     }

     if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        //alert("Invalid E-mail ID")
        return false
     }

     if (str.indexOf(dot,(lat+2))==-1){
        //alert("Invalid E-mail ID")
        return false
     }

     if (str.indexOf(" ")!=-1){
        //alert("Invalid E-mail ID")
        return false
     }

     if (str.indexOf(",")!=-1){
        //alert("Invalid E-mail ID")
        return false
     }

     return true
}



function popUpPage(url, parameters, name)
{
	//var day = new Date();
	//var pageName = name ? name : day.getTime();
    var pageName = 'send'
	//eval(pageName + " = window.open('" + url + "','" + pageName + "','" + parameters + "')");
	//if (eval(pageName) && window.focus) eval(pageName).focus();

    //if (sendWindow){
      //  sendWindow.focus()
    //}
    //else{
        sendWindow = window.open(url, pageName, parameters);
    //}
}

function fixMainColsHeight(content, sidebar, column_seperator, home_page_col_1, home_page_col_2, home_col_seperator) {
    if (document.getElementById(content) &&
        document.getElementById(sidebar) &&
        document.getElementById(column_seperator))
        {
            var lh=document.getElementById(content).offsetHeight;
            var rh=document.getElementById(sidebar).offsetHeight;
            var nh = Math.max(lh, rh);
            document.getElementById(content).style.height=nh+"px";
            document.getElementById(sidebar).style.height=nh+"px";
            document.getElementById(column_seperator).style.height=nh+"px";
        }
    else if (document.getElementById(home_page_col_1) &&
            document.getElementById(home_page_col_2) &&
            document.getElementById(home_col_seperator) &&
            document.getElementById(column_seperator))
        {
            var a=document.getElementById(home_page_col_1).offsetHeight;
            var b=document.getElementById(home_page_col_2).offsetHeight;
            var nh = Math.max(a, b);
            document.getElementById(home_page_col_1).style.height=nh+"px";
            document.getElementById(home_page_col_2).style.height=nh+"px";
            document.getElementById(home_col_seperator).style.height=nh+"px";
            document.getElementById(column_seperator).style.height=nh+"px";
        }
}

function fixHPRightColsHeight(home_rh_col_1, home_rh_col_2, column_seperator_hp_rh) {
    if (document.getElementById(home_rh_col_1) &&
        document.getElementById(home_rh_col_2) &&
        document.getElementById(column_seperator_hp_rh))
        {
            var lh=document.getElementById(home_rh_col_1).offsetHeight;
            var rh=document.getElementById(home_rh_col_2).offsetHeight;
            var nh = Math.max(lh, rh);
            document.getElementById(home_rh_col_1).style.height=nh+"px";
            document.getElementById(home_rh_col_2).style.height=nh+"px";
            document.getElementById(column_seperator_hp_rh).style.height=nh+"px";
        }
}

function do_search(search_string){
    if (document.getElementById('s')){
        document.getElementById('s').value = search_string;
        document.forms[0].submit();
    }
}
function clear_search_box(){
    if (document.getElementById('s')){
        if (document.getElementById('s').value == "Search"){
            document.getElementById('s').value = "";
            document.getElementById('s').style.color = "#333333";

        }
    }
}
function populate_search_box(){
    if (document.getElementById('s') && document.getElementById('s').value == ""){
        document.getElementById('s').style.color = "#AAAAAA";
        document.getElementById('s').value = "Search";
    }
}

var controlPanel = null;

function launch_control_panel(){
    // alert('sds');
    // check if window already exists
    if (!controlPanel || controlPanel.closed) {
        // store new window object in global variable
        controlPanel = window.open('http://affiliates.wellsprings-health.com/admin/affiliates/panel.php#Home','controlPanel');
    } else {
        // window already exists, so bring it forward
        controlPanel.focus()
    }
}

