var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;


function setOpacity(elem, opacityAsInt) {  
	var opacityAsDecimal = opacityAsInt;
	if (opacityAsInt > 100) 
		opacityAsInt = opacityAsDecimal = 100;  
	else if (opacityAsInt < 0)  
		opacityAsInt = opacityAsDecimal = 0; 
	
	if (opacityAsInt < 1) 
		opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0
	opacityAsDecimal /= 100;
	document.getElementById(elem).style.opacity = (opacityAsDecimal); 
	document.getElementById(elem).style.filter = "alpha(opacity=" + opacityAsInt + ")";
}

function navSet(currPage, amount) {
	
	for (i=1;i<=10;i=i+1) {
		if (i != currPage) {
		
			setOpacity('main'+i,amount);
		}
	}
}

function navFade(currPage) {
	// This fucntion takes the current page we are on and fades the main nav items that are not needed for that page.   gives focus to the pages we are on.

	switch (currPage) {
		case 4: navSet(currPage,50);
		break;
		case 8: navSet(currPage,50);
		break;
		default: navSet(99,100);  // set all to 100% opacity
	}
}

function equalizePanels() {
	// this function makes sure that all panels, main nave, nav2 and content are of equal height
var col1 = $('leftCol');
var col2 = $('rightCol');
var col3 = $('mainCol');
var str='';
if (col1 != null) { col1h = Element.getHeight(col1); str+='col1h,';}
if (col2 != null) { col2h = Element.getHeight(col2); str+='col2h,';}
if (col3 != null) { col3h = Element.getHeight(col3); str+='col3h,';}
var str2 = rtrim(str,',') ;

	highest = Math.max(eval(str2));
	col1.style.height = highest + 'px';
	col2.style.height = highest+10 + 'px';
	col3.style.height = highest+30 + 'px';
	
}

function initTip(){
	jQuery(".tooltip-target").ezpz_tooltip();
	jQuery(".toolpic-target").ezpz_tooltip({
	contentPosition: 'aboveFollow'});
}

function pageit(actions, page, rpp, profileid) {
//	alert('here');
	var myAjax = new Ajax.Request(
			'flow.php?page='+page+'&action='+actions+'&rpp='+rpp, 
			{
				method: 'post', 
				asynchronous: true,  
				parameters: '', 
				onFailure: function (response) {  
                   $('showContent').update(response.statusText);
                     },  
				/*onLoading: function (response) {
                $('showContent').update('<span class="loading"><img src="_images/loading.gif" title="Loading..." alt="Loading..." border="0" /></span>')},*/
				onComplete: function(response) {
					result = response.responseText;
					$('showContent').update(result);
					initTip();
				//	resarray = result.split("**SPLIT**",2);
               	 //       $('showContent').update(resarray[0]);
				//		$('showNav').update(resarray[1]);
				//	$('showPeople').innerHTML = response.responseText;
				}
			});	
}


/* menu Code START */

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = jQuery(this).find('ul').eq(0).css('visibility', 'visible');}

function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}

jQuery(document).ready(function()
{	jQuery('#jsddm > li').bind('mouseover', jsddm_open);
	jQuery('#jsddm > li').bind('mouseout',  jsddm_timer);});

document.onclick = jsddm_close;

/* Menu CODE END */

function createCookie(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+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	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(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function sendFormAddComment(event) {  
	
                 // we stop the default submit behaviour  
				 $('commentFeedback').show();
                 var oOptions = {  
                     method: "POST",  
                     parameters: Form.serialize("signin"),  
                     asynchronous: true,  
                     onFailure: function (oXHR) {  
                         $('commentFeedback').update(oXHR.statusText);
                     },  
                     onLoading: function (oXHR) {
                         $('commentFeedback').update('<span class="saving"><img src="_images/loading.gif" title="Saving..." alt="Saving..." border="0" /></span>');  
                     },                            
                     onSuccess: function(oXHR) {  
                        $('commentFeedback').update(oXHR.responseText);
						 setTimeout(
							function() {
								Effect.Fade('commentFeedback');
								 $('name').value = '';
								 $('email').value = '';
								 $('message').value = '';
								 $('phone').value = '';
								 $('commentFeedback').update('');
								jQuery(".signin").removeClass("menu-open");
								jQuery("fieldset#signin_menu").fadeOut('slow');
			
							}, 4000
						);
						
                     }                 
                 };  
//				 var currdiaryid = 14;
                 var oRequest = new Ajax.Updater({success: oOptions.onSuccess.bindAsEventListener(oOptions)}, "dbmodify.php?action=contact", oOptions);             
   }  

function sendFormAddComment2(event) {  
	
                 // we stop the default submit behaviour  
				 $('commentFeedback').show();
                 var oOptions = {  
                     method: "POST",  
                     parameters: Form.serialize("frm_contact"),  
                     asynchronous: true,  
                     onFailure: function (oXHR) {  
                         $('commentFeedback').update(oXHR.statusText);
                     },  
                     onLoading: function (oXHR) {
                         $('commentFeedback').update('<span class="saving"><img src="_images/loading2.gif" title="Saving..." alt="Saving..." border="0" /></span>');  
                     },                            
                     onSuccess: function(oXHR) {  
                        $('commentFeedback').update(oXHR.responseText);
						$('name').value = '';
					    $('email').value = '';
						$('phone').value = '';
					    $('message').value = '';
                     }                 
                 };  
//				 var currdiaryid = 14;
                 var oRequest = new Ajax.Updater({success: oOptions.onSuccess.bindAsEventListener(oOptions)}, "dbmodify.php?action=contact", oOptions);             
   }
   
function sendFormAddComment3() {  	
                 // we stop the default submit behaviour  
				 $('commentFeedback').show();
                 var oOptions = {  
                     method: "POST",  
                     parameters: Form.serialize("frm_design"),  
                     asynchronous: true,  
                     onFailure: function (oXHR) {  
                         $('commentFeedback').update(oXHR.statusText);
                     },  
                     onLoading: function (oXHR) {
                         $('commentFeedback').update('<span class="saving"><img src="_images/loading2.gif" title="Saving..." alt="Saving..." border="0" /></span>');  
                     },                            
                     onSuccess: function(oXHR) {  
                        $('commentFeedback').update(oXHR.responseText);
						$('name').value = '';
					    $('email').value = '';
						$('business').value = '';
						$('colors').value = '';
					    $('industry').value = '';
						$('message').value = '';
                     }                 
                 };  
//				 var currdiaryid = 14;
                 var oRequest = new Ajax.Updater({success: oOptions.onSuccess.bindAsEventListener(oOptions)}, "dbmodify.php?action=design", oOptions);             
   }
   

function sendFormPromoJoin() {  	
                 // we stop the default submit behaviour  
				 $('commentFeedback').show();
                 var oOptions = {  
                     method: "POST",  
                     parameters: Form.serialize("frm_promoJoin"),  
                     asynchronous: true,  
                     onFailure: function (oXHR) {  
                         $('commentFeedback').update(oXHR.statusText);
                     },  
                     onLoading: function (oXHR) {
                         $('commentFeedback').update('<span class="Wait..."><img src="_images/loading.gif" title="Wait..." alt="Wait..." border="0" /></span>');  
                     },                            
                     onSuccess: function(oXHR) {  
					    $('txtEmail').value = 'Email';
						$('commentFeedback').update(oXHR.responseText);
                     }                 
                 };  
                 var oRequest = new Ajax.Updater({success: oOptions.onSuccess.bindAsEventListener(oOptions)}, "dbmodify.php?action=promoJoin", oOptions);             
   }  
   
function sendFormAddMessage(event) {  
                 // we stop the default submit behaviour  
                 var oOptions = {  
                     method: "POST",  
                     parameters: Form.serialize("frm_chat"),  
                     asynchronous: true,  
                     onFailure: function (oXHR) {  
                         $('commentFeedback').update(oXHR.statusText);
                     },  
                     onLoading: function (oXHR) {
                        /* $('loadFeedback').update('<span class="saving"><img src="_images/loading.gif" title="Saveing..." alt="Saving..." border="0" /></span>');*/  
                     },                            
                     onSuccess: function(oXHR) {  
				/*     	$('loadFeedback').update('');*/
                  //      $('commentFeedback').update(oXHR.responseText);
						$('message').value = '';
                     }                 
                 };  
//				 var currdiaryid = 14;
                 var oRequest = new Ajax.Updater({success: oOptions.onSuccess.bindAsEventListener(oOptions)}, "dbmodify.php?action=addMessage", oOptions);             
   }
   
   
function updateChatWindow(lastId) {
	
	var myAjax = new Ajax.Request(
			'dbmodify.php?action=updateChatWindow&lastId='+lastId, 
			{
				method: 'get', 
				parameters: '', 
				asynchronous: true,
				onSuccess: function(response) {
					result = response.responseText;	
					if (result != 'uptodate') {
						resultList = result.split('<--*-->'); // split on <--*-->
						$('chatWindow').innerHTML += resultList[0];
						$('lastId').innerHTML = resultList[1];
						/*var objDiv = document.getElementById("chatWindow");
						objDiv.scrollTop = objDiv.scrollHeight;*/
						autoScroll = jQuery('#chatWindow').data('jScrollPanePosition') == jQuery('#chatWindow').data('jScrollPaneMaxScroll');
						
						jQuery(function(){jQuery('#chatWindow').jScrollPane({showArrows:true})});
						if (autoScroll)
						{
							jQuery('#chatWindow')[0].scrollTo(jQuery('#chatWindow').data('jScrollPaneMaxScroll'));
						}
						

					}
				}
			});		
}
  
function sendFormBanNickname(event) {  
                 // we stop the default submit behaviour  
                 var oOptions = {  
                     method: "POST",  
                     parameters: Form.serialize("frm_ban"),  
                     asynchronous: true,  
                     onFailure: function (oXHR) {  
                         $('commentFeedback').update(oXHR.statusText);
                     },  
                     onLoading: function (oXHR) {
                        /* $('loadFeedback').update('<span class="saving"><img src="_images/loading.gif" title="Saveing..." alt="Saving..." border="0" /></span>');*/  
                     },                            
                     onSuccess: function(oXHR) {  
				/*     	$('loadFeedback').update('');*/
                  //      $('commentFeedback').update(oXHR.responseText);
						$('ban').value = '';
						$('unban').value = '';
                     }                 
                 };  
//				 var currdiaryid = 14;
                 var oRequest = new Ajax.Updater({success: oOptions.onSuccess.bindAsEventListener(oOptions)}, "dbmodify.php?action=banNickname", oOptions);             
   }  
     


function letmeknow(what) {  

	// send request to phpbb3 and change default language
	var myAjax = new Ajax.Request(
			'dbmodify.php?action=letmeknow&what='+what, 
			{
				method: 'get', 
				parameters: '', 
				asynchronous: false,
				onSuccess: function(response) {
					translate = response.responseText;
				}
			});	
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}