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

function getStuff(what, itemnum) {
	// swaps stuff

	switch (what) {
		case 'main':
			jQuery('#productLeftMain').html(jQuery('#left-'+itemnum).html());
			jQuery('#productRight').html(jQuery('#main-'+itemnum).html());
		break;
		case 'facts':
			jQuery('#factsNav').html('<img src="_images/SUB-NAV-410-facts_01.png"/>');
			jQuery('#featuresNav').html('<img src="_images/SUB-NAV-410_02.png"/>');
			jQuery('#productRight').html(jQuery('#facts-'+itemnum).html())
		break;
		case 'features':
			jQuery('#featuresNav').html('<img src="_images/SUB-NAV-410-features_02.png"/>');
			jQuery('#factsNav').html('<img src="_images/SUB-NAV-410_01.png"/>');
			jQuery('#productBottom').html(jQuery('#features-'+itemnum).html());
		break;
	}
}

function setNav(page){
	// this function sets the navigation highlight color based on the current page we are on.
	$('nav'+page).addClassName('current');
	$('fnav'+page).addClassName('current');
}

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 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) {
                         $('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);
						$('name').value = '';
					    $('email').value = '';
						$('phone').value = '';
					    $('message').value = '';
						jQuery(document).ready(function() {
						jQuery("#frm_contact").validationEngine({	
								  success : function() { sendFormAddComment2() },
								  failure : false })
							  });

                     }                 
                 };  
//				 var currdiaryid = 14;
                 var oRequest = new Ajax.Updater({success: oOptions.onSuccess.bindAsEventListener(oOptions)}, "dbmodify.php?action=contact", oOptions);             
   }

function sendFormSupport() {
	
	jQuery.prompt('<h3 class="txt1"><strong class="p2">Error: you are not a registered user.</strong></h3>');
	
	jQuery("#frm_support").validationEngine({	
		  success : function() { sendFormSupport() },
		  failure : false })

}
