<!--
var win;

var _editor_url = "http://www.GolfNetworking.org/htmlarea";


function clickOnce(){
    clickOnceForm(document.update.submitbut);
}

function clickOnceForm(f){
    f.value='Please wait...';
    f.disabled=true;
}

function checkPopup(){
    if (!(win && win.open && !win.closed)) {
        var text = "Please enable popups on our site!";
        var html = "<P align=justify class=main_text_l><b>" + text + "</b></p>";
        //if (document.all && document.all.warning)
           // document.all.warning.innerHTML = html;
        //else if (document.getElementById('warning'))
          //  document.getElementById('warning').innerHTML = html;
    }
}

function PopUpEx(sendLink, name, width, height, scrollbars) {
    mm= "width=" + width + ",height=" + height + ",scrollbars=" + scrollbars;
    win = window.open(sendLink, name, mm);
    if (win && win.open && !win.closed)
        win.focus();
    return win;
}

function PopUp(sendLink, name, width, height, scrollbars) {
    PopUpEx(sendLink, name, width, height, scrollbars);
}

function newwindow(a,windowname, width, height, scrollbars){
    var mm= "width=" + width + ",height=" + height + ",scrollbars=" + scrollbars;
    var win = window.open(a.href, windowname, mm);
    if (win && win.open && !win.closed){
        win.focus();
    }
   return false;
}

function getXMLHttpRequest()
{
    var http_request;
        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }
        return http_request;

}

function confirmwindow(c_text,c_url,win_name,width,heigh,scrollbars) {
    if (confirm(c_text)){
        PopUpEx(c_url,win_name,width,heigh,scrollbars);
    }
}

function disp_confirm(){
    if(confirm('Are you sure you want to remove this email from invite history?')){
        return true;
    }else{
        return false;
    }
}

function check_spell_open(form_text_tag,form_name){
    if (!form_name) form_name ='update';
    var text = document.getElementById(form_text_tag).value;
    PopUpEx('/spell_checker_?form_name='+form_name+'&form_text_tag='+form_text_tag+'&text='+escape(text),'check_spell',500,400,'yes');
    //alert(text);
}

function check_spell(form_text_tag,form_name){
      if (!form_name) form_name ='update';
      var text = document.getElementById(form_text_tag).value;
      var reg = /\bblog\b|\bblogs\b|\bblogging\b|\bblogland\b|\bbloggers\b/gi;
      text = text.replace(reg,"")
      var http_request;
      http_request=getXMLHttpRequest();
      http_request.open('GET', '/_check_spell?form_name='+form_name+'&form_text_tag='+form_text_tag+'&text='+escape(text)+'&ajaxRequestUncache='+parseInt(Math.random() * 1000000), true);
      http_request.onreadystatechange =  function(){
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                var info = http_request.responseText;
                if(info == 1){
                    alert("No misspelling found!");
                }else{
                    check_spell_open(form_text_tag,form_name);
                }
            } else {
                alert('There was a problem with the request.');
            }
        }
      }
      http_request.send(null);
}

function modelesswin(url,mwidth,mheight,winname){
    if (document.all&&window.print){ 
        eval('window.showModelessDialog(url,winname,"help:0;resizable:1;dialogWidth:'+mwidth+'px;dialogHeight:'+mheight+'px")');
    }else{
        eval('window.open(url,winname,"width='+mwidth+'px,height='+mheight+'px,resizable=1,scrollbars=1")');
    }   
}

function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}

function fixForm(c)
{
  var i;
  var n = c.name;
  var l = c.form.elements.length;
  if (!c.checked) return;
  if (c.value == '0') {
    for (i = 0 ; i < l ; i++){
      var e = c.form.elements[i];
      if(e.name == n && e.value != c.value) e.checked=false;
    }
  } else {
    for (i = 0 ; i < l ; i++){
      var e = c.form.elements[i];
      if(e.name == n && e.value == '0') e.checked=false;
    }

  }
  return;
}

function check_password()
{
    var i = 6;
    jQuery("#view").html('');
    var password_obj = jQuery("input[@name=password]");
    var password_repeat_obj = jQuery("input[@name=password_repeat]");
    if (password_obj.val().length < i) {
        jQuery("#view").html('(Your password must be at least ' + i + ' characters. <br />No spaces or special characters.)');
        jQuery("#view").css("color", '#ff0000');
        jQuery("#view").css("font-size", "10px");
        password_obj.val('');
        return;
    } else if (password_obj.val().match(/\W/)) {
        jQuery("#view").html('Your password contains invalid characters! Please choose another password comprised only of letters and numbers with no spaces.');
        jQuery("#view").css("color", '#ff0000');
        jQuery("#view").css("font-size", "10px");
        password_obj.val('');
        return;
    }
    if (password_obj.val().length > 0 && password_repeat_obj.val().length > 0  && password_obj.val() != password_repeat_obj.val()) {
            jQuery("#alert_password_repeat").show();
    } else {
            jQuery("#alert_password_repeat").hide();
    }
}

function popUpPayment(){
    PopUp('pay','pay',800,700, 'yes');
}

function PaymentWindowWithUserid(prof_id){
    window.open('pay?prof_id='+prof_id);
}

function goldMemberOnly(message1,message2,message3)
{
   var mes;
   if (message1==null&&message2==null&&message3==null){
      mes="This service is for gold members only (\$19.95 monthly).";
   }
   if (message3!=""){
     mes=message3;
   }else{
     mes=message1;
     mes+= message2;
   }
   modelesswin('_goldMemberOnlyMessage?message='+mes,335,500,'paymessage');
}


function checkFrame(site) {
    try {
    var isFrame= self.parent.frames.length;
    if (isFrame==0){
        url=document.location;
        var re1 = /search_results/;
        if (re1.test(url)==true) {
            new_location = 'http://www.' + site + '/index.html?url=';
            try {
                        new_location += encodeURIComponent(url);
            } catch (e) {
                        new_location += escape(url);
            }
            document.location = new_location;
       }
    }
    } catch (e) {}
}

function RevealProfile(nextPage) {
    var newHref = "set_hidden?hide=0";
    if(nextPage!=null)
      newHref+="&next="+nextPage;
    if (confirm('Are you sure you want to reveal your profile?'))
        window.location.href = newHref;
}

function HideProfile() {
    if (confirm('You can still use all the features.  But others will not be able to see your profile.\nAre you sure you want to hide the profile?'))
        window.location.href = "set_hidden?hide=1";
}
function profileIncomplete(){
     alert("Please complete your registration to use our services!");
     //window.location.href = "my_profile";
}

function countLineBreaks (string) {
    var re = /\r\n|\r|\n/g;
    var n = 0;
    while (re.exec(string))
        n++;
    return n;
}

/* if needed, tries to increase the number of rows of a textarea */
function growTAVert (textarea) {
    var lineBreaks = countLineBreaks(textarea.value);
    if (textarea.rows * textarea.cols < textarea.value.length) {
        var newRows = lineBreaks +
                      parseInt(textarea.value.length / textarea.cols) + 2;
        newRows = newRows <= 40 ? newRows : 40;
        textarea.rows = newRows;
    } else if (textarea.rows < lineBreaks) {
        textarea.rows = lineBreaks + 2;
    }
}

function mc (id) {
    var obj = eval("document.forms.accounts.changed_" + id);
    obj.value = 1;
}

try{
     if (window.parent.document.title){
    window.parent.document.title=window.self.document.title;
     }
}catch(e){}


function checklogin()
{
     var strResult=0;
     if (document.getElementById){
         try{
           strResult = NetScapeShow();
         }catch(e){
           strResult = IEShow();
         }
     }else{
          strResult = IEShow();
     }
     return strResult;
}
 
function NetScapeShow(){
 xmlHttp = new XMLHttpRequest();
 xmlHttp.open("GET", "_check_authen", false);
 xmlHttp.send(null);
 xmlDoc = xmlHttp.responseText;
 var strResult =xmlDoc;
 return strResult;
}
 
function IEShow(){
 var oBao = new ActiveXObject("Microsoft.XMLHTTP");
 oBao.open("GET","_check_authen",false);
 oBao.send();
 var strResult = unescape(oBao.responseText);
 return strResult;
}

function syncForm(){
    var strResult=0;
    strResult = checklogin();
    if (!strResult){
        alert("Sorry, your session has expired. \nPlease log on again after copy your composing to your notepad!");
        return false;
    }else{
    return true;
    }
}

function setSelectValue(sel,val){
  var i;
  for (i=0;i<sel.length;i++) {
    if (sel.options[i].value == val){
      sel.selectedIndex = i;
    }
  }      
}

function FullSize(url,ix,iy) {
    if(ix>0) {
        PopUp(url,"fsphoto",ix+6,iy+6,"no");
    }
}

function setPhotoAbout(id){
  PopUp('_set_picabout?id='+id,"about",435,388,"no");

}



function getFormFieldValue(field) {
    switch (field.type) {

        case "button" :
        case "file" :
        case "hidden" :
        case "password" :
        case "reset" :
        case "submit" :
        case "text" :
        case "textarea" :
            return field.value;

        case "select-one" :
            var i = field.selectedIndex;
            if (i == -1)
                return "";
            else
                return (field.options[i].value == "") ? field.options[i].text : field.options[i].value;

        case "select-multiple" :
            var result = new Array();
            for (var i = 0; i < field.options.length; i++)
                if (field.options[i].selected)
                    result[result.length] = (field.options[i].value == "") ? field.options[i].text : field.options[i].value;
            return result;

        case "radio" :
        case "checkbox" :
            if (field.checked)
                return field.value;
            else
                return "";

        default :
            if (field[0].type == "radio") {
                for (i = 0; i < field.length; i++)
                    if (field[i].checked)
                        return field[i].value;

                return "";
            } else if (field[0].type == "checkbox") {
                var result = new Array();
                for (i = 0; i < field.length; i++)
                    if (field[i].checked)
                        result[result.length] = field[i].value;

                return result;
            } else {
                // unknown field type
            }
            break;
    }
   
    return "";
}

function fixPiclist(obj, usr_id, picno) {
    var form = obj.form;
    var npics = form.elements['npics__' + usr_id].value;
    var makemain = form.elements['makemain__' + usr_id];
    var picno_main = npics > 1 ? getFormFieldValue(makemain) : 0;
    if (picno_main == "") picno_main = -1;

    // clear the other rank
    if (obj.name.substr(0, 6) == 'rank__' && obj.checked == 1)
        form.elements['rank4__' + usr_id].checked = 0;
    if (obj.name.substr(0, 7) == 'rank4__' && obj.checked == 1)
        form.elements['rank__' + usr_id].checked = 0;

    // undelete the main photo if setting a rank
    if ((obj.name.substr(0, 6) == 'rank__' ||
         obj.name.substr(0, 7) == 'rank4__') && obj.checked == 1)
    {
        // if there is no main photo, then use first pic for main photo
        if (picno_main == -1) {
            picno_main = 0;
            if (npics > 1) {
                makemain.value = picno_main = 0;
                makemain[0].checked = 1;
            }
        }

        form.elements['delp__' + usr_id + '_' + picno_main].checked = 0;
    }

    // "undelete" the main photo
    if (obj.name.substr(0, 10) == 'makemain__' && picno == picno_main) {
        form.elements['delp__' + usr_id + '_' + picno].checked = 0;
    }

    if (obj.name.substr(0, 6) == 'delp__' && obj.checked == 1) {
        if (picno == 0 && npics == 1) {
            // set rank to 0
            form.elements['rank__' + usr_id].checked = 0;
            form.elements['rank4__' + usr_id].checked = 0;
        } else {
            // if pic to be deleted is the main photo,
            // then use the first not deleted pic for main photo
            if (picno == picno_main) {
                for (var i = 0; i < npics; i++) {
                     if (form.elements['delp__' + usr_id + '_' + i].checked == 0) {
                         makemain.value = picno_main = i;
                         makemain[i].checked = 1;
                         break;
                     }
                }
            }

            // if all pics will be deleted, set rank to 0
            if (i == npics) {
                form.elements['rank__' + usr_id].checked = 0;
                form.elements['rank4__' + usr_id].checked = 0;
                makemain[picno_main].checked = 0;
                makemain.value = picno_main = -1;
            }
        }
    }
}

function OnLoadPage(site) {
}

function clickSearchOnce(){
    var html="<b>Please wait...</b>";
    if (document.all && document.all.showsearch){
            document.all.showsearch.innerHTML = html;
    }else if (document.getElementById('showsearch')){
            document.getElementById('showsearch').innerHTML = html;
    }
}
function set_start_height(oForm, startValue) {
    var fOption = oForm.options;
        if(!fOption[0].selected == true) {
            return;
        }   
    for (var i = 0; i < fOption.length; i++)
        if (fOption[i].value == startValue) fOption[i].selected = true;
}

function setRadioValue(f, name, value){
  var i;
  var l = f.elements.length;
  for (i = 0 ; i < l ; i++){
      var e = f.elements[i];
      if(e.name == name){
            e.checked = (e.value == value? true: false);
      } 
  }
}
function show_hide_dist(r) {
    try{
        var r_value = r.value;
        if (r.name != 'is_distance'){
            if (r.name.indexOf('_cou')!= -1 || r.name.indexOf('state')!= -1){ // is country
                r_value = 0;
            }else{
                r_value = 1;
            }
            setRadioValue(r.form, 'is_distance', r_value);   
        }
    } catch (e) {}
}
function checkMessages(theBox,theArray) {
        if ( theBox.checked ) {
            for (i = 0; i < theArray.elements.length; i++) {
                try{
                    theArray.elements[i].checked = true ;
                }catch(e){}
            }
            theBox.form.checkall.checked = true;
        } else {
            for (i = 0; i < theArray.elements.length; i++) {
                try{
                    theArray.elements[i].checked = false ;
                }catch(e){}
            }
            theBox.form.checkall.checked = false;
        }
}

function registerAlert() {
    alert('Please register to use the feature');
}

function text_change(object, resultFieldID, maxLength) {
    var ilen = maxLength - object.value.length;
    jQuery('#' + resultFieldID).html(ilen > 0 ? ilen : 0);
    setMaxLength(object, maxLength);
}

function setMaxLength(object,length) 
{
    var tempString=object.value;
    if(tempString.length>length)
    {
        alert("Maximum "+ length +" characters.");
    
        if(tempString.length>length)
           tempString=tempString.substr(0,length);
        object.value=tempString;    
    }
} 

// utility function to retrieve an expiration date in proper

// format; pass three integer parameters for the number of days, hours,

// and minutes from now you want the cookie to expire (or negative

// values for a past date); all three parameters are required,

// so use zeros where appropriate

function getExpDate(days, hours, minutes) {

    var expDate = new Date( );

    if (typeof days == "number" && typeof hours == "number" && 

        typeof hours == "number") {

        expDate.setDate(expDate.getDate( ) + parseInt(days));

        expDate.setHours(expDate.getHours( ) + parseInt(hours));

        expDate.setMinutes(expDate.getMinutes( ) + parseInt(minutes));

        return expDate.toGMTString( );

    }

}

// utility function called by getCookie( )

function getCookieVal(offset) {

    var endstr = document.cookie.indexOf (";", offset);

    if (endstr == -1) {

        endstr = document.cookie.length;

    }

    return unescape(document.cookie.substring(offset, endstr));

}

// primary function to retrieve cookie by name

function getCookie(name) {

    var arg = name + "=";

    var alen = arg.length;

    var clen = document.cookie.length;

    var i = 0;

    while (i < clen) {

        var j = i + alen;

        if (document.cookie.substring(i, j) == arg) {

            return getCookieVal(j);

        }

        i = document.cookie.indexOf(" ", i) + 1;

        if (i == 0) break; 

    }

    return "";

}

// store cookie value with optional details as needed

function setCookie(name, value, expires, path, domain, secure) {

    document.cookie = name + "=" + escape (value) +

        ((expires) ? "; expires=" + expires : "") +

        ((path) ? "; path=" + path : "") +

        ((domain) ? "; domain=" + domain : "") +

        ((secure) ? "; secure" : "");

}

// remove the cookie by setting ancient expiration date

function deleteCookie(name,path,domain) {

    if (getCookie(name)) {

        document.cookie = name + "=" +

            ((path) ? "; path=" + path : "") +

            ((domain) ? "; domain=" + domain : "") +

            "; expires=Thu, 01-Jan-70 00:00:01 GMT";

    }

}


//Instant Messenger functions

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var chats = new Array();
var CommandBlocked = false;

function startIM (usr_id) {
   PopUp("http://GolfNetworking.org/s/im_users_list.htm","im_" + usr_id,330,500,"no, resizable=1");
}

function startPrivateChat(partyname) {
        var im_usersObj = isInternetExplorer ? document.all.im_users : document.im_users;

        if((chats[partyname]==null) || (typeof(chats[partyname])=="undefined") || (chats[partyname].closed)) {
                try {
                        var win_name = "MIM_to_" + partyname.replace("(", "").replace(")", "").replace("$", "").replace("-", "");
                        chats[partyname] = PopUpEx('http://GolfNetworking.org/s/im_private.htm?partyname=' + partyname, win_name, 500, 330, 'no, resizable=1');
                } catch(e) { alert("error:" + e)};
                if(chats[partyname]==null || typeof(chats[partyname])=="undefined") {
//TODO: Possible, popups is blocked. Display notification.
                        if(im_usersObj) {
                                im_usersObj.TGotoLabel("/", "PopupBlocked");
                        }
                }
        } else {
//TODO: Add blinking effect to window chats[partyname]. Don't know how to do it...
        }
}

function startChatRoom (room_id, room_name) {
  room_name = room_name.replace("&", "and");
/*  room_name = room_name.replace(",", "");
  room_name = room_name.replace(/\s+/gi, "");*/
  PopUp('http://GolfNetworking.org/s/im_chat_room.htm?room_id='+room_id+'&room='+room_name,'chat'+room_id,650,500,'no, resizable=1');
}

function updateAllCheckbox(form,value){
    var e = form.elements;
    if(value == "") value = false;
    for(var i = 0; i < e.length; i++){
        if(e[i].type != "checkbox")continue;
        e[i].checked = value;
    }
}

/* following function copy from prototype */

function $() {
  var results = [], element;
  for (var i = 0; i < arguments.length; i++) {
    element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);
    results.push(element);
  }
  return results.length < 2 ? results[0] : results;
}

var Ajax = {
  getTransport: function() {
    return Try.these(
      function() {return new ActiveXObject('Msxml2.XMLHTTP')},
      function() {return new ActiveXObject('Microsoft.XMLHTTP')},
      function() {return new XMLHttpRequest()}
    ) || false;
  },
  
  activeRequestCount: 0
}


var Try = {
  these: function() {
    var returnValue;

    for (var i = 0; i < arguments.length; i++) {
      var lambda = arguments[i];
      try {
        returnValue = lambda();
        break;
      } catch (e) {}
    }

    return returnValue;
  }
}

function addEvent(obj, evType, fn){
    /* adds an eventListener for browsers which support it
       Written by Scott Andrew: nice one, Scott */
    if (obj.addEventListener){
        obj.addEventListener(evType, fn, true);
        return true;
    }
    else if (obj.attachEvent){
	    var r = obj.attachEvent("on"+evType, fn);
        return r;
    }
    else {
	    return false;
    }
}

String.prototype.trim = function(){return this.replace(/(^\s*)|(\s*$)/g, "");}

function rand(n){
  return ( Math.floor ( Math.random ( ) * n + 1 ) );
}


function getStyle(el,styleProp)
{
    var x = $(el);
    if (x.currentStyle)
        var y = x.currentStyle[styleProp];
    else if (window.getComputedStyle)
        var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
    return y;
}

/* page action script */
addEvent(window, "load", _fixImageHeight);
//addEvent(window, "load", setWindowsTitle);

function _fixImageHeight(){
    var img = document.getElementsByTagName("img");
    for(var i = 0; i< img.length; i++){
        var v = getStyle(img[i],"height");
        img[i].style.height = v;
    }
}

/*
function setWindowsTitle(){
    var e = $('forum_title');
    if(e){
        document.title = e.innerText;
    } 
}
*/

function checkMessages(theBox,theArray) {
        if ( theBox.checked ) {
            for (i = 0; i < theArray.elements.length; i++) {
                try{
                    theArray.elements[i].checked = true ;
                }catch(e){}
            }
            theBox.form.checkall.checked = true;
        } else {
            for (i = 0; i < theArray.elements.length; i++) {
                try{
                    theArray.elements[i].checked = false ;
                }catch(e){}
            }
            theBox.form.checkall.checked = false;
        }
}

/*
 * clear tips when object is focused
 * obj: input, textarea
 * origval: original value, such as tips
 */
function clear_when_focused(obj, origval) {
    var o = jQuery(obj);
    if (o.val() == origval) {
        o.val('');
        o.css('color', '');
    }
}

function RotateImg(obj, usr_id, picno, nocensor) {
    var angle = 0;
    var uid = usr_id + '_' + picno;
    angle = parseInt(document.getElementById("rangle__"+uid).value) + parseInt(obj.name);
    var rotation = 0;
    if (Math.abs(angle) >= 360) {
        if (angle > 0) angle -= 360;
        else angle += 360;
    }
    document.getElementById("rangle__"+uid).value = angle;
    //only for IE v.5.5 and above 
    if (navigator.appName == "Microsoft Internet Explorer") {
        if (angle < 0) angle += 360;
        switch (angle) {
            case  90 : rotation = 3; break;
            case 180 : rotation = 2; break;
            case 270 : rotation = 1; break;
        }
        document.getElementById("photo__"+uid).style.filter = "progid:DXImageTransform.Microsoft.BasicImage(rotation=" + rotation + ")";
    } else {
        var url = "show_rotated_img_?usr_id=" + usr_id + "&picno=" + picno + "&angle=" + angle;
        if (nocensor) url += '&nocensor=1';
        document.getElementById("photo__" + uid).src = url;
    }
    document.getElementsByName('pic_id')[picno].checked = true;
}

function RotateImgWithoutDB(obj, usr_id, picno, item_id) {
    var angle = 0;
    var uid = usr_id + '_' + picno + '_' + item_id;
    angle = parseInt(document.getElementById("rangle__"+uid).value) + parseInt(obj.name);
    var rotation = 0;
    if (Math.abs(angle) >= 360) {
        if (angle > 0) angle -= 360;
        else angle += 360;
    }
    document.getElementById("rangle__"+uid).value = angle;
    //only for IE v.5.5 and above 
    if (navigator.appName == "Microsoft Internet Explorer") {
        if (angle < 0) angle += 360;
        switch (angle) {
            case  90 : rotation = 3; break;
            case 180 : rotation = 2; break;
            case 270 : rotation = 1; break;
        }
        document.getElementById("photo__"+uid).style.filter = "progid:DXImageTransform.Microsoft.BasicImage(rotation=" + rotation + ")";
    } else {
        var url = "show_rotated_img_without_db_?usr_id=" + usr_id + "&picno=" + picno+ "&item_id=" + item_id + "&angle=" + angle;
        document.getElementById("photo__" + uid).src = url;
    }
}

function selectAllWithTextarea(textarea) {
    try {
        textarea.focus();
        textarea.select();
    } catch (e) {
//       alert(e);
    }
}


// add to bookmark
function addBookmark() 
{
    if(document.all) 
    {
        window.external.AddFavorite( document.location.href, document.title);
    } 
    else if (window.sidebar) 
    {
        window.sidebar.addPanel(document.title, document.location.href,"");
    } 
    else if( window.opera && window.print )
    {
    return true;
    }
} 

function ChangeImportType(targ, selectObj){ 
    var v = selectObj.options[selectObj.selectedIndex].value;
    if (v == '--select--') {
       return;
    } else {
       PopUp('friend_import_in_pp_?type='+v,'import','560','600','yes')
    }
}

function on_maillist_focus(obj) {
    if(obj.value.indexOf("@")<0) {
        obj.value='';
        obj.style.color='#000000';
    }
}

function on_maillist_blur(obj) {
    if(obj.value == '') {
        obj.value = 'You can copy and paste the email addresses, separated by space, newline, comma or semicolon.';
        obj.style.color = '#818181';
    }
}

function checkaddress(f){
  var i;
  var noValidAddress = true;
  var subject   = document.getElementById('subject').value.trim();  
  if (subject.length == 0) {
      alert("Please fill in subject");
      return false;
  }  
  var maillistarray, maillist;
  var obj= f.elements['mail_list'];
  var text = obj.value.trim();
  maillistarray = text.split(/[,;\n\s]\s*/);
     
  for (maillist in maillistarray) {
    if (checkemail(maillistarray[maillist])) {
        noValidAddress = false;
    } else {
       if (maillistarray[maillist].length>0) {
          alert(maillistarray[maillist]+ " is not a valid email address!");
          return false;
       }
    }
  }
    
  if(noValidAddress) {
        alert("You haven't inputted any valid email address!");
        return false;
  }

  return true;
}

function checkemail(str){
    if (str.length<1 || str.length>100) return false;
    if (str.indexOf('@',0)==-1 || str == "" || str.indexOf('.',0)==-1) return false;
    thePos = str.indexOf('@',0) + 1
    if (str.indexOf('@', thePos) != -1 || str.indexOf(';', thePos) != -1 || str.indexOf(',', thePos) != -1 || str.indexOf(' ', thePos) != -1) return false;
    return true;
}

function SendToFriends(form,from_page){
  var text = '';
  if("length" in form.del){
    for(i=0;i<form.del.length;i++){
      if(form.del[i].checked == true){
        text = text + form.del[i].value + '_';
      }
    }
  }else{
    if(form.del.checked == true){
      text=form.del.value;
    }
  }
  if(text == ''){
    alert("Sorry,please select some profiles.");
  }else{
    window.open('send_friends?from_page='+from_page+'&user_list='+text);
  }
}

function on_element_blur(obj, default_val) {
    if (obj.value == '') {
        obj.value = default_val;
        obj.style.color='#818181';
    }
}

function on_element_focus(obj, default_val) {
    if (obj.value == default_val) {
        obj.value = '';
        obj.style.color='#000000';
    }
}
function check_email() {
    var email = document.update.email.value;
    var email_repeat = document.update.email_repeat.value;
    var show_diff_email = document.getElementById('show_diff_email');
    var username = jQuery("#username").val();
    var emailname = email.substring(0, email.indexOf('@'));
    var msg = '';
    if (username.toLowerCase() == emailname.toLowerCase() && email.indexOf('@') > 0) {
        msg = '<span style="font-size:10px; color: red;">Your username should not be the same as your email name.</span>';
        jQuery('#showalert').html(msg);
        document.update.username.focus();
    } else {
        msg = '';
        jQuery('#showalert').html('');
    }
    if (email.length > 0 && email_repeat.length > 0 && email != email_repeat) {
        msg = '<span style="font-size: 10px;color: red;">Your email address didn\'t match. Try again</span>';
        jQuery('#show_diff_email').html(msg);
    } else {
        msg = '';
        show_diff_email.innerHTML = '';
    }
}

function check_username_email(mark) {
    var username = jQuery("#username").val();
    var email = document.update.email.value;
    var email_repeat = document.update.email_repeat.value;
    var emailname = email.substring(0, email.indexOf('@'));
    var flag = 1;
    var msg = '<span style="font-size:10px; color: red;">Your username should not be the same as your email name.</span>';
    if (username.toLowerCase() == emailname.toLowerCase() && email.indexOf('@') > 0) {
        jQuery('#showalert').html(msg);
        flag = 0;
    } else {
        jQuery('#showalert').html('');
    }
    if (email.length > 0 && email_repeat.length > 0 && email != email_repeat) {
        jQuery('#show_diff_email').html('<span style="font-size: 10px;color: red;">Your email address didn\'t match. Try again</span>');
    } else {
        jQuery('#show_diff_email').html('');
    }
    if ((username.length > 0) && (username == emailname)) {
        if (Math.floor(Math.random() * 2)) {
            document.update.username.focus();
        } else {
            document.update.email.focus();
        }
    }
    if (mark && flag) {
        check_user_url();
    }

}

function show_hide_groups (div_id, icon_id) {
    var div_obj = jQuery("#" + div_id);
    var icon_obj = jQuery("#" + icon_id);
    if (div_obj.is(":hidden")) {
        div_obj.show();
        icon_obj.attr("class", "minus");
    } else {
        div_obj.hide();
        icon_obj.attr("class", "plus");
    }
}


var hidden_id = 0;
function show_hide_group(id, is_top_question) {
    try {
        var obj  = document.getElementById(id);
        if (is_top_question) {
            if (hidden_id && hidden_id != id) {
                document.getElementById(hidden_id).style.display = "none";
            }
            hidden_id = id;
        }
        if (obj.style.display == "none") {
            obj.style.display = "block";
        } else {
            obj.style.display = "none";
        }
    } catch(e) {
    }
}


function status_onfocus() {
    if (jQuery("#status").val() == "What's on your mind?") {
        jQuery("#status").val("");
    }
}

function status_onbulr() {
    if (jQuery("#status").val() == '') {
        jQuery("#status").val("What's on your mind?");
    } else if(jQuery("#status").val() != "What's on your mind?") {
        var share_thoughts_on_twitter = jQuery('#share_thoughts_on_twitter').attr('checked') ? 1 : 0;
        jQuery.ajax({
            type: "POST",
            url: url_map_f('de_user_status_'),
            data: "msg=" + escape(jQuery("#status").val()) + '&share_thoughts_on_twitter=' + share_thoughts_on_twitter,
            success: function(){
                jQuery("#status").val('');
                jQuery("#characters").text('160');
                get_status();
            }
        });
    }
}

function get_status() {
    jQuery.ajax({
        type: "POST",
        url: url_map_f('de_user_status_'),
        data: "getStatus=1",
        dataType: "json",
        success: function(json) {
            jQuery("#status_form").show();
            jQuery("#updated_status").html(json.content);
            jQuery("#post_time").html("Posted on " + json.time);
            jQuery("#stauts_comment").html("<span style='float: left; font-weight: normal;'>Comments (0)</span>");
        }
    });
}
//skip friend by user_id:<id>
function skip_friends(id, ajaxload) {
    jQuery.ajax({
        type: "POST",
        url: url_map_f('_skip_friend'),
        data: "prof_id=" + id,
        success: function() {
            if (ajaxload) {
                load_friend_suggestion();
            } else {
                window.location.reload();
            }
        }
    });
}

// ajax load friend suggestion
var starCount = new Array();
var rateArr = new Array("Poor", "Nothing Special", "Worth Watching", "Pretty Cool", "Awesome!");
var isRated = false;
var rateScore;

function showStars(id) {
    if (isRated)
        return false;

    for (var i = 0, j = 1; i < id; i++, j++) {
        starCount[i] = document.getElementById("star_" + j);
        starCount[i].src = "http://images.commercialless.com/stars/red_star.gif";
    }
    for (var i = id, j = id + 1; i < 5 ; i++, j++) {
        starCount[i] = document.getElementById("star_" + j);
        starCount[i].src = "http://images.commercialless.com/stars/gray_star.gif";
    }

    showRates(id);
}

function showRates(id) {
    var msg = document.getElementById("message");
    var msg_content = '';
    if (id > 0) {
        msg_content = rateArr[id - 1];
    }
    msg.innerHTML = msg_content;
    rateScore = id;
}

function add_rate_count(video) {
    if (isRated == true) return false;

    var http_request;
    http_request = getXMLHttpRequest();
    http_request.open('GET', '/add_rate_count_?video=' + video + '&score=' + rateScore + '&ajaxRequestUncache=' + parseInt(Math.random() * 1000000), true);
    for (var i = 1; i < 6; i++) {
        if (i <= rateScore) {
            document.getElementById("a" + i).innerHTML = "<img border='0' src='http://images.commercialless.com/stars/red_star.gif'>";
        } else {
            document.getElementById("a" + i).innerHTML = "<img border='0' src='http://images.commercialless.com/stars/gray_star.gif'>";
        }
    }
    http_request.onreadystatechange =  function() {
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                var info = http_request.responseText;
                if (info.trim() == '1') {
                    document.getElementById("thanks").style.display = "block";
                    document.getElementById("message").style.display = "none";
                    document.getElementById("rate").style.display = "none";
                }
            }
            else {
                alert('There was a problem with the request.');
            }
        }
    }
    http_request.send(null);
    isRated = true;
}

function add_video_to_favorite(video) {
    var favorite = document.getElementById("is_in_favorite_" + video);
    var favorite_num = document.getElementById("favorite_num");
    jQuery.ajax({
        type: "POST",
        url: url_map_f('add_video_to_favorite_'),
        data: "frompage=videos&video_to_favorite=" + video,
        success: function(info) {
            favorite.innerHTML = "Already in <a href=\"/videos?my_favorite=1\">your favorites</a>";
            favorite_num.innerHTML = "(" + info + ")";
            }
        });
}

function on_search_focus(obj) {
    obj.style.color = "#000000";
    obj.value = "";
}

function on_search_blur(obj) {
    if (obj.value == "") {
        obj.style.color = "#818181";
        obj.value = "title or tag keywords";
    }
}

function check_Character(ta, len, text, length) {
    var ilen = ta.value.length;
    if (ilen < length) {
        document.getElementById(len).innerHTML = length - ilen;
    } else {
        document.getElementById(len).innerHTML = 0;
    }
    setCharacterText(ta, length);
}

function setCharacterText(object, length) {
    var tempString = object.value;
    if (tempString.length > length) {
        tempString=tempString.substr(0, length);
        object.value = tempString;
    }
}

function reply_form_display() {
    jQuery('#quote_message').html('');
    jQuery('#quote_message_text').val('');
    jQuery('#quote_form').hide();
}

function quote_form_display(atext, btext, ctext) {
    jQuery('#quote_message_owner').html(ctext);
    jQuery('#quote_message').html(atext);
    jQuery('#quote_message_text').val(btext);
    jQuery('#quote_form').show();
}

function add_as_friend(user, friend_user_id, ajaxload, container_name) {
    var friend = jQuery("#friend_" + friend_user_id);
    var success = false;
    var request_sent = '<span style="font-size: 12px;">Friend requested</span>';
    jQuery.ajax({
        type: "POST",
        async: false,
        url: url_map_f('friend_invite'),
        data: "user=" + user + "&action_type=mark_friend&friend_user_id=" + friend_user_id,
        success: function() {
            if (typeof(container_name) == 'undefined' || container_name == null) {
                friend.html(request_sent);
            } else {
                jQuery("[name=" + container_name+ "]").each(function() {
                    jQuery(this).html(request_sent);
                });
            }
            if (ajaxload == 1) {
                jQuery('#friend_suggestion').load(url_map_f('/modules/_friend_suggestions?usr_id='));
                success = true;
            }
        }
    });
    if (ajaxload == 1) {
        return success;
    }
}

function friend_request(a_tag, username, action_type, friend_user_id) {
    jQuery.ajax({
        type: "POST",
        url: url_map_f("friend_invite"),
        data: "user=" + username + "&action_type=" + action_type + "&friend_user_id=" + friend_user_id,
        success: function() {
            jQuery(a_tag).parent().html('<font style="font-size: 11px;">Friend requested</font>');
        }
    });
}

function add_as_friend_first(user, friend_user_id, show_send_message) {
    var friend = jQuery("#friend_first" + friend_user_id);
    jQuery.ajax({
        type: "POST",
        url: url_map_f('friend_invite'),
        data: "user=" + user + "&action_type=mark_friend&friend_user_id=" + friend_user_id,
        success: function() {
            friend.html('You are waiting for ' + user +' to confirm your friendship!' + ( show_send_message ? 'Maybe you should <br /><a href="http://www.GolfNetworking.org/send_email?to=' + user + '&prof_id=' + friend_user_id + '">send him / her</a> a message?' : ""));
        }
    });
}

function click_submit_Once(form, text_id, tip) {
    var retcheck = syncForm();
    if (retcheck) {
        if (jQuery('#' + text_id).val() == tip || jQuery('#' + text_id).val() == '') {
            if (text_id == 'text_message') {
                jQuery('#' + text_id + '_div').html('<span style="color: #800000; font-weight: bold;">"quick message"</span> is required');
            } else if (text_id == 'text') {
                jQuery('#' + text_id + '_div').html('<span style="color: #800000; font-weight: bold;">"comment message"</span> is required');
            }
            return false;
        }
    } else {
        return false;
    }
}

//print a page
function doprint() {
    var bdhtml = window.document.body.innerHTML;
    var sprnstr = "<!--startprint-->";
    var eprnstr = "<!--endprint-->";
    var prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
    var prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
    window.document.body.innerHTML = prnhtml;
    window.print();
    window.location.reload();
}

// add greeting card
function add_card_to_favorite(card) {
    jQuery.ajax({
        type: "POST",
        url: url_map_f('add_card_to_favorite_'),
        data: "card_id=" + card,
        success: function() {
            var htmlText = 'already in <a href="http://www.GolfNetworking.org/customize_greeting_cards?favorite=1">favorites</a>';
            jQuery("#favorite_" + card).html(htmlText);
        }
    });
}

// add greeting multi-card
function add_cards_to_favorite() {
    var checkboxes = jQuery("input[name='cards']");
    var params = '';
    var values = [];
    for (var i = 0; i < checkboxes.length; i++) {
        if (checkboxes[i].checked) {
            params += '&cards_id=' + checkboxes[i].value;
            values.push(checkboxes[i].value);
        }
    }
    jQuery("input[type='checkbox']").attr("checked", false);
    jQuery.ajax({
        type: "POST",
        url: url_map_f('add_card_to_favorite_'),
        data: "favorite=0" + params,
        success: function() {
            show_tip();
        }
    });
    var show_tip = function() {
        for (var i = 0; i < values.length; i++) {
            var htmlText = 'already in <a href="http://www.GolfNetworking.org/customize_greeting_cards?favorite=1">favorites</a>';
            jQuery("#favorite_" + values[i]).html(htmlText);
        }
    }
}

function dele_cards_from_favorite(targetId, frm) {
    if (IsShowSelectCardsError(targetId, frm)) {
        var checkboxes = jQuery("input[name= 'cards']");
        var params = '';
        for (var i = 0; i < checkboxes.length; i++) {
            if (checkboxes[i].checked) {
                params += '&delete_cards_from_favorite=' + checkboxes[i].value;
            }
        }
        jQuery("input[type='checkbox']").attr("checked", false);
        //alert(params);return;
        jQuery.ajax({
            type: "POST",
            url: url_map_f('customize_greeting_cards'),
            data: "favorite=1" + params,
            success: function(){
                window.location.reload();
            }
        });
    }
}

function IsShowSelectCardsError(targetId, frm) {
    if (IsSelectCards(frm)) {
        target = document.getElementById(targetId);
        target.style.display = "none";
        return true;
    } else {
        window.location.href = "#";
        target = document.getElementById(targetId);
        target.style.display = "";
        return false;
    }
}

function IsSelectCards(frm) {
    var flag = 0;
    for (i = 0; i < frm.elements.length; i++) {
        if (!frm.elements[i].checked) {
            continue;
        } else {
            flag = 1;
            break;
        }
    }
    if (flag == 1) {
        return true;
    } else {
        return false;
    }
}

function show_hide_comment (usr_id) {
    if (jQuery('#note_div_' + usr_id).is(":hidden")) {
        jQuery('#comment_icon_' + usr_id).attr("class", "minus");
        jQuery('#pic_td_' + usr_id).attr('vAlign', 'top').css('padding-top', '15px');
        jQuery('#note_frame_' + usr_id).attr('src', 'add_friend_note_?friend_id=' + usr_id + '&iframe=1');
        jQuery('#note_div_' + usr_id).show();
    } else {
        jQuery('#comment_icon_' + usr_id).attr("class", "plus");
        jQuery('#pic_td_' + usr_id).removeAttr('vAlign').removeAttr('style');
        jQuery('#note_div_' + usr_id).hide();
        jQuery('#note_frame_' + usr_id).attr('src', '');
    }
}

// float window process
function popup_process(user, friend_user_id, ajaxload) {
    var pop_content ;
    if (add_as_friend(user, friend_user_id, ajaxload)) {
        jQuery("<div id='popup_content'></div>").appendTo("body");
        jQuery("<div id='bottom_layer' onclick='close_popup()'></div>").appendTo("body");
        var request_info = "<div id='request_info'>Friend Request Sent</div>";
        var friends_iframe = '<iframe src="/friends_?owner_id=' + friend_user_id + '" border="0" frameborder="0" scrolling="no" width="600" height="240" id="friends_iframe" name="friends_iframe"></iframe>';
        var popup_bottom = "<div id='popup_bottom'><input id='popup_close' type='button' name='close' value='Close' onclick='close_popup()' /></div>";
        pop_content = request_info + friends_iframe + popup_bottom;
        jQuery("#popup_content").html(pop_content);
        loadPopup()
    }
}

var popup_flag = 0;
//loading popup content
function loadPopup() {
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = jQuery("#popup_content").height();
    var popupWidth = jQuery("#popup_content").width();
    var isIE6 = jQuery.browser.msie && (jQuery.browser.version == "6.0") && !jQuery.support.style;
    var position = "fixed";
    if (isIE6) {
        position = "absolute";
    }
    jQuery("#popup_content").css({
        "position": position,
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });
    jQuery("#bottom_layer").css({"height": windowHeight});
    if(popup_flag == 0) {
        jQuery("#bottom_layer").css({"opacity": "0.7"});
        jQuery("#bottom_layer").fadeIn("slow");
        jQuery("#popup_content").fadeIn("slow");
        popup_flag = 1;
    }
}
//close  popup window
function close_popup() {
    if (popup_flag ==1 ) {
        jQuery("#bottom_layer").fadeOut("slow");
        jQuery("#popup_content").fadeOut("slow");
        jQuery("#popup_content").remove();
        jQuery("#bottom_layer").remove();
        popup_flag = 0;
    }
}

function popup_send_message_frame(to_user, to_prof_id, extra_params) {
    jQuery("<div id='popup_content' style='width: 480px; height: 415px;'></div>").appendTo("body");
    jQuery("<div id='bottom_layer' onclick='close_popup()'></div>").appendTo("body");
    var request_info = "<div id='request_info' style='width: 480px;'>New Message</div>";
    var send_message_frame = '<iframe src="http://www.GolfNetworking.org/send_email?frompage=popup_frame&to=' + to_user + '&prof_id=' + to_prof_id + '&' + extra_params + ' " border="0" frameborder="0" scrolling="no" width="450" height="350" id="send_message_frame" name="send_message_frame"></iframe>';
    var popup_bottom = "<div id='popup_bottom'><input id='popup_close' type='button' name='close' value='Close' onclick='close_popup()' /></div>";
    pop_content = request_info + send_message_frame + popup_bottom;
    jQuery("#popup_content").html(pop_content);
    loadPopup()
}

function popup_send_newsletter_frame(to_user, extra_params) {
    jQuery('<div id="popup_content" style="width: 480px; height: 415px;"></div>').appendTo("body");
    jQuery('<div id="bottom_layer" onclick="close_popup()"></div>').appendTo("body");
    var request_info = '<div id="request_info" style="width: 480px;">New newsletter to all club members</div>';
    var send_message_frame = '<iframe src="/send_email?frompage=club&to=' + to_user + '&' + extra_params + ' " border="0" frameborder="0" scrolling="no" width="450" height="350" id="send_message_frame" name="send_message_frame"></iframe>';
    var popup_bottom = '<div id="popup_bottom"><input id="popup_close" type="button" name="close" value="Close" onclick="close_popup()" /></div>';
    pop_content = request_info + send_message_frame + popup_bottom;
    jQuery("#popup_content").html(pop_content);
    loadPopup()
}

function show_hide_comment_type(usr_id, username, comment, type) {
    if (jQuery('#note_div_' + usr_id).is(":hidden")) {
        var src = '';
        if (type == 'block') {
            src = 'blocked_?active=editreason&prof_id=' + usr_id + '&username=' + username + '&comments=' + comment + '&frompage=who_blocked&iframe=1';
        }
        jQuery('#comment_icon_' + usr_id).attr("class", "minus");
        jQuery('#pic_td_' + usr_id).attr('vAlign', 'top').css('padding-top', '15px');
        jQuery('#note_frame_' + usr_id).attr('src', src);
        jQuery('#note_div_' + usr_id).show();
    } else {
        jQuery('#comment_icon_' + usr_id).attr("class", "plus");
        jQuery('#pic_td_' + usr_id).removeAttr('vAlign').removeAttr('style');
        jQuery('#note_div_' + usr_id).hide();
        jQuery('#note_frame_' + usr_id).attr('src', '');
    }
}

function add_all_as_friend() {
    var users = document.getElementsByName("user_checkbox");
    var friend_id = '';
    for (var i = 0; i < users.length; i++) {
        if (users[i].checked) {
            friend_id += (users[i].value + ',');
        }
    }
    jQuery.ajax({
        type: "POST",
        url: url_map_f("friend_invite_"),
        data: 'friend_id=' + friend_id + '&active=update',
        success: function() {
            for (var i = 0; i < users.length; i++) {
                if (users[i].checked) {
                    jQuery("#friend_" + users[i].value).html('Friend requested');
                    users[i].checked = false;
                }
            }
        }
    });
    jQuery('input[name="all_check"]').attr('checked', '');
}

// set incomplete profile note into cookie.
function set_note_close() {
    jQuery.ajax({
        type: "POST",
        url: url_map_f("set_profile_note_"),
        success: function() {
            jQuery('#incomplete_profile').hide();
        }
    });
}
function edit_top10(id) {
    jQuery('#editbox_' + id).show();
    jQuery('#text_' + id).hide();
    jQuery('#link_edit_' + id).hide();
    jQuery('#link_save_' + id).show();
}
function save_top10(id) {
    var nudist_thing = jQuery('#editbox_' + id).val();
    if (!nudist_thing) {
        return false;
    }
    jQuery.ajax({
        type: "GET",
        url: url_map_f('_save_top10'),
        data: "nudist_thing=" + escape(nudist_thing) + "&thing_id=" + id,
        dataType: "text",
        success: function() {
            jQuery('#editbox_' + id).hide();
            jQuery('#text_' + id).html(nudist_thing);
            jQuery('#text_' + id).show();
            jQuery('#link_edit_' + id).show();
            jQuery('#link_save_' + id).hide();
        }
    });
}

/**
    report video: 
*/
function report_video(video_id) {
    jQuery.ajax({
        type: "GET",
        url: url_map_f('report_abuse_video'),
        data: "video_id=" + video_id,
        dataType: "text",
        success: function() {
            jQuery("#report_link").html("Video flagged. Thanks!");
        }
    });
}
// -->
function group_status(group, action, noload) {
    jQuery.ajax({
        type: "post",
        url: url_map_f('group_actions_'),
        data: "group=" + group + "&action=" + action,
        success: function() {
            if (noload) {
                jQuery("#join_group_" + group).html("Already in this group");
            } else {
                window.location.href = 'detail?group_id=' + group + '&show_clue=1';
            }
        }
    });
}

function more(id) {
    jQuery("#max" + id).show();
    jQuery("#min" + id).hide();
}

function addToClub(club, noload) {
    jQuery.ajax({
        type: "post",
        url: url_map_f('club_actions_'),
        data: "club=" + club + "&action=add_club",
        success: function() {
            if (noload) {
                jQuery("#join_club_" + club).html("Already in this club");
            } else {
                window.location.reload();
            }
        }
    });
}

function delFromClub(club) {
    jQuery.ajax({
        type: "post",
        url: url_map_f('club_actions_'),
        data: "club=" + club + "&action=del_club",
        success: function() {
            window.location.href = 'club_search';
        }
    });
}

function sendInvite(prof_id, action) {
    jQuery.ajax({
        type: "post",
        url: url_map_f('send_invite_'),
        data: "prof_id=" + prof_id + "&action=" + action,
        success: function() {
            jQuery('#invite_' + action).html("Sent successfully!");
        }
    });
}

