String.prototype.trim = function(c, t){
    return c = "[" + (c == undefined ? " " : c.replace(/([\^\]\\-])/g, "\\\$1")) + "]+",
    this.replace(new RegExp((t != 2 ? "^" : "") + c + (t != 1 ? "|" + c + "$" : ""), "g"), "");
};

function crop(photoId)
{
	new Ajax.Request(PUBLIC_URL+'photos/crop-thumbnails', {
		method: 'post',
		postBody: $H({sqx1 :cropData.x1, sqx2 :cropData.x2, sqy1 :cropData.y1, sqy2 :cropData.y2, rtx1 :cropData2.x1, rtx2 :cropData2.x2, rty1 :cropData2.y1, rty2 :cropData2.y2, photoId: photoId}).toQueryString(),
		evalJS: 'force',
		onSuccess: function(transport) {
			window.location = transport.responseText;
		}
	});

}

function saveRotate(photoId) {
	new Ajax.Request(PUBLIC_URL+'photos/rotate/'+photoId, {
		method: 'post',
		postBody: $H({angle: finalAngle}).toQueryString(),
		evalJS: 'force',
		onSuccess: function(transport) {
			window.location = transport.responseText;
		}
	});
}

function setUiLanguage(languageId)
{
	new Ajax.Request(PUBLIC_URL+'ajax/set-language/',
			{
			method: 'post',
			postBody: 'languageId='+languageId,
			onSuccess: function(transport) {
				eval(transport.responseText);
			}
			});
}
function showHide2Object(obj1, obj2)
{
	$(obj1).toggle();
	$(obj2).toggle();
}
function voteUser(votedUser, voteType)
{
	$('setVote').innerHTML = '<img src="'+staticContentImages+'loading.gif" alt="" style="width: 16px; height: 16px; vertical-align: middle" />';
	new Ajax.Request(PUBLIC_URL+'ajax/rate-user/', {
			method: 'post',
			postBody: $H({ votedUser: votedUser, voteType: voteType }).toQueryString(),
			onSuccess: function(transport) {
				$('rateBlock').replace(transport.responseText);
		//		new Effect.Appear('rateUser');
			}
	});
}

function sendFriendRequest(userId, from)
{
	//default
	if (from == null) from = 'profile';
	new Ajax.Request(PUBLIC_URL+'ajax/send-friend-request/', {
			method: 'post',
			postBody: 'userId='+userId,
			onSuccess: function(transport) {
				eval(transport.responseText);
				
				switch(from) {
				case 'mail':
					$('friend_mail_cnt_' + userId).innerHTML = '<span class="msg_unfrnd">&nbsp;</span>';
					break;
				case 'search':
					$('addFriendLi'+userId).addClassName('fpl_passive');
					$('addFriendLi'+userId).innerHTML = $('addFriendLink'+userId).innerHTML; 
					break;
				default:
					$('sendFR').innerHTML = '<img src="'+staticContentImages+'profile/people_gray.jpg" alt="" width="38" height="32" />';
					$('sendFRLinkCont').innerHTML = $('sendFRLink').innerHTML;
				}
			}
	});
}

function blockUser(userId, from, numberOfSubscribers)
{
	//default
	if (from == null) from = 'profile';
	new Ajax.Request(PUBLIC_URL+'ajax/block-user/', {
			method: 'post',
			postBody: 'userId='+userId,
			onSuccess: function(transport) {
				eval(transport.responseText);
				
				switch(from) {
				case 'mail':
					if (numberOfSubscribers > 2) {
						$('block_mail_cnt_' + userId).innerHTML = '<span class="msg_greybock">&nbsp;</span>';
					} else {
						window.location = PUBLIC_URL + 'mail/inbox';
					}
					break;
				default:
					$('sendBl').innerHTML = '<a href="javascript:void(0)" onclick="unblockUser('+ userId +')"><img src="'+staticContentImages+'profile/deblocked.jpg" alt="" width="38" height="32" /></a>';
					$('sendBlLinkCont').innerHTML = '<a href="javascript:void(0)" onclick="unblockUser('+ userId +')">' + this.imageLabelUnblock + '</a>';
				}
			}
	});
}

function unblockUser(userId, from)
{
	//default
	if (from == null) from = 'profile';
	new Ajax.Request(PUBLIC_URL+'ajax/unblock-user/', {
			method: 'post',
			postBody: 'userId='+userId,
			onSuccess: function(transport) {
				eval(transport.responseText);
				
				switch(from){
				case 'mail':
					$('block_mail_cnt_' + userId).innerHTML = '<span class="msg_greybock">&nbsp;</span>';
					break;
				default:
					$('sendBl').innerHTML = '<a href="javascript:void(0)" onclick="blockUser(' + userId + ')"><img src="'+staticContentImages+'profile/blocked_red.jpg" alt="" width="38" height="32" /></a>';
					$('sendBlLinkCont').innerHTML = '<a href="javascript:void(0)" onclick="blockUser('+ userId +')">' + this.imageLabelBlock + '</a>';
				}
			}
	});
}

/** Progress Dialog **/
 
var ProgressDialog = Class.create();

ProgressDialog.prototype = {
	/**
	 * default constructor		  
	 */
	initialize: function() {		
	},
	
	show: function(elementId) {
		//$(elementId).setStyle({height: $(elementId).childNodes[5].getHeight() + 'px'});
		$(elementId).addClassName('loading_cnt');		
	},
	
	hide: function(elementId) {
		$(elementId).removeClassName('loading_cnt');
	},
	
	set: function(message) {
		return;
	}
}

var progress = new ProgressDialog();
/** End of Progress Dialog **/

function emoticon(text,txtarea) {
 text = ' ' + text + ' ';
 if (txtarea.createTextRange && txtarea.caretPos) {
  var caretPos = txtarea.caretPos;
  caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
  txtarea.focus();
  txtarea.scrollTop = txtarea.scrollHeight;
 } else {
  txtarea.value  += text;
  txtarea.focus();
  txtarea.scrollTop = txtarea.scrollHeight;
 }
}
/*--------------------------------------------------------------------------------------------------------*/

var sms_type = 1;

function sms_change_content()
{
	var id = document.forms["imageform"].id.value;
	var value = document.forms["imageform"].message.value;
	var content = document.getElementById('sms_content');
	switch(sms_type)
	{
		case 1:
		case 2:
			content.innerHTML = '<strong class="f_red">F' + id + '</strong> ' + value;
			break;
	}
}

function hoverStars(starNumber) {
	for(i = 1; i <= starNumber; i++) {
		$('star'+i).src = $('star'+i).src.replace('star_grey.gif', 'star.gif');
	}
	
	for(i = starNumber+1; i <= 5; i++) {
		$('star'+i).src = $('star'+i).src.replace('star.gif', 'star_grey.gif');
	}
}

function ratePhoto(photoId, mark, userId) {
	$('starRate').innerHTML = '<img src="'+staticContentImages+'loading.gif" alt="" style="width: 16px; height: 16px; vertical-align: middle" />';
	new Ajax.Request(PUBLIC_URL+'ajax/rate-photo/', {
			method: 'post',
			postBody: $H({ photoId: photoId, mark: mark, uid: userId }).toQueryString(),
			onSuccess: function(transport) {
				eval(transport.responseText);
			}
	});
}

function rateGroupPhoto(photoId, mark, userId) {
	$('starRate').innerHTML = '<img src="'+staticContentImages+'loading.gif" alt="" style="width: 16px; height: 16px; vertical-align: middle" />';
	new Ajax.Request(PUBLIC_URL+'ajax/rate-group-photo/', {
			method: 'post',
			postBody: $H({ photoId: photoId, mark: mark, uid: userId }).toQueryString(),
			onSuccess: function(transport) {
				eval(transport.responseText);
			}
	});
}

function subscribeToParty(){
	new Ajax.Request(PUBLIC_URL+'ajax/subscribe-to-party/',{
	method: 'post',
	postBody: '',
	onSuccess: function(transport) {
		eval(transport.responseText);
	}
	});
}

function unsubscribeToParty(){
	new Ajax.Request(PUBLIC_URL+'ajax/unsubscribe-to-party/',{
	method: 'post',
	postBody: '',
	onSuccess: function(transport) {
		eval(transport.responseText);
	}
	});
}

function confirmParty(){
	new Ajax.Request(PUBLIC_URL+'ajax/confirm-party/',{
	method: 'post',
	postBody: '',
	onSuccess: function(transport) {
		eval(transport.responseText);
	}
	});

}





function changeDays() {
	var currentDay = $('day').value;
	try {
		$('day30').remove();
		$('day31').remove();
	} catch(e){;}
	
	if($('month').value == '1' ||
	   $('month').value == '3' ||
	   $('month').value == '5' ||
	   $('month').value == '7' ||
	   $('month').value == '8' ||
	   $('month').value == '10' ||
	   $('month').value == '12') {
			try {
				if (!$('day29')) {
					$('day').insert({bottom: '<option id=day29 value=29>29</option>'});
				}
				$('day').insert({bottom: '<option id=day30 value=30>30</option>'});
				$('day').insert({bottom: '<option id=day31 value=31>31</option>'});
			} catch(e){;}
	} else if ($('month').value == '4' ||
		$('month').value == '6' ||
		$('month').value == '9' ||
		$('month').value == '11'){
			try {
				if (currentDay>30)
					currentDay = 0;
				if (!$('day29')) {
					$('day').insert({bottom: '<option id=day29 value=29>29</option>'});
				}
				$('day').insert({bottom: '<option id=day30 value=30>30</option>'});
			} catch(e){;}
	} else if ($('month').value == '2'){ 
		try {
				if (currentDay>29)
						currentDay = 0;
				if ($('year').value % 4 == 0 && !$('day29')) {
					$('day').insert({bottom: '<option id=day29 value=29>29</option>'});
				}
				else if ($('year').value % 4 != 0 && $('day29')) {
					if (currentDay>28)
						currentDay = 0;
					$('day29').remove();
				}
			} catch(e){;}
	}
	$('day').selectedIndex = currentDay;
}

function CreateBookmarkLink(opTitle)
{
	if (opTitle)
		title = document.title + ' - ' + opTitle;
	else
		title = document.title;
	url = document.location.href;

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true;
	}
}

function sendMailShare(id)
{
	var email = $('friendMail_'+id).value;
	var emailTest = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*(\s*[,]\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*/;
	var regex = new RegExp(emailTest);
	if (!regex.test(email)) {
		systemMessenger.set(this.lang['23440_shere_is_no_send'],  0);
		systemMessenger.display();
		return false;    
   	}
	
	var lang = this.lang;
	new Ajax.Request(PUBLIC_URL+'ajax/send-mail-share/', {
			method: 'post',
				postBody: $H({ username: $('name_'+id).value, myMail: $('myMail_'+id).value,  friendMail:$('friendMail_'+id).value, message:$('message_'+id).value, link:$('link_'+id).value}).toQueryString(),
			onSuccess: function(transport) {
				function callback() {
						$('mail_'+id).style.display = 'none';
				}
				new Effect.BlindUp('mail_'+id, {duration: 1, delay: 0.2, afterFinish: callback});
				systemMessenger.set(lang['23195_shere_is_send'], 1);
				systemMessenger.display();
				return false;
			}
	});
}

//---------------------------------------------------------------
function activationPopDisorder(objId){
	$('mod_descr').style.left = parseInt(findPosX(objId) - 170)+'px';
	$('mod_descr').style.top = parseInt(findPosY(objId) - 400)+'px';
	$('mod_descr').style.display = 'block';
}
						
function reportDisorder(){
			//ceck if selected
			var reportedUserId = arguments[0];
			var reportedContentId = arguments[1]; 
			var otherInfo = arguments[2];
			var disorderType = false;
			var disorderMsg = null;
			var contentType = $F('contentType');
			
			if($F('erotic_dis') == null && $F('advert_dis') == null && $F('negative_dis') == null && $F('copyright_dis') == null){
				systemMessenger.set(lang['23495_choose_reason_disorder'], 0); 
				systemMessenger.display();
				return false;
			}else if ($F('copyright_dis') && $F('copyright_msg') == ''){
				systemMessenger.set(lang['23496_copyright_need_comment_disorder'], 0); 
				systemMessenger.display();
				return false;
			}else {
				switch(true){
					case ($F('erotic_dis') != null): disorderType = $F('erotic_dis'); break;
					case ($F('advert_dis') != null): disorderType = $F('advert_dis'); break;
					case ($F('negative_dis') != null): disorderType = $F('negative_dis'); break;
					case ($F('copyright_dis') != null): disorderType = $F('copyright_dis'); disorderMsg = $F('copyright_msg'); break;
				}
				//return false;
					$('loadingContent').style.display = 'block';
					$('otherContent').style.display = 'none';
					$('loadingContent').innerHTML = '<img src="'+staticContentImages+'loading.gif" alt="" style="width: 20px; height: 20px; vertical-align: middle" />';
					new Ajax.Request(PUBLIC_URL+'ajax/signal-disorder/', {
							method: 'post',
							postBody: $H({ disorderType: disorderType, comment: disorderMsg, reportedUserId: reportedUserId, contentId: reportedContentId, contentType: contentType, otherInfo: otherInfo}).toQueryString(),
							onSuccess: function(transport) {
								$('disorderLink').innerHTML = (transport.responseText);
								$('mod_descr').style.display = 'none';
								systemMessenger.set(lang['23497_thanks_for_report_disorder'], 1);
								systemMessenger.display();
							}
					});
					
				}
			}
						
function copyrightActBlock(flag){
	if(flag == true ){
		$('black_content').style.height = '372px';
		$('white_content').style.height = '285px';
		$('copyright_dis_msg').style.display = 'block'
	}else {
		$('copyright_dis_msg').style.display = 'none'
		$('black_content').style.height = '232px';
		$('white_content').style.height = '145px';
	}
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else if (obj.y) curtop += obj.y;
	return curtop;
}

//	tracker function
function ifr_add(ifr_src,obj) {
	var urlstat_ifr=document.createElement("iframe");
	urlstat_ifr.style.width="0px";
	urlstat_ifr.style.height="0px";
	urlstat_ifr.style.margin="0px";
	urlstat_ifr.style.display="none";
	urlstat_ifr.src=ifr_src;
	obj.parentNode.appendChild(urlstat_ifr);
	return;
}
function trackThis(idurl,obj) {
	if(arguments[2]) {//poate sa fie un al treilea parametru,care restrictioneaza trackerul pentru o singura tara
		if(parseInt(arguments[2])==parseInt(1)) {
			ifr_add("http://url.neogen.ro/index/increment/" + idurl + "/" + escape(REMOTE_ADDR) + "/" + escape(DOMAIN_NAME + '/'),obj);
		}
	}
	else {
		ifr_add("http://url.neogen.ro/index/increment/" + idurl + "/" + escape(REMOTE_ADDR) + "/" + escape(DOMAIN_NAME + '/'),obj);
	}
}
//	end tracker function

function getSmiles(toContent, textArea)
{
	new Ajax.Request(PUBLIC_URL+'ajax/get-smiles/', {
			method: 'post',
			postBody: $H({textArea: textArea }).toQueryString(),
			onSuccess: function(transport) {
				$(toContent).innerHTML = transport.responseText;
			}
	});
}