var STATIC_HOST;
var noPageLoad = 0; // global which says if pageLoad have not really to load page, ugly solution :-(
var alertId = 0;
var subMenuDivId = 'subMenuDiv'; // DOM id of div showing submenu
var subMenuClosedClass = 'showmenu'; // class of link for submenu activation
var subMenuOpenedClass = 'hidemenu'; // class of link for submenu deactivation
var subMenuTopOffset = -7; // how many pixels should subMenu be placed from top border of the opening link
var subMenuLeftOffset = 10; // how many pixels should subMenu be placed from left border of the opening link
var subMenuUlClass = 'subsubmenu'; // css class for UL tag of submenu options
var subMenuLastLiClass = 'last'; // css class for bottom (last on the list) LI tag of submenu options
var subMenuNamesSeparator = '^^^'; // string separating option names
var subMenuActionsSeparator = '^^^'; // string separating option actions
var subMenuActivHref = ''; // string view submenu 
var CREDITS_MULTIPLIER = 100000; // credit multiplier
var MODAL_SPEED = 'fast';
var BASE_HTTP_HOST;


//for prevent 2 load page without hash
var historyInit = true;

// if utterance change set TRUE
var modUt = false;

// debug function
function showdbg(s) {
	if ($('#myDebug').length == 0) {
		jQuery('\
<div id="myDebug" style="position: absolute; top: 0px; right: 0px; \
width: 220px; border: 1px solid black; background: lightgrey;"> \
JS Debug: <a href="javascript: $(\'#myDebug\').remove(); void null;">X</a> <br /> \
</div>').prependTo('body');
	}
	jQuery('#myDebug').append('<div class="br">' + s + '</span><br />');
}



function loadProjectToFlash(id,name,text,allow)
{
	getFlashMovieObject("flasheditor").loadProject(id,name,text,allow);
}
function setUTRules(arr)
{
	getFlashMovieObject("flasheditor").setRulesArray(arr);
}
function getRules()
{
	setUTRules(userRules_pl)
}
function setNewRule(wcenter,wvalue,wstat)
{
	alert("\n Wcenter: "+wcenter+"\n\n Wvalue:"+wvalue+"\n\n Wstat:"+wstat)
}

// center button
function centerButton(id) {
	var button = document.getElementById(id);
	button.style.position="relative";
	var parentpadding = 16;
	var	poz=((button.parentNode.offsetWidth - parentpadding - button.offsetWidth) / 2);
	button = document.getElementById("boxpubuttonpoz");
	if(poz<20){
		poz=((button.parentNode.offsetWidth - parentpadding - button.offsetWidth) / 2);
	}
	button.style.padding = "0 0 0 "+ poz + "px";
}

// trim string
// by Steven Levithan (http://blog.stevenlevithan.com/archives/faster-trim-javascript)
function trim(str) {
	var str = str.replace(/^\s\s*/, ''), ws = /\s/, i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

function getCenterWindows(idpopup){
	var IE = (document.all && !window.opera)?true:false;
	var tempsX = 0;
	var tempsY = 0;
	var tempoX = 0;
  var tempoY = 0;	
  var centerX = 0;
	var centerY = 0;
  
	if (IE) {
		tempoX = document.documentElement.clientWidth;
		tempoY = document.documentElement.clientHeight;
		tempsX = document.documentElement.scrollLeft;
		tempsY = document.documentElement.scrollTop;
	}
	else {
		tempoX = window.innerWidth;
		tempoY = window.innerHeight;
		tempsX = window.pageXOffset;
		tempsY = window.pageYOffset;
	}

	centerX = Math.round(tempoX/2)+tempsX-(Math.round(jQuery('#'+idpopup).attr("offsetWidth")/2));
	centerY = Math.round(tempoY/2)+tempsY-(Math.round(jQuery('#'+idpopup).attr("offsetHeight")/2));

	return new Array(centerX,centerY);

}


function getScrollObject(){
	var pozScrool = 0;
	if(jQuery('#dictAddModW').attr('scrollTop')!=undefined)
		pozScrool =	jQuery('#dictAddModW').attr('scrollTop');
	return pozScrool;
}


// close alert box
function closeAlertBox(){
	jQuery('#alertbox').css("visibility","hidden");
}

function sPrompt(sPre, sPost, promptParam, otherParams, defValue) {
	jQuery('#alertbox_header').html(langSett.question);
	jQuery('#alertbox_content').html(sPre+'<input id="alertboxprompt" style="width:270px" maxlength="30" type="text" value="'+defValue+'"/>'+sPost+'<span id="boxpubuttonpoz" style="display:block"><a href="javascript:closeAlertBox(); prompt=trim(document.getElementById(\'alertboxprompt\').value); if(prompt.length>0) ajaxCall(\''+promptParam+'=\'+encodeURIComponent(prompt)+\''+otherParams+'\', false); void null;" class="rgbutton-19" name="alertboxpubutton" id="alertboxpubutton"><span>'+langSett.ok+'</span></a></span>');
	centerButton('alertboxpubutton');
	poz = getCenterWindows('alertbox');
	jQuery('#alertbox').css({left:+poz[0]+"px",top:+poz[1]+"px",visibility:"visible"});

	document.getElementById('alertboxprompt').focus();
	document.getElementById('alertboxprompt').select();
	// enter keypress reaction (same as click on 'ok' button)
	jQuery('#alertboxprompt').keypress(function (e) {
			if (e.which == 13) {
				closeAlertBox();
				prompt=trim(document.getElementById('alertboxprompt').value);
				if(prompt.length>0)
					ajaxCall(promptParam+'='+encodeURIComponent(prompt)+otherParams, false);
			}
		});
}

function sMove(sPre, sPost, promptParam, otherParams, defValue) {
	var choose = 0;
	jQuery('#alertbox_header').html(langSett.move);
	tmp = sPre + '<select id="selmove" >';
	for(id in otherParams){
		tmp += '<option value="'+id+'">'+otherParams[id]+'</option>';
	}
	tmp += '</select>'+sPost+'<span id="boxpubuttonpoz" style="display:block">'
			+'<a href="javascript:closeAlertBox(); choose=document.getElementById(\'selmove\').value; ajaxCall(\''+promptParam+'&amp;toCat=\'+choose, false); void null;" class="rgbutton-19" name="alertboxpubutton" id="alertboxpubutton"><span>'+langSett.ok+'</span></a></span>';
	jQuery('#alertbox_content').html(tmp);
	centerButton('alertboxpubutton');
	poz = getCenterWindows('alertbox');
	jQuery('#alertbox').css({left:+poz[0]+"px",top:+poz[1]+"px",visibility:"visible"});
}


function sAlert(s) {
	jQuery('#alertbox_header').html(langSett.notice);
	jQuery('#alertbox_content').html(s+'<br /><span id="boxpubuttonpoz" style="display:block"><a href="javascript:closeAlertBox();void null;" class="rgbutton-19" id="alertboxpubutton"><span>'+langSett.ok+'</span></a></span>');
	centerButton('alertboxpubutton');
	poz = getCenterWindows('alertbox');
	jQuery('#alertbox').css({left:+poz[0]+"px",top:+poz[1]+"px",visibility:"visible"});
	jQuery('#alertboxpubutton').focus();
}

function sError(s) {
	jQuery('#alertbox_header').html(langSett.warning);
	jQuery('#alertbox_content').html('<strong>'+s+'</strong><br /><span id="boxpubuttonpoz" style="display:block"><a href="javascript:closeAlertBox();void null;" class="rgbutton-19" id="alertboxpubutton"><span>'+langSett.ok+'</span></a></span>');
	centerButton('alertboxpubutton');
	poz = getCenterWindows('alertbox');
	jQuery('#alertbox').css({left:+poz[0]+"px",top:+poz[1]+"px",visibility:"visible"});
	jQuery('#alertboxpubutton').focus();
}

function sErrorNew(s) {

	jQuery('#infopopup').html('<div class="confirmation"><div class="bc"><a href="javascript:sErrorNewClose(); void null;" style="text-decoration:none;"><div class="button left">'+langSett.ok+'</div></a></div><div class="text">'+s+'</div><div class="head">'+langSett.warning+'</div><div class="close" onclick="sErrorNewClose();"></div></div></div>');

	poz = getCenterWindows('infopopup');
	jQuery('#infopopup').css({left:+poz[0]+"px",top:+poz[1]+"px",visibility:"visible"});

}

function sErrorNewClose() {
	jQuery('#infopopup').css({visibility:"hidden"});
}


function sErrorAjax(s,param) {
	jQuery('#alertbox_header').html(langSett.warning);
	jQuery('#alertbox_content').html('<strong>'+s+'</strong><br /><span id="boxpubuttonpoz" style="display:block"><a href="javascript:ajaxCall(\''+param+'\',false); closeAlertBox(); void null;" class="rgbutton-19" id="alertboxpubutton"><span>'+langSett.ok+'</span></a></span>');
	centerButton('alertboxpubutton');
	poz = getCenterWindows('alertbox');
	jQuery('#alertbox').css({left:+poz[0]+"px",top:+poz[1]+"px",visibility:"visible"});
	jQuery('#alertboxpubutton').focus();
}

function sModalConfirm(message, callback){
	jQuery('#modConfirm').modal({
			containerCss: {height: '155px', width:'385px', left:'50%', margin:'0px auto 0px -192px' },						
			onOpen: function (dialog) {
				dialog.overlay.fadeIn(MODAL_SPEED, function () {
					dialog.container.slideDown(MODAL_SPEED, function () {
						dialog.data.fadeIn(MODAL_SPEED);
						dialog.container.css('position', 'absolute');
					});
				});
			},
			onShow: function (dialog) {
				dialog.data.find('.message').append(message);
				// if the user clicks "yes"
				dialog.data.find('.yes').click(function () {
					// call the callback
					if (jQuery.isFunction(callback)) {
						callback.apply();
					}
					// close the dialog
					//jQuery.modal.close();
					dialog.data.fadeOut(MODAL_SPEED, function () {
						dialog.container.slideUp(MODAL_SPEED, function () {
							dialog.overlay.fadeOut(MODAL_SPEED, function () {
	  						jQuery.modal.close(); // must call this to have SimpleModal                    
							});
						});
					});
				});
			},
			onClose: function (dialog) {
				dialog.data.fadeOut(MODAL_SPEED, function () {
					dialog.container.slideUp(MODAL_SPEED, function () {
						dialog.overlay.fadeOut(MODAL_SPEED, function () {
  						jQuery.modal.close(); // must call this to have SimpleModal                    
						});
					});
				});
			}
		});				
}

function sModalError(message){
	jQuery('#modError').modal({
			containerCss: {height: '155px', width:'385px', left:'50%', margin:'0px auto 0px -192px' },						
			onOpen: function (dialog) {
				dialog.overlay.fadeIn(MODAL_SPEED, function () {
					dialog.container.slideDown(MODAL_SPEED, function () {
						dialog.data.fadeIn(MODAL_SPEED);
						dialog.container.css('position', 'absolute');
					});
				});
			},
			onShow: function (dialog) {
				dialog.data.find('.message').append(message);				
			},
			onClose: function (dialog) {
				dialog.data.fadeOut(MODAL_SPEED, function () {
					dialog.container.slideUp(MODAL_SPEED, function () {
						dialog.overlay.fadeOut(MODAL_SPEED, function () {
  						jQuery.modal.close(); // must call this to have SimpleModal                    
						});
					});
				});
			}
		});				
}

function sModalOk(message){
	jQuery('#modOk').modal({
			containerCss: {height: '155px', width:'385px', left:'50%', margin:'0px auto 0px -192px' },						
			onOpen: function (dialog) {
				dialog.overlay.fadeIn(MODAL_SPEED, function () {
					dialog.container.slideDown(MODAL_SPEED, function () {
						dialog.data.fadeIn(MODAL_SPEED);
						dialog.container.css('position', 'absolute');
					});
				});
			},
			onShow: function (dialog) {
				dialog.data.find('.message').append(message);				
			},
			onClose: function (dialog) {
				dialog.data.fadeOut(MODAL_SPEED, function () {
					dialog.container.slideUp(MODAL_SPEED, function () {
						dialog.overlay.fadeOut(MODAL_SPEED, function () {
  						jQuery.modal.close(); // must call this to have SimpleModal                    
						});
					});
				});
			}
		});				
}

function sConfirm(s, callback) {
	jQuery('#alertbox_header').html(langSett.confirmation);
	jQuery('#alertbox_content').html(s+'<br /><div id="butdiv"><a href="javascript:'+callback+'; closeAlertBox();void null;" id="but1" class="rgbutton-19-2"><span>'+langSett.yes+'</span></a> '
			+'<a href="javascript:closeAlertBox(); void null;" id="but2" class="rgbutton-19-2"><span>'+langSett.no+'</span></a></div>');

	// Center button
	button = document.getElementById("butdiv");
	butH1 = document.getElementById("but1");
	butH2 = document.getElementById("but2");
	button.style.position="relative";
	butH1.style.position="relative";
	butH2.style.position="relative";
	parentpadding = 16;
	button.style.left = (button.parentNode.offsetWidth - butH1.offsetWidth - butH2.offsetWidth - parentpadding - 24) / 2 + "px";
	//butH1.style.left = '80px';
	//butH2.style.left = '120px';

	poz = getCenterWindows('alertbox');
	jQuery('#alertbox').css({left:+poz[0]+"px",top:+poz[1]+"px",visibility:"visible"});

	return false;
}

function initFileUploads() {

	var W3CDOM = (document.createElement && document.getElementsByTagName);
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}

function sConfirmNew(title,text,callbackYes){

	if(title == ''){
		title=langSett.confirmation;
	}

	jQuery('#infopopup').html('<div class="confirmation"><div class="bc"><a href="javascript:'+callbackYes+' sConfirmNewClose(); void null;" style="text-decoration:none;"><div class="button left">'+langSett.yes+'</div></a><div class="button right"><a href="javascript:sConfirmNewClose(); void null;" style="text-decoration:none;">'+langSett.no+'</a></div></div><div class="text">'+text+'</div><div class="head">'+title+'</div><div class="close" onclick="sConfirmNewClose();"></div></div>');

	poz = getCenterWindows('infopopup');
	jQuery('#infopopup').css({left:+poz[0]+"px",top:+poz[1]+"px",visibility:"visible"});
	jQuery('#infopopup').show();


}

function sConfirmNewClose() {
	
	jQuery('#infopopup').css({visibility:"hidden"});
	jQuery('#modalClose').click();

}

function sModUt(s, yes, no) {
	jQuery('#alertbox_header').html(langSett.confirmation);
	jQuery('#alertbox_content').html(s+'<br /><div id="butdiv"><a href="javascript:'+yes+'; closeAlertBox();void null;" id="but1" class="rgbutton-19-2"><span>'+langSett.yes+'</span></a> '
			+'<a href="javascript:'+no+'; closeAlertBox(); void null;" id="but2" class="rgbutton-19-2"><span>'+langSett.no+'</span></a></div>');

	// Center button
	button = document.getElementById("butdiv");
	butH1 = document.getElementById("but1");
	butH2 = document.getElementById("but2");
	button.style.position="relative";
	butH1.style.position="relative";
	butH2.style.position="relative";
	parentpadding = 16;
	button.style.left = (button.parentNode.offsetWidth - butH1.offsetWidth - butH2.offsetWidth - parentpadding - 24) / 2 + "px";
	//butH1.style.left = '80px';
	//butH2.style.left = '120px';
	poz = getCenterWindows('alertbox');
	jQuery('#alertbox').css({left:+poz[0]+"px",top:+poz[1]+"px",visibility:"visible"});

	return false;
}


function sModalUt(message, yes, no){
	jQuery('#modUtConfirm').modal({
			containerCss: {height: '155px', width:'385px', left:'50%', margin:'0px auto 0px -192px' },						
			onOpen: function (dialog) {
				dialog.overlay.fadeIn(MODAL_SPEED, function () {
					dialog.container.slideDown(MODAL_SPEED, function () {
						dialog.data.fadeIn(MODAL_SPEED);
						dialog.container.css('position', 'absolute');
					});
				});
			},
			onShow: function (dialog) {
				dialog.data.find('.message').append(message);				
				
				// if the user clicks "yes"
				dialog.data.find('.yes').click(function () {
					// call the callback
					if (jQuery.isFunction(yes)) {
						yes.apply();
					}
					// close the dialog
					//jQuery.modal.close();
					dialog.data.fadeOut(MODAL_SPEED, function () {
						dialog.container.slideUp(MODAL_SPEED, function () {
							dialog.overlay.fadeOut(MODAL_SPEED, function () {
	  						jQuery.modal.close(); // must call this to have SimpleModal                    
							});
						});
					});
				});				
				// if the user clicks "no"
				dialog.data.find('.no').click(function () {
					// call the callback
					if (jQuery.isFunction(no)) {
						no.apply();
					}
					//jQuery.modal.close();
					// close the dialog
					jQuery.modal.close();
					//dialog.data.fadeOut(MODAL_SPEED, function () {
						//dialog.container.slideUp(MODAL_SPEED, function () {
							//dialog.overlay.fadeOut(MODAL_SPEED, function () {
	  						//jQuery.modal.close(); // must call this to have SimpleModal                    
							//});
						//});
					//});
				});
				
			},
			onClose: function (dialog) {				
				dialog.data.fadeOut(MODAL_SPEED, function () {
					dialog.container.slideUp(MODAL_SPEED, function () {
						dialog.overlay.fadeOut(MODAL_SPEED, function () {
  						jQuery.modal.close(); // must call this to have SimpleModal                    
						});
					});
				});
			}
		});				
}


function ajaxCall ( hash, withHistory ) {
	//withHistory=false;
	if (withHistory == undefined)
		withHistory = true;
	if (withHistory){
		jQuery.history.load(hash);
	}
	else
		jQuery.ajax( { data : hash } );
}

function addHistory ( hash ) {
	if (jQuery.history.callback != undefined)
		jQuery.history.load(hash);
}

function pageload(hash) {
	uri = jQuery(location).get(0).toString();
	uri = uri.replace(/^.*\//, '');
	uri = uri.replace(/#.*$/, '');
	query = uri.replace(/^.*\?/, '');
	uri = uri.replace(/\?.*$/, '');

	hash = hash.replace(/^.*#/, '');
	
	if(hash) {
		ajaxCall( hash, false );
	}
}

function makeVoices( lang ) {
	for( i in listIdVoice){
		var idik = "#void" + i;
		var start = true;
		if(listIdVoice[i][0] == lang){
			jQuery(idik).css("display", "block");
			if(start){
				start = false;
				jQuery('#voiceIdH').attr("value", i);
				jQuery('#voiceId').attr("value", listIdVoice[i][1]);
			}
		}
		else
			jQuery(idik).css("display", "none");
	}
}



// UTTER FUNCTIONS - START

function utterListToChange() {
	jQUtter = jQuery('#utter_id');
	if (jQUtter.length == 0)
		return;
	linkId = '#uLLink_'+jQUtter.val();
	if ((cat_id = jQuery('#cat_id').val()) != undefined)
		linkId += '_'+cat_id;

	jQuery('a[id^=uLLink]').removeClass('br').removeClass('nolink');
	jQuery(linkId).addClass('br').addClass('nolink');
}

function utterLink(utter_id) {
	if(modUt){
		sModalUt(messageModUt
				,function(){ jQuery('#utterAddMod').ajaxSubmit(optionSub); }
				,function(){ ajaxCall('utter_id='+utter_id+'&utterEdit=1&delC=1', (0==utter_id ? false : true));});
	}
	else{		
		ajaxCall('utter_id='+utter_id+'&utterEdit=1&delC=1', (0==utter_id ? false : true) );
	}
}

function checkProject( link ){
	if(modUt){
		sModalUt(messageModUt
				,function(){ jQuery('#utterAddMod').ajaxSubmit(optionSub); }
				,function(){ window.location = link; });
	}
	else{		
		if('http'!=link.substring(0,4)){
			window.location = 'http://'+BASE_HTTP_HOST+'/'+link;
		} else {
			window.location = link;
		}
	}
}

function utterDel(utter_id) {
	ajaxCall( 'utterDel='+utter_id+(jQuery('#utter_id').val() == utter_id ? '&utterEditEmpty=1' : ''), false);
}

function selectTab(nr){
	if( 2 == nr ){
		jQuery('#tabLic').removeClass('whitetab');
		jQuery('#tabLic').addClass('blacktab');

		jQuery('#tabUtt').removeClass('blacktab');
		jQuery('#tabUtt').addClass('whitetab');
	}
	else if( 1 == nr ){
		jQuery('#tabUtt').removeClass('whitetab');
		jQuery('#tabUtt').addClass('blacktab');

		jQuery('#tabLic').removeClass('blacktab');
		jQuery('#tabLic').addClass('whitetab');
	}
}

function utterEditTab(nr) {

	if('block'==jQuery('#utterAbout').css('display')){
		modUt = false;
	 	return;
	}

	activ=1;
	if ( nr == 2) {
		if(modUt){
			sModUt(messageModUt
				,"jQuery('#utterAddMod').ajaxSubmit(optionSub);"
				,"selectTab("+nr+"); ajaxCall('utter_id='+jQuery('#utter_id').val()+'&utterEdit=2&activ='+activ, true);");
		}
		else{
			selectTab(nr);
			ajaxCall('utter_id='+jQuery('#utter_id').val()+'&utterEdit=2&activ='+activ, true);
		}
	}
	else if ( nr == 1) {
		if(modUt){
			sModUt(messageModUt
				,"jQuery('#utterAddMod').ajaxSubmit(optionSub);"
				,"selectTab("+nr+"); ajaxCall('utter_id='+jQuery('#utter_id').val()+'&utterEdit=1&activ='+activ, true);");
		}
		else{
			modUt = false;
			selectTab(nr);
			ajaxCall('utter_id='+jQuery('#utter_id').val()+'&utterEdit=1&activ='+activ, true);
		}
	}
}

function utterEditTabToChange() {
	if (!(uE1 = document.getElementById('utterEditTab1'))
		|| !(uE2 = document.getElementById('utterEditTab2')))
		return;

	if (!(utter_id = document.getElementById('utter_id'))
		 || utter_id.value == 0) {
		uE1.className = 'br nolink';
		uE2.className = 'nolink';
	}
	else {
		if (document.getElementById('utterAddMod')) {
			uE1.className = 'br nolink';
			uE2.className = 'a';
		}
		else if (document.getElementById('utterLicenses')) {
			uE1.className = 'a';
			uE2.className = 'br nolink';
		}
		else {
			uE1.className = 'a';
			uE2.className = 'a';
		}
	}
}

function dlvAdd(vtId, downloadType, licenseType, addCredits, price, addPrice) {
	//alert( vtId +' : '+ downloadType +' : '+ licenseType +' : '+ addCredits +' : '+  price +' : '+ addPrice );
	ajaxCall( 'utter_id='+jQuery('#utter_id').val()+'&dlvAdd='+vtId+','+downloadType+','+licenseType+','+addCredits+','+price+','+addPrice, false );	
}

function dlvAddDls(dlv_id, dlsChange, credits) {
	ajaxCall( 'utter_id='+jQuery('#utter_id').val()+'&dlv_id='+dlv_id+'&dlvAddDls='+dlsChange+'&dlvCredits='+credits, false );
}

function dlvDel(dlv_id) {
	ajaxCall( 'utter_id='+jQuery('#utter_id').val()+'&dlvDel='+dlv_id, false );
}

// UTTER FUNCTIONS - END

function userDel(){
	ajaxCall('userDel=1',false);
}

function checkEmail( nameEl, nameTxtEl, valueTxtEl ){
  var emailFormat = /^[-\w](\.?[-\w])*@[-\w](\.?[-\w])*\.[a-z]{2,4}$/i;
  if( (document.getElementById(nameEl).value=="") || (!emailFormat.test(document.getElementById(nameEl).value)) ){
    changeTxt( nameTxtEl, valueTxtEl );
    return false;
  }
  else{
    changeTxt( nameTxtEl, "" );
    return true;
  }
}

function checkLogin( nameEl, nameTxtEl, valueTxtEl ){
  var loginFormat = /^[a-zA-Z0-9]{3,}$/i;
  if( !loginFormat.test(document.getElementById(nameEl).value) ){
    changeTxt( nameTxtEl, valueTxtEl);
    return false;
  }
  else{
    changeTxt( nameTxtEl, "");
    return true;
  }
}

function checkPass( name1El, name2El, nameTxtEl, value1TxtEl, value2TxtEl){
  var passFormat = /^[a-zA-Z0-9`~!@#\$%\^&\*\(\)-_\+=\[\]\{\}\\\|;:'",<>\.\?\/]{3,}$/i;
  if( !passFormat.test(document.getElementById(name1El).value) ){
    changeTxt( nameTxtEl, value1TxtEl );
    return false;
  }
  else if( document.getElementById(name1El).value != document.getElementById(name2El).value ){
    changeTxt( nameTxtEl, value2TxtEl );
    return false;
  }
  else{
    changeTxt( nameTxtEl, "");
    return true;
  }
}




// activate/deactivate submenu handling function
function subMenu(a, namesList, actionsList) {
	aHref = document.getElementById(a);	
	if (aHref.className == subMenuOpenedClass) {
		closeSubMenus();
		return;
	}
	showSubMenu(a, namesList, actionsList);


}

// show submenu
function showSubMenu(a, namesList, actionsList) {
	// close other existing submenus
	closeSubMenus();
	var subMenuDiv = document.getElementById(subMenuDivId);
	var aHref = document.getElementById(a);
	// change class of link to show that menu is open
	aHref.className = subMenuOpenedClass;
	// separate submenu options from each other
	var names = namesList.split(subMenuNamesSeparator);
	var actions = actionsList.split(subMenuActionsSeparator);

	var menuHtml = '<ul class="'+subMenuUlClass+'">';
	// build submenu options
	for (var i = 0; i < names.length; i++) {
		// last li need to have other class
		if (i == names.length-1) {
			menuHtml += '<li class="'+subMenuLastLiClass+'">';
		} else {
			menuHtml += '<li>';
		}
		menuHtml += '<a href="javascript:'+actions[i]+'; closeSubMenus(); void null;">'+names[i]+'</a></li>';
	}

	menuHtml += '</ul>';
	subMenuDiv.innerHTML = menuHtml;
	var aHrefPos = findObjectPosition(aHref);

	var existID = a.indexOf('wordl');
	var scrollTopId = 0;
	if(existID != -1){
		 scrollTopId = getScrollObject();
	}

	subMenuDiv.style.top = parseInt(aHrefPos[1]+subMenuTopOffset-scrollTopId)+'px';
	subMenuDiv.style.left = parseInt(aHrefPos[0]+subMenuLeftOffset)+'px';
	subMenuDiv.style.display='block';

	subMenuActivHref = aHref;
}

// close existing submenus
function closeSubMenus() {

	return;
	if(document.getElementById(subMenuDivId)==null)
		return false;

	var subMenuDiv = document.getElementById(subMenuDivId);
	subMenuDiv.style.display='none';

	if(subMenuActivHref!=''){
		if(subMenuActivHref.className == subMenuOpenedClass){
			subMenuActivHref.className = subMenuClosedClass;
		}

		subMenuActivHref = '';
	}
}

// find position of an object on page
function findObjectPosition(obj) {
	var objTop = 0; // how far from top
	var objLeft = 0; // how far from left

	// loop trough parent positions adding their offsets
	while (obj.offsetParent) {
		objTop += obj.offsetTop;
		objLeft += obj.offsetLeft;
		obj = obj.offsetParent
	}
	return new Array(objLeft, objTop);
}


function setActive( id ){
	jQuery('div').removeClass("active");
	jQuery('li').removeClass("active");
	obj = '#' + id;
	jQuery(obj).addClass("active");
}

function remActive(){
	jQuery('div').removeClass("active");
}

function setChosen( id ){
	jQuery('li').removeClass("chosen");
	obj = '#' + id;
	jQuery(obj).addClass("chosen");
}

function remChosen(){
	jQuery('li').removeClass("chosen");
}


function addslashes(str) {
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\0/g,'\\0');
	return str;
}

function validator(string){
	if(string==undefined)
		return false;
	return true;
}

function htmlspecialchars(string){
	if(!validator(string))
		return '';

	string = string.replace(/>/g,'&gt;');
	string  = string.replace(/</g,'&lt;');
	return string;
}

function unhtmlspecialchars(string){
	if(!validator(string))
		return '';

	string = string.replace(/&gt;/g,'>');
	string  = string.replace(/&lt;/g,'<');
	return string;
}

function sendSubmit( id ) {
	obj = '#' + id;
	jQuery(obj).submit();
}






//
function in_array( what, where ){
	var test = 1;
	for(id in where){
		if(what == where[id])
			return true;
	}
	return false;
}

function makePrice(currency, price){
	if('PLN' == currency){
		return ' ' + (String(price)).replace(/\./, ",") + ' zł';
	}
	else if('EUR' == currency){
		return ' &#8364;' + price;
	}
	else{
		return ' $' + price;
	}
	return;
}

// visualise credits
function visCredits(credits) {

	credits = credits/CREDITS_MULTIPLIER;
	if(credits<0.01 && credits>0) {
	        credits = 0.01;
	}
	credits=Math.ceil(credits*100)/100;
	return sprintf("%7.2f",credits);

}

/**
*
*  Javascript sprintf
*  http://www.webtoolkit.info/
*
*
**/
sprintfWrapper = {

	init : function () {

		if (typeof arguments == "undefined") { return null; }
		if (arguments.length < 1) { return null; }
		if (typeof arguments[0] != "string") { return null; }
		if (typeof RegExp == "undefined") { return null; }

		var string = arguments[0];
		var exp = new RegExp(/(%([%]|(\-)?(\+|\x20)?(0)?(\d+)?(\.(\d)?)?([bcdfosxX])))/g);
		var matches = new Array();
		var strings = new Array();
		var convCount = 0;
		var stringPosStart = 0;
		var stringPosEnd = 0;
		var matchPosEnd = 0;
		var newString = '';
		var match = null;

		while (match = exp.exec(string)) {
			if (match[9]) { convCount += 1; }

			stringPosStart = matchPosEnd;
			stringPosEnd = exp.lastIndex - match[0].length;
			strings[strings.length] = string.substring(stringPosStart, stringPosEnd);

			matchPosEnd = exp.lastIndex;
			matches[matches.length] = {
				match: match[0],
				left: match[3] ? true : false,
				sign: match[4] || '',
				pad: match[5] || ' ',
				min: match[6] || 0,
				precision: match[8],
				code: match[9] || '%',
				negative: parseInt(arguments[convCount]) < 0 ? true : false,
				argument: String(arguments[convCount])
			};
		}
		strings[strings.length] = string.substring(matchPosEnd);

		if (matches.length == 0) { return string; }
		if ((arguments.length - 1) < convCount) { return null; }

		var code = null;
		var match = null;
		var i = null;

		for (i=0; i<matches.length; i++) {

			if (matches[i].code == '%') { substitution = '%' }
			else if (matches[i].code == 'b') {
				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(2));
				substitution = sprintfWrapper.convert(matches[i], true);
			}
			else if (matches[i].code == 'c') {
				matches[i].argument = String(String.fromCharCode(parseInt(Math.abs(parseInt(matches[i].argument)))));
				substitution = sprintfWrapper.convert(matches[i], true);
			}
			else if (matches[i].code == 'd') {
				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)));
				substitution = sprintfWrapper.convert(matches[i]);
			}
			else if (matches[i].code == 'f') {
				matches[i].argument = String(Math.abs(parseFloat(matches[i].argument)).toFixed(matches[i].precision ? matches[i].precision : 6));
				substitution = sprintfWrapper.convert(matches[i]);
			}
			else if (matches[i].code == 'o') {
				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(8));
				substitution = sprintfWrapper.convert(matches[i]);
			}
			else if (matches[i].code == 's') {
				matches[i].argument = matches[i].argument.substring(0, matches[i].precision ? matches[i].precision : matches[i].argument.length)
				substitution = sprintfWrapper.convert(matches[i], true);
			}
			else if (matches[i].code == 'x') {
				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(16));
				substitution = sprintfWrapper.convert(matches[i]);
			}
			else if (matches[i].code == 'X') {
				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(16));
				substitution = sprintfWrapper.convert(matches[i]).toUpperCase();
			}
			else {
				substitution = matches[i].match;
			}

			newString += strings[i];
			newString += substitution;

		}
		newString += strings[i];

		return newString;

	},

	convert : function(match, nosign){
		if (nosign) {
			match.sign = '';
		} else {
			match.sign = match.negative ? '-' : match.sign;
		}
		var l = match.min - match.argument.length + 1 - match.sign.length;
		var pad = new Array(l < 0 ? 0 : l).join(match.pad);
		if (!match.left) {
			if (match.pad == "0" || nosign) {
				return match.sign + pad + match.argument;
			} else {
				return pad + match.sign + match.argument;
			}
		} else {
			if (match.pad == "0" || nosign) {
				return match.sign + match.argument + pad.replace(/0/g, ' ');
			} else {
				return match.sign + match.argument + pad;
			}
		}
	}
}

sprintf = sprintfWrapper.init;

function hideMenu(){
	closeSubMenus();
}

function hideLangVoice(){
	jQuery('#langList').hide();
	jQuery('#voiceList').hide();
	jQuery('.liLanglist').removeClass('selLang');
	jQuery('.liVoicelist').removeClass('selVoice');
	voiceSelect=-1;
	langSelect=-1;
}

jQuery(document).ready(function(){
});


function showErrorLog(text) {
	jQuery('div').removeClass('regError');
	jQuery('#errorLog').html(text);
	jQuery('#errorLog').show();
	
	return;
}

function replaceAllEnter(text){
	text = text.replace(/\r\n/gi," ");
	text = text.replace(/\r/gi," ");
	text = text.replace(/\n/gi," ");
	return text;
}

function copyClipboard(label,info){

	var flashvars = {};
	flashvars.label = label;
	flashvars.info = info;
	flashvars.element = "#p1";
	flashvars.flashid = "copier1";
	var flashvars2 = {};
	flashvars2.label = label;
	flashvars2.info = info;
	flashvars2.element = "#p2";
	flashvars2.flashid = "copier2";
	var attributes = {
id: "copier1",
		name: "copier1"
	};
	var attributes2 = {
id: "copier2",
		name: "copier2"
	};
	var params = {};
	params.quality = "autohigh";
	params.swliveconnect = "true";
	params.wmode = 'transparent';
	params.AllowScriptAccess = "always";

	swfobject.embedSWF(STATIC_HOST+"flash/copier.swf?v=1.1.2.3", "flashcopier1", "116", "21", "9.0.0",STATIC_HOST+"flash/expressInstall.swf", flashvars, params, attributes);
	swfobject.embedSWF(STATIC_HOST+"flash/copier.swf?v=1.1.2.3", "flashcopier2", "116", "21", "9.0.0",STATIC_HOST+"flash/expressInstall.swf", flashvars2, params, attributes2);

}




function showTotalFunc(curr,minCurr) {

	jQuery('#hostPriceD').show();
	jQuery('#hostClicks').show();
	jQuery('#noLoginDiv').show(); 
	jQuery('#noLoginDiv1').show();

	if(jQuery('#chkAddClicks')[0].checked) {
		var totalPrice = visCredits(parseInt(jQuery('#synthPrice').val())+parseInt(jQuery('#clicksPrice').val()));
		jQuery('#hostPriceD').show();
	} else {
		var totalPrice = visCredits(parseInt(jQuery('#synthPrice').val()));
		jQuery('#hostPriceD').hide();                                                                                                         
	}
	var hostPrice = visCredits(parseInt(jQuery('#clicksPrice').val()));

	jQuery('#totalPrice').html(makePrice(''+curr+'',totalPrice));     
	jQuery('#realPrice').html(makePrice(''+curr+'',totalPrice));
	jQuery('#hostPrice').html(makePrice(''+curr+'',hostPrice));

	if( 'free' == jQuery('#selectedLicense').attr('value') ){
		jQuery('#clicksPrice').attr('value', '0');
                if(jQuery('#chkAddClicks')[0].checked){
			jQuery('#additionalClicks').attr('value', '-1000');
		} else {
			jQuery('#additionalClicks').attr('value', '0');
		}
		jQuery('#totalPrice').html(makePrice(''+curr+'', visCredits(0)));
		jQuery('#realPrice').html(makePrice(''+curr+'', visCredits(0)));
		jQuery('#hostPrice').html(makePrice(''+curr+'', visCredits(0)));
		jQuery('#hostPriceD').hide();
		jQuery('#hostClicks').hide();                                                                                                          		 jQuery('#realPriceD').hide();
		if(!noLogin){
			jQuery('#noLoginDiv').hide();
			jQuery('#noLoginDiv1').hide();                                                                                                         }
			return;
	}


	if (noLogin && (parseInt(totalPrice)<minCurr)) {
		jQuery('#totalPrice').html(makePrice(''+curr+'',visCredits(''+minCurr*CREDITS_MULTIPLIER+''))+'*');
		jQuery('#realPrice').html(makePrice(''+curr+'',totalPrice));
		jQuery('#hostPrice').html(makePrice(''+curr+'',hostPrice));
		jQuery('#realPriceD').show();
	} else {
		jQuery('#realPriceD').hide();
		jQuery('#noLoginDiv').hide();
		jQuery('#noLoginDiv1').hide();
	}
	if(noLogin){
		jQuery('#noLoginDiv').show();
		jQuery('#noLoginDiv1').show();
	}

}

