var t;
var inreplyto=0;
var arrowpos=0;
// var culmulative = 10;
//live chat stuff
// var ConsSrv = Components.classes['@mozilla.org/consoleservice;1'].getService(Components.interfaces.nsIConsoleService);
var chathandle="";
var myp = {
myBrowser: {
    IE:     !!(window.attachEvent && !window.opera),
    Opera:  !!window.opera,
    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
  }
}

// 
if(myp.myBrowser.Gecko)
{
	window.addEventListener('DOMContentLoaded', initpage, true);
// 	alert("i am FF");
}
else 
{
// 	document.onreadystatechange = mimicmozdomready;
// 	alert("i am MSIE");
	setTimeout("mimicmozdomready()", 10);
}

// 
var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// 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;
	}
 
}

// 
var boardhash='';
var boardchecker;


function dorandomimage()
{
	var imgs = document.getElementsByTagName('div');
	for(var i=0; i<imgs.length; ++i)
	{
		if((imgs[i].className).indexOf("logoforoverflow")>-1)
		{
			var thisimage = imgs[i];
			break;
		}
	}
	var dir = randomImage['defaults'].path;
	var imageNames = randomImage['defaults'].myImages;
	var imageMessages = randomImage['defaults'].myMessage;
	var imageNamesSize = imageNames.length;
	var lotteryNumber = Math.floor(Math.random()*imageNamesSize);
	var winnerImage = imageNames[lotteryNumber];
	

	thisimage.style.backgroundImage = "url('"+dir+winnerImage+"')";
	document.getElementById('random_message').innerHTML = imageMessages[lotteryNumber];;
}

function loadsearchresult(searchterm)
{
	location.hash="#boardsearch_"+searchterm;
// 	var ajxpath =
// 	"/mod/jam_functions.php?laqu=ajaxboard&hash="+escape(location.hash.replace('#',''));
// 	alert(ajxpath);
	loadboardhash();

}
// function loadbloghash()
// {
// 	clearTimeout(boardchecker);
// 	if (boardhash!=location.hash.replace('#','')) 
// 		  {
// 		  boardhash=location.hash.replace('#','');
// 			
// 				var ajxpath = "/mod/blog_functions.php?laqu=ajaxblog&hash="+escape(location.hash.replace('#',''));
// 			}
// }
function loadboardhash()
{
		clearTimeout(boardchecker);
		if (boardhash!=location.hash.replace('#','')) 
		  {
		  boardhash=location.hash.replace('#','');
			
				var ajxpath = "/mod/jam_functions.php?laqu=ajaxboard&jamid="+jamid+'&hash='+escape(location.hash.replace('#',''));
				if(Ajax)
				{
					new Ajax.Request(ajxpath, { method:'GET', onComplete:function(transport)
						{
							posts.length=0;
							eval(transport.responseText);
							loadboardview();
						}
					});
				}
		}
		else 
		{
// 			alert("load on load !"+typeof(posts));
			
			loadboardview();
		}
}
function loadboardview()
{
      var boardmain='';
      if (posts.length==0) boardmain='<div class="jamboardeach"><br><em>Sorry; no posts match that search</em><br><br></div>';
      else for (var a=0;a<posts.length;a++)
			{
// 				alert("compile list");
				var d = posts[a].split('|%|');
				if(!((d[9]==undefined) || (d[9] == null) || (d[9]=="")))
				{
					var boardattach = "<a class='attachlink' href='"+d[9]+"'>Download Attachment</a>";
				}
				else
					var boardattach = "<span class='noattach'></span>";
				boardmain = boardmain + "<div class=\"jamboardmaineach\"><div class=\"userthumb\" style=\"background-image:url('"+d[8]+"');\"></div><div class=\"boardtextdiv\"><div class=\"mainboardtitle\">"+d[1]+"</div><div class=\"whowhen\"><div class=\"whopost\">Posted by : "+d[2]+"</div><div class=\"whenpost\">"+d[3]+"</div><br style=\"clear:both;\"></div><div class=\"snippet\">"+d[4]+"</div><div></div><div class=\"functionbtn\"><div class=\"reply\"  onClick=\"location.hash='#reply_"+d[7]+"';inreplyto="+d[6]+";loadboardhash();\">Reply to this comment</div><div class=\"viewallsubject\" onClick=\"location.hash='#thread_"+d[6]+"';loadboardhash();\">View all on this subject</div>"+boardattach+"<br style=\"clear:both;\"></div></div><br style=\"clear:both;\"></div>";
   if ((location.hash.indexOf('reply')!=-1)&&(d[1].length>0)) $('commenttitle').value='Re: '+d[1];
			}
    $('boardcontents').innerHTML=boardmain;
    boardchecker = setTimeout('checkhash()',100);
}
function commentfilter1(username)
{
	location.hash = "#filter_"+username;
}
function notafunction()
{
// 	alert("doifguyerioui");
}
function blogsearchresult(searchterm)
{
// 	var topblock = $$('.topblock')[0];
// 	var img = document.createElement('img');
// 	img.setAttribute("src", "/images/ajax-loader.gif");
// 	Element.extend(img);
// 	img.addClassName("ajaxload");
// 	new Insertion.Bottom(topblock, img);

	var ajxpath = "/mod/blog_functions.php?laqu=ajaxblog&hash=blogsearch_"+escape(searchterm);
	if(Ajax)
	{
	 new Ajax.Request(ajxpath, { method:'GET', onComplete:function(transport)
			  {
// 					$$(".ajaxload")[0].parentNode.removeChild($$(".ajaxload")[0]);
            var posts = new Array();
// 				  posts.length=0;
					
				  eval(transport.responseText);
          
				  loadblogview(posts);
			  }
		  });
	}
}
/*function isArray(obj) {
//returns true is it is an array
if (obj.constructor.toString().indexOf(”Array”) == -1)
return false;
else
return true;
}*/
function loadblogview(posts)
{
	
	// 		$out.="
// <div class=\"article\">
//   <h1>$r[title]</h1>
//   <div class=\"author\">$r[author]</div>
//   <div class=\"date\">".date("d M Y",$r['date'])."</div><br style=\"clear:both;\">
//   <div class=\"content\">$r[text]</div>
//   <div class=\"articlefoot\">
// 		<div class=\"reply\" onClick=\"window.location='/$path[0]/$r[url]/$r[urlfrag].jam'\">
// 			Leave a comment to this blog
// 		</div> 
// 		<div class=\"share\"><div>|&nbsp;&nbsp;&nbsp;Share this</div> ".blogsharethis($r)."</div><br style=\"clear:both;\">
// 	</div>
// </div>
// ";
// 	$out.="posts[$k]=$title|%|$author|%|$date|%|$test|%|$onclickpath|%|$share|%|";
	
// 	alert(posts.length);
	var blogdmain = "";
	 if (posts.length==0) 
	 {
// 		 alert("foiwueoiruwopiuerpowuipoeriop");
// 		 blogdmain='<div class="article"><br><em>Sorry; no posts match that search</em><br><br></div>';
	 }
	 else 
		 for (var a=0;a<posts.length;a++)
		 {
// 			 alert("replace");
			 var d = posts[a].split('|%|');
				blogdmain = blogdmain + "<div class='article'><h1>"+d[0]+"</h1><div class='author'>"+d[1]+"</div><div class='date'>"+d[2]+"</div><br style=\"clear:both;\"><div class='content'>"+d[3]+"</div><div class=\"articlefoot\"><div class=\"reply\" onClick=\"window.location='"+d[4]+"'\">Leave a comment to this blog</div> <div class=\"share\"><div>|&nbsp;&nbsp;&nbsp;Share this</div> "+d[5]+"</div><br style=\"clear:both;\"></div></div></div>";
		 }
// 		 alert(blogdmain);
		 $$('.articlelist')[0].innerHTML = blogdmain;
// 		 setTimeout("checkhashforblogpage()", 100);
}
function checkhashforblogpage()
{
	if (boardhash!=location.hash.replace('#','')) 
		loadbloghash();
	boardchecker =  setTimeout('checkhashforblogpage()',100);
}
function ajaxblogsearch(key)
{
  window.location="/blog-search.jam?searchkey="+Url.encode(key);
  
}
function checkhash()
{
	if (boardhash!=location.hash.replace('#','')) loadboardhash();
	boardchecker =  setTimeout('checkhash()',100);
}

function mimicmozdomready()
{
	if(document.getElementsByTagName('body')[0])
	{
// 		alert("culmulative : "+culmulative);
		initpage();
	}
	else
	{
// 		culmulative = culmulative +1;
		setTimeout("mimicmozdomready()", 10);
	}
}

function myinsert(insertto, ele, position)
{
	if(position == "TOP")
	{
		var first = insertto.childNodes[0];
		insertto.insertBefore(ele, first);
	}
	if(position == "BOTTOM")
	{
		var first = insertto.childNodes[0];
		insertto.appendChild(ele);
	}
}

function initpage()
{
	var ajxpath = "/mod/jam_functions.php?laqu=ajax";
	checklogin();
	document.getElementById('lightboxform_id').style.display="none";
	var imgsdiv = document.createElement("div");
	imgsdiv.style.width="0px";
	imgsdiv.style.height="0px";
	imgsdiv.style.border="none";
	imgsdiv.style.overflow="hidden";
	imgsdiv.setAttribute('id', 'imagespreloaded');
// 	new Insertion.Top($$('body')[0], imgsdiv);
	myinsert(document.getElementsByTagName('body')[0], imgsdiv, 'TOP');
	if($('jamshelf') && 0)
	{
		if(Ajax)
		new Ajax.Request(ajxpath, { method:'GET', onComplete:function(transport)
			{
				xmlobj = transport.responseXML;
	
					var alljams = (xmlobj.getElementsByTagName('jam_id')).length;
					
					for(var j=0; j<alljams; ++j)
					{
						
						var id = parseInt(xmlobj.getElementsByTagName('jam_id')[j].childNodes[0].nodeValue);
						var imgobj = document.createElement('img');
						imgobj.setAttribute('src', '/mod/showjam.php?jam_id='+id+'&jamheight=335&jamwidth=181');
						imgobj.setAttribute("id", id)
						new Insertion.Bottom(imgsdiv, imgobj);
						
					}
				//
				showjamdetails(transport.responseXML);
			}
		});
	}
	
	//system used images preloading
	var systemimages = document.createElement('div');
	systemimages.style.width = "0px";
	systemimages.style.height = "0px";
	systemimages.style.overflow="hidden";
// 	new Insertion.Top($$('body')[0], systemimages);
		myinsert(document.getElementsByTagName('body')[0], systemimages, 'TOP');
	var imagesarr = Array("close.png", "topline.png", "bottomline.png", "leftbg.png", "rightbg.png", "loginbtn.png", "joinbtn.png", "jointopline.png", "joinbottomline.png", "joinrightbg.png", "joinleftbg.png", "joinsubmitbtn.png", "defaultprofile.png", "button_select.gif");
	for(var j=0; j<imagesarr.length; ++j)
	{
		var imgobj = document.createElement('img');
		imgobj.setAttribute('src', '/images/'+imagesarr[j])
// 		new Insertion.Bottom(systemimages, imgobj);
		myinsert(systemimages, imgobj, "BOTTOM");
	}
	//
	
	checkmenuactive();
// 	showloginbyhash();
// 	if(Prototype.Browser.IE)
// 	{
// 		var border = RUZEE.ShadedBorder.create({ corner:15, shadow:0,  border:0 });
// 		border.render($('makejscorner'));
// 	}
	makeselectelegant();
	if(document.getElementById('enable_random_background'))
		dorandomimage();
	var movetobottom = Array('latestsmallgallery', 'aboutus_bottom', 'contact_app', 'footerinfo');
// 	alert(((document.getElementById("footerinfo")).parentNode).className);
// 	var movetobottom = Array('latestsmallgallery', 'aboutus_bottom', 'contact_app');
	for(var i=0; i<movetobottom.length; ++i)
	{
		
		
		if(document.getElementById(movetobottom[i]))
		{
			var smallgallery = document.getElementById(movetobottom[i]);
			var parentnode = smallgallery.parentNode;
			parentnode.removeChild(smallgallery);
			var content = getElementsByClassName("content", "div");
			content.appendChild(smallgallery);
		}
	}
	
		var leftbtn = document.getElementById('clicktogoleft');
	var rightbtn = document.getElementById('clicktogoright');	
	
// 	Event.observe(leftbtn, 'click', function(){twowaydirection('previous');});
// 	Event.observe(rightbtn, 'click', function(){twowaydirection('next');});
	
	if(jQuery.browser['msie'] && document.getElementById('canscrollingbar'))
	{

		leftbtn.attachEvent('onclick',function(){twowaydirection('previous');})
		rightbtn.attachEvent('onclick',function(){twowaydirection('next');});

	}
	else if(jQuery.browser['mozilla'] && document.getElementById('canscrollingbar'))
	{

		leftbtn.addEventListener('click',function(){twowaydirection('previous');}, false);
		rightbtn.addEventListener('click',function(){twowaydirection('next');}, false);
	}
	
}


function makeselectelegant()
{
// 	var allselectsonpage = $$('.elegantselect');
// 	for(var i=0; i<allselectsonpage.length; ++i)
// 	{
// 		new Autocompleter.SelectBox(allselectsonpage[i]);	
// 	}
}
function makecorner()
{
	var allcorners = $$(".jsmakecorner");
	var border = RUZEE.ShadedBorder.create({ corner:15, shadow:0,  border:0 });
	for(var i=0; i<allcorners.length; ++i)
	{
		border.render(allcorners[i]);
	}
}
function checkmenuactive()
{
	var jqueryobj = $('.topmenu div a');
	var nowlocation = window.location.href;
	var setactive = true;
	jqueryobj.each(function(index, iobj)
	{
		if((nowlocation.indexOf((iobj.getAttribute('href')))) > -1)
		{
			$(iobj).toggleClass("curactive");
			setactive = false;
		}
	});
	if(nowlocation.indexOf("b42/work")>-1 && setactive)
	{
		$(jqueryobj[1]).toggleClass("curactive");
	}
}
function cleararrows()
{
	var jamscover = $$('.eachjam');
	for (var a=0;a<jamscover.length;a++) $(jamscover[a].id).getElementsByTagName('div')[0].style.backgroundPosition='left';
}
function shelffocus(id)
{
//move arrow	
  
	var jamscover = $$('.eachjam');
	for (var a=0;a<jamscover.length;a++) $(jamscover[a].id).getElementsByTagName('div')[0].style.backgroundPosition='left';
	$(id).getElementsByTagName('div')[0].style.backgroundPosition='120px 0';
	for (var a=0;a<jamscover.length;a++) if (jamscover[a].id==id) arrowpos=a;
	showjamdetails();	
}
function showjamdetails()
{
	
	var jamscover = $$('.eachjam');

	var jamnode = jamscover[arrowpos];
	
	var jam_id = ((jamnode.getAttribute('id')).split('jam'))[1];
	
	var cur_jam = xmlobj.getElementsByTagName('jam_'+jam_id);

	var ideatitle = cur_jam[0].getElementsByTagName('title')[0].childNodes[0].nodeValue;
	
	var url = cur_jam[0].getElementsByTagName('url')[0].childNodes[0].nodeValue;
	var businessname = cur_jam[0].getElementsByTagName('company')[0].childNodes[0].nodeValue;
	
	var authorname = cur_jam[0].getElementsByTagName('fullname')[0].childNodes[0].nodeValue;
	var description_ = cur_jam[0].getElementsByTagName('description')[0].childNodes[0].nodeValue;
	var lastmod = cur_jam[0].getElementsByTagName('lastmod')[0].childNodes[0].nodeValue;
	var watchcount = cur_jam[0].getElementsByTagName('watchcount')[0].childNodes[0].nodeValue;
	
	Event.observe($$('.deepgreybtn')[0],'click', function () {top.location=url;});
	$$('.ideatitle')[0].innerHTML = ideatitle;
	$$('.business .value')[0].innerHTML = businessname;
	$$('.author .value')[0].innerHTML = authorname;
	$$('.ideapreview .description')[0].innerHTML = description_;
	$$('.lastmodded')[0].innerHTML = lastmod;
	$$('.watchcount')[0].innerHTML = watchcount;
	
var imgpath = '/mod/showjam.php?jam_id='+jam_id+'&jamheight=335&jamwidth=181';
	$$('.bigjamjar')[0].style.backgroundImage="url("+imgpath+")";
}
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64( input ) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      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 + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}
function clickleft()
{
cleararrows();
	var eachjams = $$('.jamshost .eachjam');
	var lastone = eachjams[(eachjams.length)-1];
	lastone.style.width = "0px";
	lastone.style.marginLeft = "0px";
	
	
	var addtohead = lastone.parentNode.removeChild(lastone);
	new Insertion.Before(eachjams[0], addtohead);
	
	new Effect.Morph(addtohead.id, {style: 'width:105px;margin-left:26px', duration: 0.8});
// 	setTimeout("cleararrows()", 820);
}
function clickright()
{
  cleararrows();
	var eachjams = $$('.jamshost .eachjam');
	var firstone = eachjams[0];
// 	if(parseInt(eachjams.length)==6)
// 		equalsixclonenode();
	new Effect.Morph(firstone.id, {style: 'width:0px;margin-left:0px;margin-right:0px;',duration: 0.8});
	
	setTimeout("movetoend('"+firstone.id+"')",820);
	
}
function equalsixclonenode()
{
	var jams = $$('.eachjam');
	var firstjam = jams[0];
	var tmpjam = firstjam.cloneNode(true);
	tmpjam.addClassName("tmpnode");
// 	var existingcls = tmpjam.getAttribute("class");
	tmpjam.setAttribute("id", "tmpnode");
	new Insertion.Bottom(firstjam.parentNode, tmpjam);
	
}
function checklogin()
{
// 	var ajxpath = '/mod/checklogin.php';
// 	if(Ajax)
// 	new Ajax.Request(ajxpath, {method:'GET', onComplete:function(transpost)
// 		{
// 			var strarr = (transpost.responseText).split("#");
// 
// 			switch(strarr[1])
// 			{
// 				case 'true':
// 					useraccess = true;
// 					break;
// 				default:
// 					useraccess = false;
// 					break;
// 			}
// 			var lsinter = $$('.loginsignup')[0];
// 			if(useraccess)
// 			{
// 
// 				lsinter.innerHTML = "<span class='username'>"+strarr[0]+"</span> | <span onClick='userlogout()' class='signoutbtn'>Sign out?</span><br style='clear:both;'>";
// 			}
// 			else
// 			{
// 				lsinter.innerHTML = 
// 					"<div class='signinbtn'></div>or<div class='signupbtn'></div>";
// 					
// 					$$('.signinbtn')[0].stopObserving('click');
// 					$$('.signupbtn')[0].stopObserving('click');
// 					Event.observe($$('.signinbtn')[0], 'click', function(){showlightbox('login')})
// 					Event.observe($$('.signupbtn')[0], 'click', function(){showlightbox('join')})
// 			}
// 					
// 			
// 		if(location.hash)
// 		{
// 			var knowhash = location.hash;
// 			knowhash = knowhash.replace("#", "");
// 			if(knowhash=="login")
// 			{
// 				showlightbox('login');
// 			}
// 		}
// 		}
// 	});
}
function movetoend(id)
{
	
	var obj = $(id);
	
	var thisobj = obj.parentNode.removeChild(obj);
// 	var modules = $$('.sliderformodules .eachmodule');
	var eachjams = $$('.jamshost .eachjam');
	new Insertion.After(eachjams[parseInt(eachjams.length)-1], thisobj);
	var addwidthtothis = $(thisobj.id);
	addwidthtothis.style.width = '105px';
	addwidthtothis.style.marginLeft = "26px";
// 	addwidthtothis.style.paddingRight = "5px";
// if(($('tmpnode').length)>0)
// {
// 	var tmpnodes = $$('.tmpnode');
// 	for(var i=0; i<tmpnodes.length; ++i)
// 		tmpnodes[i].parentNode.removeChild(tmpnodes[i]);
// }
	

shelffocus($$('.jamshost')[3].getAttribute('id'));
  
}
function checktimestatus()
{
	if($('lightboxform_id').style.display='none')
		checktimestatus();
// 	else
// 		showlightbox('login');
	
		
}
function showlightbox(action_)
{
// 	if(action_=="login")
// 	{
// 		if($$("input[name='formaction']")[0]!=undefined)
// 		{
// 			
// 			if($$("input[name='formaction']")[0].value=="joinjamsite")
// 			{
// 				closejoin();
// 				setTimeout("showlightbox('login');", 1100);
// 				checktimestatus();
// // 				break;
// 			}
// 		}
// 	}
	
	var formcover = $$('.lightboxform')[0];
	if($$('.globalmove')[0])
		var globalmove=$$('.globalmove')[0];
	else
	{
		var globalmove = document.createElement('div');
// 		globalmove.setAttribute("class", 'globalmove');
Element.extend(globalmove);
globalmove.addClassName("globalmove");
		globalmove.setAttribute("id", 'globalmove_id');
		new Insertion.After(formcover, globalmove);
	}
	globalmove.style.display="none";
	classdiv = document.createElement('div');
	
	if($$("form[name='formbox']")[0])
		formbox = $$("form[name='formbox']")[0];
	else
	{
		formbox = document.createElement('form');
		formbox.setAttribute('method', 'POST');
		formbox.setAttribute('name', 'formbox');
		new Insertion.Bottom(globalmove, formbox);
	}
	
	new Insertion.Bottom(formbox, classdiv);
	switch(action_)
	{
		case 'login' : 
		/*$$('.signinbtn')[0].setAttribute('onClick', "closefirst('login')");
			$$('.signupbtn')[0].setAttribute('onClick', "closefirst('Join')")*/;
// 	Event.observe(element, eventName, handler)
if($$('.closetopglobalmove')[0])
	$$('.closetopglobalmove')[0].removeClassName('closetopglobalmove');
$$('.signinbtn')[0].stopObserving('click');
$$('.signupbtn')[0].stopObserving('click');
Event.observe($$('.signinbtn')[0], 'click', function(){closefirst('login')})
Event.observe($$('.signupbtn')[0], 'click', function(){closefirst('join')})
		
// 			classdiv.setAttribute('class', "loginformcover");
Element.extend(classdiv);
classdiv.addClassName("loginformcover");
			
			var signinprompt = document.createElement('div');
// 			signinprompt.setAttribute('class', 'signinprompt')
			
			Element.extend(signinprompt);
signinprompt.addClassName("signinprompt");
signinprompt.setAttribute("id", "signinpromptdiv");
			
			signinprompt.innerHTML="Sign in";
			new Insertion.Bottom(classdiv, signinprompt);
			
			var textinputgather = document.createElement('div');
// 			textinputgather.setAttribute('class', 'textinputgather');
			
			Element.extend(textinputgather);
textinputgather.addClassName('textinputgather');
			
			new Insertion.Bottom(classdiv, textinputgather);
			
			var lightboxfc = document.createElement('div');
// 			lightboxfc.setAttribute("class", "lightboxfc");

Element.extend(lightboxfc);
lightboxfc.addClassName('lightboxfc');

			new Insertion.Bottom(textinputgather, lightboxfc);
			var label = document.createElement('label');
			label.setAttribute('for', 'username');
			label.innerHTML = "Username";
			var control = document.createElement('input');
			control.setAttribute('id', 'username');
			control.setAttribute('name', 'username');
			control.setAttribute('type', 'text');
			new Insertion.Bottom(lightboxfc, label);
			new Insertion.Bottom(lightboxfc, control);
			
			var lightboxfc = document.createElement('div');
// 			lightboxfc.setAttribute("class", "lightboxfc");
Element.extend(lightboxfc);
lightboxfc.addClassName('lightboxfc');

			lightboxfc.style.height = "24px";
			new Insertion.Bottom(textinputgather, lightboxfc);
			var label = document.createElement('label');
			label.setAttribute('for', 'username');
			label.innerHTML = "Password";
			var control = document.createElement('input');
			control.setAttribute('id', 'password');
			control.setAttribute('name', 'password');
			control.setAttribute('type', 'password');
			new Insertion.Bottom(lightboxfc, label);
			new Insertion.Bottom(lightboxfc, control);
			
			var lightboxfc = document.createElement('div');
// 			lightboxfc.setAttribute("class", "lightboxfc");
Element.extend(lightboxfc);
lightboxfc.addClassName('lightboxfc');

			lightboxfc.style.height = "20px";
			new Insertion.Bottom(classdiv, lightboxfc);
			
			var forgotpassword = document.createElement('a');
// 			forgotpassword.setAttribute('class', 'getpasswordlink');
Element.extend(forgotpassword);
forgotpassword.addClassName('getpasswordlink');

			forgotpassword.setAttribute('href', '#');
			forgotpassword.innerHTML="Forgotten Password?";
			new Insertion.Bottom(lightboxfc, forgotpassword);
			
			var footpartform = document.createElement('div');
// 			footpartform.setAttribute('class', 'rememberlogin');
Element.extend(footpartform);
footpartform.addClassName('rememberlogin');


			new Insertion.Bottom(classdiv, footpartform);
			
			var lightboxfc = document.createElement('div');
// 			lightboxfc.setAttribute("class", "lightboxfc");
Element.extend(lightboxfc);
lightboxfc.addClassName("lightboxfc");

			lightboxfc.setAttribute("id", "checkboxinside");
// 			lightboxfc.style.width="187px";
// 			lightboxfc.style.height="24px";
			new Insertion.Bottom(footpartform, lightboxfc);
			var label = document.createElement('label');
			label.setAttribute('for', 'rememberme');
			label.innerHTML = "Remember me";
			var control = document.createElement('input');
			control.setAttribute('id', 'rememberme');	
			control.setAttribute('name', 'rememberme');
			control.setAttribute('type', 'checkbox');
			new Insertion.Bottom(lightboxfc, label);
			new Insertion.Bottom(lightboxfc, control);
			
			var loginbtn = document.createElement('input');
			
			loginbtn.setAttribute('type', 'image');
			loginbtn.setAttribute('id', 'imagebtn');
				Element.extend(loginbtn);
// 				loginbtn.readOnly = true;
				loginbtn.observe('click', submitlogin);
			if(Prototype.Browser.IE)
			{
// 				Element.extend(loginbtn);
// 				loginbtn.readOnly = true;
// 				loginbtn.observe('click', submitlogin);
				
			}
			else
			{
// 				loginbtn.setAttribute('onClick', 'submitlogin(); return false;');
				loginbtn.onclick = function(){};
			}
			loginbtn.setAttribute('src', '/images/loginbtn.png');
			new Insertion.Bottom(lightboxfc, loginbtn);
			
			var registermember = document.createElement('div');
// 			registermember.setAttribute('class', 'toplinediv');
Element.extend(registermember);
registermember.addClassName("toplinediv");

			new Insertion.Bottom(classdiv, registermember);
			
			var jointext = document.createElement('div');
			Element.extend(jointext);
jointext.addClassName("jointext");

// 			jointext.setAttribute('class', 'jointext');
			jointext.innerHTML = "Not a member?";
			new Insertion.Bottom(registermember, jointext);
			
			var joinbtn = document.createElement('a');
// 			joinbtn.setAttribute('class', 'joinbtn');
Element.extend(joinbtn);
joinbtn.addClassName("joinbtn");
//
if(Prototype.Browser.IE)
	joinbtn.attachEvent("onclick", function(){showlightbox('join')});
	else
			joinbtn.setAttribute('onclick', "showlightbox('join')");


	
	//
			new Insertion.Bottom(registermember, joinbtn);
			
			var closediv = document.createElement('div');
Element.extend(closediv);
closediv.addClassName("closediv");
// 			closediv.setAttribute('class', 'closediv');
if(Prototype.Browser.IE)
	closediv.attachEvent('onclick', function(){closelogin()});
else
	closediv.setAttribute('onClick', "closelogin()")
			
			new Insertion.Bottom(classdiv, closediv);
			
			var leftbg = document.createElement("div");
			Element.extend(leftbg);
leftbg.addClassName("leftbg");
// 			leftbg.setAttribute('class', 'leftbg');
			new Insertion.Bottom(classdiv, leftbg);
			
			var rightbg = document.createElement("div");
// 			rightbg.setAttribute('class', 'rightbg');
Element.extend(rightbg);
rightbg.addClassName("rightbg");

			new Insertion.Bottom(classdiv, rightbg);
			
			var topbg = document.createElement("div");
// 			topbg.setAttribute('class', 'topbg');

Element.extend(topbg);
topbg.addClassName("topbg");

			new Insertion.Bottom(classdiv, topbg);
			
			var bottombg = document.createElement("div");
// 			bottombg.setAttribute('class', 'bottombg');
Element.extend(bottombg);
bottombg.addClassName("bottombg");

			new Insertion.Bottom(classdiv, bottombg);
			
			Effect.Appear('lightboxform_id', { duration: 1, from:0, to:0.6	});
// 			(function(){Effect.Appear('globalmove_id', { duration: 1, from:0, to:1});}, 1100);
	setTimeout("Effect.Appear('globalmove_id', { duration: 1, from:0, to:1})", 1100)
		break;
		case 'join' :
// 			globalmove.setAttribute('class', "globalmove closetopglobalmove");
// 			globalmove.setAttribute('class', "globalmove closetopglobalmove");
			Element.extend(globalmove);
globalmove.addClassName("globalmove");
globalmove.addClassName("closetopglobalmove");
			closelogin();
$$('.signinbtn')[0].stopObserving('click');
$$('.signupbtn')[0].stopObserving('click');
Event.observe($$('.signinbtn')[0], 'click', function(){closefirst('login')})
Event.observe($$('.signupbtn')[0], 'click', function(){closefirst('join')})
			setTimeout("showjoinform()", 920);
			
		break;
	}
	
	
	
	
}

function showjoinform()
{
	
// 			classdiv.setAttribute('class', "joinformcover");
			Element.extend(classdiv);
classdiv.addClassName("joinformcover");
			
			var formtype = document.createElement("input");
			formtype.setAttribute('type', 'hidden');
			formtype.setAttribute('name', 'formaction');
			formtype.setAttribute('value', 'joinjamsite');
			new Insertion.Bottom(classdiv, formtype);
			
			var joinprompt = document.createElement('div');
// 			joinprompt.setAttribute('class', 'joinprompt')
Element.extend(joinprompt);
joinprompt.addClassName("joinprompt");
			joinprompt.innerHTML="Join";
			new Insertion.Bottom(classdiv, joinprompt);
			
			var lightboxfc = document.createElement('div');
// 			lightboxfc.setAttribute("class", "lightboxfc lightboxfc_extra");
Element.extend(lightboxfc);
lightboxfc.addClassName("lightboxfc");
lightboxfc.addClassName("lightboxfc_extra");
			new Insertion.Bottom(classdiv, lightboxfc);
			var label = document.createElement('label');
			label.setAttribute('for', 'yourname');
			label.innerHTML = "Name";
			var control = document.createElement('input');
			control.setAttribute('id', 'yourname');
			control.setAttribute('name', 'yourname');
			control.setAttribute('type', 'text');
			new Insertion.Bottom(lightboxfc, label);
			new Insertion.Bottom(lightboxfc, control);
			
			var lightboxfc = document.createElement('div');
// 			lightboxfc.setAttribute("class", "lightboxfc lightboxfc_extra");
Element.extend(lightboxfc);
lightboxfc.addClassName("lightboxfc");
lightboxfc.addClassName("lightboxfc_extra");
			new Insertion.Bottom(classdiv, lightboxfc);
			var label = document.createElement('label');
			label.innerHTML = "Username";
			label.setAttribute('for', 'username');
			var control = document.createElement('input');
			control.setAttribute('id', 'username');
			control.setAttribute('name', 'username');
			control.setAttribute('type', 'text');
			new Insertion.Bottom(lightboxfc, label);
			new Insertion.Bottom(lightboxfc, control);
			
			var lightboxfc = document.createElement('div');
// 			lightboxfc.setAttribute("class", "lightboxfc lightboxfc_extra");
Element.extend(lightboxfc);
lightboxfc.addClassName("lightboxfc");
lightboxfc.addClassName("lightboxfc_extra");
			new Insertion.Bottom(classdiv, lightboxfc);
			var label = document.createElement('label');
			label.setAttribute('for', 'email');
			label.innerHTML = "Email";
			var control = document.createElement('input');
			control.setAttribute('id', 'email');
			control.setAttribute('name', 'email');
			control.setAttribute('type', 'text');
			new Insertion.Bottom(lightboxfc, label);
			new Insertion.Bottom(lightboxfc, control);
		
			var lightboxfc = document.createElement('div');
// 			lightboxfc.setAttribute("class", "lightboxfc lightboxfc_extra");
Element.extend(lightboxfc);
lightboxfc.addClassName("lightboxfc");
lightboxfc.addClassName("lightboxfc_extra");
			new Insertion.Bottom(classdiv, lightboxfc);
			var label = document.createElement('label');
			label.setAttribute('for', 'password');
			label.innerHTML = "Password";
			var control = document.createElement('input');
			control.setAttribute('id', 'password');
			control.setAttribute('name', 'password');
			control.setAttribute('type', 'password');
			new Insertion.Bottom(lightboxfc, label);
			new Insertion.Bottom(lightboxfc, control);
			
			var lightboxfc = document.createElement('div');
// 			lightboxfc.setAttribute("class", "lightboxfc lightboxfc_extra");
Element.extend(lightboxfc);
lightboxfc.addClassName("lightboxfc");
lightboxfc.addClassName("lightboxfc_extra");
			new Insertion.Bottom(classdiv, lightboxfc);
			var label = document.createElement('label');
			label.innerHTML = "Confirm Password";
			label.setAttribute('for', 'confirmpassword');
			var control = document.createElement('input');
			control.setAttribute('id', 'confirmpassword');
			control.setAttribute('name', 'confirmpassword');
			control.setAttribute('type', 'password');
			new Insertion.Bottom(lightboxfc, label);
			new Insertion.Bottom(lightboxfc, control);
			

			
			var expertise = Array("Design", "Development", "Branding", "Marketing", "Other");
			var lightboxfc = document.createElement('div');
// 			lightboxfc.setAttribute('class', 'lightboxfc lightboxfc_withselectinside');
Element.extend(lightboxfc);
lightboxfc.addClassName("lightboxfc");
lightboxfc.addClassName("lightboxfc_extra");
			new Insertion.Bottom(classdiv, lightboxfc);
			var label = document.createElement('label');
			label.setAttribute('for', 'expertise');
			label.innerHTML = "Your field of expertise";
			var control = document.createElement('SELECT');
			control.setAttribute('id', 'expertise');
			control.setAttribute('name', 'expertise');
			new Insertion.Bottom(lightboxfc, label);
			new Insertion.Bottom(lightboxfc, control);
			for(var i=0; i< expertise.length; ++i)
			{
				var opt = document.createElement('option');
				opt.setAttribute('value', expertise[i]);
				opt.innerHTML = expertise[i];
				new Insertion.Bottom(control, opt);
			}

			var leftbg = document.createElement("div");
// 			leftbg.setAttribute('class', 'joinleftbg');
Element.extend(leftbg);
leftbg.addClassName("joinleftbg");
			new Insertion.Bottom(classdiv, leftbg);
			
			var rightbg = document.createElement("div");
// 			rightbg.setAttribute('class', 'joinrightbg');
Element.extend(rightbg);
rightbg.addClassName('joinrightbg');
			new Insertion.Bottom(classdiv, rightbg);
			
			var topbg = document.createElement("div");
// 			topbg.setAttribute('class', 'jointopbg');
Element.extend(topbg);
topbg.addClassName("jointopbg");
			new Insertion.Bottom(classdiv, topbg);
			
			var bottombg = document.createElement("div");
// 			bottombg.setAttribute('class', 'joinbottombg');
Element.extend(bottombg);
bottombg.addClassName('joinbottombg');
			new Insertion.Bottom(classdiv, bottombg);
			
			//profile div
			var profile = document.createElement('div');
// 			profile.setAttribute('class', "profilediv");
Element.extend(profile);
profile.addClassName("profilediv");
			new Insertion.Bottom(classdiv, profile);
			
			var thumnail = document.createElement('div');
// 			thumnail.setAttribute('class', 'profilethum');
Element.extend(thumnail);
thumnail.addClassName("profilethum");
			thumnail.setAttribute('id', 'profilethum_id');
			new Insertion.Bottom(profile, thumnail);
			
			var curprofilepic = document.createElement('span');
// 			curprofilepic.setAttribute('class', 'profilecon');
Element.extend(curprofilepic);
curprofilepic.addClassName("profilecon");
			curprofilepic.innerHTML="Your profile picture	";
			curprofilepic.setAttribute('id', 'upprofilepic_id');

			var upprofilepic = document.createElement('span');
// 			upprofilepic.setAttribute('class', 'profilecon');
Element.extend(upprofilepic);
upprofilepic.addClassName("profilecon");
			upprofilepic.innerHTML="<small style=\"cursor:pointer\"><u>Upload your picture</u></small>";
			upprofilepic.setAttribute('id', 'upprofilepic_id');
			if(Prototype.Browser.IE)
				upprofilepic.attachEvent("onclick", function(){showuploadbtn($('upprofilepic_id'))});
			else
				upprofilepic.setAttribute('onClick', "showuploadbtn(this)");
			
			var usedefault = document.createElement('span');
// 			usedefault.setAttribute('class', 'profilecon');
Element.extend(usedefault);
usedefault.addClassName('profilecon');
			
			usedefault.setAttribute('id', 'usedefault_id');
			usedefault.innerHTML="";
			new Insertion.Bottom(profile, curprofilepic);
			new Insertion.Bottom(profile, upprofilepic);
			new Insertion.Bottom(profile, usedefault);
			//
			
			//join checkbox gather
			var joincheckboxes = document.createElement('div');
// 			joincheckboxes.setAttribute('class', 'joinchecks');
Element.extend(joincheckboxes);
joincheckboxes.addClassName('joinchecks');
			new Insertion.Bottom(classdiv, joincheckboxes);
						
			var lightboxfc = document.createElement('div');
// 			lightboxfc.setAttribute('class', 'lightboxfc');
Element.extend(lightboxfc);
lightboxfc.addClassName("lightboxfc");

			new Insertion.Bottom(joincheckboxes, lightboxfc);
			
			var label = document.createElement('label');
			label.setAttribute('for', 'tc_check');
			label.innerHTML = "I have read full <a>Terms and Conditions</a>";
			new Insertion.Bottom(lightboxfc, label);
			
			var control = document.createElement('input');
			control.setAttribute('id', 'tc_check');
			control.setAttribute('name', 'tc_check');
			control.setAttribute('type', 'checkbox');
			new Insertion.Bottom(lightboxfc, control);
			
			var lightboxfc = document.createElement('div');
// 			lightboxfc.setAttribute('class', 'lightboxfc');
Element.extend(lightboxfc);
lightboxfc.addClassName("lightboxfc");

			new Insertion.Bottom(joincheckboxes, lightboxfc);
			
			var label = document.createElement('label');
			label.setAttribute('for', 'updatenews_check');
			label.innerHTML = "Send me updates and latest Jam news";
			new Insertion.Bottom(lightboxfc, label);
			
			var control = document.createElement('input');
			control.setAttribute('id', 'updatenews_check');
			control.setAttribute('name', 'updatenews_check');
			control.setAttribute('type', 'checkbox');
			new Insertion.Bottom(lightboxfc, control);

			
			var joinsubmit = document.createElement('div');
// 			joinsubmit.setAttribute('class', 'joinsubmit');
Element.extend(joinsubmit);
joinsubmit.addClassName('joinsubmit');
			new Insertion.Bottom(classdiv, joinsubmit);
			
			var joinsubmitbtn = document.createElement('a');
// 			joinsubmitbtn.setAttribute('class', 'joinsubmitbtn');
Element.extend(joinsubmitbtn);
joinsubmitbtn.addClassName('joinsubmitbtn');
if(Prototype.Browser.IE)
{
	
	joinsubmitbtn.attachEvent("onclick", function(){createaccount()})
}
	else
		joinsubmitbtn.setAttribute('onclick', "createaccount()");
			new Insertion.Bottom(joinsubmit, joinsubmitbtn);
			
			//
			var closediv = document.createElement('div');
// 			closediv.setAttribute('class', 'closediv');
Element.extend(closediv);
closediv.addClassName('closediv');
	if(Prototype.Browser.IE)
		closediv.attachEvent("onclick", function(){closejoin()});
		else
			closediv.setAttribute('onClick', "closejoin()")
			new Insertion.Bottom(classdiv, closediv);
			
			Effect.Appear('lightboxform_id', { duration: 0.8, from:0, to:0.6	});
			setTimeout(function(){Effect.Appear('globalmove_id', { duration: 1, from:0, to:1});}, 900);
}
function closelogin()
{
// 	alert("Close!!");
// $$('.signinbtn')[0].setAttribute('onClick', "showlightbox('login')");
// $$('.signupbtn')[0].setAttribute('onClick', "showlightbox('join')");


	if($$('.loginformcover')[0])
	{
		$$('.loginformcover')[0].parentNode.removeChild($$('.loginformcover')[0]);
		Effect.Appear('lightboxform_id', { duration: 0.8, from:0.6, to:0	});
		setTimeout("$('lightboxform_id').style.display='none'; restoreevent()", 900);
	}
	
}
function restoreevent()
{
	if($('closeprompt'))
	{
		$('closeprompt').parentNode.removeChild($('closeprompt'));
	}
	$$('.signinbtn')[0].stopObserving('click');
	$$('.signupbtn')[0].stopObserving('click');
	Event.observe($$('.signinbtn')[0], 'click', function(){showlightbox('login')})
	Event.observe($$('.signupbtn')[0], 'click', function(){showlightbox('join')})
}
function closejoin()
{
// 	$$('.signinbtn')[0].setAttribute('onClick', "showlightbox('login')");
// $$('.signupbtn')[0].setAttribute('onClick', "showlightbox('join')");
// Event.observe($$('.signinbtn')[0], 'click', function(){showlightbox('login')})
// Event.observe($$('.signupbtn')[0], 'click', function(){showlightbox('join')})

// $$('.signinbtn')[0].stopObserving('click');
// $$('.signupbtn')[0].stopObserving('click');
// Event.observe($$('.signinbtn')[0], 'click', function(){showlightbox('login')})
// Event.observe($$('.signupbtn')[0], 'click', function(){showlightbox('join')})
// 
// if($('closeprompt'))
// {
// 	$('closeprompt').parentNode.removeChild($('closeprompt'));
// }
	if($$('.joinformcover')[0])
	{
		$$('.globalmove')[0].setAttribute('class', "globalmove");
		$$('.joinformcover')[0].parentNode.removeChild($$('.joinformcover')[0]);
		Effect.Appear('lightboxform_id', { duration: 1, from:0.6, to:0	});
		setTimeout("$('lightboxform_id').style.display='none';restoreevent()", 1100);
	}
}
function showprompt()
{
	showlightbox('login');
}
function createaccount()
{
// 	var formtoserialized = $$("form[name='formbox']")[0];
// 	var allfields = formtoserialized.elements;
// 	var tmpform = document.createElement('form');
// 	
// 	for(var i=0; i<allfields.length; ++i)
// 	{
// 		if(!(allfields[i].getAttribute('name')=="confirmpassword"))
// 		{
// 			var tmpnode = document.createElement('input');
// 			tmpnode.setAttribute('type', 'text');
// 			tmpnode.setAttribute('name', allfields[i].getAttribute('name'));
// 			tmpnode.setAttribute('value', allfields[i].value);
// 			
// 			new Insertion.Bottom(tmpform, tmpnode);
// 		}
// 		
// 	}
// 		Element.extend(tmpform);
// 		datetosent = tmpform.serialize();
// 	
// 	var path = "/mod/createaccount.php";
// 	new Ajax.Request(path, {method:'GET',parameters:{formdata:datetosent}, onComplete:function(transport)
// 	{
// 		if(transport.responseText=="successfully created")
// 		{
// 			closejoin();
// 			setTimeout("showprompt()", 1150)
// 		}
// 		
// 	}});

if(checkcompletion("join"))
{
	accontavailable = false;
	var path = "/mod/createaccount.php?ajaxaction=checkavailable";
	username = $$("input[name='username']")[0].value;
	email = $$("input[name='email']")[0].value;
	if(Ajax)
	new Ajax.Request(path, {method:'GET', parameters:{causername:username, caemail:email}, onComplete:function(transport)
		{
// 			alert(transport.responseText);
if($('emailerror'))
{
	$('emailerror').parentNode.removeChild($('emailerror'));
}
if($('usernameerror'))
{
	$('usernameerror').parentNode.removeChild($('usernameerror'));
}

			var separates = (transport.responseText).split("|");
			var emailstatus = separates[0].split("#");
			var usernamestatus = separates[1].split("#");
			
			if(!(emailstatus[1]=="valid" && usernamestatus[1]=="valid"))
			{
// 				alert("X");
				if(emailstatus[1]=="invalid")
				{
					
					var errorp = document.createElement("div");
					errorp.setAttribute("ID", "emailerror");
					errorp.style.position="absolute";
					errorp.style.right="0px";
					errorp.style.top = "23px";
					errorp.style.color = "#f9f8a6";
					errorp.innerHTML = "Existing Email";
					new Insertion.Bottom($$("input[name='email']")[0].parentNode, errorp);
					
				}
				if(usernamestatus[1]=="invalid")
				{
					var errorp = document.createElement("div");
					errorp.setAttribute("ID", "usernameerror");
					errorp.style.position="absolute";
					errorp.style.right="0px";
					errorp.style.top = "23px";
					errorp.style.color = "#f9f8a6";
					errorp.innerHTML = "Existing Username";
					new Insertion.Bottom($$("input[name='username']")[0].parentNode, errorp);
				}
			}
			else
			{
				accontavailable = true;
				var formtosubmit = $$("form[name='formbox']")[0];
				formtosubmit.setAttribute("action", "/mod/createaccount.php");
				formtosubmit.setAttribute("enctype", "multipart/form-data");
				formtosubmit.submit();
			}
				
			
				
		}}
	);
}

// if(accontavailable)
// {
// 	
// 	var formtosubmit = $$("form[name='formbox']")[0];
// 	formtosubmit.setAttribute("action", "/mod/createaccount.php");
// 	formtosubmit.setAttribute("enctype", "multipart/form-data");
// 	formtosubmit.submit();
// // 	alert(formtosubmit);
// }

}
function submitlogin(e)
{
// 	alert("submit login");
	if($$('span.failloginpromptspan')[0]) 
	{
// 		alert("delete prompt"+$$('span.failloginpromptspan')[0].className);
		$$('span.failloginpromptspan')[0].parentNode.removeChild($$('span.failloginpromptspan')[0]);
	}
	returnto = (location.hash).replace("#", "");
	returnto = (returnto).replace(" ", "");
// 	alert("'"+returnto+"'");
// 	if(returnto=="return")
// 	{
// // 		alert(returnto+" : "+readCookie('return_to'));
// 		var addtopath = "&returnto="+readCookie('return_to');
// 	}
// 	alert("login submit");
	var path = "/mod/createaccount.php?ajaxaction=login";
	formtosent = $$("form[name='formbox']")[0];
	datatosent = formtosent.serialize();
// 	alert("submit login");
// 	alert("login submit : ajax start");
if(Ajax)
	new Ajax.Request(path, {method:'GET',parameters:{formdata:datatosent}, onComplete:function(transport)
		{
// 			alert("login submit : ajax complete");
// 			alert('here	'+transport.responseText);
			if(transport.responseText == "login successfully")
			{
// 				alert("syfowieu");
				if((returnto != "login") && (returnto))
				{
// 					alert("Execute this ?");
					var returnpage = Url.decode(readCookie('return_to'));
// 					alert('return to previous'+returnpage);
					window.location=returnpage;
				}
				else if(returnto=="login")
				{
// 					var returnpage = Url.decode(readCookie('return_to'));
// // 					alert('return to previous'+returnpage);
					window.location="http://b42.co.uk/home.b42";;
				}
				else
				{
// 						alert('return cuttent');
// 	alert("location hash : "+location.hash);
						
						location.href = (location.href).replace("#", "");
				window.location = location.href;
				}
			}
			else
			{
				var failloginprompt = document.createElement("span");
				Element.extend(failloginprompt);
				failloginprompt.setAttribute("id", "failloginprompt");
				
				if(Prototype.Browser.webkit)
				{
					failloginprompt.className = "failloginpromptspan";
				}
				else
					failloginprompt.addClassName("failloginpromptspan");
				failloginprompt.innerHTML = "Incorrect user name or password";
				new Insertion.Bottom($('signinpromptdiv'), failloginprompt);
			}
		}});
// 	alert("login submit : ajax end");
		Event.stop(e);

		
}
function userlogout()
{
	var path = "/mod/createaccount.php?ajaxaction=logout";
	if(Ajax)
	new Ajax.Request(path, {method:'GET', onComplete:function(transport)
		{
			if(transport.responseText == "logout successully")
			{
// 				$$('.loginsignup')[0].setAttribute('onClick', "showlightbox('login')");
// 				$$('.loginsignup')[0].innerHTML = 
// 					"<div class='signinbtn' 'showlightbox(\'login\')'></div>or<div onClick=\"showlightbox('join')\" class='signupbtn'></div>";
					
					
					$$('.loginsignup')[0].innerHTML = "";
					
					
					
						$$('.loginsignup')[0].innerHTML = 
					"<div class='signinbtn'></div>or<div class='signupbtn'></div>";
					
					$$('.signinbtn')[0].stopObserving('click');
					$$('.signupbtn')[0].stopObserving('click');
					Event.observe($$('.signinbtn')[0], 'click', function(){showlightbox('login')})
					Event.observe($$('.signupbtn')[0], 'click', function(){showlightbox('join')})
					
			}
		}
	});
}
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 showuploadbtn(obj)
{
	
var parentobj = obj.parentNode;
// alert(parentobj);
	if(Prototype.Browser.IE)
	{
		Element.extend(parentobj);
		
		parentobj.addClassName('uploadinside');
	}
	else
	{
		var existingclass = parentobj.getAttribute("class");
		parentobj.setAttribute('class', existingclass+" uploadinside");
	}

	var faceelement = document.createElement('div');
// 	faceelement.setAttribute("class", "face");
Element.extend(faceelement);
		faceelement.addClassName("face");

// 	parentobj.removeChild(obj);
	
	var upload = document.createElement("input");
	upload.setAttribute('type', 'file');
	upload.setAttribute('name', 'userheader');
// 	upload.setAttribute('class', 'profilecon upload');
Element.extend(upload);
		upload.addClassName("upload");
		upload.addClassName("profilecon");

	if(Prototype.Browser.IE)
		upload.attachEvent("onchange", function(){copyvalue(this)});
		else
	upload.setAttribute("onChange", "copyvalue(this)");
	new Insertion.Before(obj, upload);
	parentobj.removeChild(obj);
	new Insertion.Before(upload, faceelement);	

}
function makeattachFile(obj)
{
	var parentnode = obj.parentNode;
	parentnode.removeChild(obj);
	
	var upload = document.createElement("input");
	upload.setAttribute("type", "file");
	upload.setAttribute("name", "commentattach");
	Element.extend(upload);
	upload.addClassName("attachcontrol");
	upload.observe("change", function(){copyvalue2($$("input[name='commentattach']")[0])});
	
	var faceelement = document.createElement("div");
	Element.extend(faceelement);
	faceelement.addClassName("faceofattach");
	
	
	parentnode.style.border = "none";
	parentnode.style.width="257px";
	parentnode.style.height="21px";
	
	new Insertion.Bottom(parentnode, faceelement);
	new Insertion.Bottom(parentnode, upload);
	
	
}
function copyvalue2(obj)
{
	$$('.faceofattach')[0].innerHTML = obj.value;
}
function copyvalue(obj)
{
// 	alert("onchange fire");
	$$('.face')[0].innerHTML = obj.value;
}
function closefirst(action_)
{
// 	var oTextNode = document.createTextNode("Please Close the "+action_+" box first to do anything else.");
// 	$$(".topblock")[0].appendChild(oTextNode);
if(!$('closeprompt'))
{
$$(".topblock")[0].style.position="relative";
	var spantext = document.createElement('span');
	spantext.setAttribute("id", "closeprompt");
	spantext.innerHTML = "Close the form first.";
	spantext.style.position="absolute";
	spantext.style.left="430px";
	spantext.style.fontSize="10.5pt";
	spantext.style.color="red";
	spantext.style.bottom="0px";
	
// 	element.style {
// bottom:0;
// color:red;
// font-size:10.5pt;
// left:430px;
// position:absolute;
// }
	
	new Insertion.Bottom($$(".topblock")[0], spantext);
}
	
}

function checkcompletion(form_)
{
	var fieldcompletion = true;
	switch(form_)
	{
		case "login" : 
			break;
		case "join" :
			var fieldtocheck = Array("yourname", "username", "email", "password", "confirmpassword");
			for(var i=0; i<fieldtocheck.length; ++i)
			{
				
				if(!($$("input[name='"+fieldtocheck[i]+"']")[0].value))
				{
					fieldcompletion = false;
// 					alert($$("input[name='"+fieldtocheck[i]+"']")[0].getAttribute("name")+":"+i);
					var chs = $$("input[name='"+fieldtocheck[i]+"']")[0].parentNode.childNodes;
					var create = true;
					for(var i_=0; i_<chs.length; ++i_)
					{
						if(chs[i_].getAttribute("class") == "mandatorynotfiled")
						{
							create = false;
							break;
						}
					}
					if(create)
					{
						var error_p = document.createElement('div');
						error_p.innerHTML = "mandatory field";
						error_p.setAttribute("class", "mandatorynotfiled");
						error_p.style.position="absolute";
						error_p.style.top="23px";
						error_p.style.color="red";
						error_p.style.right="0px";
						fieldcompletion = false;
						new Insertion.Bottom($$("input[name='"+fieldtocheck[i]+"']")[0].parentNode, error_p);
					}
				}
				else
				{
					
					var childs = $$("input[name='"+fieldtocheck[i]+"']")[0].parentNode.childNodes;
					
					for(var j=0; j<childs.length; ++j)
					{
						
						if(childs[j].getAttribute("class")=="mandatorynotfiled")
						{
							
							(childs[j].parentNode).removeChild(childs[j]);
						}
						
					}
// 					while($$("input[name='"+fieldtocheck[i]+"']")[0].parentNode.firstChild)
// 					{
// 						alert("XX");
// 						var first = $$("input[name='"+fieldtocheck[i]+"']")[0].parentNode.firstChild;
// 						if(first.getAttribute("class") == "mandatorynotfiled")
// 						{
// 							first.parentNode.removeChild(first);
// 						}
// 					}
				}
				
				if($$("input[name='confirmpassword']")[0].value)
				{
					
					if(!($$("input[name='confirmpassword']")[0].value == $$("input[name='password']")[0].value))
					{
						var pschildnodes = $$("input[name='confirmpassword']")[0].parentNode.childNodes;
						for(var psi = 0; psi < pschildnodes.length; ++psi)
						{
							if(pschildnodes[psi].getAttribute('class') == "mandatorynotfiled")
							{
								pschildnodes[psi].parentNode.removeChild(pschildnodes[psi]);
								break;
							}
						}
						
						fieldcompletion = false;
						var ps_error_p = document.createElement('div');
						ps_error_p.innerHTML = "Password Not Match";
						ps_error_p.setAttribute("class", "mandatorynotfiled");
						ps_error_p.style.position="absolute";
						ps_error_p.style.top="23px";
						ps_error_p.style.color="red";
						ps_error_p.style.right="0px";
						
						
						new Insertion.Bottom($$("input[name='confirmpassword']")[0].parentNode, ps_error_p);
					}
					else
					{
							var pschilds = $$("input[name='confirmpassword']")[0].parentNode;
							for(var k=0; k<pschilds.length; ++k)
							{
								if(pschilds[k].getAttribute("class")=="mandatorynotfiled")
									pschilds[k].parentNode.removeChild(pschilds[k]);
							}
					}
				}
				
				
				
			}
			if($$("input[name='email']")[0].value)
			{
// 					alert("VALUE : "+$$("input[name='email']")[0]);
				var usnchildnodes = $$("input[name='email']")[0].parentNode.childNodes;
// 					alert("email loop")
				for(var usni = 0; usni < usnchildnodes.length; ++usni)
				{
					if((usnchildnodes[usni].getAttribute('class') == "mandatorynotfiled") || ((usnchildnodes[usni].getAttribute('id') == "emailerror")))
					{
// 							alert(usnchildnodes[usni].getAttribute('class'));
						usnchildnodes[usni].parentNode.removeChild(usnchildnodes[usni]);
						
					}
				}
// 					alert("end email loop")
// 					alert("check email"); 
				var myregex = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
				var strtosearch = $$("input[name='email']")[0].value;
// 					alert(strtosearch.search(myregex));
				if(strtosearch.search(myregex) < 0)
				{
					fieldcompletion = false;
// 						alert("not valid");
					var ps_error_p = document.createElement('div');
					ps_error_p.innerHTML = "Not a valid Email Address";
					ps_error_p.setAttribute("class", "mandatorynotfiled");
					ps_error_p.setAttribute("ID", "emailnotvalid");
					ps_error_p.style.position="absolute";
					ps_error_p.style.top="23px";
					ps_error_p.style.color="red";
					ps_error_p.style.right="0px";
					
					new Insertion.Bottom($$("input[name='email']")[0].parentNode, ps_error_p);
				}
			}
			
			if($$("input[name='username']")[0].value)
			{
// 					alert("VALUE : "+$$("input[name='email']")[0]);
				var usnchildnodes = $$("input[name='username']")[0].parentNode.childNodes;
// 					alert("email loop")
				for(var usni = 0; usni < usnchildnodes.length; ++usni)
				{
// 					alert(usni);
					if((usnchildnodes[usni].getAttribute('class') == "mandatorynotfiled") || (usnchildnodes[usni].getAttribute('id') == "usernameerror"))
					{
// 							alert(usnchildnodes[usni].getAttribute('class'));
						usnchildnodes[usni].parentNode.removeChild(usnchildnodes[usni]);
						
					}
				}
// 					alert("end email loop")
// 					alert("check email"); 
				var myregex = /^[A-Za-z0-9\.\_\-]{2,150}$/;
				var strtosearch = $$("input[name='username']")[0].value;
// 					alert(strtosearch.search(myregex));
				if(strtosearch.search(myregex) < 0)
				{
					fieldcompletion = false;
// 						alert("not valid"+strtosearch);
					var ps_error_p = document.createElement('div');
					ps_error_p.innerHTML = "Not a valid Username";
					ps_error_p.setAttribute("class", "mandatorynotfiled");
					ps_error_p.setAttribute("ID", "usernamenotvalid");
					ps_error_p.style.position="absolute";
					ps_error_p.style.top="23px";
					ps_error_p.style.color="red";
					ps_error_p.style.right="0px";
					
					new Insertion.Bottom($$("input[name='username']")[0].parentNode, ps_error_p);
				}
			}
			
			break;
	}
	return fieldcompletion;
}
function getElementsByClassName(classname, tagname)
{
	var eles = document.getElementsByTagName(tagname);
	for(var i=0; i<eles.length; ++i)
	{
		if((eles[i].className).indexOf(classname)>-1)
		{
			var thisele = eles[i];
			break;
		}
	}
	return thisele;	
}
var indexUnit = 1;
var scrollwidth;
function twowaydirection(direction)   // Woking well Gallery Javascript Code
{
	var ele = $('#canscrollingbar');
	var itemunit = 833;
	var currentPosPixel = (-itemunit)*(indexUnit-1);
	var xmove = ((direction.toLowerCase()).indexOf("next") > -1)?(-833):(833);
	var xunit = ((direction.toLowerCase()).indexOf("next") > -1)?(1):(-1);
	ele.each(function(index, iele){scrollwidth = iele.scrollWidth});

	var islast = (indexUnit==(scrollwidth/itemunit))?(true):(false);
	
	var isfirst = (indexUnit == 1)?(true):(false);
	if(islast && isfirst)
	{}
	else
	{
		
		if(islast && ((direction.toLowerCase()).indexOf("next") > -1))
		{		
			ele.animate({left:'0px'}, 1000, function() {});
			indexUnit = 1;
		}
		else if(isfirst && ((direction.toLowerCase()).indexOf("previous") > -1))
		{
			ele.animate({left:-(scrollwidth-itemunit)+'px'}, 1000, function() {});
			indexUnit = scrollwidth/itemunit;
		}
		else
		{
			if(xunit>0)
			{ele.animate({left:(xmove*indexUnit)+'px'}, 1000, function() {});}
			else
			{ele.animate({left:(currentPosPixel+itemunit)+'px'}, 1000, function() {});}
			indexUnit = indexUnit+(xunit);
		}
	}
}

