function SwitchMylink() {
  	var buttons = document.getElementById('linkButtons').getElementsByTagName("img");
	var img_link = document.getElementById('linkMe').getElementsByTagName("a");
	var img_src = document.getElementById('linkMe').getElementsByTagName("img");

	for(var i=0; i<buttons.length; i++) {
		var button = buttons[i];
		button.onclick = function() {
			img_link[0].href='gfx/models/normal/'+this.id;
			img_src[0].src='gfx/models/midi/'+this.id;
		}
	}
}

var global_i = 1;

onerror=handleErr

function handleErr(msg,url,l)
{
//Handle the error here
return true;
}

function ImageChanger(dir) {
	if(dir == 'forward') {
		global_i++;
		if(global_i > 9)
			global_i = 1;
	}	
	if(dir == 'back') {
		global_i--;
		if(global_i < 1)
			global_i = 9;
	}
		
	var desc 		= new Array();
	var imgHandler 	= document.getElementById('changePic');
	var descHandler = document.getElementById('changeDesc');
	
	desc[1] 		= 'Adriana Recchi - Events P.A.';
	desc[2] 		= 'Chialin Chiang - Stylist';
	desc[3] 		= 'Cris Casza - Acessorisses De';
	desc[4] 		= 'Eliana Dias - Model';
	desc[5] 		= 'Fabianne Semprebom - Model';
	desc[6] 		= 'Helder - model';
	desc[7] 		= 'José Camaro - Stylist';
	desc[8] 		= 'Marcelo Otaviano - Fashion';
	desc[9] 		= 'Marina Dias - Model Events P';
	
	imgHandler.src 		  = 'gfx/sfw/0'+global_i+'.jpg';
	descHandler.innerHTML = desc[global_i];
}
function paging(page) {
	document.getElementById('next_page').value=page;
	document.getElementById('search').submit();
}
function colaps(element) {
	var rollMe = document.getElementById(element);
	if(rollMe.style.display == 'none') {
		rollMe.style.display = "block";
	} else {
		rollMe.style.display = "none";
	}
}
function pop(address,title,w,h) {
	var height	= 600;
	var width	= 800;
	if (h)
		height	= h;
	if (w)
		width 	= w;
	window.open(address, title, 'height='+height+',width='+width+',resizable=yes,scrollbars=yes,status=no');
}
function popup(address,title, width, height) {
  	window.open(address, 'mini', 'height='+height+',width='+width+',resizable=1,scrollbars=no');
}
function PostAction(action,id) {
	var postForm	= document.getElementById('shortlist');
	var postAction 	= document.getElementById('action');
	var postId 		= document.getElementById('edit_id');
	postAction.value	= action;
	postId.value		= id;
	
	postForm.submit();
}
function postAlertSearch(alertid) {
	
}
/*
* Otwiera popup z drukowaniem, emailowaniem i forwardowaniem zaznaczonych talentow
*
* @param string sesid Identyfikator sesji, potrzeby do przekazania aby sesja byla zachowana w nowym oknie pod IE
*/
function searchFuncTalents(sesid, action) {
	var selectedTalents = getSelectedTalents();
	if (selectedTalents.length == 1) {// akcja dla jednego talenta
		var fn = selectedTalents[0].name;
		popup('index.php5?sid='+sesid+'&do='+action+'&shortlist=0&talent='+fn.substring(7,fn.indexOf(']')), action,800,600);
	}
	else if (selectedTalents.length > 1) {	// print dla wiecej niz jednego talenta
		var talentsURL = '';
		for (var i = 0; i < selectedTalents.length; i++) {
			talentsURL += '&'+selectedTalents[i].name+'=1';
		}
		popup('index.php5?sid='+sesid+'&do='+action+'All&noshortlist=1&shortlist=0'+talentsURL, action+'All', 800, 600);
	}
}
function emailTalents(sesid) {
	
}
/*
*	Zwraca tablice zaznaczonych talentow
*/
function getSelectedTalents() {
	var inputs = document.getElementById('clientSearch').getElementsByTagName('input');
	var checked = new Array();
	var j = 0;
	for (var i = 0; i < inputs.length; i++) {
//		if (inputs[i].title == 'checked' && inputs[i].checked) {
		if (inputs[i] && inputs[i].checked) {
			checked[j] = inputs[i];
			j++;
		}
	}
	return checked;
}
function signupFinish() {
	document.getElementById('add_').value='1';
	document.getElementById('page_').value='3';
	document.getElementById('signupform').action ='?do=talentSignup&registred=1';
}
function signupFinisho(option) {
	document.getElementById('add_').value='1';
	document.getElementById('page_').value='3';
	document.getElementById('option_').value=option;
	document.getElementById('signupform').action ='?do=talentSignup&registred=1';
}
function $(id) {
	return document.getElementById(id);
}
/**
 * Ukrywa lub pokazuje pola charakterystyczne dla kobiet w formularzu wyszukiwania i face alert
 */
function setGirlField() {
	var il = $('girl_il');
	var ds = $('girl_ds');
	var cu = $('girl_cu');
	var female = $('female');
	if (female && il && ds) {
		if (female.checked) {
			cu.className = 'fieldsShown';
			il.className = 'fieldsShown';
			ds.className = 'fieldsShown';
		}
		else {
			cu.className = 'fieldsHidden';
			il.className = 'fieldsHidden';
			ds.className = 'fieldsHidden';
		}
	}
}
/*
 * Wyswietla wyniki wyszukiwania face alerta
 */
function postFaceAlertResults() {
	var dovar = $('do');			// pobieram wskaznik do kolejnej akcji
	var faceform = $('searchForm');	// pobieram formularz face alerta
	dovar.value = 'clientSeach';	// ten formularz bedzie wyswietlal wyniki a nie zapisywal face alerta
	faceform.submit();				// wyslij formularz
}
/**
 * 
 */
function add2ShortlistFunc(sesid) {
	var selectedTalents = getSelectedTalents();		// lista
	if (selectedTalents.length > 0) {
		var talentsURL = '';
		for (var i = 0; i < selectedTalents.length; i++) {
			talentsURL += '&'+selectedTalents[i].name+'=1';
		}
		popup('index.php5?sid='+sesid+'&do=clientAdd2Shortlist'+talentsURL, 'add2shortlist', 400, 185);
	}
}
/**
 * Wyswietla chmurke z podpowiedzia
 */
function cloud(that,t){
	that.title=''
	that.parentNode.getElementsByTagName('div')[0].style.display=t?'block':'none';
}
function cloudId(that,t,what){
	that.title=''
	document.getElementById(what).style.display=t?'block':'none';
}
function qm(that, disp) {
	//that.src = disp?'gfx/layout/qmo.gif':'gfx/layout/qm.gif';
	that.parentNode.getElementsByTagName('div')[0].style.display=disp?'block':'none';

	//if (disp)
	//	alert();
	//that.parentNode.lastChild.style.display=disp?'block':'none';
}

function qm2(that, disp) {
	that.parentNode.getElementsByTagName('span')[0].style.display=disp?'block':'none';
}
function showthunbail(pic_id) {
	var pic = document.getElementById('link_pic');
	var link = document.getElementById('showlink');
	if (pic) {
		pic.src = 'gfx/models/midi/'+pic_id;
		link.href = 'gfx/models/normal/'+pic_id;
	}
}

/**
 * Date w zlym formacie sprowadza do dobrego formatu
 */
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

/**
 * Odlicza roznice czasu od aktualnego do podanego i zapisuje efekt w obiekcie HTML
 */
function timeLeft(when, what) {
    var now = new Date();
    var difference = Date.UTC(y2k(when.getYear()),when.getMonth(),when.getDate(),when.getHours(),when.getMinutes(),when.getSeconds()) -
                     Date.UTC(y2k(now.getYear()),now.getMonth(),now.getDate(),now.getUTCHours(),now.getMinutes(),now.getSeconds())
    var daysDifference = Math.floor(difference/1000/60/60/24);
    difference = difference - daysDifference*1000*60*60*24
    var hoursDifference = Math.floor(difference/1000/60/60);
    difference = difference - hoursDifference*1000*60*60
    var minutesDifference = Math.floor(difference/1000/60);
    difference = difference - minutesDifference*1000*60
    var secondsDifference = Math.floor(difference/1000);
    if (daysDifference < 0) daysDifference = daysDifference * (-1);
    var fieldValue = daysDifference + ' day(s), ' + hoursDifference + ' hour(s), ' + 
                     minutesDifference + ' minute(s), ' + secondsDifference + ' second(s)';
	document.getElementById(what).innerHTML = fieldValue;
}
function timeLeftV2(when, what) {
    var now = new Date();
    var difference = Date.UTC(y2k(when.getUTCFullYear()),when.getUTCMonth(),when.getUTCDate(),when.getHours(),when.getUTCMinutes(),when.getUTCSeconds()) -
                     Date.UTC(y2k(now.getUTCFullYear()),now.getUTCMonth(),now.getUTCDate(),now.getUTCHours(),now.getUTCMinutes(),now.getUTCSeconds())
    var hoursDifference = Math.floor(difference/1000/60/60);
    difference = difference - hoursDifference*1000*60*60
    var minutesDifference = Math.floor(difference/1000/60);
    difference = difference - minutesDifference*1000*60
    var secondsDifference = Math.floor(difference/1000);
    var fieldValue = hoursDifference + ':' + 
                     (minutesDifference < 10 ? '0'+minutesDifference : minutesDifference)  + ':' + (secondsDifference < 10 ? '0'+secondsDifference : secondsDifference);
	document.getElementById(what).innerHTML = fieldValue;
}

function showDiv(id){
	$(id).style.display = 'block';
}

function hideDiv(id){
	$(id).style.display = 'none';
}

function proceedOn(that) {
	that.src='gfx/registration/proces_on.gif';
}

function proceedOff(that) {
	that.src='gfx/registration/proces.gif';
}

function accountSelected(option) {
	document.getElementById('add_').value='0';
	document.getElementById('page_').value='25';
	document.getElementById('option_').value=option;
}

// ExpressCheckout
function ECaccountSelected(option) {
	window.location = 'webapp/PPExpressCheckout.php5?type='+option+'';
}

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  

  return true
}

var curTname = '';

function triggerShowThumb(that, session, uid) {
	curTname = that.alt;
	id = that.id;
	setTimeout('showThumb('+'\''+that.alt+'\''+', \'' + id + '\', \'' + session + '\', \'' + uid + '\')',500);
}

function clearTname() {
	curTname = '';
}

function showThumb(tname, id, session, uid) {
	if (tname == curTname) {
		$('midiThumb').innerHTML = '<a style="cursor: pointer" onClick="javascript:popup(\'index.php5?sid='+session+'&do=clientTalentView&talent='+uid+'\', \'Viewtalent\',\'870\',\'600\')"><img src="/gfx/models/mini2/'+tname+'?' + new Date().getTime()+'" alt="'+tname+'" /></a>';
		$('midiThumb').style.top = (tempY-90)+'px'; //jak by cos sie sypało to tu wczesniej bylo 'px;(średnik)'
		$('midiThumb').style.left = (tempX-90)+'px';
		$('midiThumb').style.display = 'block';
	}
	//else
		//alert(tname+' != '+curTname);
}

function hideThumb() {
	$('midiThumb').style.display = 'none';
}

var curTnameT = '';

function triggerShowThumbT(that, session, uid) {
	curTnameT = that.alt;
	id = that.id;
	var titleA = that.title.split(':');
	var res = titleA[1].split('x');
	var widthThumb = parseInt(res[0])+20;
	var heightThumb = parseInt(res[1])+20;
	setTimeout('showThumbT('+'\''+that.alt+'\''+', \'' + id + '\', \'' + session + '\', \'' + uid + '\', \''+widthThumb+'\', \''+heightThumb+'\')',200);
}

function clearTnameT() {
	curTnameT = '';
}

function showThumbT(tname, id, session, uid, widthThumb, heightThumb) {
	if (tname == curTnameT) {
		$('midiThumb').innerHTML = '<a style="cursor: pointer" onClick="javascript:popup(\'/gfx/models/normal/'+tname+'\', \'Viewtalent\',\''+widthThumb+'\',\''+heightThumb+'\')"><img src="/gfx/models/mini2/'+tname+'?' + new Date().getTime()+'" alt="'+tname+'" /></a>';
		$('midiThumb').style.top = (tempY-90)+'px'; //jak by cos sie sypało to tu wczesniej bylo 'px;(średnik)'
		$('midiThumb').style.left = (tempX-90)+'px';
		$('midiThumb').style.display = 'block';
	}
	//else
		//alert(tname+' != '+curTname);
}

function hideThumbT() {
	$('midiThumb').style.display = 'none';
}


function triggerShowThumbForFA(that) {
	curTname = that.alt;
	id = that.id;
	setTimeout('showThumbForFA('+'\''+that.alt+'\''+', \'' + id + '\')',500);
}

function showThumbForFA(tname,id) {
	if (tname == curTname) {
		$('midiThumb').innerHTML = '<a href="http://www.modelsconnect.net/index.php5?do=clientTalentView&talent=' + id + '&fromFaceAlert=1"><img src="/gfx/models/mini2/'+tname+'?' + new Date().getTime()+'" alt="'+tname+'" /></a>';
		$('midiThumb').style.top = (tempY-90)+'px'; //jak by cos sie sypało to tu wczesniej bylo 'px;(średnik)'
		$('midiThumb').style.left = (tempX-90)+'px';
		$('midiThumb').style.display = 'block';
	}
}



//expands all skills
function expandAll(){
	for(var i = 1; i <= 5; i++){
		document.getElementById('s'+i).style.display = 'block';
		document.getElementById('show'+i).style.display = 'none';
	}
}

//expands one sklill
function expandOne(id){
	document.getElementById('s'+id).style.display = 'block';
	document.getElementById('show'+id).style.display = 'none';
}

//displays shop preveiws
//
//
var shopSrc = '';

function triShopShow(that){
	shopSrc = that.alt;
	setTimeout('showShop(\''+that.alt+'\')',500);
}
function showShop(aname){
	if (aname == shopSrc) {
		$('shopThumb').innerHTML = '<img style="cursor: pointer" src="/gfx/shop/'+aname+'.jpg'+'" alt="'+aname+'" />';
		$('shopThumb').style.top = (tempY-150)+'px'; //jak by cos sie sypało to tu wczesniej bylo 'px;(średnik)'
		$('shopThumb').style.left = (tempX-150)+'px';
		$('shopThumb').style.display = 'block';
	}
}
function shopHide(){
	shopSrc = '';
}
function shopHideThumb() {
	$('shopThumb').style.display = 'none';
}


/**

   Dynamic font sizer

**/
//Specify affected tags. Add or remove from list:
var tgs = new Array( 'div','td','tr', 'span', 'font', 'p');

//Specify spectrum of different font sizes:
var szs = new Array( 'x-small','','medium');
var startSz = 1;
var srcs = new Array( 'small', 'normal', 'big');

var activeSize = 1;

function ts( trgt,inc ) {
	if (!document.getElementById) return
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	
	activeSize = inc;
	
	for ( var ix = 0; ix <=2; ix++){
		if(ix == inc){
			$('size'+(ix+1)).src = '/gfx/layout/font_size/'+srcs[ix]+'_on.jpg';
		}else{
			$('size'+(ix+1)).src = '/gfx/layout/font_size/'+srcs[ix]+'_off.jpg';
		}
	}
	
	sz = inc;
	if ( sz < 0 ) sz = 0;
	if ( sz > (szs.length-1) ) sz = (szs.length-1);
	startSz = sz;
		
	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

	cEl.style.fontSize = szs[ sz ];

	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
	}
}


/**

	FOTM - Foace Of The Month

**/
function go(dir){
	if(dir == 1)
		current++;
	else if(dir == 0)
		current--;
	else current++;
	if(current==max && dir == 1)
		current = 0;
	if(current==0 && dir == 0)
		current = (max-1);
		
	$('fotm_picture').style.backgroundImage = 'url("'+arFotmImgList[current].src+'")';
	$('fotm_namesurname').innerHTML =  fotms[current]['name']+' '+fotms[current]['surname']+'.';
	$('fotm_age').innerHTML =  'Age:&nbsp;'+fotms[current]['birthdate'];
	$('fotm_height').innerHTML =  'Height:&nbsp;'+fotms[current]['height']+"&quot;";
	$('fotm_hips').innerHTML =  'Hips:&nbsp;'+fotms[current]['hips']+"&quot;";
	$('fotm_chest').innerHTML =  'Chest:&nbsp;'+fotms[current]['chest']+"&quot;";
	$('fotm_waist').innerHTML =  'Waist:&nbsp;'+fotms[current]['waist']+"&quot;";
}
function play(dir){
	var tmp = direction;
	switch(dir){
	case 0:
		active = 1;
		clearInterval(interval);
		activate(0); 
	break;
	case 1:
		active = 1;
		clearInterval(interval);
		activate(1); 
	break;
	case 2:
		active = 0;
		clearInterval(interval); 
	break;
	default:
		active = 1;
		activate(tmp); 
	break;
	}
}
function openFOTM(){
	window.location = 'fotm'+fotms[current]['user_id']+'.html';
}
function activate(dir){
	direction = dir;
	interval = window.setInterval("go("+dir+")", 6000);
}

/* Set Flash Main Page */
function setFlashMP() {
	var moovieArray = new Array('baner.swf','baner2.swf','baner3.swf','baner4.swf','baner5.swf','baner6.swf','baner7.swf');
	var randValue = Math.floor(Math.random() * moovieArray.length);
	var movie = '/gfx/v2/swf/'+moovieArray[randValue]; 	
	var emswf = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="637" height="200"><param name="movie" value="'+movie+'" /><param name="quality" value="high" /><param name="menu" value="false" /><param name="wmode" value="" /><embed src="'+movie+'" wmode="" quality="high" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="637" height="200"></embed>';
	//var empic = '<img style="vertical-align: top" src="gfx/layout/hello1.jpg" alt="Hello" width="210" height="200" />';
	if(document.getElementById('pictureFrame')){
	$('pictureFrame').innerHTML = emswf;
	}else document.write(emswf);
}
function aar(question, location) {	
	if(confirm(question))
		window.location = location;
}
/**
 * This script contains embed functions for common plugins. This scripts are complety free to use for any purpose.
 */

function writeFlash(p) {
	writeEmbed(
		'D27CDB6E-AE6D-11cf-96B8-444553540000',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'application/x-shockwave-flash',
		p
	);
}

function writeShockWave(p) {
	writeEmbed(
	'166B1BCA-3F9C-11CF-8075-444553540000',
	'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0',
	'application/x-director',
		p
	);
}

function writeQuickTime(p) {
	writeEmbed(
		'02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
		'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0',
		'video/quicktime',
		p
	);
}

function writeRealMedia(p) {
	writeEmbed(
		'CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'audio/x-pn-realaudio-plugin',
		p
	);
}

function writeWindowsMedia(p) {
	p.url = p.src;
	writeEmbed(
		'6BF52A52-394A-11D3-B153-00C04F79FAA6',
		'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',
		'application/x-mplayer2',
		p
	);
}

function writeEmbed(cls, cb, mt, p) {
	var h = '', n;

	h += '<object classid="clsid:' + cls + '" codebase="' + cb + '"';
	h += typeof(p.id) != "undefined" ? 'id="' + p.id + '"' : '';
	h += typeof(p.name) != "undefined" ? 'name="' + p.name + '"' : '';
	h += typeof(p.width) != "undefined" ? 'width="' + p.width + '"' : '';
	h += typeof(p.height) != "undefined" ? 'height="' + p.height + '"' : '';
	h += typeof(p.align) != "undefined" ? 'align="' + p.align + '"' : '';
	h += '>';

	for (n in p)
		h += '<param name="' + n + '" value="' + p[n] + '">';

	h += '<embed type="' + mt + '"';

	for (n in p)
		h += n + '="' + p[n] + '" ';

	h += '></embed></object>';

	document.write(h);
}

function advBar(element) {
	var rollMe = document.getElementById(element);
	var advField = document.getElementById('advancedOptions');
	//var pic = document.getElementById('switch_pic');
	
	if(rollMe.className == 'hidden') {
		advField.value="1";
		rollMe.className = "show";
		//pic.src="gfx/layout/client/more_opt_1.gif";
	} else {
		advField.value="0";
		rollMe.className = "hidden";
		//pic.src="gfx/layout/client/more_opt.gif";
	}
}

function randInt(){
	var rNum = Math.ceil(Math.random()*5);
	return rNum;
}