<!--
var win;
var xmlHttp;
var chats = new Array();

timedouturl = "index";

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

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

function url_map_f(p_url) {
    if (p_url.substr(0, 1) != '/') {
        p_url = '/' + p_url;
    }
    return p_url;
}


function send_email(p,new_win){
	if (new_win=='new'){
		window.open('send_email?'+p);
	}else{
		window.location.href='send_email?'+p;
	}
}

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

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

function changeSbGifToPleaseWait(){
    document.getElementById("pleaseWait").innerHTML = "<input type='button' value=\"Please wait...\" disabled>";
}

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 + ",resizable=" + 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, process_link){
    var mm= "width=" + width + ",height=" + height + ",scrollbars=" + scrollbars + ",resizable=" + scrollbars;
    var url = a.href;
    var win = window.open(a.href, windowname, mm);
    if (win && win.open && !win.closed){
        win.focus();
    }
    if(process_link == null){
    	process_link = false;
    }
   return process_link;
}

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 blog_del_confirm(info)
{
    var hint = info;
    if(confirm(hint))
    {
        return true;
    }else{
        return false;
    }
}

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 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 CheckPassLenght(c,from)
{
    var i = 4;
    if (from && from == 'affiliate') {
        document.getElementById('view').style.color='#000000';
        i = 6;
    } else {
        document.getElementById('view').style.color='#000000';
    }
    if (from == 'ms') {
        document.getElementById('view').innerHTML = '';
    } else {
        if (i == 4) {
            document.getElementById('view').innerHTML = '(Minimum 4 characters for security reasons. No spaces or special characters.)';
        } else if (i == 6) {
            document.getElementById('view').innerHTML = '(Minimum 6 characters for security reasons. No spaces or special characters.)';
        } else {
            alert("Report translation bug!");
        }
    }
    document.getElementById('view').style.fontWeight = '';
    if ( (c.value.length < i) || (c.value.length > 12) ) {
        if (i == 4) {
            document.getElementById('view').innerHTML = '(Your password must contain between 4 and 12 characters. No spaces or special characters.)';
        } else if (i == 6) {
            document.getElementById('view').innerHTML = '(Your password must contain between 6 and 12 characters. No spaces or special characters.)';
        } else {
            alert("Report translation bug!");
        }
        document.getElementById('view').style.color = '#FF0000';
        c.value = '';
    } else if (c.value.match(/\W/)) {
        document.getElementById('view').innerHTML = 'Your password contains invalid characters! Please choose another password comprised only of letters and numbers with no spaces.';
        document.getElementById('view').style.color = '#FF0000';
        document.getElementById('view').style.fontWeight = 'bold';
        c.value = '';
    }
}
 
function popUpPayment() {
    window.open('/pay');
}

function im_guest_notice(fname){
    window.open('im_guest_notic.htm?fname='+fname);
}

function goldMemberOnly(message1,message2,message3)
{
   var mes;
   if ((message1==null) && (message2==null) && (message3==null)){
      mes = "This service is for gold members only. By becoming a gold member, you can access all services without restriction.";
   } else {
      if (message3!=""){
        mes=message3;
      }else{
        mes=message1;
        mes+= message2;
      }
   }
   modelesswin('goldMemberOnlyMessage_?message='+mes,440,486,'paymessage');
}

function goldMemberOnlyChat(party_id, party_name)
{
  goldMemberOnly(null,null,null);
}

function subscribe_today(message1,message2,message3)
{
   var mes;
   if ((message1==null) && (message2==null) && (message3==null)){
      mes = "This service is for gold members only. By becoming a gold member, you can access all services without restriction.";
   } else {
      if (message3!=""){
        mes=message3;
      }else{
        mes=message1;
        mes+= message2;
      }
   }
   modelesswin('_subscribe_today?message='+mes,420,486,'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;
    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 ret = true;
    jQuery.ajax({
        type: "GET",
        url: url_map_f('_check_authen'),
        async: false,
        cache: false,
        success: function( msg ){
            ret = jQuery.trim(msg) == '1';
        }
    });


    return ret;
}

function syncForm(){
    var result = checklogin();
    if (!result) {
        alert("Sorry, your session has expired. \nCopy your message into notepad, log in again and paste your message from notepad!");
    }


    return result;
}

function setSelectValue(sel,val) {
    if (typeof(sel) != 'undefined') {
        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;
        form.elements['move2extra__' + 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;
        form.elements['move2extra__' + usr_id + '_' + picno].checked = 0;
    }

    if ((obj.name.substr(0, 6) == 'delp__' && obj.checked == 1) || (obj.name.substr(0, 12) == 'move2extra__')) {
        if (obj.name.substr(0, 12) == 'move2extra__')
        {
            form.elements['delp__' + usr_id + '_' + picno].checked = 0;
        } else {
            form.elements['move2extra__' + usr_id + '_' + picno].checked = 0;
        }

        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)  && 
                         (form.elements['move2extra__' + 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 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, rotate_and_save) {
    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 (!rotate_and_save)
        rotate_and_save = 0;
    if(navigator.appName == "Microsoft Internet Explorer" && rotate_and_save == 0){
        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 + '&rotate_and_save=' + rotate_and_save;
        document.getElementById("photo__" + uid).src = url;
    }
}

function OnLoadPage(site) {
}

function clickSearchOnce(){
    var html="<center><br><input type='submit' value=\"Please wait...\" disabled></center>";
    if (document.getElementById('showsearch')) {
        document.getElementById('showsearch').innerHTML = html;
    } else if (document.all && document.all.showsearch) {
        document.all.showsearch.innerHTML = html;
    }
	return true;
}

function clickContinueOnce() {
    var html="<input type='submit' value=\"Please wait...\" disabled>";
    if (document.check.showcontinue){
            document.check.showcontinue.innerHTML = html;
    }else if (document.getElementById('showcontinue')){
            document.getElementById('showcontinue').innerHTML = html;
    }
	return true;
}
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 uncheckAll(theBox) {
    try {
        if (!theBox.checked) {
            $("input[@name='checkall']").each(function(){
                this.checked="";
            });
        }
    } catch(e) {}
}

function checkForm(frm){
	var sel = false;
	if(frm.del.length){
		for(var i=0;i<frm.del.length;i++){ 
			if(frm.del[i].checked){
				sel = true;
				break;
			}
		}
	}
	else{
		sel = frm.del.checked;
	}
	if(!sel){
		document.getElementById("error_div").style.display = 'block';
		document.location ='#top';
		return false;
	}
	return true;
}
function registerAlert() {
    alert('Please register to use the feature');
}


function createHiddenFormElement(inputForm, elementName, elementValue){
    var newElement = document.createElement("INPUT");
    newElement.type = "HIDDEN";
    newElement.name = elementName;
    newElement.value = elementValue;
    return inputForm.appendChild(newElement);
}

var submitForm, c_form_name, c_formtag, c_text, c_extra;

function check_spell_open(form_text_tag,form_name){
    if (!form_name) form_name ='update';
    var text = document.getElementById(form_text_tag).value;

    if(text.length < 1000) {
      return PopUpEx('/spell_checker_?form_name='+form_name+'&form_text_tag='+form_text_tag+'&text='+escape(text),'check_spell',500,400,'yes');
    } 

    PopUpEx('about:blank','check_spell',500,400,'yes');

    if(typeof(submitForm) == 'undefined') {
        submitForm = document.createElement("FORM");
        document.body.appendChild(submitForm);
        c_form_name = createHiddenFormElement(submitForm, "form_name", form_name);
        c_formtag = createHiddenFormElement(submitForm, "form_text_tag", form_text_tag);
        c_text=  createHiddenFormElement(submitForm, "text", text);
    } else {
        c_form_name.value = form_name;
        c_formtag.value = form_text_tag;
        c_text.value = text;
    }
    submitForm.method = "POST";
    submitForm.target = 'check_spell';
    submitForm.action= "/spell_checker_";
    submitForm.submit();
}

function check_spell_open_for_multi_tags(form_text_tags, form_name) {
    if (!form_name)
        form_name ='update';
    var form_text_tag = form_text_tags[0];
    var text = document.getElementById(form_text_tag).value;

    var len = form_text_tags.length;

    var next_url = '';
    var text_ = text;
    for (var i = 1; i < len; i++) {
        var v = document.getElementById(form_text_tags[i]).value;
        text_ += " " + v;
        next_url += 'tag' + i + '_' + form_text_tags[i] + '=' + escape(v) + '&';
    }
    jQuery.ajax({
        type: "POST",
        url: url_map_f('_check_spell'),
        data: { 
              text: escape(text_), ajaxRequestUncache: parseInt(Math.random() * 1000000) 
        },
        success: function(info) {
            if (jQuery.trim(info) == '1') {
                alert("No misspelling found!");
                return;
            }
        }
    });

    PopUpEx('about:blank','check_spell',500,400,'yes');

    if (typeof(submitForm) == 'undefined') {
        submitForm = document.createElement("FORM");
        document.body.appendChild(submitForm);
        c_form_name = createHiddenFormElement(submitForm, "form_name", form_name);
        c_formtag = createHiddenFormElement(submitForm, "form_text_tag", form_text_tag);
        c_text = createHiddenFormElement(submitForm, "text", text);
        c_extra = createHiddenFormElement(submitForm, "next_url", next_url);
    } else {
        c_form_name.value = form_name;
        c_formtag.value = form_text_tag;
        c_text.value = text;
        c_extra.value = next_url;
    }
    submitForm.method = "POST";
    submitForm.target = 'check_spell';
    submitForm.action = "/spell_checker_";
    submitForm.submit();
}

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,"")

      jQuery.ajax({
          type: "POST",
          url: url_map_f('_check_spell'),
          data: { 
              form_name: form_name, form_text_tag: form_text_tag, text: escape(text), ajaxRequestUncache: parseInt(Math.random() * 1000000) 
          },
          success: function(info){
             if(jQuery.trim(info)=='1'){
                alert("No misspelling found!");
             }else{
                check_spell_open(form_text_tag,form_name);
             }
          }
      });
}


// 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 CommandBlocked = false;

function startIM (usr_id) {
   PopUp("http://www.motorcycle-dating.co.uk/im_users_list.htm","im_" + usr_id,450,530,"yes");
}

function startPrivateChat(partyname, username) {
	var im_usersObj = isInternetExplorer ? document.all.im_users : document.im_users;
    var param = 'partyname=' + partyname;
	if((chats[partyname]==null) || (typeof(chats[partyname])=="undefined") || (chats[partyname].closed)) {
		try {
			chats[partyname] = PopUpEx('http://www.BikerKiss.com/im_private.htm?' + param, 'MIM_to_' + partyname, 600, 360, 'yes');
		} 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 startPrivateChatForClone(partyname, username, hostname, session) {
    if((chats[partyname]==null) || (typeof(chats[partyname])=="undefined") || (chats[partyname].closed)) {
        try {
            chats[partyname] = PopUpEx('http://' + hostname + '/s' + session + '/im_private.htm?partyname=' + partyname, 'MIM_to_' + partyname, 600, 360, 'yes');
        } catch(e) {
            alert("error:" + e);
        }
    }
}

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

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

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 popupMsg(id){
       document.getElementById(id).style.display='';
}
function hiddenMsg(id){
       document.getElementById(id).style.display='none';
}

function HideandUNhideObj(i){
        nav=document.getElementById('div'+i).style;
        con=document.getElementById('ul'+i);
        if(nav.display=="none"){
                // set mouseout function here
                nav.display = 'block';
                con.onmouseout = function(evt) {
                    if (checkMouseLeave(this, evt)) {
                        i = parseInt(this.id.substr(2));
                        nav=document.getElementById('div'+i).style;
                        nav.display = 'none';
                    }
                }
        } else {
                nav.display='none';
                con.onmouseout = function (evt) {
                    if (checkMouseLeave(this, evt)) {
                        i = parseInt(this.id.substr(2));
                        nav=document.getElementById('div'+i).style;
                        nav.display= 'none';
                    }
                }
        }
}

function checkMouseLeave (element, evt) {

  evt = (evt) ? evt : ((window.event) ? window.event : "");
  window.status = evt;
  if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  } else {
        if (element.contains(evt.toElement)) {
                return(false);
        } else {
                return(true);
        }
  }
}

function containsDOM (container, containee) {
  var isParent = false;
  do {
    if ((isParent = container == containee))
      break;
    containee = containee.parentNode;
  }
  while (containee != null);
  return isParent;
}

// for image show/hide

function getElementPosX(element) {
    var left = 0;
    if (element.offsetParent) {
        while (element.offsetParent) {
            left += element.offsetLeft;
            element = element.offsetParent;
        }
    } else if (element.x) {
        left += element.x;
    }
    return left;
}
function getElementPosY(element) {
    var top = 0;
    if (element.offsetParent) {
        while (element.offsetParent) {
            top += element.offsetTop;
            element = element.offsetParent;
        }
    } else if (element.y) {
        top += element.y;
    }
    return top;
}
function layoutImageBox(owner, box, offset) {
    try {
        if (typeof(offset) != 'undefined'){
            box.style.left = getElementPosX(owner) + offset + 'px';
        } else {
            box.style.left = getElementPosX(owner) + 'px';
        }
        box.style.top = getElementPosY(owner) + 'px';
        box.style.visibility = 'visible';
    } catch (e) {
//        alert(e);
    }
}
function showFullImage(owner, url, linkto, offset) {
    try{
        imageBox = document.getElementById('image_box');
        imageBoxUrl = document.getElementById('image_box_url');
        var img = new Image();
        img.onload = function() {
            imageBox.src = img.src;
            w = img.width;
            h = img.height;
            max = 300.0;
            if (img.width > max) {
                scale = max / img.width;
                w *= scale;
                h *= scale;
            } else if (img.height > max) {
                scale = max / img.height;
                w *= scale;
                h *= scale;
            }
            imageBox.width = w;
            imageBox.height = h;
            img = null;
            layoutImageBox(owner, imageBox, offset);
        }
        img.src = url;
        imageBoxUrl.href = linkto;
    } catch (e) {
//        alert(e);
    }
}

function show_full_img(owner, url, linkto, offset) {
    try{
        imageBox = $('#image_box');

        var img = new Image();
        img.onload = function() {
            w = img.width;
            h = img.height;
            max = 300.0;
            if (img.width > max) {
                scale = max / img.width;
                w *= scale;
                h *= scale;
            } else if (img.height > max) {
                scale = max / img.height;
                w *= scale;
                h *= scale;
            }
            imageBox.css({width: w, height: h, cursor: "pointer"});
            $(img).css({width: w, height: h});
            $(img).bind("click", function(){
               eval(linkto);
            });
            imageBox.empty();
            imageBox.append(img);
            img = null;
            layoutImageBox(owner, imageBox[0], offset);
        }
        $(img).attr("src", url);
    } catch (e) {
    //    alert(e);
    }
}

function hidden_full_img() {
    $('#image_box').css("visibility","hidden");
}

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

function setMaxLength(object,length) {

    var tempString=object.value;

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


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 check_username_email(mark) {
    var username = $("#username").val();
    var email = document.update.email.value;
    var email_repeat = document.update.email_repeat.value;
    var emailname = email.substring(0, email.indexOf('@'));
    var pattern = /^(.*)@(.*)$/;
    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()) {
        $('#showalert').html(msg);
    } else {
        $('#showalert').html('');
    }
    if (email.length > 0 && !(pattern.test(email))) {
        $('#show_invalid_email').html('<span style="font-size:10px;">Your email address is invaild. please choose a vaild one.</span>');
    } else {
        $('#show_invalid_email').html('');
    }
    if (email.length > 0 && email_repeat.length > 0 && email != email_repeat) {
        $('#show_diff_email').html('<span style="font-size:10px;">Your email address didn\'t match. Try again</span>');
    } else {
        $('#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();
        }
    }
}

function check_fname() {
    var fname = document.update.fname.value;
    if (fname.match(/^[a-zA-Z]*$/)) {
        $('#show_fname_alert').html('');
        $('#show_fname_alert').hide();
    } else {
        $('#show_fname_alert').html('<span style="font-size:10px; color: red;">First name may only contain letters.</span>');
        $('#show_fname_alert').show();
    }
}

function show_hide(obj_name){
	var obj = document.getElementById('s_h_'+obj_name);
	var showhide = document.getElementsByName(obj_name);
	var hideselect = document.getElementsByName(obj_name)[0];
	if(obj.style.display=='') {
		obj.style.display='none';
		document.getElementById('s_h_t_'+obj_name).innerHTML="<A HREF=\"javascript:show_hide('"+obj_name+"')\">Show</A>";	
		for (var i = 0;i < showhide.length;i++) {
		    showhide[i].checked = false;
		    if (showhide[i].value == "0") {
		        showhide[i].checked = true;
		    }
		}
		for (var i=0; i < hideselect.options.length; i++){
		    hideselect.options[i].selected = false;
		    if (i == (hideselect.options.length - 1)){
		        hideselect.options[i].selected = true;
		    }
		}
	} else {
		obj.style.display=''
		document.getElementById('s_h_t_'+obj_name).innerHTML="<A HREF=\"javascript:show_hide('"+obj_name+"')\">Hide</A>";						
	}
 }					

function show_hide_div(obj_name) {
    try {
        var obj = document.getElementById('div_'+obj_name);
        if (obj.style.display == 'none') {
            obj.style.display = ''
            document.getElementById(obj_name).innerHTML="<A HREF=\"javascript:show_hide_div('"+obj_name+"')\">Hide</A>";
        }else{
            obj.style.display = 'none'
            document.getElementById(obj_name).innerHTML="<A HREF=\"javascript:show_hide_div('"+obj_name+"')\">Show</A>";
        }
    } catch(e) {
//      alert(e);
    }
}

function show_hide_form() {
    try {
        var board = document.getElementById("past_board");
        if (board.style.display == 'none') {
               board.style.display = ''
        }else{
          board.style.display = 'none'
        }
    } catch(e) {
//        alert(e);
    }
}
// -->
function layoutImageBoxMenu(owner, box) {
    try {
        box.style.left = getElementPosX(owner) + owner.width + 'px';
        box.style.top  = getElementPosY(owner) + 'px';
        box.style.visibility = 'visible';
    } catch (e) {
//        alert(e);
    }
}
function showFullImageMenu(owner, url, height) {
    try{
        imageBox = document.getElementById('image_box');
//      imageBoxUrl = document.getElementById('image_box_url');
        var img = new Image();
        img.onload = function() {
            imageBox.src = img.src;
            w = img.width;
            h = img.height;
            max = 300.0;
            if (img.width > max) {
                scale = max / img.width;
                w *= scale;
                h *= scale;
            } else if (img.height > max) {
                scale = max / img.height;
                w *= scale;
                h *= scale;
            }
            imageBox.width = w;
            imageBox.height = h;
            img = null;
            layoutImageBoxMenu(owner, imageBox);
        }
        img.src = url;
//        imageBoxUrl.href = linkto;
    } catch (e) {
//        alert(e);
    }
}

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

function IsSelectProfile(frm){
	var format = /^mark_[0-9]{1,}$/i;
	var userlists="";
	for (i = 0; i < frm.elements.length; i++) {
   	    try{
           if(format.test(frm.elements[i].name)){
             if(!frm.elements[i].checked) {
				 continue;
			 }
             var param=frm.elements[i].name.split("_");
			 if(userlists!=""){
			    userlists=userlists+"_";
			 }
			 userlists=userlists+param[1];
		   }
	    }catch(e){}
	}
    if(userlists=="") {
	   return false;
	} else {
		return true;
	}
}

function deleteBatch(theBox,theArray) {
    var has_selected = 0;

    $('input[@type="checkbox"][@name^="email_"][@value*="@"]').each(function() {
        if ($(this).attr('checked')) {
            has_selected = 1;
            return;
        }
    });

    if (has_selected == 0) {
        $('#invite_pending_error_msg').show();
        return;
    }

    $('#invite_pending_error_msg').hide();

    if(confirm('Are you sure you want to remove these emails from invite history?'))
    {
        theArray.delete_batch.value=1;
        theArray.submit();
    }
}

function copy2clip(Element) {
    inElement = document.getElementById(Element);
    if (inElement.createTextRange) {
         var range = inElement.createTextRange();
         if (range)
             range.execCommand('Copy');
         } else {
             var flashcopier = 'flashcopier';
             if(!document.getElementById(flashcopier)) {
             var divholder = document.createElement('div');
             divholder.id = flashcopier;
             document.body.appendChild(divholder);
         }
         document.getElementById(flashcopier).innerHTML = '';
         var divinfo = '<embed src="http://images.commercialless.com/_clipboard.swf" FlashVars="clipboard='+escape(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
        document.getElementById(flashcopier).innerHTML = divinfo;
  }
}
function ShowORHidden(obj){
	try{
		if(document.getElementById(obj+"_trtag").style.display == 'none'){
			document.getElementById(obj+"_trtag").style.display="";
		}else{
			document.getElementById(obj+"_trtag").style.display="none";
		}
	}catch(err){}
}

function copy_clip(copytext){
   text2copy = copytext.value;
	if (window.clipboardData) {   
		window.clipboardData.setData("Text",text2copy);   
	} else {   
		var flashcopier = 'flashcopier';
		if(!document.getElementById(flashcopier)) {
			var divholder = document.createElement('div');
			divholder.id = flashcopier;
			document.body.appendChild(divholder);
		}
		document.getElementById(flashcopier).innerHTML = '';
		var divinfo = '<embed src="http://images.commercialless.com/_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
		document.getElementById(flashcopier).innerHTML = divinfo;
	}
	copytext.select();
        //alert("The hyperlink address that you copy is:\n\n"+text2copy);
}

function jquery_show_search_omitted_profile (match_id){
    jQuery("#proflie_show_" + match_id).hide();
    jQuery.ajax({
        type: "POST",
        url: url_map_f('_process_user_info_by_jquery'),
        data: "action=search_user_show&match_id=" + match_id,
        success: function(){
        }
    });
}


function jquery_show_profiles ( frm ) {
    var format = /^mark_[0-9]{1,}$/i;
    for (i = 0; i < frm.elements.length; i++) {
        try {
           if(!format.test(frm.elements[i].name) || !frm.elements[i].checked)
             continue;
           var param=frm.elements[i].name.split("_");
           var match_id = param[1]
           jQuery("#proflie_show_" + match_id).hide();
           frm.elements[i].checked = false;
           jQuery.ajax({
              type: "POST",
              url: url_map_f('_process_user_info_by_jquery'),
              data: "action=search_user_show&match_id=" + match_id,
              success: function(data){
                  jQuery("#proflie_hide_" + jQuery.trim(data)).show();
               }
           }); 
        }catch(e){}
    }
}

function dd(show) {
   document.getElementById('min'+show).style.display=document.getElementById('min'+show).style.display?"":"none";
   document.getElementById('max'+show).style.display=document.getElementById('max'+show).style.display?"":"none";
}

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 highlightStatus(status) {
    jQuery.ajax({
        type: "POST",
        url: url_map_f('highlight_status_'),
        data: "status=" + status,
        success: function( msg ){
            window.location='/highlight_status?status='+msg;
        }
    });
}

function email_replies(status) {
    var http_request;
    http_request=getXMLHttpRequest();
    http_request.open('GET', '/email_replies_status_?status='+status+'&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(jQuery.trim(info)=='1'){
                        window.location.reload();                
                    }
                } else {
                    alert('There was a problem with the request.');
            }
       }
    }
   http_request.send(null);
}

function deleteConfirm()
{
    var count=0;
    var obj = document.forms.del_form.del;
    if (obj == null)
        return false;
    
    if (obj.length == null)//only one
	{
        if( obj.checked)
	        count=1;
	}else {
        for(i = 0; i < obj.length; i++)
		    if ( obj[i].checked )
                count++;
	}        
    if (count==0)
	{
        alert("Note:Please select the topics first!");
        return false;
	}
    else
        return confirm("Are you sure you want to remove the checked topics?");
}


function dyniframesize(iframename) {
  var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
  var FFVersion = getFFVersion.substr(0,2)
  //extra height in px to add to iframe in FireFox 1.0+ browsers
  var FFextraHeight=FFVersion>=0.1? 30 : 0 

  var pTar = null;
  if (document.getElementById){
    pTar = document.getElementById(iframename);
  }
  else{
    eval('pTar = ' + iframename + ';');
  }
  if (pTar && !window.opera){
    //begin resizing iframe
    pTar.style.display="block";
    
    if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight){
      //ns6 syntax
      pTar.height = pTar.contentDocument.body.offsetHeight+FFextraHeight; 
      pTar.width = pTar.contentDocument.body.scrollWidth;
    }
    else if (pTar.Document && pTar.Document.body.scrollHeight){
      //ie5+ syntax
      pTar.height = pTar.Document.body.scrollHeight;
      pTar.width = pTar.Document.body.scrollWidth;
    }
  }
}

function dont_allow_newuser_add_favorites (id) {
    jQuery('span#addFavoritesInfo'+id).html('<font color="blue">We are sorry, but you may add to favorites only after your profile has been approved by our staff</font>');
}

function jquery_add_to_favoriate (match_id, username) {
    if (username) {
        jQuery("#favoriate_add_comment_" + match_id).html("<b>saving...</b>");
    } else {
        jQuery("#favoriate_add_" + match_id).html("<b>saving...</b>");
        jQuery("input[@name='fav_button']").each(function(){
            jQuery(this).val("saving");
        });
    }

    jQuery.ajax({
        type: "POST",
        url: url_map_f('_process_user_info_by_jquery'),
        data: "action=favoriate_add&match_id=" + match_id,
        success: function(){
            if (username) {
                jQuery("#favoriate_add_comment_" + match_id).html('Already in <a href="http://www.motorcycle-dating.co.uk/favorites" target="_blank">favorites</a>');
                jQuery('#fav_comment_title_' + match_id).show();
                jQuery('#favorite_rank_' + match_id).load('/favorite_rank_?prof_id=' + match_id + '&title=1');
            } else {
                jQuery("#favoriate_add_" + match_id).html('Already in <a href="http://www.motorcycle-dating.co.uk/favorites" target="_blank">favorites</a>');
                jQuery("#favoriate_add_" + match_id).show();
            }

            jQuery("input[@name='fav_button']").each(function(){
                jQuery(this).val("Already in favorites");
                jQuery(this).show();
                var obj = jQuery(this)[0];
                obj.onclick = new Function("window.open('favorites','','')");
            });
        }
    });
}

function jquery_add_profiles_to_favoriate (){
    var match_id;
    var count = 0;
    for (var i = 0; i < document.f.del.length; i++){
        if( document.f.del[i].checked ) {
            match_id = document.f.del.value;
            jquery_add_to_favoriate( match_id );
            count ++;
        }
    }
    if ( count ==0 ){
        alert("You did not select profiles to add to your favorite profile list.")
    }
}

function jquery_hide_search_profile ( match_id ) {
    jQuery("#proflie_show_" + match_id).hide();
    //jQuery("#proflie_show_" + match_id).html("<b>loading...</b>");

    jQuery.ajax({
        type: "POST",
        url: url_map_f('_process_user_info_by_jquery'),
        data: "action=search_user_hide&match_id=" + match_id,
        success: function(){
            jQuery("#proflie_hide_" + match_id).show();
            jQuery("#proflie_hide_" + match_id).css({border: "1px solid rgb(221, 221, 221)", margin: "0.5em", width: "95%"});
            jQuery("input[name='mark_" + match_id + "']").attr("disabled", "true");
        }
    });
}

function jquery_show_search_profile ( match_id ) {
    jQuery("#proflie_hide_" + match_id).hide();
    //jQuery("#proflie_show_" + match_id).html("<b>loading...</b>");

    jQuery.ajax({
        type: "POST",
        url: url_map_f('_process_user_info_by_jquery'),
        data: "action=search_user_show&match_id=" + match_id,
        success: function(){
            jQuery("#proflie_show_" + match_id).show();
            jQuery("input[name='mark_" + match_id + "']").attr("disabled", "");
        }
    });
}

function jquery_un_block ( match_id ) {
//    jQuery("#proflie_show_" + match_id).html("<b>loading...</b>");
    jQuery.ajax({
        type: "POST",
        url: url_map_f('_process_user_info_by_jquery'),
        data: "action=un_block&match_id=" + match_id,
        success: function(){
            jQuery("#proflie_show_" + match_id).hide();
        }
    });
}

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\">favorites</a>";
                favorite_num.innerHTML = "(" + info + ")";
          }
      });
}

function jquery_add_forum_to_favoriate (topic_id) {
    jQuery("#save_topic").html("<b>saving...</b>");

    jQuery.ajax({
        type: "POST",
        url: url_map_f('_forum_by_jquery'),
        data: "id=" + topic_id,
        success: function(){
            jQuery("#save_topic").html("Already in <a href=\"/forum_saved_topics\">favorite topics</a>");
            jQuery("#save_topic").show();
        }
    });
}


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 = "username or title";
  }
}

function show_whole_comments(n){
    document.getElementById('display_comments_'+n).style.display='none';
    document.getElementById('whole_comments_'+n).style.display='';

}

function jquery_show_gally_profile ( match_id ) {
    jQuery("#gally_hide_" + match_id).hide();
    jQuery.ajax({
        type: "POST",
        url: url_map_f('_process_user_info_by_jquery'),
        data: "action=search_user_show&match_id=" + match_id,
        success: function(){
            jQuery("#gally_show_" + match_id).show();
        }
    });
}

function escapeHTML(str) {
    return str.replace(/&/g, "&amp;")
	.replace(/</g, "&lt;")
	.replace(/>/g, "&gt;")
	.replace(/"/g, "&quot;");
}

function ChangeColor(obj){
    document.getElementById("show_color").value=obj.options[obj.selectedIndex].value;
    obj.options[obj.selectedIndex].selected=true;
    document.getElementsByName("c_color").item(0).style.color = obj.options[obj.selectedIndex].value;
    $('#text').css({'color': obj.value});
    obj.style.background = obj.value;
}

function on_maillist_focus(obj) {
    if(obj.value == 'You can copy and paste the email addresses, separated by space, newline, comma or semicolon. ex:lily@yahoo.com, Joe@gmail.com, bill@hotmail.com,tim@aol.com') {
        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. ex:lily@yahoo.com, Joe@gmail.com, bill@hotmail.com,tim@aol.com';
        obj.style.color='#818181';
    }
}

function checkImgType(fileURL, allow_pdf){
    if (allow_pdf){
        var right_type=new Array(".gif",".jpg",".jpeg",".png",".bmp", ".pdf")
    } else {
        var right_type=new Array(".gif",".jpg",".jpeg",".png",".bmp")
    }
    var right_typeLen=right_type.length;
    var imgUrl=fileURL.toLowerCase();
    var postfixLen=imgUrl.length;
    var len4=imgUrl.substring(postfixLen-4,postfixLen);
    var len5=imgUrl.substring(postfixLen-5,postfixLen);
    for (i=0;i<right_typeLen;i++) {
        if((len4==right_type[i])||(len5==right_type[i])) {
            return 1;
        }
    }
    return 0;
}

function jquery_accept_field_modify ( id, action, field ) {
    jQuery("#" + field + "_" + id).html("<b>loading...</b>");
    fieldValue = document.getElementById("txt_" + field + "_" + id).value;
    jQuery.ajax({
        type: "POST",
        url: url_map_f('_friend_by_jquery'),
        data: "action=" + action + "&id=" + id + "&fieldValue=" + fieldValue,
        success: function( msg ){
            if (msg == '0') {
                jQuery("#" + field + "_" + id).html("<b>Operation Failed</b>");
            } else {
                jQuery("#" + field + "_" + id).html("<b>Edit accepted</b>");
                jQuery("#" + field + "1_" + id).hide();
                jQuery("#" + field + "_" + id).show();
            }
        }
    });
}

function jquery_reject_field_modify ( id, action, field ) {
    jQuery("#" + field + "_" + id).html("<b>loading...</b>");
    fieldValue = document.getElementById("txt_" + field + "_" + id).value;

    jQuery.ajax({
        type: "POST",
        url: url_map_f('_friend_by_jquery'),
        data: "action=" + action + "&id=" + id,
        success: function( msg ){
            if (msg == '0') {
                jQuery("#" + field + "_" + id).html("<b>Operation Failed</b>");
            } else {
                jQuery("#" + field + "_" + id).html("<b>Edit rejected</b>");
                jQuery("#" + field + "1_" + id).hide();
                jQuery("#" + field + "_" + id).show();
            }
        }
    });
}

function selectall (name, value) {
    if(value==1){
        $('input[@name='+ name + ']').attr('checked',true);
    } else {
        $('input[@name=' + name + ']').attr('checked',false);
    }
}

function check_all (name, tag) {
    if(tag==1){
        $('input[@name='+ name + ']').each(function() {
            if ($(this).val() != 0) {
                $(this).attr("checked", true);
            } else {
                $(this).attr("checked", false);
            }
        });
    } else {
        $('input[@name='+ name + ']').each(function() {
            if ($(this).val() != 0) {
                $(this).attr("checked", false);
            } else {
                $(this).attr("checked", true);
            }
        });
    }
}

function invite_as_affiliate(id) {
    jQuery.ajax({
        type: "POST",
        url: url_map_f('_affiliate_by_jquery'),
        data: {prof_id:id, action:'invite_as_aff'},
        success: function( msg ){
           if (jQuery.trim(msg) == '1') {
               $("#invite_aff_link_" + id).html("Sent successfully!");
           } else {
               $("#invite_aff_link_" + id).html("Sent failed!");
           }
        }
    });
}


function saveCallData(usr_id, val, phone_location){
    if(val==1){
        PopUp('/de/censor_call_log_?prof_id=' + usr_id + '&phone_location=' + phone_location, 'user_call_log', 600, 400, 'yes');
    }
}

function visible_quote(item) {
    $("#quote_" + item).toggle();
    if ($("#quote_title_" + item).text() == "- Hide quoted text -") {
        $("#quote_title_" + item).html("- Show quoted text -");
    } else {
        $("#quote_title_" + item).html("- Hide quoted text -");
    }
}
// ######################invite page, check email begin#####################
function error_show(msg) {
    $("#error").show();
    $("#error_msg").html(msg);
    return false;
}

function checkaddress(f) {
    var mailError = 0;
    var mailList = $("#mail_list").val();
    if (mailList == "" || mailList == "You can copy and paste the email addresses, separated by space, newline, comma or semicolon. ex:lily@yahoo.com, Joe@gmail.com, bill@hotmail.com,tim@aol.com") {
        mailError = 1;
    }
    if (mailError) {
        return error_show("A valid email address is required!");
    }

    var emails1 = "";
    var email1;
    var noValidAddress = true;
    var maillistarray, maillist;
    var obj = f.elements['mail_list'];
    var text = obj.value.trim();
    if (text == 'You can copy and paste the email addresses, separated by space, newline, comma or semicolon. ex:lily@yahoo.com, Joe@gmail.com, bill@hotmail.com,tim@aol.com') {
        text = '';
    }
    maillistarray = text.split(/[,;\n\s]\s*/);
    var wrong_email = '';
    for (maillist in maillistarray) {
        email1 = maillistarray[maillist];
        if (checkemail(email1)) {
            noValidAddress = false;
        } else {
            if (email1.length > 0) {
                wrong_email += email1 + ","
            }
        }
        if (email1.length > 0 && emails1.indexOf(email1 + ",") != -1) {
            return error_show("You have inputted duplicated email address!");
        }
        emails1 += email1 + ",";
    }
    if (noValidAddress) {
        return error_show("You haven't inputted any valid email address!");
    }
    if (wrong_email) {
        return error_show("The following email address is not valid: " + wrong_email.substring(0, wrong_email.length - 1));
    }
    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 ChangeImportType(targ, selectObj) {
    var v = selectObj.options[selectObj.selectedIndex].value;
    if (v == '--select--') {
        return;
    } else {
        PopUp('friend_import_in_pp_?skip_member=0&type=' + v, 'import', '560', '600', 'yes');
        var obj = document.getElementById('past_board');
        if (obj) {
            obj.style.display = '';
        }
    }
}
// ######################invite page, check email end#####################

function flash_element(element_id) {
    var obj = document.getElementById(element_id);
    obj.style.visibility = obj.style.visibility == "hidden" ? "visible" : "hidden";
    setTimeout("flash_element('" + element_id + "')", 500);
}

function YYDD(year,month,day){

    MonHead = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    var day_value = day.options[day.selectedIndex].value;
    var year_value = year.options[year.selectedIndex].value;
    var n = MonHead[month.selectedIndex];

    if (month.selectedIndex == 1 && IsPinYear(year_value)){
        n++;
    }

    if (day_value > n) {
        day_value = n;
    }

    writeDay(n, day);
    day.value = day_value;
}

function MMDD(year,month,day){

    MonHead = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

    var day_value = day.options[day.selectedIndex].value;
    var year_value = year.options[year.selectedIndex].value;
    var n = MonHead[month.selectedIndex];

    if (month.selectedIndex == 1 && IsPinYear(year_value)){
        n++;
    }
    if (day_value > n) {
        day_value = n;
    }

    writeDay(n, day);
    day.value = day_value;

}

function writeDay(n, day){
    var e = day;
    optionsClear(e);
    for (var i=1; i<(n+1); i++){
        e.options.add(new Option(i,i));
    }
}

function IsPinYear(year){
    return(0 == year%4 && (year%100 !=0 || year%400 == 0));
}

function optionsClear(e){
    for (var i=e.options.length; i>=0; i--)
    e.remove(i);
}

function UpdateCountryInfoByJSON() {
    cou_id = $('select[@name=country]').val();
    $.getJSON(
        "js_fill_states.xml",
        {country: cou_id, type: 'json'},
        function(json){
            cLeng = json.countries.length;
            options = '';
            for(var i=1; i < cLeng; i++){
                options += '<option value="' + json.countries[i].value + '">' + json.countries[i].text + '</option>';
            }
            $("select[@name=state_id]").empty();
            $("select[@name=state_id]").html(options);
        }
    );
}

function jquery_request_photo(usr_id, about_id) {
    jQuery.ajax({
        type: "POST",
        url: url_map_f('_request_photo'),
        data: "usr_id=" + usr_id + "&about_id=" + about_id,
        success: function(n){
            if (n == 0) {
                alert('You need to upload a photo before you can request photos from others.');
                window.open('/picture_form');
            } else {
                $('#request_photo_' + about_id).html('request sent');
                $('#request_photo_' + about_id).parent().css("cursor", "default");
                $('#request_photo_' + about_id).parent().removeAttr("onclick");
            }
        }
    });
}

function edit_phone_number(id, person_id) {
    var obj = $("#" + id);
    var number = obj.text();

    var usa_pattern = /^(\d+-)?\d{3}-\d{3}-\d{4}$/;

    if (usa_pattern.test(number))
        return;

    number = number.replace(/\D/g, '');

    if (number) {
        var len = number.length;

        var new_number = (len > 10 ? (number.substr(0, len - 10) + '-') : '')
            + number.substr(len - 10, 3)
            + '-' + number.substr(len - 7, 3)
            + '-' + number.substr(len - 4, 4);

        $.getJSON(
            url_map_f('censor_edit_phone_number_'), 
            { new_number: new_number, person_id: person_id },
            function(data) {
                $("#" + id).html(data.new_number);
                var whitepages_phone_number = "http://www.whitepages.com/search/ReversePhone?full_phone=" + data.new_number;
                $("#whitepages_phone_number_" + person_id).attr("href", whitepages_phone_number);
                $("#phone_location_" + person_id).html(data.phone_number_location);
                if (data.distance_between_phone_zip > 40) {
                    $("#distence_photo_billing_" + person_id).attr("class", "tips_red");
                } else {
                    $("#distence_photo_billing_" + person_id).attr("class", "");
                }
                $("#distence_photo_billing_" + person_id).html(data.distance_between_phone_zip_desc);
            }
        );
    }
}

function jquery_vote_blog_topic (blog_id, vote) {
    jQuery.ajax({
        type: "POST",
        url: url_map_f('_process_vote_by_jquery'),
        data: "vote=" + vote + "&blog_id=" + blog_id,
        success: function(data){
            if (vote == 1) {
                jQuery("#vote_" + vote).html(data + " up");
            } else {
                jQuery("#vote_" + vote).html(data + " down");
            }
        }
    });
}

/**
 * 
 * 
 * @author User (2009-10-19)
 * 
 * @param msg_id : Blog post message id
 * @param vote : deside whether up or down when user vote
 */
function jquery_vote_blog_msg(msg_id, vote) {
    jQuery.ajax({
        type: "POST",
        url: url_map_f('_process_vote_by_jquery'),
        data: "vote=" + vote + "&msg_id=" + msg_id,
        success: function(data){
            if (vote == 1) {
                jQuery("#msg_" + msg_id).html(data + " up");
            } else {
                jQuery("#msg_" + msg_id).html(data + " down");
            }
        }
    });
}

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';
    }
}

// Photo upload pop on user_details page
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup() {
    //loads popup only if it is disabled
    if (popupStatus == 0) {
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
        $("#popupContact").fadeIn("slow");
        popupStatus = 1;
    }
}

function disablePopup() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#backgroundPopup").fadeOut("slow");
        $("#popupContact").fadeOut("slow");
        popupStatus = 0;
    }
}

function centerPopup() {
    var windowWidth = window.document.body.offsetWidth;
    var windowHeight = document.body.scrollHeight;
    var popupHeight = $("#popupContact").height();
    var popupWidth = $("#popupContact").width();
    //centering
    $("#popupContact").css({
        "position": "absolute",
        "top": "300px",
        "left": windowWidth/2-popupWidth/2
    });
    //only need force for IE6
    $("#backgroundPopup").css({
        "height": windowHeight,
        "width": windowWidth
    });
}


function on_input_with_tip_focus(obj, text) {
    if (obj.value == text) {
        obj.value = '';
        obj.style.color = '#000000';
    }
}

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

function on_form_with_tip_obj_submit(obj, text) {
    if (obj.value == text) {
        obj.value = '';
    }
    return true;
}
function checkUserID () {
    jQuery.ajax({
        type: "POST",
        url: url_map_f('_check_authen'),
        success: function(){}
    }); 
}

function update_blog_submit() {
    clickOnce();
    document.update.action='blog_post';
    document.update.target='';
    document.update.submit();
}

function add_or_replace_str(source, oldstr, newstr) {
    if (source.indexOf(oldstr) >= 0) {
        source = source.replace(oldstr, newstr);
    } else {
        source = source + newstr;
    }

    return source;
}

function jquery_save_mail_to_draft (obj, to, subject, text, del_draft_msg_id) {
    $(obj).attr('disabled', 'disabled');
    jQuery.ajax({
        type: "GET",
        url: url_map_f('_save_mail_to_draft'),
        data: "to=" +  to+ "&subject=" + subject + "&text=" + text +"&del_draft_msg_id=" + del_draft_msg_id,
        success: function(data) {
            $('#del_draft_msg_id').val(data);
            $(obj).val('Saved to draft');
        }
    });
}
function jquery_delete_draft(del_draft_msg_id) {
    jQuery.ajax({
        type: "GET",
        url: url_map_f('_save_mail_to_draft'),
        data: "only_delete_draft=1&del_draft_msg_id=" + del_draft_msg_id,
        success: function() {}
    });
}
function add_card_to_favorite(card) {
    var favorite = document.getElementById("favorite_" + card);
    jQuery.ajax({
        type: "POST",
        url: url_map_f('add_card_to_favorite_'),
        data: "card_id=" + card,
        success: function() {
            favorite.innerHTML = "already in <a href=\"/customize_greeting_cards?favorite=1\">favorites</a>";
        }
    });
}

function add_cards_to_favorite() {
    var checkboxes = $("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++) {
            document.getElementById("favorite_" + values[i]).innerHTML = "already in <a href=\"/customize_greeting_cards?favorite=1\">favorites</a>";
        }
    }
}

function dele_card_from_favorite(card) {
    if (confirm("Are you sure you want to remove the card from your favorites?")) {
        jQuery.ajax({
            type: "POST",
            url: url_map_f('customize_greeting_cards'),
            data: "favorite=1&delete_from_favorite=" + card,
            success: function(){
                window.location.reload();
            }
        });
    }
}

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

function more_or_less(a) {
    var a_obj = $("#" + a);
    if (a_obj.html() == 'More') {
        a_obj.html('Less');
    } else {
        a_obj.html('More');
    }

}

function jquery_unblock(unblock_id) {
    jQuery.ajax({
        type: "get",
        url: url_map_f('_process_user_info_by_jquery'),
        data: "action=un_block&match_id=" + unblock_id,
        success: function() {
            window.location.reload();
        }
    });
}

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();
}

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 add_game_to_favorite(game) {
    var favorite = document.getElementById("is_in_favorite_" + game);
    var favorite_num = document.getElementById("favorite_num");
    jQuery.ajax({
        type: "post",
        url: url_map_f('add_game_to_favorite_'),
        data: "frompage=games&game_to_favorite=" + game,
        success: function(info) {
            favorite.innerHTML = "Already in <a href=\"/games?my_favorite=1\">favorites</a>";
            favorite_num.innerHTML = "(" + info + ")";
        }
    });
}

function SendToFriends(frm, from_page) {
    var text = '';
    if (frm.del.length) {
        for (var i = 0; i < frm.del.length; i++) {
            if (frm.del[i].checked) {
                text = text + frm.del[i].value + '_';
            }
        }
    } else {
        if (frm.del.checked) {
            text = frm.del.value;
        }
    }
    if (text == '') {
        document.getElementById("error_div").style.display = 'block';
        document.location = '#';
    } else {
        window.open('send_friends?from_page=' + from_page + '&user_list=' + text);
    }
}

function IsNum(s)
{
    if( s!=null ){
        var r,re;
        re = /[\d|.]*/i;
        r = s.match(re);
        return (r==s)?true:false;
    }
    return false;
}
var comment_usr_id;
function show_hide_comment (usr_id, username, fav_comment, type) {
    if (comment_usr_id != usr_id) {
        jQuery('#comment_icon_' + comment_usr_id).attr("class", "plus");
        jQuery('#pic_td_' + comment_usr_id).removeAttr('vAlign').removeAttr('style');
        jQuery('#ckbox_td_' + comment_usr_id).removeAttr('vAlign').removeAttr('style');
        jQuery('#comment_td_' + comment_usr_id).hide();
        jQuery('#commend_frame_' + comment_usr_id).attr('src', '');
    }
    if (jQuery('#comment_td_' + usr_id).is(":hidden")) {
        fav_comment = fav_comment ? fav_comment : 0;
        var src = 'favorites_comments_?active=editcomments&prof_id=' + usr_id + '&username=' + username + '&edit=1&iframe=1&fav_comment=' + fav_comment;
        if (type == 'block') {
            src = 'blocked_?active=editreason&prof_id=' + usr_id + '&username=' + username + '&iframe=1&frompage=who_blocked&blocked_comment=' + fav_comment;
        } else if (type == 'friends') {
            src = 'friends_comments_?active=editcomments&prof_id=' + usr_id + '&username=' + username + '&iframe=1';
        } else if (type == 'chat_comments') {
            src = 'whom_had_chat_comments_?active=editcomments&prof_id=' + usr_id + '&username=' + username;
        } else if (type == 'photo_album') {
            src = 'favorites_comments_?active=editcomments&prof_id=' + usr_id + '&username=' + username + '&edit=1&iframe=1&from_page=photo_album&fav_comment=' + fav_comment;
        }
        jQuery('#comment_icon_' + usr_id).attr("class", "minus");
        jQuery('#pic_td_' + usr_id).attr('vAlign', 'top').css('padding-top', '15px');
        jQuery('#ckbox_td_' + usr_id).attr('vAlign', 'top').css('padding-top', '92px');
        jQuery('#commend_frame_' + usr_id).attr('src', src);
        jQuery('#comment_td_' + usr_id).show();
        comment_usr_id = usr_id;
    } else {
        jQuery('#comment_icon_' + usr_id).attr("class", "plus");
        jQuery('#pic_td_' + usr_id).removeAttr('vAlign').removeAttr('style');
        jQuery('#ckbox_td_' + usr_id).removeAttr('vAlign').removeAttr('style');
        jQuery('#comment_td_' + usr_id).hide();
        jQuery('#commend_frame_' + usr_id).attr('src', '');
    }
}

function jquery_add_to_favoriate_reload (match_id) {
    jQuery("#favoriate_add_" + match_id).html("<b>saving...</b>");
    jQuery.ajax({
        type: "POST",
        url: url_map_f('_process_user_info_by_jquery'),
        data: "action=favoriate_add&match_id=" + match_id,
        success: function(){
            window.location.reload();
        }
    });
}

function jquery_add_new_category(owner_id) { 
    var category_name = $("#card_category_id").find("option:selected").val(); 
    if (category_name == 'new_category') {
        var new_category_name = window.prompt("What would you like to name this Category?");
        if (new_category_name) {
            new_category_name.replace(/^\.*/g,"");
            if (new_category_name) {
                jQuery.ajax({
                    type: "POST",
                    url: url_map_f('add_new_greeting_category_'),
                    data: "owner_id=" + owner_id + "&category_name=" + new_category_name,
                    success: function(data) {
                        if (data != 0) {
                            var new_option = new Option(new_category_name, data);
                            $("#card_category_id")[0].options.add(new_option);
                            new_option.selected = true;
                        } else {
                            jQuery("#message").html(new_category_name + " is exist.");
                            jQuery("#message").show();
                        }
                    }
                });
            }
        }
    }
}

function fill_ipal_address() {
    var fname = jQuery("input[@name=fname]").val();
    var lname = jQuery("input[@name=lname]").val();
    if (fname && fname != 'First' && lname && lname != 'Last') {
        jQuery("#ipail_email").html(fname + lname + '@iPal.com');
    } else {
        jQuery("#ipail_email").html('');
    }
}

var hidden_div_id = 0, hidden_icon_id = 0;
function fold_group(div_id, icon_id) {
    if (hidden_div_id && hidden_div_id != div_id && hidden_icon_id && hidden_icon_id != icon_id) {
        $("#" + hidden_div_id).hide();
        $("#" + hidden_icon_id).attr("class", "plus"); 
    }
    hidden_div_id = div_id;
    hidden_icon_id = icon_id;
    show_hide_group(div_id, icon_id);
}

// censor telphone number lengh check.
function censor_check_tel_lengh() {
    var sel_value = $("select[@name='type'] option[@selected]").val();
    if (sel_value == "telphone") {
        var lengh = $("#arg").val().length;
        if (lengh < 4) {
            $("#telphone_info").html("telphone number should at least 4 symbols/digits");
            return false;
        }
    }
    return true;
}

var writing_ideas_div = "";
var writing_ideas_icon = "";
function show_writing_ideas (div_id, icon_id, url) {
    if (writing_ideas_div && writing_ideas_div != div_id && writing_ideas_icon && writing_ideas_icon != icon_id) {
        $("#" + writing_ideas_div).hide();
        $("#" + writing_ideas_icon).attr("class", "plus"); 
    }
    var div_obj  = $("#" + div_id);
    var icon_obj = $("#" + icon_id);
    if (div_obj.is(":hidden")) {
        div_obj.load(url);
        div_obj.show();
        icon_obj.attr("class", "minus"); 
        writing_ideas_div = div_id;
        writing_ideas_icon = icon_id;
    } else {
        div_obj.html('');
        div_obj.hide();
        icon_obj.attr("class", "plus"); 
    }

}

function remove_travelling(about_id) {
    jQuery.ajax({
        type: "POST",
        url: url_map_f('_remove_travelling'),
        data: "&about_id=" + about_id,
        success: function(data) {
            $('#show_travelling').hide();
        }
    });
}

function rank_profile(prof_id, rank) {
    rank = rank || 0;
    $('#favorite_rank_' + prof_id + '_').html('');
    for (var i = 1; i <= 5; i++) {
        $('#favorite_rank_' + prof_id + '_').append('<a href="javascript:;" onclick="rank_profile(' + prof_id + ', ' + (i == rank ? i - 1 : i) + ');"><img src="http://images.commercialless.com/stars/' + (i <= rank ? "red_star" : "gray_star") + '.gif" alt="Rank among favorites" border="0" width="13" height="12" /></a> ');
    }
    $('#rank_' + prof_id).val(rank);
}

function save_note(from_page, prof_id, default_comment) {
    var new_comment_value = $('#comments_' + prof_id).val();
    new_comment_value = jQuery.trim(new_comment_value);
    if (new_comment_value == default_comment) new_comment_value = '';
    var url, text_id, whole_text_id;
    if (from_page == 'favorites') {
        url = 'favorites_comments_?active=update&comments=' + escape(new_comment_value) + '&prof_id=' + prof_id + '&rank=' + $('#rank_' + prof_id).val();
        text_id = '#fav_comment_' + prof_id;
        whole_text_id = '#fav_whole_text_' + prof_id;
    }
    if (from_page == 'whom_had_chat') {
        url = 'whom_had_chat_comments_?active=update&comments=' + escape(new_comment_value) + '&prof_id=' + prof_id;
        text_id = '#chat_comment_' + prof_id;
        whole_text_id = '#chat_whole_text_' + prof_id;
    }
    if (from_page == 'who_blocked') {
        if (new_comment_value == '') {
            $('#note_null_' + prof_id).show();
            return false;
        }
        url = 'blocked_?active=update&prof_id=' + prof_id + '&iframe=1&frompage=who_blocked&comments=' + new_comment_value;
        text_id = '#blocked_comment_' + prof_id;
        whole_text_id = '#block_whole_text_' + prof_id;
    }
    if (from_page == 'friends') {
        url = 'friends_comments_?active=update&comments=' + escape(new_comment_value) + '&prof_id=' + prof_id + '&iframe=1';
        text_id = '#fav_comment_' + prof_id;
    }
    jQuery.ajax({
        type: "GET",
        url: url,
        cache: false,
        success: function() {
            $(text_id).html(new_comment_value);
            if (from_page != 'friends') {
                $(whole_text_id).html(new_comment_value);
            }
            $('#comment_icon_' + prof_id).attr("class", "plus");
            $('#comment_td_' + prof_id).hide();
        }
    });
}

