// so the jquery doesnt conflict with prototype
var $j = jQuery.noConflict();
var balloon = 0;
var isIE = (document.all) ? true : false;

$j(document).ready
(
  function() 
  {
  	$j('#dock').Fisheye
    (
  		{
				maxWidth: 25,
				items: 'a',
				itemsText: 'span',
				container: '.dock-container',
				itemWidth: 80,
				proximity: 80,
				alignment : 'left',
				valign: 'bottom',
				halign : 'center'
  		}
  	)
  	
  	$j(".fq").click
    (
  		function ()
      {
  			$j(".fq").removeClass('active');
  			$j(this).addClass('active');
  			ieFix($j(this).html(), $j(this).next().html());
  			//$j("#balloon").html($j(this).next().html());
  		}		   
  	);
  	
  	$j("#pabou #team a").click
    (
  		function ()
      {
  			$j('#pabou #team_detail div').removeClass('show');
  			arrT = this.href.split('#');
  			$j("#"+arrT[1]).addClass('show');
  			$j("#pabou #team a").removeClass('active');
  			$j(this).addClass('active');
  		}					   
  	);
  	
  	$j("#inside-menu a").click
    (
  		function ()
      {
  			$j('.shcontent').removeClass('show');
  			//arrT2 = this.href.split('#');
  			arrT2 = $j(this).attr("href").split('#')
  			$j("#"+arrT2[1]).addClass('show');
  			$j("#inside_menu a").removeClass('active');
  			$j(this).addClass('active');
  		}					   
  	);
  }
);

function ieFix(header, code)
{
  if (isIE)
    var html = code.split('</H1>');
  else
    var html = code.split('</h1>');
  var p = html[1];
	document.getElementById('balloon_h1').innerHTML = header;
	document.getElementById('balloon_p').innerHTML = p;
}

function loadSignIn()
{
  if (top != window)
  {
    document.member_form.action = prodDomain +"/ItzBig.aspx?cm=8&refid="+ top.refid;
    document.rec_form.action = recDomain +"/ItzBig.aspx?cm=8&refid="+ top.refid;  
  }
  else
  {
    document.member_form.action = prodDomain +"/ItzBig.aspx?cm=8";
    document.rec_form.action = recDomain +"/ItzBig.aspx?cm=8";
  }
  if (document.getElementById('precr')) 
  {
    var f = chkCkeOnLoad('R','itzbigreccke','rec_form');
    if(f != null)
    {
      act('recruiters'); 
      f.submit();
    }
    else
    {
      act('recruiters');
    }
  }
  else
  {
    var f = chkCkeOnLoad('S','itzbigseekcke','member_form');
    if(f != null)
    {
      act('candidates');
      f.submit();
    }
    else
    {
      act('candidates');
    }
  }  
}

function toggle(id)
{
	document.getElementById('input-'+id).style.display = "none";
	document.getElementById('pass-'+id).style.display = "block";  
	if (id == 'candidates')
    document.getElementById('email_S').focus();
  else
    document.getElementById('email_R').focus();
}

function act(id)
{
	document.getElementById('signin-candidates').style.display = "none";
	document.getElementById('signin-recruiters').style.display = "none";
	document.getElementById('pass-'+id).style.display = "none";
	document.getElementById('input-'+id).style.display = "block";  
	document.getElementById('signin-'+id).style.display = "block";
	if (id == 'candidates')
    document.getElementById('email1').focus();
  else
    document.getElementById('email2').focus();
}

var passId = 'S';
function recoverPassword(id)
{
  var verifyEmail = /^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
  var email = document.getElementById('email_'+ id).value;
  if (!verifyEmail.test(email))
  {
    var d = document.getElementById('pass_err_'+ id);
    d.style.color = "red";
    d.innerHTML = "You entered an invalid email address.<br />Please try again.";
  }
  else
  {
    passId = id
	  new Ajax.Request(getWebServiceURL("getPassword"), { postBody: "email="+ email +"&type="+ id, onSuccess: recoverSuccess, onFailure: eglc });
  }
}

function recoverSuccess(r)
{
	var obj = se(r);
  if (obj == 0)
  {
    var msg = "<div style='text-align: center; font-size: 1.5em; overflow: visible; margin: -20px 0 -5px 0;'>Your password was sent to your email.</div>";
    if (passId == 'S')
    {
      document.getElementById('member_error').innerHTML = msg;
      act('candidates');
    }
    else
    {
      document.getElementById('rec_error').innerHTML = msg;
      act('recruiters');
    }
  }
  else
  {
    var d = document.getElementById('pass_err_'+ passId);
    d.style.color = "red";
    d.innerHTML = "The email address you entered was not found.<br />Please try again.";
  }
}


function selectTab(from)
{
  if (from == 'R') 
  {
    var f = chkCkeOnLoad('R','itzbigreccke','rec_form');
    if(f != null)
    {
      act('recruiters'); 
      f.submit();
    }
    else
    {
      act('recruiters');
    }
  }
  else
  {
    var f = chkCkeOnLoad('S','itzbigseekcke','member_form');
    if(f != null)
    {
      act('candidates');
      f.submit();
    }
    else
    {
      act('candidates');
    }
  }  
}

// ********************* code pasted from cookie.js ****************************
var ckeNameS = 'itzbigseekcke';
var ckeNameR = 'itzbigreccke';
var daysCke = 15;
var sepCke = '<&>';
//var flagAutoCke = false;

function chkCkeOnLoad(from,ckeName,formName)
{
    var f = document.forms[formName];
    
    var ckeValue = '';		
	if(from == 'S')
	{
	    ckeValue = readCke(ckeName);	
	    if(ckeValue != '' )
	    {
	        var splitCke = ckeValue.split(sepCke);
	        email = splitCke[0]; 
	        f.email.value = email;   	    
            pwd = splitCke[1];   
            f.password.value = pwd;   
            
            return f;  
	    }
	    
	 }
	 else if(from == 'R')
	 {
	    ckeValue = readCke(ckeName);	
	    if(ckeValue != '' )
	    {
	        var splitCke = ckeValue.split(sepCke);
	        email = splitCke[0];  
	        f.email.value = email;   	      	    
            pwd = splitCke[1];  
            f.password.value = pwd;  
            return f;      
	    }
	    
	 }
	 
	 return null;
}	 
	

function checkCke(ckeName,chkID,email,pwd)
{
    var ckeValue = readCke(ckeName);
    if(ckeValue == '' )
	{
	        setCke(ckeName,email + sepCke + pwd,daysCke);	  
	}else
	{	
	    //alert('cookie Found');    
	    if($(chkID)!= null && $(chkID).checked == false  )
	    {
	        removeCke();	        
	    }else
	    {
	        var splitCke = ckeValue.split(sepCke);
	        var emailCke = splitCke[0];  
	        if(emailCke != email)
	        {
	            setCke(ckeName,email + sepCke + pwd,daysCke);	            
	        }
	        
	    }
	}
}

function readCke(name) 
{
      var nameSG = name + "=";
      var nuller = '';
      if (document.cookie.indexOf(nameSG) == -1)
        return nuller;

      var ca = document.cookie.split(';');
      for(var i=0; i<ca.length; i++) 
      {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameSG) == 0) return decodeCke(c.substring(nameSG.length,c.length)); 
      }
    return nuller; 
}

function setCke(name,value,days) 
{             
  if (days) 
  {
       var date = new Date();
       date.setTime(date.getTime()+(days*24*60*60*1000));
       var expires = "; expires="+date.toGMTString(); 
   }
   else var expires = "";
   document.cookie = name +"="+ encodeCke(value) + expires+"; path=/"; 
   //alert('cookie Set');
 }
 
 function removeCke()
 {
    setCke(ckeName,'',-1);
    //alert('cookie Deleted');
 }
 
 function encodeCke(ckevalue) {

  // This variable holds the encoded cookie characters
  var coded_string = ""
  
  // Run through each character in the cookie value
  for (var counter = 0; counter < ckevalue.length; counter++) {
  
    // Add the character's numeric code to the string
    coded_string += ckevalue.charCodeAt(counter)
    
    // Separate each code with a plus sign (+)
    if (counter < ckevalue.length - 1) {
      coded_string += "+"
    }
  }
  return coded_string
}


function decodeCke(coded_string) {

  // This variable holds the decoded cookie value
  var ckevalue = ""
  
  // Use + to split the coded string into an array
  var code_array = coded_string.split("+")
  
  // Loop through the array
  for (var counter = 0; counter < code_array.length; counter++) {

    // Convert the code into a character and 
    // add it to the cookie value string
    ckevalue += String.fromCharCode(code_array[counter])
  }
  return ckevalue
}


