function animatePic(){
				$(".side_image A").animate({opacity: 0}, 1500,function(){
			
															if($(".side_image A").attr('href') == "/home/entrepreneur/")
															{
																$(".side_image A").attr('href',"/register/?redirect=awards/" ) ;
																$(".side_image A IMG").attr('src',"../images/panel-"+dir+".jpg" )
																$(".side_image A IMG").attr('alt',"Entrepreneur of the Year Award" )
																$(".side_image A IMG").attr('title',"Entrepreneur of the Year Award" )
															}
															else
															{
																$(".side_image A").attr('href',"/home/entrepreneur/" ) ;
																$(".side_image A IMG").attr('src',IMG );
																$(".side_image A IMG").attr('alt',"I'm an Entrepreneur" )
																$(".side_image A IMG").attr('title',"I'm an Entrepreneur" )
															}
															$(".side_image A").animate({opacity: 100}, 1500);

			});
}

IMG = "";

$(document).ready(function() {
	
	$(".hidden").slideUp();
	
	$("#openads").bind("click", function() {
		if ($("#theads").css("display") == "none") {
			$("#theads").slideDown();	
		} else {
			$("#theads").slideUp();
		}
		return false;
	});
	
	$(".widget .head a").bind("click", function() {
		$(".sliderContainer").css("width","258px").css("height","85px");
		if ($(this).parent().parent().children(".body").css("display") == "none") {
			$(this).parent().parent().children(".body").slideDown(300, function() {
				updateWidgetCookie();
			});	
		} else {
			$(this).parent().parent().children(".body").slideUp(300, function() {
				updateWidgetCookie();
			});	
		}
		return false;
	});

	if($(".side_image A").attr('href') == "/home/entrepreneur/")
	{
	  //alert("/home/entrepreneur/")
		//if(dir == rtl) do this  else do other.
		//setInterval("animatePic()",3000)
		//	IMG = $(".side_image A IMG").attr('src');


	}

	$("#newsSlider").easySlider({
		controlsBefore:	'<p id="controls">',
		controlsAfter:	'</p>'
	});
	$("#caseSlider").easySlider({
		controlsBefore:	'<p id="controls2">',
		controlsAfter:	'</p>',
		prevId: 'prevBtn2',
		nextId: 'nextBtn2'
	});
    
    $(".question").bind("click", function() {
        
       var id = $(this).attr("id");
       $("#research").val(id.substring(8));
       $(".question").removeClass("active").removeClass("noborder").addClass("disabled");
       $(this).removeClass("disabled").addClass("active").addClass("noborder"); 
       $(".answer").hide();
       $("#"+id+"a").addClass("activated").show();
    });
	
});

function toggleResearch(id) {
	$("#research1, #research2, #research3, #research4").hide();
	$("#research"+id).show();
}

function updateWidgetCookie() {
	
	var data = ''
	
	$(".widget .head a").each(function () {
		var id = $(this).parent().parent().attr("id");
		var state = $(this).parent().parent().children(".body").css("display");
		data += id + "=" + state +";";
	}); 	
	

	Set_Cookie('lwsaWidgetState',data,30);
}

// COOKIE FUNCTIONS
function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}


/* AWARDS FUNCTIONS */
function check_length_all(){
	var countable = new Array();

	for (var i=0; i < countable.length; i++) {
		check_length(document.getElementById(countable[i]));
	};
}

function check_length(obj) { 
	var maxwords = 200;
	rem = document.getElementById(obj.name+'_remaining');
	var char_count = obj.value.length;
	var fullStr = obj.value + " ";
	var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
	var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
	var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
	var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
	var ary = cleanedStr.split(" ");

	var len = ary.length -1; 
	rem.innerHTML = maxwords - len; 
	if (len > maxwords) { 
		alert("Message in '" + obj.name + "' limited to " + maxwords + " words."); 
		ary = ary.slice(0,maxwords-1); 
		obj.value = ary.join(" "); // truncate additional words  
		rem.innerHTML = 0; 
		return false; 
	} 
	return true; 
}

function EntryForm(part) {
	
	$(".entry-form").hide();
	$("#form-part"+part).show();
	
	$("#myMenu li.active").removeClass();
	$("#myMenu #part"+part).addClass("active");
	
	if (part == 'video') {
		$("#shortlisted").hide();
	} else {
		$("#shortlisted").show();	
	}
	
	$('html').animate({scrollTop:0}, 'slow'); 
	
}

function saveEntry(next, hide) {
	var data = $("#entryform").serialize();  
  
	
	if (next == '99') {
		data += "&submit=1";
	}
	if (hide != 1)
		$("#saveAlert").show().pause(5000).fadeOut();
	
	$.post("/common/ajax/save_comp_entry.php", data, function(data,status) {
																												
		// put save successful message up
		
		if (data.entryid) {
			$("#entryID").attr("value",data.entryid); // set the entryID for future saves
		}
		
		if (data.submitted == '1') {
			window.location='http://www.intilaaqah.org/complete-ye';
		}
	}, "json");
	
	if (next && next != 99) {
		EntryForm(next);
	}

}

function SubmitEntry(next) {
    
    $("#saveAlert").hide();
    var errors = 0;
    
/*    var fname = $("#firstname").val();
    var sname = $("#surname").val();
    var address = $("#address").val();
    var email = $("#email").val();
    var bname = $("#businessname").val();
    var baddress = $("#businessaddress").val();
    var bpcode = $("#businesspostcode").val();
    var bmail = $("#businessemail").val();
    var btel = $("#businesstelno").val();
    var bweb = $("#businesswebsite").val();
    var bcomm = $("select[name=businesscommenced[day]").val()+"/"+$("select[name=businesscommenced[month]").val()+"/"+$("select[name=businesscommenced[year]").val();
    var struct = $("#businessstructure").val();
    var bdesc = $("#businessdescription").val();
    var bg = $("#background").val();
    var edu = $("#educationtraining").val();
    var market = $("#yourmarket").val();
    var inno = $("#innovation").val();
    var comp = $("#competitionsource").val();
    var means = $("#winningmeans").val();
    var sig = $("#signature").val();
    var dec = $("input[name=declarationconfirm]:checked").val();
    
    if (fname==''||sname==''||address==''||email==''||bname==''||baddress==''||bpcode==''||bmail==''||btel==''||bweb==''||bcomm==''||struct==''||bdesc==''||bg==''||edu==''||market==''||inno==''||comp==''||means==''||sig==''||dec=='undefined') {
        errors = 1;
    }*/
    
		alert( "SubmitEntry");
		
    if (errors > 0) {
        $("#saveAlert").show();       
    } else {
    
    	var data = $("#entryform").serialize();
    	
    	data += "&submit=1";
    
    	$.post("/common/ajax/save_comp_entry.php", data ,function(data,status){
																																alert( data.toString() );
    		// put save successful message up
    		$("#saveAlert").show().pause(5000).fadeOut();
    		
				
				

    		

    	}, 'json');
     }

}

function EntryPrint(id) {
	saveEntry('',1);
	
	if (id) {
		id = '?competitionID='+id;
	}
	
	window.open ("/home/awards/entry-form/print/"+id,"mywindow","status=1,resize=1,scrollbars=1"); 
}

function castVote(comp, user, entry) {
	
	$(".vote").hide();
	
	data = "compID="+comp+"&entryID="+entry+"&userID="+user;
	$.post("/common/ajax/cast_vote.php", data, function(data, status) {
		if (data == 'success') {
			$(".vote-cast").show().pause(3000).fadeOut('slow');
		} else {
			$(".vote").show();
		}
	});
	
}