function Tip() {
	
}
function UnTip() {
	
}

function showMoreVMC(id)
	{
		if ($(id).style.display=='none')
			new Effect.BlindDown(id, {duration: 0.5});
		else
			new Effect.BlindUp(id, {duration: 0.5});
	}

/*
// �������������� ������� ��������
var trans = [];
for (var i = 0x410; i <= 0x44F; i++)
  trans[i] = i - 0x350; // �-��-�
trans[0x401] = 0xA8;    // �
trans[0x451] = 0xB8;    // �

// ��������� ����������� ������� escape()
var escapeOrig = window.escape;

// �������������� ������� escape()
window.escapeIE = function(str)
{
  var ret = [];
  var t = '';
  // ���������� ������ ����� ��������, ������� ��������� ���������
  //alert(unescape('%u0420%u2019'));
  for (var i = 0; i < str.length; i++)
  {
    var n = str.charCodeAt(i);
    
    //t += n + ' - ';
    if (typeof trans[n] != 'undefined') {
      n = trans[n];
    }
  if (n <= 0xFF)
      ret.push(n);
  }
  
  //return String.fromCharCode.apply(null, ret);
  return escapeOrig(String.fromCharCode.apply(null, ret));
}
*/

function trimlr(s)
{
	return s.replace(/^\s*(.*?)\s*$/, "$1");
}

function changedEducationPlan(epId) {
  var a = $$('.ss');
  if(a)
  {
    for(var i=0; i<a.length; i++)
    {
      a[i].enable();
    }
    if (epId != '') {
      if(ar[epId]!=undefined)
      {
        b = $('business_course_'+ar[epId]);
        if(b)
        {
          $('business_course_'+ar[epId]).disable();
        }
      }
    }
  }
}
function updateResSum(obj, val_obj, perc)
{
	var v = ($(val_obj).value)/100;
	var v = Math.abs(($(val_obj).value)) + Math.abs(v*perc);
	
	if( !isNaN(v) )
		obj.innerHTML = v.toFixed(2);
	else
		obj.innerHTML = '';
}

function onlyLatinCheckForm(msg, frm)
{
	if(!isOnlyLatin(frm.first_name.value)) {
		alert(msg);
		return false;
	}
	
	if(!isOnlyLatin(frm.last_name.value)) {
		alert(msg);
		return false; 
	}
	
}

function isOnlyLatin(str)
{
	var re = /^[a-z]+$/i;
    var result = re.test(str);
	return result;
}

function WT(date, time, add, ord)
{
	// $('top-date').setValue();
	this.date = date;
	this.time = time;
	this.add  = add;
	this.ord  = ord;
	this.lastTime = null;
}
WT.prototype.getDate = function() {
	if(this.ord == 0) {
		return "GMT " + this.time + this.add + " " + this.date;
	} else {
		return "GMT " + this.date + " " + this.time + this.add;
	}
}
WT.prototype.update = function() {
	new Ajax.Request('/home/getDate', {
	    method: 'get',
	    onSuccess: function(transport) {
			if($('topDate'))
				$('topDate').innerHTML = transport.responseText;
	    }
	  });	
}
WT.prototype.tic = function() {
	
	if($('topDate')) {
		var d = $('topDate').innerHTML;
		if ( d.indexOf(':') !== -1 ) {
			this.lastTime = d;
			d = d.replace(':',  "&nbsp;");
		} else {
			d = this.lastTime;
		}
		$('topDate').innerHTML = d;
	}
	
}

WTimer = new WT();

document.observe('dom:loaded', function(){  
	//$('topDate').html( "<b>!@#</b>" );
	if($('topDate')) {
		$('topDate').innerHTML = WTimer.getDate();
		window.setInterval('WTimer.update()', 50000);
		window.setInterval('WTimer.tic()', 1200);
	}
	//alert($('top-date'));
});  

/*
 function clockUpdate () {
    var now = new Date()
    var timeHH = now.getHours();
    var timeMM = now.getMinutes()
    var timeSS = now.getSeconds()
    var msec = now.getTime ()
    var timeSSm = msec - 1000 * Math.floor (msec / 1000)
    timeSSm = '00' + timeSSm
    timeSSm = timeSSm.substring(timeSSm.length-3, timeSSm.length)
    var timeString = ((timeHH < 10) ? '0' : '') + timeHH
                 + ':' + ((timeMM < 10) ? '0' : '') + timeMM
                 + ':' + ((timeSS < 10) ? '0' : '') + timeSS
                 + '.' + timeSSm
    if (this.output) {
        this.output.value = timeString
    } else {
        self.status = timeString
    }
}
 */
// For the flash menu

function FlashMenu() {
  // sfSimpleCMS IDs
  this.about              = 2;
  this.edu_process        = 3;
  this.terms_of_admission = 16;
	
  this.calc              = 25;
	
  this.inv_obj              = 12;
  this.inv_model              = 13;
  this.inv_ex              = 23; // !
  this.inv_res              = 15;
	
  this.webmeet              = 19;
  this.opportunity = 26;
  //this.pres_45 = 2;
  this.comp_ex = 27;
	
  this.course_description = 23;
	
  this.legal = 28;
  this.terms = 29;
	
}
FlashMenu.prototype.RedirectTo = function( to ) {
	
  var fm = this;
  var id = 0;
	
  switch(to)
  {
    case 'about':
      id = fm.about;
      break;
	  
    case 'edu_process':
      id = fm.edu_process;
      break;
	  
    case 'terms_of_admission':
      id = fm.terms_of_admission;
      break;
	  
    case 'calc':
      id = fm.calc;
      break;
	  
    case 'inv_obj':
      id = fm.inv_obj;
      break;
	  
    case 'inv_model':
      id = fm.inv_model;
      break;
	  
    case 'inv_ex':
      //id = fm.inv_ex;
      var url = '/lesson/show/id/8';
      var w = window.open(url);
      w.focus();
      return;
      break;
	  
    case 'inv_res':
      id = fm.inv_res;
      break;
	  
    case 'webmeet':
      id = fm.webmeet;
      break;
	  
    case 'opportunity':
      id = fm.opportunity;
      break;
	  
    case 'comp_ex':
      id = fm.comp_ex;
      break;
	  
    case 'course_description':
      id = fm.course_description;
      break;
	  
    case 'legal':
      id = fm.legal;
      break;
	  
    case 'terms':
      id = fm.terms;
      break;
	  
    case 'pres_45':
      //id = fm.pres_45;
      var url = 'http://www.amazon.com/Second-Presentation-That-Will-Change/dp/1933057327/ref=sr_1_2?ie=UTF8&s=books&qid=1223893768&sr=8-2';
      var w = window.open(url);
      w.focus();
      	
      return;
      break;
	  
  }

  
  new Ajax.Updater('middle-part', '/home/getPageUrl?id='+id, {
	    asynchronous :true,
	    evalScripts :true
	  });
  
  return;
  
  new Ajax.Request('/home/getPageUrl?id='+id, {
    method: 'get',
    onSuccess: function(transport) {
	  //alert(transport.responseText);
      $('middle-part').innerHTML = transport.responseText;
      						
      /*if(arguments.length == 2 && arguments[1] == 'same')
      {
      	$('middle-part').innerHTML = transport.responseText;
        //document.location.href = transport.responseText;
      }
      else
      {
        var w = window.open(transport.responseText);
        w.focus();
      }*/
    }
  });
}
fMenu = new FlashMenu();


// Video loading

function SlideVideo() {
  this.bigHeadID = 'top-big-head';
  this.smallHeadID = 'top-big-head-small';
	
  this.bigHeadFlashButtonID = 'logo-flash';
  this.bigLogoTextID = 'logo-text';
  this.bigLogoID = 'main-logo';
	
  this.smallHeadFlashButtonID = 'logo-flash-small';
  this.smallLogoTextID = 'logo-text-small';
  this.smallLogoID = 'main-logo-small';
	
  this.symfonyMethod = '/home/getVideo';
  this.State = null;
	
  this.startTime = 0;
  this.delay = 0;
  this.StateSetTo = null;
	
  this.showVideo = false;
}
SlideVideo.prototype.checkState = function() {
	
  if(this.delay && this.StateSetTo && this.startTime)
  {
    var d = new Date();
		
    if( (d.getTime() - this.startTime) > this.delay )
    {
      this.State = this.StateSetTo;
		
      this.delay = 0;
      this.StateSetTo = null;
      this.startTime = 0;
    }
  }
	
  if(!this.State)
    return;
		
  //alert(this.State);
  var s = this;
  switch(this.State)
  {
    case "redirect":
      s.redirect();
      break;
    case "BlindUpBigHeadBlindDownSmallHeadAndRedirect":
      s.BlindUpBigHeadBlindDownSmallHeadAndRedirect();
      break;
    case "BlindUpBigHeadBlindDownBigHeadWithVideo":
    	//alert("!");
      s.BlindUpBigHeadBlindDownBigHeadWithVideo();
      break;
    case "hideBigHeadFlashButtonID":
      s.hideBigHeadFlashButtonID();
      break;
    case "hideBigLogo":
      s.hideBigLogo();
      break;
    case "BlingUpBigHead":
      s.BlingUpBigHead();
      break;
    case "hideBigLogoText":
      s.hideBigLogoText();
      break;
    case "setVideoContent":
      s.setVideoContent();
      break;
    case "BlindDownBigHead":
      s.BlindDownBigHead();
      break;
    case "BlindDownSmallHead":
      s.BlindDownSmallHead();
      break;
    case "BlindUpSmallHeadBlindDownBigHeadWithVideo":
      s.BlindUpSmallHeadBlindDownBigHeadWithVideo();
      break;
  }
	
  this.State = null;
}

SlideVideo.prototype.setState = function( st ) {
  this.State = st;
}


SlideVideo.prototype.redirect = function() {
  //window.location.reload();
  window.location.href = '/education';
}

SlideVideo.prototype.HideBigHeadInfoShowVideo = function() 
{
  this.hideBigHeadFlashButton();
  this.hideBigLogoText();
  this.setVideoContent();
}

SlideVideo.prototype.BlindUpBigHeadBlindDownSmallHeadAndRedirect = function() {

  this.hideBigHeadFlashButton();
  this.hideBigLogoText();
  this.hideBigLogo();
	
  var d = new Date();
	
  this.delay = 350;
  this.startTime  = d.getTime();
  this.StateSetTo = "BlindDownSmallHead";
    
  this.State = null;
  this.showVideo = true;
    
  this.BlingUpBigHead();
	
/*
	this.hideFlashLogo();
	this.hideLogoText();
	this.hideLogo()
	setTimeout('Slide.hideHead()', 150);
	setTimeout('Slide.showMeSmall()', 600);
	setTimeout('Slide.redirect()', 1000);
	*/
}

SlideVideo.prototype.BlindUpSmallHeadBlindDownBigHeadWithVideo = function() {

  this.hideSmallHeadFlashButton();
  this.hideSmallLogoText();
  this.hideSmallLogo();
	
  var d = new Date();
	
  this.delay = 350;
  this.startTime  = d.getTime();
  this.StateSetTo = "BlindDownBigHead";
    
  this.State = null;
  this.showVideo = true;
    
  this.BlingUpSmallHead();
}


SlideVideo.prototype.BlindUpBigHeadBlindDownBigHeadWithVideo = function() {
	
  this.HideBigHeadInfoShowVideo();
	
/*
	this.hideBigHeadFlashButton();
	this.hideBigLogoText()
	
	var d = new Date();
	
	this.delay = 300;
    this.startTime  = d.getTime();
    this.StateSetTo = "BlindDownBigHead";
    this.showVideo = true;
    this.State = null;
    
	this.BlingUpBigHead();
	*/
	
/*
	setTimeout('Slide.hideHead()', 250);
	setTimeout('Slide.showMe()', 600);
	setTimeout('Slide.setVideoContent()', 1100);
	*/
}

SlideVideo.prototype.hideBigHeadFlashButton = function() {
  new Effect.Fade(this.bigHeadFlashButtonID, {
    duration :0.1
  });
}
SlideVideo.prototype.hideSmallHeadFlashButton = function() {
  var s = this;
  new Effect.Fade(s.smallHeadFlashButtonID, {
    duration :0.1
  });
}
SlideVideo.prototype.hideBigLogo = function() {
  new Effect.Fade(this.bigLogoID, {
    duration :0.1
  });
}
SlideVideo.prototype.hideSmallLogo = function() {
  var s = this;
  new Effect.Fade(s.smallLogoID, {
    duration :0.1
  });
}

SlideVideo.prototype.hideBigLogoText = function() {
  $(this.bigLogoTextID).innerHTML = '';
}
SlideVideo.prototype.hideSmallLogoText = function() {
  $(this.smallLogoTextID).innerHTML = '';
}

SlideVideo.prototype.BlingUpBigHead = function() {
  var s = this;
  new Effect.BlindUp(s.bigHeadID, {
    duration :0.3
  });
}

SlideVideo.prototype.BlingUpSmallHead = function() {
  var s = this;
  new Effect.BlindUp(s.smallHeadID, {
    duration :0.3
  });
}

SlideVideo.prototype.setVideoContent = function() {
  var s = this;
  $(s.bigLogoTextID).setStyle( {
    marginTop :'0',
    paddingTop :'0'
  });
  new Ajax.Updater(s.bigLogoTextID, s.symfonyMethod, {
    asynchronous :true,
    evalScripts :true
  });
}

SlideVideo.prototype.BlindDownBigHead = function() {
  var s = this;
  s.State = null;
  if(s.showVideo)
  {
    s.State = null;
    s.showVideo = false;
    var d = new Date();
    s.delay = 550;
    s.startTime  = d.getTime();
    s.StateSetTo = "setVideoContent";
  }
  new Effect.BlindDown(s.bigHeadID, {
    duration :0.5
  });
}
SlideVideo.prototype.BlindDownSmallHead = function() {
  var s = this;
	
  this.State = null;
	
  var d = new Date();
  this.delay = 550;
  this.startTime  = d.getTime();
  this.StateSetTo = "redirect";
    
  new Effect.BlindDown(s.smallHeadID, {
    duration :0.5
  });
    
}

Slide = new SlideVideo;

//Slide.setState('BlindUpBigHeadBlindDownSmallHeadAndRedirect');

slideInt = setInterval("Slide.checkState()", 500);

function addInputSubmitEvent(form, input) {
  input.onkeydown = function(e) {
    e = e || window.event;
    if (e.keyCode == 13) {
      form.onsubmit();
      return false;
    }
  };
}

function addInputEnterCustomFuncEvent(func, id) {
	  input = $(id);
	  if(!input) return;
	  
	  input.onkeydown = function(e) {
	    e = e || window.event;
	    if (e.keyCode == 13) {
	      //eval(func);
	      window[func]();
	      return false;
	    }
	  };
	}

window.onload = function() {
  var form = $('login_form');
  if(form)
  {
    var inputs = form.getElementsByTagName('input');
    for (var j=0;j < inputs.length;j++)
      addInputSubmitEvent(form, inputs[j]);
  }
};

/**
 * edit user go tab
 */
var activeTab = 0;
function editUserGoTab(tab) {
  Effect.Shrink('tab'+activeTab);
  activeTab = tab;
  Effect.Grow('tab'+activeTab);
}
