function checkAll(mode) {
	var f = document.forma;
	
	for (var i = 0; i < f.elements.length; i++) {
		var e = f.elements[i];
		if (e.type == 'checkbox') {
			if (mode) {
				if (mode == 1)
					e.checked = true;
				else
					e.checked = false;
			} else {
				if (!f.check_all.checked)
					e.checked = false
				else
					e.checked = true
			}
		}
	}
}

function bookmark(form_id, action, id) {
	var f = document.forms[form_id];
	
	f.bookmark.value = action;
	if (id>0)
		f.bookmark_id.value = id;
	f.submit();
}

function setFriendsActions(form_id, fr_action, fr_id)
{
	var f = document.forms[form_id];
	
	f.friends_action.value = fr_action;
	f.friends_id.value = fr_id;
	
	f.submit();
}

function addrelationship(form_id, id, rel)
{
	var f = document.forms[form_id];
	if (id > 0)
	{
		f.friend_id.value = id;
		f.relation.value = rel;
		f.submit();
	}
}



// flirt zone gifts (kisses, flowers)
function send_gift(form_id, type, id)
{
	var f = document.forms[form_id];
	if (id > 0)
	{
		f.gift_type.value = type;
		f.gift_to.value = id;
		
		f.submit();
	}
}


function addToFavorites(obj, event) 
{ 
	if (window.external)
	{	
		window.external.AddFavorite(location.href,document.title);
		domTT_activate(obj, event, 'predefined', 'bookmark_ok');
	}
	else 
		domTT_activate(obj, event, 'predefined', 'bookmark_error');
}
function enableDisable(check, type)
{
	switch (type) 
	{
		case 'actor':
			var hide = ["hide1","hide2","hide3","hide4","hide5", "hide6", "hide7", "hide8", "hide9"];
			var show = ["show2", "show3", "show4", "show5", "show6", "show7", "show8", "show9"];
			break;
		case 'adult':
			var hide = ["hide1","hide2","hide3","hide5", "hide7", "hide8", "hide9"];
			var show = ["show2", "show3", "show5", "show7", "show8", "show9"];
			break;
		case 'advertising':
			var hide = ["hide1", "hide2", "hide3", "hide8", "hide9", "hide10", "hide11", "hide12"];
			var show = ["show2", "show3", "show8", "show9", "show10", "show11", "show12"];
			break;
		case 'agency':
			var hide = ["hide1", "hide2", "hide3", "hide8", "hide9", "hide10", "hide11", "hide12"];
			var show = ["show2", "show3", "show8", "show9", "show10", "show11", "show12"];
			break;
		case 'casting':
			var hide = ["hide1", "hide2", "hide3", "hide8", "hide9", "hide10", "hide11", "hide12"];
			var show = ["show2", "show3", "show8", "show9", "show10", "show11", "show12"];
			break;
		case 'company':
			var hide = ["hide1","hide2","hide3","hide5", "hide7", "hide8"];
			var show = ["show2", "show3", "show5", "show7", "show8"];
			break;
		case 'dancer':
			var hide = ["hide1","hide2","hide3","hide4","hide5", "hide6", "hide7", "hide8", "hide9"];
			var show = ["show2", "show3", "show4", "show5", "show6", "show7", "show8", "show9"];
			break;
		case 'dancestudio':
			var hide = ["hide1","hide2","hide3", "hide8", "hide9", "hide10", "hide11"];
			var show = ["show2", "show3", "show8", "show9", "show10", "show11"];
			break;
		case 'designer':
			var hide = ["hide1","hide2","hide3","hide5", "hide6", "hide7", "hide8", "hide9"];
			var show = ["show2", "show3", "show5", "show6", "show7", "show8", "show9"];
			break;
		case 'member':
			var hide = ["hide1", "hide2", "hide3", "hide5", "hide6", "hide9"];
			var show = ["show2", "show3", "show5", "show6", "show9"];
			break;
		case 'model':
			var hide = ["hide1","hide2","hide3","hide4","hide5", "hide6", "hide7", "hide8", "hide9"];
			var show = ["show2", "show3", "show4", "show5", "show6", "show7", "show8", "show9"];
			break;
		case 'musicstudio':
			var hide = ["hide1","hide2","hide3", "hide8", "hide9", "hide10", "hide11"];
			var show = ["show2", "show3", "show8", "show9", "show10", "show11"];
			break;
		case 'actingstudio':
			var hide = ["hide1","hide2","hide3", "hide8","hide9", "hide10", "hide11"];
			var show = ["show2", "show3", "show8", "show9", "show10", "show11"];
			break;
		case 'photographer':
			var hide = ["hide1","hide2","hide3", "hide8", "hide9", "hide10", "hide11", "hide12", "hide13"];
			var show = ["show2", "show3", "show8", "show9", "show10", "show11", "show12", "show13"];
			break;
		case 'producer':
			var hide = ["hide1","hide2","hide3","hide5", "hide7", "hide8", "hide9"];
			var show = ["show2", "show3", "show5", "show7", "show8", "show9"];
			break;
		case 'singer':
			var hide = ["hide1","hide2","hide3","hide4","hide5", "hide6", "hide7", "hide8", "hide9"];
			var show = ["show2", "show3", "show4", "show5", "show6", "show7", "show8", "show9"];
			break;
		case 'stylist':
			var hide = ["hide1","hide2","hide3","hide5", "hide7", "hide8", "hide9"];
			var show = ["show2", "show3", "show5", "show7", "show8", "show9"];
			break;
		case 'scout':
			var hide = ["hide1", "hide2", "hide3", "hide8", "hide9", "hide10", "hide11", "hide12"];
			var show = ["show2", "show3", "show8", "show9", "show10", "show11", "show12"];
			break;
		case 'fzone':
			var hide = ["hide102"];
			var show = ["show102", "show103"];
			break;
		case 'entertainer':
			var hide = ["hide1", "hide2", "hide3", "hide5", "hide6", "hide8", "hide9", "hide10", "hide11", "hide12"];
			var show = ["show2", "show3", "show5", "show6", "show8", "show9", "show10", "show11", "show12"];
			break;
		case 'speaker':
			var hide = ["hide1", "hide2", "hide3", "hide5", "hide6", "hide8", "hide9"];
			var show = ["show2", "show3", "show5", "show6", "show8", "show9"];
			break;
	}
	
	if (check.checked) {
		for(var i=0; i < hide.length; i++)
			document.getElementById(hide[i]).className = 'show';
		for(var i=0; i < show.length; i++)
			document.getElementById(show[i]).className = 'hide';

	}
	else { 
		for(var ii=0; ii < hide.length; ii++)
				document.getElementById(hide[ii]).className = 'hide';
		for(var ii=0; ii < show.length; ii++)
			document.getElementById(show[ii]).className = 'show';
	}
}

function checkstate(form_id, country_id, default_state) {
	var f = document.forms[form_id];
	if (country_id != 224) {
		f.state_id.value = 0;
		f.state_id.disabled = true;
	} else {
		f.state_id.disabled = false;
		f.state_id.value = default_state;
	}
}

function checkmainmodelingtypes(form_id, type, current) {
	var f = document.forms[form_id];
	if (type == 'fashion') {
		f.fashion_editorial.checked = current;
		f.fashion_runway.checked = current;
		f.fashion_catalog.checked = current;
		f.fashion_print.checked = current;
		f.fashion_showroom.checked = current;
		f.fashion_lingeries.checked = current;
		f.fashion_fitness.checked = current;
		f.fashion_fit.checked = current;
		f.fashion_tearoom.checked = current;
		f.fashion_bodypart.checked = current;
	} else if (type == 'commercial') {
		f.commercial_product.checked = current;
		f.commercial_lifestyle.checked = current;
		f.commercial_corporate.checked = current;
		f.commercial_demo.checked = current;
		f.commercial_tradeshow.checked = current;
	} else if (type == 'glamour') {
		f.glamour_lingerie.checked = current;
		f.glamour_art_nude.checked = current;
		f.glamour_adult.checked = current;
	}
}

function checksubmodelingtypes(form_id, type) {
	var f = document.forms[form_id];
	if (type == 'fashion') {
		f.fashion_available.checked = (
			f.fashion_editorial.checked ||
			f.fashion_runway.checked ||
			f.fashion_catalog.checked ||
			f.fashion_print.checked ||
			f.fashion_showroom.checked ||
			f.fashion_lingeries.checked ||
			f.fashion_fitness.checked ||
			f.fashion_fit.checked ||
			f.fashion_tearoom.checked ||
			f.fashion_bodypart.checked
		);
	} else if (type == 'commercial') {
		f.commercial_available.checked = (
			f.commercial_product.checked ||
			f.commercial_lifestyle.checked ||
			f.commercial_corporate.checked ||
			f.commercial_demo.checked ||
			f.commercial_tradeshow.checked
		);
	} else if (type == 'glamour') {
		f.glamour_available.checked = (
			f.glamour_lingerie.checked ||
			f.glamour_art_nude.checked ||
			f.glamour_adult.checked
		);
	}
}

function getmessagecost(form_id, send_to_type, sentmessages) {
	//send_to_type = userlevel
	
	var f = document.forms[form_id];
	//if (send_to_type)
	//	type = send_to_type;
	//else
	//	type = 0;
	
	if (send_to_type == 1 && sentmessages >= 1)
		cost = 0.3;
	else if (send_to_type == 2 && sentmessages >= 5)
		cost = 0.2;
	else if (send_to_type == 3 && sentmessages >= 15)
		cost = 0.1;
	else
		cost = 0;
	
	// 20071120 //20070904
	//cost = 0;
	
	// pagal tipus nenaudojam
	//if (type == 1 || type == 7 || type == 10 || type == 14)
	//	cost = 0.2;
	//else if (type == 9 || type == 20 || type == 21)
	//	cost = 0.1;
	//else if (type == 3 || type == 4 || type == 5 || type == 6 || type == 8 || type == 11 || 
	//	type == 12 || type == 13 || type == 15 || type == 16 || type == 17 || type == 18 || type == 19)
	//	cost = 0.5;
	//else
	//	cost = 0;
	//cost = 0.1;
	
	
	if (f.is_reply.value == 1)
		cost = 0;
	
	return cost;
}

function checkmessagecost(form_id,sentmessages) {
	var f = document.forms[form_id];
	if (f.userlevel)
		credits = getmessagecost('m_form', f.userlevel.value, sentmessages);
	//else if (f.message_to_type)
	//	credits = getmessagecost('m_form', f.message_to_type.value);
	else
		credits = 0;
	
	if (credits && f.is_reply.value != 1) {
		if (confirm('Sending this message will cost you '+credits+' credits. Are you sure you want to continue?'))
			f.submit();
	} else {
		f.submit();
	}
}

function externalMailSelect(clicked, type)
{
	switch (clicked)
	{
		case 'email':
			var hide = ['pid','oid'];
			break;
		case 'pid':
			var hide = ['email','oid'];
			break;
		case 'oid':
			var hide = ['email','pid'];
			break;
	}
	
	for(var i=0; i < hide.length; i++) {
		document.getElementById(type+'_'+hide[i]).className = 'hide';
		document.getElementById(type+'_'+hide[i]+'_a').className = 'link-inactive';
	}
	
	document.getElementById(type+'_'+clicked).className = 'show';
	document.getElementById(type+'_'+clicked+'_a').className = 'link-active';
}

function insertSample(str, shiftTimes)
{
	var find = ['$full_name', '$Dear'];
	var replace = ['Testas Testukas', 'Brangus'];
	
	str = str ? str : document.getElementById('tpl_text').innerHTML;
	shiftTimes = shiftTimes ? shiftTimes : 0;
	
	//alert('searching in: '+str);
	if (shiftTimes) {
		for (var xx = 0; xx < shiftTimes; xx++) {
			find.shift();
			replace.shift();
		}
	}
	
	for (var i=0; i < find.length; i++) {
		//alert('current: '+str);
		//alert('cycle '+shiftTimes+', i='+i);
		//alert('searchin for: '+find[i]);
		pos = str.indexOf(find[i]);
		newstr = "";
		if (pos == -1) {
			//alert('not found');
			newstr = str;
		} else {
			//alert('found');
			newstr += str.substring(0, pos) + replace[i];
			if ( pos + find[i].length < str.length)
				newstr += insertSample(str.substring(pos + find[i].length, str.length), i);
			str = newstr;
		}
	}
	//alert('returning: '+newstr);
	return newstr;
}

function toggleTplText(type)
{
	if (document.getElementById('tpl_text').className == 'show') {
		document.getElementById('tpl_text').className = 'hide' ;
		document.getElementById('org_tpl_text').className = 'show' ;
		document.getElementById('toddle_sapmle').innerHTML = 'View template';
	} else {
		document.getElementById('tpl_text').className = 'show';
		document.getElementById('org_tpl_text').className = 'hide';
		document.getElementById('toddle_sapmle').innerHTML = 'View sample';
	}
}

function toggleTplTags()
{
	if (document.getElementById('tpl_tags').className == 'hide') {
		document.getElementById('tpl_tags').className = 'show';
		document.getElementById('toggle_tags').innerHTML = 'Hide available placeholders';
	} else {
		document.getElementById('tpl_tags').className = 'hide';
		document.getElementById('toggle_tags').innerHTML = 'Show available placeholders';
	}
}


function toggleShow(checkbox, table_id)
{
	t_obj = document.getElementById(table_id);
	if (checkbox.checked)
	{
		//display table
		
		t_obj.style.display = 'block';
	}
	else
	{
		//hide table
		t_obj.style.display = 'none';
	}
}


function f_toggle_img(id, img_obj)
{
	var obj = document.getElementById(id);
	
	if (obj.style.display == 'none')
	{
		img_obj.src = 'http://www.jurgita.com/css/toggle_up.gif';
	}
	else
	{
		img_obj.src = 'http://www.jurgita.com/css/toggle_down.gif';
	}
	
}

function f_selectByValue(obj, type)
{
	if (obj)
	{
		for (i=0; i < obj.length; i++)
		{
			if (obj.options[i].value == type)
			{
				obj.options[i].selected = true;
				break;
			}
		}
	}
}

var win = null;
// onclick="popup(this.href,this.target,'300','400','yes');return false;"
function popup(url, title, width, height, scroll)
{
	pos_left = (screen.width) ? (screen.width-width) / 2 : 0;
	pos_top = (screen.height) ? (screen.height-height) / 2 : 0;
	win = window.open(url,title,'height='+height+',width='+width+',top='+pos_top+',left='+pos_left+',scrollbars='+scroll+',resizable')
}


function bookmark_site(url, title)
{
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
		window.external.AddFavorite(url,title);
	}
	else 
	{
		alert('Press CRTL+D to bookmark us!');
	}
}

function load_vip_photo(file, path, description, main, list, id)
{
	main_obj = document.getElementById(main)
	main_parent = 'photo'
	
	document.getElementById(main_parent).innerHTML = '<div style="padding: 50px; margin: auto; width:'+(parseInt(main_obj.width)-100)+'px;"><img src="http://www.jurgita.com/css/ajax-loader_tr.gif" alt="" title="" /></div>'
	
	images = document.getElementById(list).getElementsByTagName('img')
	for (var i=0;i<images.length;i++)
	{
		if (images[i].getAttribute('class') == 'photo48' || images[i].getAttribute('className') == 'photo48')
		{
			tmp_src = images[i].src
			tmp_file = tmp_src.substring(tmp_src.lastIndexOf('/')+1)
			if (tmp_file == file)
			{
				images[i].style.borderColor = '#86BADF'
			}
			else
			{
				images[i].style.borderColor = '#FFF'
			}
		}
	}
	document.getElementById('photo-desc').innerHTML = description //+ vote_form;
	f_load_main_photo(main_parent, 'http://www.jurgita.com'+path+'w422xh450/'+file, id)
}

function photo_vote(obj, id, vote)
{
	document.getElementById(obj).value = id+':'+vote
	document.getElementById(obj).parentNode.submit()
}

function getCookie( name ) 
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) 
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure )
{
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) 
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

function deleteCookie( name, path, domain ) 
{
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
function correctPNG()
{
	//do nothing
}
function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else {
		elm['on' + evType] = fn;
	}
}
function togglecheckbox(class_name, obj)
{
	if (obj.checked == true)
	{
		state = true;
	}
	else
	{
		state = false;
	}
	elems = document.getElementsByClassName(class_name);
	for (i=0;i<elems.length;i++)
	{
		elems[i].checked = state;
	}
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function aj_checkMail()
{
	Event.observe(window,'load',function(){cb_checkMail();});
	new PeriodicalExecuter(cb_checkMail, 900);
	
}
function cb_checkMail()
{
	new Ajax.Request('/ajax/mail-check-req.php', {
		method: 'post',
		onSuccess: function(transport) {
			if (transport.responseText != 0)
			{
				$('mail_status').innerHTML = '<b style="color:#C5281D;">('+transport.responseText+')</b>';
			}
		}
	});
}
