// JavaScript Document

/**********************
  Displays Message
  Created: Paul Carlton
  Updated for jQuery
**********************/
//jQuery.noConflict();



var AjaxRequest={
	post:function( obj )
	{
		//deprecate once blog information comes in
		if( obj.constructor.toString().match(/string/i)!=null )
		{
			//Serialized form data FORM DATA
			var tmp=data.split('&');
			for( var j=0;j<tmp.length;j++ ){
				var dat=tmp[j].split('=');
				Args[dat[0]]=dat[1];
			}
			obj=Args;
		}

		jQuery.postJSON = function(url, data){  //optional callback parameter not needed
		    jQuery.ajax({
			'url': url,
			'type': 'post',
			'processData': false,
			'data': JSON.stringify(data),
			contentType: 'application/json',
			success: function (data) { AjaxRequest.parseResponse(JSON.parse(data)); },
		    });
		};

		jQuery.postJSON('process.php',{'ajax':true,'data':JSON.stringify(obj)});

		
	},
	parseResponse:function( Commands )
	{
	}
}




function drop(n){
	if( n!==false )
	{
		jQ='#'+n+'-submenu';
		var t=jQuery(jQ).css('display');
		if( t=='none' )jQuery(jQ).css('display','block');
		else jQuery(jQ).css('display','none');
	}
	//alert(jQuery('#'+cmonth+'-submenu').css('display'));
	if( n===false )if( cmonth!='' )jQuery('#'+cmonth+'-submenu').css('display','block')
}
function submitLanguage(val)
{
	if (val=='')return;
	href=location.href.toString();
	var tmp=href.split(/\?/);
	location.href=tmp[0]+'?lang='+val;
}
var navUnderline=function( id ){ jQuery('#'+id).css('text-decoration','underline'); }
var navNoUnderline=function( id ){ jQuery('#'+id).css('text-decoration','underline'); }
function navHighlight( navig )
{
	var nav=navig;
	jQuery('ul#menusystem a').each(function(  ){
		var id=jQuery(this).attr('id');
		if( nav === '' )navUnderline('home');
		if( nav === id )passSwitch( navUnderline );
		else passSwitch( navNoUnderline );
	});
	function passSwitch( funct )
	{
		switch( nav )
		{
			case 'home':funct(nav);break;
			case 'services':funct('services');break;
			case 'process':funct('services');break;
			case 'design':funct('services');break;
			case 'development':funct('services');break;
			case 'vitae':funct('services');break;
			case 'blog':funct(nav);break;
			case 'apod':funct(nav);break;
			default:break;
		}
	}
}





Message={
	interval:false,
	interval2:false,
	timer:true,
	int:5,
	show:function(message,type,opt)
	{
		this.init( type , opt );
		if(!opt)div_id='_MESSAGE';
		else div_id=opt;
		if( this.timer === true || (this.interval !== false && this.timer===false) )
			message='<b>'+message+'</b><br />This Message will self destruct in: <span id="selfDestruct">'+this.int+'</span> seconds.';
		else message='<b>'+message+'</b>';
		$(div_id).innerHTML=message;
	},
	setIntervals:function( boolean ){ this.timer=(boolean===true||boolean===false)?boolean:true; },
	init:function( type , opt)
	{
		clearInterval(this.interval);
		clearInterval(this.interval2);
		if(!opt)div_id='_MESSAGE';
		else div_id=opt;
		$(div_id).style.display='block';
		$(div_id).setAttribute( 'class' , type );
		var scrolls=GPS.get(div_id);
		this.int=8;
		window.scrollTo(0,scrolls[1]);
		Effect.Pulsate(div_id,{pulses:1,duration:0.5});
		if( this.timer === true ){
			this.interval=setInterval( 'Message.fade("'+div_id+'");' , (this.int*1000) );
			this.interval2=setInterval( 'Message.selfDestruct();', 1000 );
		}
	},
	fade:function( div_id )
	{
		try{$('selfDestruct').innerHTML=0;}
		catch(e){}
		clearInterval(this.interval);
		clearInterval(this.interval2);
		Effect.Fade(div_id,{duration:1});
	},
	hide:function( opt )
	{
		try{$('selfDestruct').innerHTML=0;}
		catch(e){}
		clearInterval(this.interval);
		clearInterval(this.interval2);
		if(!opt)div_id='_MESSAGE';
		else div_id=opt;
		$(div_id).style.display='none';
		//Effect.Fade(div_id,{duration:1});
	},
	selfDestruct:function(  )
	{
		this.int--;
		try{$('selfDestruct').innerHTML=this.int;}
		catch(e){ }
	}
};

var GPS={
	//gets where the element STARTS
	get:function(obj)
	{
		var curleft = curtop = 0;
		do{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
		while (obj = obj.offsetParent);
		return [curleft,curtop];
	},
	//gets the height of the element
	height:function( obj ){ return obj.offsetHeight; },
	width:function( obj ){ return obj.offsetWidth; },
	widthHeight:function( obj ){ return [obj.offsetWidth,obj.offsetHeight]; }
};



/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Base64 ={
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
	// public method for encoding
	encode : function (input)
	{
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
		input = Base64._utf8_encode(input);
		while (i < input.length)
		{
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
		}
		return output;
	},
	// public method for decoding
	decode : function (input)
	{
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
		while (i < input.length)
		{
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
			output = output + String.fromCharCode(chr1);
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
		}
		output = Base64._utf8_decode(output);
		return output;
	},
	// private method for UTF-8 encoding
	_utf8_encode : function (string)
	{
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
		for (var n = 0; n < string.length; n++)
		{
			var c = string.charCodeAt(n);
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	},
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext)
	{
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		while ( i < utftext.length )
		{
			c = utftext.charCodeAt(i);
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}






function validateEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   //var addresss = document.forms[form_id].elements[email].value;
   var address=email;
   if(reg.test(address) === false) {
      //alert('Invalid Email Address');
      return false;
   } else return true;
}
function cap(a){
	b=[];
	a=a.replace(/_/,' ');
	v=a.split(' ');
	for(var j=0;j<v.length;j++)
		b.push(v[j].substr(0,1).toUpperCase()+v[j].substr(1).toLowerCase());
	return b.join(' ');
}
function decode(str) {
     var result = "";
     for (var i = 0; i < str.length; i++) {
          if (str.charAt(i) == "+") result += " ";
          else result += str.charAt(i);
     }
     return unescape(result);
}
