// JavaScript Document
	var lastZ=1;
	var openWindows=0;
	var id;
	var userInfo;
	function makeDraggable(id){
		$("#"+id).draggable({ containment: '#containment-wrapper', scroll: false});
		raiseMyIndex(id);
	}

	function removeDraggable(id){
		$("#"+id).draggable('destroy');
	}	
	function raiseMyIndex(id){
		lastZ = lastZ +2;
		$("#"+id).css('z-index',lastZ)
	}	
	function showWindow(id,type,userId){

		if((myID == -1 || myID == '') && ((id==1) || (id==2) || (id==3) || (id==7) || (id==11)))
		{
			getLogin();
			return false;
		}	
		else if($('#win'+id).attr('id') )
		{
			var myWidth = $("#win"+id).width();
			var parentWidth =$($("#win"+id).parent('div')).width();
			var leftValue = (parentWidth/2)-(myWidth/2);
			raiseMyIndex("win"+id);
			if(!($('#win'+id).css("display")=="block")){			
				$('#win'+id).css("display", "block");
				$("#win"+id).css({"top":"70px", "left": leftValue+"px"});
			}		
			if(id==3) getPhotos();
		}
		else{
			winTitle='';
			switch(id)
			{
				case '0':
					winTitle='Register';
					break;				
				case '1':
					winTitle='My Profile';
					break;				
				case '2':
					winTitle='Friends';
					break;					
				case '3':
					winTitle='Photos';
					break;
				case '4':
					winTitle='Search';
					break;
				case '5':
					winTitle='Videos';
					break;
				case '6':
					winTitle='Blogs';
					break;
				case '7':
					winTitle='Messages';
					break;	
				case '8':
					winTitle='Games';
					break;
				case '9':
					winTitle='Downloads';
					break;
				case '11':
					winTitle='Settings';
					break;
			}
			html='<div class="png'+id+'" id="win'+id+'" style="top:70px;left:130px;" onmousedown="raiseMyIndex(this.id)" onmouseup="removeDraggable(this.id)">'
			+'<div>'
				+'<div class="top_center" onmousedown="makeDraggable(\'win'+id+'\')" onmouseup="removeDraggable(\'win'+id+'\')">'
					+'<div class="winTitle" id="winTitle_'+id+'">'+winTitle+'</div>'
					+'<div class="win_controls" onclick="hideWindow(\''+id+'\')">'
						+'<img class="png'+id+'" src="'+CDN_IMG+'/new/close.png" alt="Close window" title="Close" /></div>'		
				+'</div>'
				+'<div class="top_left png'+id+'">'
				+'</div>'
				+'<div class="top_right">'
				+'</div>'
			+'</div>'
			+'<div id="winContent'+id+'" class="win_content">'			
			+'</div>'
			+'<div class="footer">'
				+'<div class="bottom_left">'
				+'</div>'
				+'<div class="bottom_center">'
				+'</div>'
				+'<div class="bottom_right">'
				+'</div>'
			+'</div>'
			+'</div>';		
			if($('#containment-wrapper').append(html))
			{
				raiseMyIndex("win"+id);
				if(id==0)getRegisterationForm();
				else if (id==1)	getProfile();	
				else if(id==2)getFriends();	
				else if(id==3) getPhotos();
				else if (id==5)	getVideo(type);
				else if (id==6) getMessages();				
				else if(id==7) getMessages();
				else if (id==8)	loadGames();	
				else if (id==9)	getDownloads();	
				else if(id==11) getSettingsHTML()
			}
		}	
	}
	function getDownloads()
	{
		html='<div class="download_categories">'
			+'<div class="main_cate" onclick="listDownloadCat(1)"></div>'
			+'<div class="main_cate" onclick="listDownloadCat(2)"></div>'
			+'<div class="main_cate" onclick="listDownloadCat(3)"></div>'						
			+'</div>';
		if($('#winContent9').html(html))	
		{
			
		}		
	}	
	function listDownloadCat(parentCat)
	{
		html='';
		$.post(URL+"/downloads.php/categories/listCategories",'parent_category='+parentCat,function(data) {
			if(data.errors!=null)
			{
				catPath='';
				for(x=0;x<data.errors.length;x++)
				{	
					xx='<span style="cursor:pointer;" onclick="'
						 if(data.errors[x]['root_cat']!=1)
							 xx+='listDownloadCat('+data.errors[x]['category_id']+')'; 
						 else
							 xx+='listDownloadFiles('+data.errors[x]['category_id']+')';
						 xx+='" >'+data.errors[x]['category_title']+'</span> / ';
					catPath=xx+catPath;
				}
				html+='<div class="directory_title"><span style="cursor:pointer;" onclick="getDownloads()">Root</span> / '+catPath+'</div> '
			}
			if(data.message!=null)
			{					
				html+='<div style="height:340px;width:93%;margin:20px 0px 0px 20px;overflow-y: auto;">'
				for(i=0;i<data.message.length;i++)
				{	
					html+='<div class="subcategory_block" onclick="'
						 if(data.message[i]['root_cat']!=1)
							 html+='listDownloadCat('+data.message[i]['category_id']+')'; 
						 else
							 html+='listDownloadFiles('+data.message[i]['category_id']+')';
						 html+='"><img src="'+CDN_DOWNLOADS+'/thumb/'+data.message[i]['category_image']+'" width="140px" height="100px"/><div class="subcategory_text">'+data.message[i]['category_title']+'</div></div>'
				}	
				html+='</div>'				
			}	
			else
			{
				html+='<div style="margin:20px 0px 0px 30px;color:#fff;font-weight:bold;">There is no SubCategories</div>';
			}
			$('#winContent9').html(html);			
		},'json');		
	}
	
	function listDownloadFiles(parentCat)
	{
		html='';
		$.post(URL+"/downloads.php/files/list",'parent_category='+parentCat,function(data) {
			if(data.errors!=null)
			{
				catPath='';
				for(x=0;x<data.errors.length;x++)
				{	
					xx='<span style="cursor:pointer;" onclick="'
						 if(data.errors[x]['root_cat']!=1)
							 xx+='listDownloadCat('+data.errors[x]['category_id']+')'; 
						 else
							 xx+='listDownloadFiles('+data.errors[x]['category_id']+')';
						 xx+='" >'+data.errors[x]['category_title']+'</span> / ';
					catPath=xx+catPath;
				}
				html+='<div class="directory_title"><span style="cursor:pointer;" onclick="getDownloads()">Root</span> / '+catPath+'</div> '
			}
			if(data.message!=null)
			{		
				html+='<div class="subcategory_list_header">'
					+'<div class="subcategory_name">File Name</div>'
					+'<div class="subcategory_preview">Preview</div>'				 
					+'<div class="subcategory_download">Download</div>'			
					+'</div>'					
					+'<div class="downloads_content">'
				for(i=0;i<data.message.length;i++)
				{					
					html+='<div class="downloads_list">'
						 +'<div class="subcategory_name">'+data.message[i]['file_title']+'</div>'
						 +'<div  class="subcategory_preview" ><img src="'+CDN_IMG+'/new/palette.png" onmouseout="$(\'#file_'+data.message[i]['file_id']+'\').hide();" onmouseover="$(\'#file_'+data.message[i]['file_id']+'\').show();"/></div>'
						 +'<div id="file_'+data.message[i]['file_id']+'" onmouseover="$(this).show();" onmouseout="$(this).hide()" class="previewDownload">'
						 //alert(data.message[i]['file_type'].substring(0,5))
						 if(data.message[i]['file_type'].substring(0,5)=='audio')
							{ 
		/*html+='<object  classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" name="player" width="295" height="242">'
		+'<param name="movie" value="'+CDN_SWF+'/player-viral.swf" /><param name="wmode" value="transparent" />'
		+'<param name="allowfullscreen" value="true" />'
		+'<param name="allowscriptaccess" value="always" />'
		+'<param name="flashvars" value="file='+CDN_SWF+'/video.flv&autostart=true&logo='+CDN_SWF+'/kfc.png" />'
		+'<object type="application/x-shockwave-flash" data="'+CDN_SWF+'/player-viral.swf" width="295" height="242">'
			+'<param name="movie" value="'+CDN_SWF+'/player-viral.swf" />'
			+'<param name="allowfullscreen" value="true" />'
			+'<param name="allowscriptaccess" value="always" /><param name="wmode" value="transparent" />'
			+'<param name="flashvars" value="file='+CDN_SWF+'/'+data.message[i]['file_file']+'&autostart=true&logo='+CDN_SWF+'/kfc.png" />'
		+'</object>'
	+'</object>';*/
							/* html += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" '
								html += 'width="320" ';
								html += 'height="60" ';
								html += 'title="MultiBoxMedia">';
					  			html += '<param name="movie" value="'+CDN_SWF+'/mp3player.swf" />'
					  			html += '<param name="quality" value="high" />';
					  			html += '<param name="salign" value="TL" />';
					  			html += '<param name="scale" value="noScale" />';
					  			html += '<param name="FlashVars" value="path='+CDN_DOWNLOADS+'/'+data.message[i]['file_file']+'" />';
					  			html += '<embed src="'+CDN_SWF+'/mp3player.swf" ';
					  			html += 'quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" ';
					  			html += 'width="320" ';
					  			html += 'height="60"';
					  			html += 'salign="TL" ';
					  			html += 'scale="noScale" ';
					  			html += 'FlashVars="path='+CDN_DOWNLOADS+'/'+data.message[i]['file_file']+'"';
					  			html += '></embed>';
								html += '</object>';*/
								html+='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"  '
									+'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" '
									+'align="middle" height="27" width="400">'
									+'<param name="quality" value="best">'
									+'<param name="allowScriptAccess" value="never">'
									+'<param name="wmode" value="window">'
									+'<param name="movie" '
									+'value="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl='+CDN_DOWNLOADS+'/'+data.message[i]['file_file']+'">'
									+'<embed classname="audio-player-embed" type="application/x-shockwave-flash" '
									+'src="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl='+CDN_DOWNLOADS+'/'+data.message[i]['file_file']+'" '
									+'allowscriptaccess="never" quality="best" bgcolor="#ffffff" wmode="window" flashvars="playerMode=embedded" '
									+'pluginspage="http://www.macromedia.com/go/getflashplayer" height="27" width="400">'
									+'</object>'
									
								//html+='<embed height="27" width="400" flashvars="playerMode=embedded" wmode="window" bgcolor="#ffffff" quality="best" allowscriptaccess="never" src="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl='+CDN_DOWNLOADS+'/'+data.message[i]['file_file']+'" type="application/x-shockwave-flash"/>'
								//html+='<embed type="application/x-shockwave-flash" src="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl='+CDN_DOWNLOADS+'/'+data.message[i]['file_file']+'" width="400" height="27" allowscriptaccess="never" quality="best" bgcolor="#ffffff" wmode="window" flashvars="playerMode=embedded" />';
								//html+='<object height="50%" width="50%" classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95"><param name="AutoStart" value="1" /><param name="FileName" value="'+CDN_DOWNLOADS+'/'+data.message[i]['file_file']+'" /></object>';
								
							}							 
						else if(data.message[i]['file_preview']=='')
							html+='<img src="'+CDN_IMG+'/new/no-image.gif"/>'
						else
							html+='<img src="'+CDN_DOWNLOADS+'/thumb/'+data.message[i]['file_preview']+'"/>'
						 
						 html+='</div>'
						 +'<div class="subcategory_download"><a href="'+CDN_DOWNLOADS
						 
						 if(data.message[i]['file_type'].substring(0,5)=='audio'){
							 html+=''
						 }else{
							html+=''
						 }
						 html+='/'+data.message[i]['file_file']+'"><img src="'+CDN_IMG+'/new/arrow_down.png" alt="Download" title="Download"/></a></div>'
						 +'</div>'		
						 
				 /*				  
					html+='<tr>'
						+'<td><input type="checkbox" class="checkbox" value="'+data.message[i]['category_id']+'" id="downloadCheckbox[]" name="downloadCheckbox[]"/></td>'
						+'<td>'+data.message[i]['category_title']+'</td>'		
						if(data.message[i]['root_cat']!=1)
							html+='<td><a href="javascript:void(null)" title="Post" onclick="loadContent(\'downloadCatList\','+data.message[i]['category_id']+');">Sub Categories</a></td>'
						else
							html+='<td><a href="javascript:void(null)" title="Post" onclick="loadContent(\'uploadFiles\','+data.message[i]['category_id']+');">Upload Files</a></td>'
						//+'<td><a href="javascript:void(null)" title="Post"><img src="'+CDN_IMG+'/icon-edit.gif"/></a></td>'
						html+='<td><a href="javascript:void(null)"  title="Delete" onclick=" deleteDownloadCat('+parentCat+','+data.message[i]['category_id']+')"><img src="'+CDN_IMG+'/icon-trash.gif"/></a></td></tr>'						
						*/												
				}	
				html+='</div>'				
			}
			else
			{
				html+='<div style="margin:20px 0px 0px 30px;color:#fff;font-weight:bold;">There is no Files</div>';
			}
			$('#winContent9').html(html);
		},'json');
		
	}

function getSettingsHTML()
	{
		html='<div class="win_content_middle">'
			+'<div class="settings_tab_nav">'
			+'<div id="accountDiv" class="settings_tab_selected" onclick="doAccountDiv()">Account</div>'
			+'<div id="passwordDiv" class="settings_tab_disabled" onclick="doPasswordDiv()">Password</div>'
			+'<div id="prefDiv" class="settings_tab_disabled" onclick="doPrefDiv()">My Photo</div></div>'
			+'<div id="accountSettings" class="settings_tab_content">'
			+'<form><fieldset><legend>Login info</legend>'
			+'<div class="settings_element_container">'
			+'<div class="input_title"><label for="settingUsername">User Name:</label></div>'
			+'<div class="input_div"><input type="text" name="settingUsername" id="settingUsername" /><div id="settingUsername_error_text" style="margin-top:3px"></div></div>'
			+'</div><div class="settings_element_container">'			
			+'</div></fieldset>'
			+'<legend>Security</legend>'
			+'<div class="settings_element_container">'
			+'<div class="input_title"><label for="settingQuestion">Security Question:</label></div>'
			+'<div class="input_div">'
			+'<select id="settingQuestion" name="settingQuestion">'
				+'<option value="1">What\'s your favorite book?</option>'
				+'<option value="2">Who is your favorite Hero?</option>'
				+'<option value="3">What\'s your favorite Movie or Car?</option>'
				+'</select></div></div>'		
				+'<div class="settings_element_container">'
				+'<div class="input_title"><label for="settingAnswer">Security Answer:</label></div>'
				+'<div class="input_div"><input type="text" name="settingAnswer" id="settingAnswer"/></div></div>'
				+'<div class="settings_tab_selected" onclick="submitAllSettings();">Save Settings</div>'
				+'</form><br/><br/><br/><br/><br/><br/><br/><br/><br/><div  id="updateSettingsMess" ></div></div>'
				+'<div id="passwordSettings" class="settings_tab_content"><form><fieldset>'
				+'<legend>Password</legend>'
				+'<div class="settings_element_container">'
				+'<div class="input_title"><label for="settingOldPassword">Old Password:</label></div>'
				+'<div class="input_div"><input type="password" name="settingOldPassword" id="settingOldPassword"  onblur="password_validation(\'settingOldPassword\')" /><div id="settingOldPassword_error_text" style="margin-top:3px"></div>'
				+'</div></div>'
				+'<div class="settings_element_container">'
				+'<div class="input_title"><label for="settingNewPassword">New Password:</label></div>'
				+'<div class="input_div"><input type="password" name="user_password" id="user_password"  onblur="password_validation(\'user_password\');"/>'
				+'<div id="user_password_error_text" style="margin-top:3px"></div></div></div>'
				+'<div class="settings_element_container">'
				+'<div class="input_title"><label for="settingRetype">Retype Password:</label></div>'
				+'<div class="input_div"><input type="password" name="user_re_password" id="user_re_password" onblur="re_password_validation(\'user_re_password\',\'user_password\')"/>'
				+'<div id="user_re_password_error_text" style="margin-top:3px"></div></div></div>'
				+'<div class="settings_tab_selected" onclick="submitPassword();">Save Settings</div>'
				+'</form><br/><br/><br/><br/>'
				+'<span  id="passwordSettingsMess" ></span></div>'
				+'<div id="prefSettings" class="settings_tab_content_disabled">'
				+'<fieldset>'
				+'<legend>Upload photo</legend>'
				+'<div class="settings_element_container">'
				+'<div class="input_title"><label for="settingUsername">User photo:</label></div>'
				+'<div class="input_div">'
				+'<form action="'+URL+'/settings.php/upload/uploadUserPhoto" method="post" id="photoForm" enctype="multipart/form-data" >'
				+'<input type="file" size="20" style="*width:200px !important;" name="profilePhoto" id="profilePhoto"  />'
				+'<br/><br/><br/>'
				+'<span style="display:none" id="debugPhoto" ></span><input type="hidden" name="myUserID" id="myUserID" value="'+myID+'" >'
				+'<br/><br/><input type="submit" value="Update Photo"  class="settings_btn" >'
				+'</form></div></div></fieldset></div><br/><br/><br/><br/><br/><br/><br/><br/>'
				+'<div class="user_photo" ><img id="theUserPhotoSettings" src=""></div></div>';

		if($('#winContent11').html(html))	
		{
			var options = { 
				dataType:  'json', 
				beforeSubmit:  CheckExt,  // pre-submit callback 
				success:       showUploadResponse  // post-submit callback 
			} 
			$('#photoForm').ajaxForm(options); 
	
			loadWithAjax.loadContent(11);
		}	
	}
	function get_cookie(Name) { 
		var search = Name + "="
		var returnvalue = "";
		if (document.cookie.length > 0) {
			offset = document.cookie.indexOf(search)			
			if (offset != -1) { 
				offset += search.length
				end = document.cookie.indexOf(";", offset);
				if (end == -1) end = document.cookie.length;
				returnvalue=unescape(document.cookie.substring(offset, end))
				}
		}
		return returnvalue;
	}
	function saveBgrnd(){
		var cookiename="bgchange"
		var cookievalue=$('#rbBackground').attr('src')+";"
		document.cookie=cookiename+"="+cookievalue
	}
	//change background image
	function change_background(img_url)
	{	
		if(!$('#rbBackground').attr('id'))
			$('#bg').html('<img id="rbBackground" src="'+img_url+'" alt=""/>');
			
		else
			$('#rbBackground').attr('src',img_url);
			
		if(img_url==''){$('#rbBackground').attr('style','display:none');}else{$('#rbBackground').attr('style','');}
		saveBgrnd();	
	}
	//on window load get the background image from cookies
	function onloadfunction(){		
		var cookiename="bgchange";
		var cookievalue=get_cookie(cookiename);		
		if (cookievalue!="")
		{
			if(!$('#rbBackground').attr('id'))
				$('#bg').html('<img id="rbBackground" src="'+cookievalue+'" alt=""/>');
			else
				$('#rbBackground').attr('src',cookievalue);
		}
		else
		{
			$('body').css('background-color','#7F0B14');
			//$('#rbBackground').attr('src',CDN_IMG+'/wallpapers/bg.jpg');
		}
	}	
	function hideWindow(id){
	$('#win'+id).fadeOut(1000);
	}	
	function controlFullScreen(contentId, status){
		if(status=='show'){
			$('#fullscreen').addClass('fullscreen');
			$('#fullscreen').fadeIn(1000);			
			$('#fullscreen').fadeTo(500, 0.90, function(){
			$('#fullscreen').fadeTo("slow", 0.90)			
			});
			$('#fullscreen').html($('#'+contentId).html());
			
		}
		else{
			$('#fullscreen').empty();			
			$('#fullscreen').fadeOut(1000);
		}
	}

	
	function controlFullScreenHTML(contentHTML, status){
		if(status=='show'){
			$('#fullscreen').addClass('fullscreen');
			$('#fullscreen').fadeIn(1000);			
			$('#fullscreen').fadeTo(500, 0.90, function(){
			$('#fullscreen').fadeTo("slow", 0.90)			
			});
			$('#fullscreen').html(contentHTML);
			
		}
		else{
			$('#fullscreen').empty();			
			$('#fullscreen').fadeOut(1000);
		}
	}

	/*
	 * Date Format 1.2.2
	 * (c) 2007-2008 Steven Levithan <stevenlevithan.com>
	 * MIT license
	 * Includes enhancements by Scott Trenda <scott.trenda.net> and Kris Kowal <cixar.com/~kris.kowal/>
	 *
	 * Accepts a date, a mask, or a date and a mask.
	 * Returns a formatted version of the given date.
	 * The date defaults to the current date/time.
	 * The mask defaults to dateFormat.masks.default.
	 */
	var dateFormat = function () {
		var	token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
			timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
			timezoneClip = /[^-+\dA-Z]/g,
			pad = function (val, len) {
				val = String(val);
				len = len || 2;
				while (val.length < len) val = "0" + val;
				return val;
			};

		// Regexes and supporting functions are cached through closure
		return function (date, mask, utc) {
			var dF = dateFormat;

			// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
			if (arguments.length == 1 && (typeof date == "string" || date instanceof String) && !/\d/.test(date)) {
				mask = date;
				date = undefined;
			}

			// Passing date through Date applies Date.parse, if necessary
			date = date ? new Date(date) : new Date();
			if (isNaN(date)) throw new SyntaxError("invalid date");

			mask = String(dF.masks[mask] || mask || dF.masks["default"]);

			// Allow setting the utc argument via the mask
			if (mask.slice(0, 4) == "UTC:") {
				mask = mask.slice(4);
				utc = true;
			}

			var	_ = utc ? "getUTC" : "get",
				d = date[_ + "Date"](),
				D = date[_ + "Day"](),
				m = date[_ + "Month"](),
				y = date[_ + "FullYear"](),
				H = date[_ + "Hours"](),
				M = date[_ + "Minutes"](),
				s = date[_ + "Seconds"](),
				L = date[_ + "Milliseconds"](),
				o = utc ? 0 : date.getTimezoneOffset(),
				flags = {
					d:    d,
					dd:   pad(d),
					ddd:  dF.i18n.dayNames[D],
					dddd: dF.i18n.dayNames[D + 7],
					m:    m + 1,
					mm:   pad(m + 1),
					mmm:  dF.i18n.monthNames[m],
					mmmm: dF.i18n.monthNames[m + 12],
					yy:   String(y).slice(2),
					yyyy: y,
					h:    H % 12 || 12,
					hh:   pad(H % 12 || 12),
					H:    H,
					HH:   pad(H),
					M:    M,
					MM:   pad(M),
					s:    s,
					ss:   pad(s),
					l:    pad(L, 3),
					L:    pad(L > 99 ? Math.round(L / 10) : L),
					t:    H < 12 ? "a"  : "p",
					tt:   H < 12 ? "am" : "pm",
					T:    H < 12 ? "A"  : "P",
					TT:   H < 12 ? "AM" : "PM",
					Z:    utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
					o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
					S:    ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
				};

			return mask.replace(token, function ($0) {
				return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
			});
		};
	}();

	// Some common format strings
	dateFormat.masks = {
		"default":      "ddd mmm dd yyyy HH:MM:ss",
		shortDate:      "m/d/yy",
		mediumDate:     "mmm d, yyyy",
		longDate:       "mmmm d, yyyy",
		fullDate:       "dddd, mmmm d, yyyy",
		shortTime:      "h:MM TT",
		mediumTime:     "h:MM:ss TT",
		longTime:       "h:MM:ss TT Z",
		isoDate:        "yyyy-mm-dd",
		isoTime:        "HH:MM:ss",
		isoDateTime:    "yyyy-mm-dd'T'HH:MM:ss",
		isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
	};

	// Internationalization strings
	dateFormat.i18n = {
		dayNames: [
			"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
			"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
		],
		monthNames: [
			"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
			"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
		]
	};

	// For convenience...
	Date.prototype.format = function (mask, utc) {
		return dateFormat(this, mask, utc);
	};



// JavaScript Document


	var now = new Date();
	now=dateFormat(now, "dS 'of' mmmm yyyy");


function doLogin()
{	
	var errors=0;
	$('#loginUserEmail_error_text').text('');
	$('#loginUserPassword_error_text').text('');
	if (($('#loginUserEmail').attr('value').search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) == -1)
	{
		$('#loginUserEmail_error_text').css('display','block');
		$('#loginUserEmail_error_text').text('Enter valid Email.');
		errors=1;		
	}
	if($('#loginUserPassword').val()=='')
	{		
		$('#loginUserPassword_error_text').css('display','block');
		$('#loginUserPassword_error_text').text('Enter Password.');	
		errors=1;
	}
	if(errors==0)
	{
		var toPost= "userEmail="+$('#loginUserEmail').val()+"&userPassword="+$('#loginUserPassword').val()+"&userGroup="+$('#loginUserGroup').val();
		var link=URL+'/accounts.php/login/login';
		$.post(link,toPost,  function(data)
			{	
				if(data.reply=='0')
				{	
					if(data.errors['userEmail']!=''&& data.errors['userEmail']!=null)
					{
						$('#loginUserEmail_error_text').css('display','block');
						$('#loginUserEmail_error_text').text(data.errors['userEmail']);
					}
					else
					{
						$('#loginUserEmail_error_text').css('display','none');
						$('#loginUserEmail_error_text').text('');
					}
					
					if(data.errors['userPassword']!='' && data.errors['userPassword']!=null )
					{
						$('#loginUserPassword_error_text').css('display','block');
						$('#loginUserPassword_error_text').text(data.errors['userPassword']);
					}
					else
					{
						$('#loginUserPassword_error_text').css('display','none');
						$('#loginUserPassword_error_text').text('');
					}				
				}
				else if(data.reply=='1')
				{	
						myID = data.userId;
						userName=data.message;
						viewNotifications(myID);
					$('#loginUserPassword_error_text').css('display','none');
					$('#loginUserPassword_error_text').text('');
	
					$('#loginUserEmail_error_text').css('display','none');
					$('#loginUserEmail_error_text').text('');	
	
					$('#login_error').css('display','none');
					$('#login_error').text('');	
					
					$('#login_div').slideToggle();
					controlFullScreen('logInMsg','hide');					
					showSettings('on');
					draw_menu(myID);					
					$('#welcomeMessage').append(data.message);
					$('#welcomeMessage').css("display", "block");
					$('#notfMainDiv').css("display", "block"); 
				}	
			}
		,'json');				
	}
}
function logout()
{
	 $('#notfMainDiv').css("display", "none");
	var toPost= "userLevel="+$('#logoutUserLevel').val();
	if($('#logoutUserLevel').val()=='admin'){
		locationURL='/cpanel.php/pages';
	}else{
		locationURL='/homepage.php/main';
	}
		
	$.post(URL+ '/accounts.php/logout/index',toPost,function(errors){			
		if(errors.reply=='0')
		{
			$('#logout_div').text(errors.errors);
		}		
		else if(errors.reply=='1')
		{			
			$('#registerButton').toggle();
			$('#loginButton').toggle();
			$('#logoutButton').toggle();			
			$('#settingsButton').toggle();
			window.location= URL +locationURL;
		}	
	},'json');	
}
function show_hide(hideElement,showElement)
{	
	$('#'+hideElement).slideUp();
	$('#'+showElement).slideDown();
}
function Reset_password()
{
	var errors=0;
	$('#forgotUserEmail_error_text').text('');
	
	if (($('#forgotUserEmail').attr('value').search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) == -1)
	{
		$('#forgotUserEmail_error_text').css('display','block');
		$('#forgotUserEmail_error_text').text('Enter a valid Email.');
		errors=1;		
	}
	if(errors==0)
	{
		$.getJSON( URL+'/accounts.php/password/retrieve','user_email='+$('#forgotUserEmail').val(),function(errors){		
			if(errors.reply=='0')
			{
				//$('#forgotUserEmail_error_text').removeClass('discreption');
				$('#forgotUserEmail_error_text').addClass('error');
				$('#forgotUserEmail_error_text').text(errors.errors['userEmail']);
			}		
			else if(errors.reply=='1')
			{	
				$('#forgotUserEmail_error_text').text(errors.message);
			}	
			else if(errors.reply=='2')
			{	
				$('#forgotUserEmail_error_text').text(errors.message);
				//$('#ChangeFormDiv').slideDown();
				//$('#ForgotFormDiv').slideUp();
			}
		});
	}
}
function getChangePasswordHTML(contentDiv)
{
	html="<div id='change_password_div'>"
		+"<div class='input_div_signup'>"
			+"<div class='reg_label'>Email</div>"
			+"<div class='reg_label'><input type='text' id='changeUserEmail' value=''  onblur='email_format_validation(this.id)'/></div>"
			+"<div class='reg_error_text' id='changeUserEmail_error_text'></div>"
		+"</div>"
		
		+"<div class='input_div_signup'>"
			+"<div class='reg_label'>New Password</div>"
			+"<div class='reg_label'><input type='password' id='changeUserPassword' value=''  onblur='password_validation(this.id)'/></div>"
			+"<div class='reg_error_text' id='changeUserPassword_error_text'></div>"
		+"</div>"
		
		+"<div class='input_div_signup'>"
			+"<div class='reg_label'>Confirm Password</div>"
			+"<div class='reg_label'><input type='password' id='changeUserConfirmPassword' value=''  onblur=\"re_password_validation(this.id,'changeUserPassword')\"/></div>"
			+"<div class='reg_error_text' id='changeUserConfirmPassword_error_text'></div>"
		+"</div>"
		
		+"<div class='input_div_signup'>"
			+"<input type='button' value='Change Password' onclick='changePassword()' />"
		+"</div>"
		+"<div class='reg_error_text' id='change_error'></div>"
	+"</div>";
	$('#'+contentDiv).html(html);	
}

function changePassword()
{
	var errors=0;
	$('#changeUserEmail_error_text').text('');
	$('#changeUserPassword_error_text').text('');
	$('#changeUserConfirmPassword_error_text').text('');
	if (($('#changeUserEmail').attr('value').search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) == -1)
	{
		$('#changeUserEmail_error_text').css('display','block');
		$('#changeUserEmail_error_text').text('Enter valid Email.');
		errors=1;		
	}
	
	if($('#changeUserPassword').val()==''||$('#changeUserPassword').val().length<6)
	{		
		$('#changeUserPassword_error_text').css('display','block');
		$('#changeUserPassword_error_text').text('Enter Password at least 6 charcters.');	
		errors=1;
	}
	if($('#changeUserConfirmPassword').val()!=$('#changeUserPassword').val())
	{		
		$('#changeUserConfirmPassword_error_text').css('display','block');
		$('#changeUserConfirmPassword_error_text').text('Password dose not match.');	
		errors=1;
	}
	if(errors==0)
	{
		var data='user_email='+$('#changeUserEmail').attr('value')
				+'&user_password='+$('#changeUserPassword').attr('value')
				+'&user_re_password='+$('#changeUserConfirmPassword').attr('value');

		
		$.getJSON(URL+ '/accounts.php/password/update',data,function(errors){					
			if(errors.reply=='0')
			{
				$('#userEmail_error_text').css('display','block');
				$('#userEmail_error_text').text(errors.errors['userEmail']);
				$('#userPassword_error_text').css('display','block');
				$('#userPassword_error_text').text(errors.errors['userPassword']);
				$('#userConfirmPassword_error_text').css('display','block');
				$('#userConfirmPassword_error_text').text(errors.errors['userConfirmPassword']);
			}		
			else if(errors.reply=='1')
			{	
				controlFullScreen('logInMsg','hide');					
			}	
		});
	}
}
/*
 * registerNewUser Send user Info
 */
function registerNewUser()
{
	if(user_name_validation('userName')&& email_validation('userEmail')&&password_validation('RegUserPassword')&& re_password_validation('userConfirmPassword','RegUserPassword'))
	{
	
		var data={'userEmail':$('#userEmail').val()
		,'userName':$('#userName').val()
		,'userPassword':$('#RegUserPassword').val()
		,'userConfirmPassword':$('#userConfirmPassword').val()
		,'userSecurityQuestion':$('#userSecurityQuestion').val()
		,'userSecurityAnswer':$('#userSecurityAnswer').val()};		
		
		$.getJSON( URL+'/accounts.php/register/insert',data,function(errors){
			
			if (errors.reply==1)				
			{	
				$("#toHideLater").slideUp(500, function(){
					$("#toHideLater").html('<div style="margin-left:40px;margin-top:40px;"><h3>Thank you for registering!<br/> <br/>Please check your mail to activate your account ..</h3><div>').slideDown();
				});				
			}
			else if (errors.reply==0)
			{
				$('#userName_error_text').css('display','block');
				$('#userName_error_text').text(errors.errors['userName']);
				
				if(errors.errors['userEmail']!='')
				{
					$('#userEmail_error_text').removeClass('discreption');
					$('#userEmail_error_text').addClass('error');
					$('#userEmail_error_text').css('display','block');
					$('#userEmail_error_text').text(errors.errors['userEmail']);
				}

				$('#RegUserPassword_error_text').css('display','block');
				$('#RegUserPassword_error_text').text(errors.errors['userPassword']);

				$('#userConfirmPassword_error_text').css('display','block');
				$('#userConfirmPassword_error_text').text(errors.errors['userConfirmPassword']);					
			}		
			});	
	}
}
function showSettings(on) 
{
	if(on=='on')
	{		
		$('#settingsButton').show()
		$('#logoutButton').show()
		$('#registerButton').hide()
		$('#loginButton').hide()
	}
	else
	{
		$('#settingsButton').hide()
		$('#logoutButton').hide()
		$('#registerButton').show()
		$('#loginButton').show()
		userName="";
	}
}
function getProfile(type,friendId)
{	
	typeURL="";
	param='';
	profileFeedCount=0;
	profileWallCount=0;
	if(type==null)
		type='feeds';
	if(friendId==null)
		friendId=0;
	
	if(friendId==0)
		finalURL=URL+ '/accounts.php/login/checkLogin';
	else
	{
		param='friendId='+friendId;
		finalURL=URL+ '/friends.php/friendDetails/friendDetails';
	}		
	$.getJSON(finalURL,param,function(data){
		if(data.reply==1)
		{	
			userInfo=data.message;
			param1='userID='+userInfo['user_id'];
					
			if(type=='wall')
				typeURL=URL+"/myProfile.php/myWall/myWall";	
			else if (type=='feeds')
			{
				typeURL=URL+"/feeds.php/view/viewFeeds";	//ViewMyFeeds
				param1+='&feeds_rel=1';
			}
			else if (type=='requests')
				typeURL=URL+"/friends.php/requestFriend/requestFriend";
				
			if( userInfo['status']==null ||userInfo['status']=='')
				if(friendId==0)
					userInfo['status']="Change your status.";
				else
					userInfo['status']="";
			
			html='<div class="win_content_middle">'
					+'<div class="user_left_col">'
						+'<div  class="user_photo" ';
						if(friendId==0)
						{
							html+='onmouseover="$(\'#changeProfilePhoto\').show()" onmouseout="$(\'#changeProfilePhoto\').hide()">'
								+'<div id="changeProfilePhoto" class="changeProfilePhoto" onclick="showWindow(\'11\');editUserProfilePhoto()">Change photo</div>'
						}
						else
						{
							html+='>';
						}
						html+='<img src="'+data.message.photo+'" alt="" />'						
						+'</div>';
				
			if(friendId==0)
					html+='<div class="user_vertical_menu">';
				else
					html+='<div class="friends_vertical_menu">';
				
					html+='<ul>'
							html+='<li><a';
							if(type=='feeds')
								html+=' class="selected" ';
							
								if(friendId==0) feedTab='My Feeds'; else feedTab=/*userInfo['user_name']+*/'Friend Feeds';
								if(friendId==0)wallTab='My Wall';else wallTab=/*userInfo['user_name']+*/'Friend Wall';
								if(friendId==0)infoTab='My Info';else infoTab=/*userInfo['user_name']+*/'Friend Info';
							html+=' href="javascript:void(null)"title="" onclick="getProfile(\'feeds\','+friendId+')">'+feedTab+'</a></li>'							
								+'<li><a';
								if(type=='wall')
									html+=' class="selected" ';
									
								html+='  href="javascript:void(null)"title="" onclick="getProfile(\'wall\','+friendId+')">'+wallTab+'</a></li>'
								+'<li><a';
								if(type=='info')
									html+=' class="selected" ';
									
								html+='  href="javascript:void(null)"title="" onclick="getProfile(\'info\','+friendId+')">'+infoTab+'</a></li>'
								if(friendId==0)
								{
									html+='<li><a';
									if(type=='requests')
										html+=' class="selected" ';									
									html+='  href="javascript:void(null)"title="" onclick="getProfile(\'requests\','+friendId+')">Requests</a></li>';								
								}	
							html+='</ul>'
						+'</div>'
					+'</div>'
					html+='<div class="user_name" style="float:left;">'+userInfo['user_name']+'</div>'
					if(friendId!=0)
					{
						html+='<img src="'+CDN_IMG+'/new/image.png"  alt="Friend Photos" title="Friend Photos" class="getFriendPhotosImg" onclick="getFriendPhotos(\''+friendId+'\')"/>'
						+'<img src="'+CDN_IMG+'/new/delete_user.png" alt="Delete Friend" title="Delete Friend"  class="getFriendPhotosImg" onclick="deleteConfirmation('+friendId+',\'friend\')"/>'
					}
					else
					{
						html+='<br/><br/>'
					}
					if(friendId==0)
						html+='<div id="profileUserStatus" >'
					else
						html+='<div>'
					
					if(friendId==0)
						html+='<span id="userStautsText" '
					else
						html+='<span '	
					
					html+=' class="user_status">'+userInfo['status']+'</span>'
					if(friendId==0)
					{
						html+='<span class="user_status_change">'
						+'<a href="javascript:void(null)" title="Change your status" onclick="viewEditUserStatus()">(Change...)</a></span>'
					}
					html+='</div>'
					if(friendId==0)
					{	
						html+='<div id="editUserStatusDiv"  style="float:left; width:412px;height:33px;">'
						+'<div class="user_status_change">'
						+'<input onkeypress="if(onPressEnter(event))editUserStatus()" style="color: #004080;background-color: transparent;border: 0px;background-image: url(\''+CDN_IMG+'/new/change_status_bg.gif\');background-position: left top;background-repeat: no-repeat;					width: 350px;					height: 23px;					overflow: hidden;					float: left;					padding-top: 10px;					font-size: 12pt;" maxlength="70" type="text" id="userStatusInput" name="userStatusInput" value="'					+userInfo['status']+'" /></div>'					
						+'<div class="post_btn" style="margin-top:5px" onclick="editUserStatus()">Update</div></div>';
					}
					//+'<div id="editUserStatusDiv"><input onfocus="this.value=\'\'" id="userStatusInput" type="text" value="'+userInfo['status']+' "/><input type="button" value="Post" onclick="editUserStatus()"/></div>'
					if(friendId==0)
					{
						html+='<div class="user_right_col">'						
					}
					else
					{
						html+='<div class="friends_right_col">'																	
					}								
		if(type=='info')
		{
			html+='<div class="feed_container">'
			
			+'<div class="feed_container_center">'
			
			html+='<div class="user_info_heading">Personal info</div>'
							
	
			+'<div class="personalInfoContainer">'
			+'<div class="personalInfoTitle">Name:</div>'
			+'<div id="personalInfoData_user_fullname" class="personalInfoData"><span id="personalData_user_fullname">'+userInfo['user_fullname']+'</span>'
			if(friendId==0)
			{
				html+='<div class="personalInfoEdit" onclick="editProfileInfo(\'user_fullname\')">Edit</div>';
			}			
			html+='</div>'	
			
				if(friendId==0)		
				{
					html+='<div id="personalInfoInput_user_fullname" class="personalInfoInput">'
						+'<input value="'+userInfo['user_fullname']+'" type="text" id="personaluser_fullname" />'
						+'<div class="personalInfoPost"  onclick="postProfileInfo(\'user_fullname\')">Post</div>'
						+'</div>'
					
				}
		html+='</div>'
			+'<div class="personalInfoContainer">'
			+'<div class="personalInfoTitle">Date of Birth:</div>'
			+'<div id="personalInfoData_user_birth_date" class="personalInfoData"><span id="personalData_user_birth_date">'+userInfo['user_birth_date']+'</span>'
			if(friendId==0)
				html+='<div class="personalInfoEdit" onclick="editProfileInfo(\'user_birth_date\')">Edit</div>'
			html+='</div>'
			if(friendId==0)
			{
				html+='<div id="personalInfoInput_user_birth_date" class="personalInfoInput">'

					+dateSeparte(userInfo['user_birth_date'])
					+'<input value="'+userInfo['user_birth_date']+'" type="hidden"  id="personaluser_birth_date" />'
					+'<div class="personalInfoPost"  onclick="postProfileInfo(\'user_birth_date\')">Post</div>'
					+'</div>'
			}
			html+='</div>'
				//+'<p><input class="inputDate" id="inputDate" value="06/14/2008" /></p>'
			
			
			+'<div class="personalInfoContainer">'
			+'<div class="personalInfoTitle">Gender:</div>'
			+'<div id="personalInfoData_user_sex" class="personalInfoData"><span id="personalData_user_sex">'+userInfo['user_sex']+'</span>'
			if(friendId==0)
				html+='<div class="personalInfoEdit" onclick="editProfileInfo(\'user_sex\')">Edit</div>'
			html+='</div>'
			if(friendId==0)
			{
				html+='<div id="personalInfoInput_user_sex" class="personalInfoInput">'					
					+'<select id="personaluser_sex" >'
					+'<option value="Male" '
					if(userInfo['user_sex']=='Male')html+=' selected="selected"';
					html+='>Male</option>'
					+'<option value="Female" '
					if(userInfo['user_sex']=='Female')html+=' selected="selected"';
					html+='>Female</option>'
					+'</select>'
					+'<div class="personalInfoPost"  onclick="postProfileInfo(\'user_sex\')"">Post</div>'
					+'</div>'
			}
			html+='</div>'			
			
			+'<div class="personalInfoContainer">'								
			+'<div class="personalInfoTitle">Martial status:</div>'
			+'<div id="personalInfoData_user_relationship" class="personalInfoData"><span id="personalData_user_relationship">'+userInfo['user_relationship']+'</span>'
			if(friendId==0)
				html+='<div class="personalInfoEdit" onclick="editProfileInfo(\'user_relationship\')">Edit</div>'
			html+='</div>'
			if(friendId==0)
			{
				html+='<div id="personalInfoInput_user_relationship" class="personalInfoInput">'
					//+'<input value="'+userInfo['user_relationship']+'" type="text"  id="personaluser_relationship" />'
					
					+'<select id="personaluser_relationship" >'
					
					+'<option value="Single" '
					if(userInfo['user_sex']=='Single')html+=' selected="selected"';
					html+='>Single</option>'
				
					+'<option value="Maried" '
					if(userInfo['user_sex']=='Maried')html+=' selected="selected"';
					html+='>Maried</option>'
						
					+'<option value="Engaged" '
					if(userInfo['user_sex']=='Engaged')html+=' selected="selected"';
					html+='>Engaged</option>'
					
					+'</select>'
					+'<div class="personalInfoPost"  onclick="postProfileInfo(\'user_relationship\')">Post</div>'
					+'</div>'
			}
			html+='</div>'
				
			
			+'<div class="personalInfoContainer">'
			+'<div class="personalInfoTitle">Education:</div>'
			+'<div id="personalInfoData_school_education" class="personalInfoData"><span id="personalData_school_education">'+userInfo['school_education']+'</span>'
			if(friendId==0)
				html+='<div class="personalInfoEdit" onclick="editProfileInfo(\'school_education\')">Edit</div>'
			html+='</div>'
			if(friendId==0)
			{	html+='<div id="personalInfoInput_school_education" class="personalInfoInput">'
					+'<input value="'+userInfo['school_education']+'" type="text"  id="personalschool_education" />'
					+'<div class="personalInfoPost"  onclick="postProfileInfo(\'school_education\')">Post</div>'
					+'</div>'	
			}			
		html+='</div>'				
			
			+'<div class="personalInfoContainer">'
			+'<div class="personalInfoTitle">Job title:</div>'
			+'<div id="personalInfoData_work_position" class="personalInfoData"><span id="personalData_work_position">'+userInfo['work_position']+'</span>'
			if(friendId==0)
				html+='<div class="personalInfoEdit" onclick="editProfileInfo(\'work_position\')">Edit</div>'
			html+='</div>'
			if(friendId==0)
			{
				html+='<div id="personalInfoInput_work_position" class="personalInfoInput">'
					+'<input value="'+userInfo['work_position']+'" type="text"  id="personalwork_position" />'
					+'<div class="personalInfoPost"  onclick="postProfileInfo(\'work_position\')">Post</div>'
					+'</div>'
			}
			html+='</div>'
				

			+'<div class="personalInfoContainer">'
			+'<div class="personalInfoTitle">Country:</div>'
			+'<div id="personalInfoData_country_code" class="personalInfoData"><span id="personalData_country_code">'+userInfo['country_code']+'</span>'
			if(friendId==0)
				html+='<div class="personalInfoEdit" onclick="editProfileInfo(\'country_code\')">Edit</div>'
			html+='</div>'
			if(friendId==0)
			{	html+='<div id="personalInfoInput_country_code" class="personalInfoInput">'
					+'<select  id="personalcountry_code" style="width:200px">'+allCountries(userInfo['country_code'])+'</select>'
					+'<div class="personalInfoPost"  onclick="postProfileInfo(\'country_code\')">Post</div>'
					+'</div>'
			}
					
			html+='</div>'
		

			/*+'<div class="user_info_heading">Contact Info</div>'
			 */
			
			html+='</div>'
				
			+'</div>'	;		
			html+='</div>';
			if(friendId==0)
			{
				if($('#winContent1').html(html))
				{
					/*
					$('#inputDate').DatePicker({
						format:'m/d/Y',
						date: $('#inputDate').val(),
						current: $('#inputDate').val(),
						starts: 1,
						position: 'right',
						onBeforeShow: function(){
							$('#inputDate').DatePickerSetDate($('#inputDate').val(), true);
							
						},
						onChange: function(formated, dates){
							$('#inputDate').val(formated);
						}
					});	*/	
					
				}				
			}
			else
			{
				$('#winContent3'+friendId).html(html);
			}								
		}
		else
		{
			if(type=='wall')
			{
				html+='<div style="position:relative;width:400px;" ><textarea class="wallTextArea" id="wallTextArea_'+userInfo['user_id']+'"></textarea>'
				html+='<div class="'
				if(friendId==0)
				html+='wallpost_btn'
				else
					html+='wallpost_friends_btn'
				html+='"  onclick="addToWall(\''+userInfo['user_id']+'\',\'wallTextArea_\')">Post</div></div>'
					+'<hr style="color:#fff;border:1px #fff solid;width:95%"/>'
			}
			
			$.post(typeURL,param1,function(data2){	
				html+='<div id="cont_'+userInfo['user_id']+'">';
				if(data2.friends!=null)
				{
						for(i=0;i<data2.friends.length;i++)
						{
							html+='<div id="feed_container_'+i+'" class="feed_container">'
									
									+'<div  id="feed_container_center'+i+'" class="feed_container_center">'
									+'<span class="feed_date">'+data2.friends[i]['date']+'</span>'
									+'<br />';
							if(type=='wall')
							{
								html+='<span class="feed_text">'+data2.friends[i]['userPhoto']+'&nbsp;';
								if(data2.friends[i]['id']==data2.friends[i]['sentTo']){html+=data2.friends[i]['name']}else{if(friendId==0){html+=data2.friends[i]['name']}else{if(data2.friends[i]['sentTo']==myID){html+='You'}else{html+=data2.friends[i]['name']}}}
								//html+=data2.friends[i]['name']
								html+=' wrote on ';
								if(data2.friends[i]['id']==data2.friends[i]['sentTo']){html+='his/her';}else{if(friendId==0){html+='your';}else{html+=data2.friends[i]['myData'];}}
								html+=' wall on KFC Arabia :<div class="wallTextMsg">'+data2.message[i]+'</div></span>';
								profileWallCount++;
							}
							if(type == 'feeds')
							{
								html+='<span class="feed_text">'+data2.friends[i]['user']+data2.friends[i]['friend']+'</span>';
								profileFeedCount++;
							}
							else if (type=='requests')
							{
								html+='<span class="feed_text">'+data2.friends[i]['name']+' has added you as a friend on</span> <br/><span class="feed_text">KFC Arabia.</span>';							
								html+='<div class="request_action">'
									html+='<div class="accept_request" onclick="acceptFriendRequest('+i+','+data2.friends[i]['user_id']+','+data2.friends[i]['friend_id']+',\''+data2.friends[i]['name']+'\');">Accept</div>'
									html+='<div class="reject_request" onclick="ignoreFriendRequest('+i+','+data2.friends[i]['user_id']+','+data2.friends[i]['friend_id']+');">Reject</div>'
								html+='</div>'
							}							
							html+='</div>'
									
								+'</div>'	;				
						}
						if(type=='feeds')
						{
							if(data2.message[1]=="true")
								html+='<div class="show_more" id="feedsResults_'+userInfo['user_id']+'" onclick="showMore(\''+param1+'&theCounter='+profileFeedCount+'\',\'/feeds.php/view/viewFeeds/\',\'profileFeeds\','+userInfo['user_id']+');$(\'#feedsResults_'+userInfo['user_id']+'\').remove();">Show more</div>';
						}
						else if(type=='wall')
						{
							if(data2.reply=="true")
								html+='<div class="show_more" id="wallResults_'+userInfo['user_id']+'" onclick="showMore(\''+param1+'&theCounter='+profileWallCount+'\',\'/myProfile/myWall/myWall\',\'profileWall\','+userInfo['user_id']+');$(\'#wallResults_'+userInfo['user_id']+'\').remove();">Show more</div>';								
						}						
					
				}	
				html+='</div>';
				html+='</div>';				
					if(friendId==0)
						$('#winContent1').html(html);
					else
						$('#winContent3'+friendId).html(html);			
					},'json');		
	  }
		}
		
	});		
	
}
function allCountries(theCoun){
	$.post(URL+"/friends.php/requestFriend/getCountries",'theCoun='+theCoun,function(data){
			var real='';
			for(i=0;i<data.message.length;i++){
				real+=data.message[i];
			}
			$('#personalcountry_code').html(real);
		},'json');
}
function acceptFriendRequest(i,userId,friendId,friendName)
{
	$.post(URL+"/friends.php/requestFriend/acceptFriend",'userid='+userId+'&friendid='+friendId,function(data){		
			$('#feed_container_center'+i).html('<span class="feed_text">'+friendName+' is now friend.</span>');
		},'json');
}
function ignoreFriendRequest(i,userId,friendId)
{
	$.post(URL+"/friends.php/requestFriend/ignorFriend",'userid='+userId+'&friendid='+friendId,function(data){		
		$('#feed_container_'+i).hide();
		},'json');
}
function viewEditUserStatus()
{
	$('#editUserStatusDiv').slideToggle();
	$('#profileUserStatus').slideToggle();
}
function editUserStatus()
{
	if ($('#userStatusInput').val()=="Change your status.")
		userStatus='';
	else
		userStatus=$('#userStatusInput').val();
		
		$.post(URL+ '/accounts.php/changeUserStatus/index',"userStatus="+userStatus,function(data){		
			if(data.reply=='1')
			{
				if ($('#userStatusInput').val()=='')
					$('#userStautsText').text("Change your status.");
				else	
					$('#userStautsText').text($('#userStatusInput').val());
				viewEditUserStatus();
			}
			else 
			{
				alert('Errors:'+data.errors.toString());
			}
		},'json');	
}
function playVideo(videoId,videoName,videoFile,videoRank,videoViews,uploader)
{		
	//$('#secectedVideoDiv'+videoId).addClass('single_video_hover');	
	details='<div class="rank_favorit">'
			+'<div class="all_details">'
		+'<ul>'
			+'<li>'+videoName+'</li>';
			if(uploader!='' && uploader!=null &&  uploader!='null'){details+='<li>Uploaded by: '+uploader+'</li>';}
			details+='<li>Views: '+(parseInt(videoViews)+1)+'</li>'
			//+'<li>Rank:<span id="videoRatingImage"></span></li>'
			+'<li><img src="'+CDN_IMG+'/new/favorites.gif" alt="" /><a href="javascript:void(null)" title="" onclick="addVideoToFavorit('+videoId+')">Add to favorites</a></li>'
		+'</ul>'
	+'</div>'
	+'</div>';
	$('#videoPart2Bottom').html(details);
	//$('#videoRatingImage').rater('',{curvalue:videoRank,style:'basic'});  
	
html='';
	
	html='<div class="video_tab_container" style="margin-top:15px; margin-left:10px;">'			
		
			+'<div id="commentsTab" class="video_tab_selected" onclick="$(\'#uploadTab\').removeClass(\'video_tab_selected\').addClass(\'video_tab_disabled\');ChangeCommentTab(\'commentsTab\',\''+videoId+'\')">Comments</div>'
			+'<div id="addCommentTab" class="video_tab_disabled" onclick="checkForVideo(1,\''+videoId+'\');">Add Comment</div>'
			+'<div id="uploadTab" class="video_tab_disabled" onclick="checkForVideo(2,\''+videoId+'\');">Upload</div>'
		
			+'<div id="addCommentTabContents" style="display:none;clear:both">'
			+'<textarea name="videoCommentText" id="videoCommentText"></textarea>'
			+'<div class="comment_btn"  onclick="addVideoComment('+videoId+')">Post a Comment</div>'
		//	+'<input type="button" value="Post Comment" onclick="addVideoComment('+videoId+')"/>'
			+'</div>'
			
			
			+'<div  id="commentsTabContents" style="clear:both;">'
			
			+'</div>'
			
			+getUploadVideoHTML();
			
		+'</div>';
	$('#videoPart3').html(html);
	
var videoOptions = { 
			
				dataType:  'json', 
				beforeSubmit:  CheckExtVideo,  // pre-submit callback 
				success:       showUploadResponseVideo  // post-submit callback 
			} 
			$('#videoUploadForm').ajaxForm(videoOptions);			
	$.getJSON( URL + '/videos.php/videoCategories/list',function(data)
			{			
				catlist='';
				for(i=0;i<data.message.length;i++)
					catlist+="<option value='"+data.message[i]['category_id']+"'>"+data.message[i]['category_name']+"</option>";
				$('#selectVideoCategory').html(catlist);
			});	
	viewPlayer(videoId,videoFile);
	listVideoComment(videoId)

}
function getUploadVideoHTML(first)
{
	if(first==null)first=0;
	videoHTML='';
	if(first==1)
	{
		videoHTML+='<div  id="UploadTabContents" style="display:block;margin-top:15px; margin-left:10px;">'
			+'<div style="width:300px;float:left;"><div class="video_tab_selected" style="clear:both;">Upload</div></div>';
	}
	else
	{
		videoHTML+='<div  id="UploadTabContents" style="display:none;clear:both;">'
		+'<form action="'+URL+'/videos.php/new/upload" method="post" id="videoUploadForm" enctype="multipart/form-data" >'
		+'<div><div class="video_element_container">'
		+'<div>Video Title</div>'
		+'<div><input type="text" name="videoName" id="videoName"/></div>'
		+'</div>'				
		
		+'<div class="video_element_container">'
		+'<div>Privacy settings</div>'
		+'<div><input type="radio" name="videoPrivacy" id="onlyMe" value="0"/><label for="onlyMe" style="margin:2px;">&nbsp;Only Me</label></div>'
		+'<div><input type="radio" name="videoPrivacy" id="friends" value="1"/><label for="friends" style="margin:2px;">&nbsp;Friends</label></div>'		
		+'<div><input type="radio" name="videoPrivacy" id="everyOne" value="3" checked="checked"/><label for="everyOne" style="margin:2px;">&nbsp;Every one</label></div>'
		+'</div>'				
		
		+'<div class="video_element_container">'
		
		+'<div>Video Channel '
		+'<select name="selectVideoCategory" id="selectVideoCategory">'
		+'</select>'
		+'</div> </div>'	
					
		+'<div class="video_element_container">'
		+'<div>Upload your video file:</div>'
		
		+'<div><input type="file" name="videoFile" id="videoFile" /></div>'
		
		+'<div>Allowed File Types :<br>(\'wmv\',\'avi\' ,\'asx\',\'mov\', \'mpg\')<br>Maximum file size: 32 mb</div>'
		
		+'</div>'
		
		+'<input class="comment_btn_input" type="submit" style="*width:90px !important;"  value="Upload Video"/>'
			+'</div>'
		+'</form>'
	
	+'</div>'
	+'<span style="display:none" id="debugVideo" ></span>'
	+'<div  id="UploadLoaderImage" style="display:none;text-align:center;padding-top:100px;">'
		+'<img src="'+CDN_IMG+'/ajax-loader_2.gif">'
	+'</div>';
	}
	return videoHTML;
}
function viewPlayer(videoId,videoFile)
{
	$.post(URL+"/videos.php/list/playVideo",{'videoId':videoId,'videoFile':videoFile},function(data) {
		
		if(data.reply==1)
		{
			if(data.message!=null)
			{				
				$('#videoPart2Top').html(data.message);	
			}
		}
	},'json');
	
}
function CheckExtVideo() {
	$('#debugVideo').hide()
	var ext = $("#videoFile").val();
	ext = ext.substring(ext.length-3,ext.length);
	ext = ext.toLowerCase();
	if(myID==-1)
	{
		$('#debugVideo').html('<br/><br/><div class="photoError"><h4>Please sign in first ..<h4></div>').fadeIn(500);
		return false;
	}
	else if ($('#videoName').val()=='')
	{
		$('#debugVideo').html('<br/><br/><div class="photoError"><h4>Please enter video title ..<h4></div>').fadeIn(500);
		return false;
	}
	else if((ext != 'avi') && (ext != 'asx')&& (ext != 'mov')&& (ext != 'mpg')&& (ext != 'wmv')){
		$('#debugVideo').html('<br/><br/><div class="photoError"><h4>Please select a proper video file ..<h4></div>').fadeIn(500);
		return false;
	}
	else if($('#videoFile').val().length<3){	
		$('#debugVideo').html('<br/><br/><div class="photoError"><h4>Please select a file before submission ...<h4></div>').fadeIn(500);
		return false;
	}
	$('#UploadTabContents').hide();
	$('#UploadLoaderImage').show();
	return true;
}
function showUploadResponseVideo(data){	
	//alert(data.reply+'<br/>'+data.message);
	/*videoParams='videoName='+$('#videoName').val()+'&videoFile='+data.reply+'&selectVideoCategory='+$('#selectVideoCategory').val()+'&videoPrivacy='+$('input:radio[name=videoPrivacy]:checked').val();
	$.post(URL+"/videos.php/new/new",videoParams,function(data) {*/		
	
		$('#debugVideo').show();
		$('#debugVideo').html('<br/><br/><h4 style="color:white;margin-left:20px;"><br/>The video file has been successfully uploaded ..</h4>');
		$('#UploadLoaderImage').hide();
//	},'json');
}
function ChangeCommentTab(tab,videoId)
{	
	if(tab=='commentsTab')
	{
		$('#commentsTab').removeClass('video_tab_disabled');
		$('#commentsTab').addClass('video_tab_selected');
		$('#addCommentTab').removeClass('video_tab_selected');
		$('#addCommentTab').addClass('video_tab_disabled');	
		$('#UploadTab').removeClass('video_tab_selected');
		$('#UploadTab').addClass('video_tab_disabled');
		$('#UploadTabContents').hide();
		$('#addCommentTabContents').hide();
		$('#commentsTabContents').show();
		listVideoComment(videoId);
		$('#debugVideo').hide();
	}
	else if(tab=='addCommentTab')
	{
		$('#commentsTab').addClass('video_tab_disabled');
		$('#commentsTab').removeClass('video_tab_selected');
		$('#addCommentTab').addClass('video_tab_selected');
		$('#addCommentTab').removeClass('video_tab_disabled');
		$('#UploadTab').removeClass('video_tab_selected');
		$('#UploadTab').addClass('video_tab_disabled');		
		
		$('#UploadTabContents').hide();
		$('#commentsTabContents').hide();
		$('#addCommentTabContents').show();
		$('#debugVideo').hide();
	}
	else if(tab=='uploadTab')
	{
		$('#UploadTab').addClass('video_tab_selected');
		$('#UploadTab').removeClass('video_tab_disabled');				
		$('#commentsTab').addClass('video_tab_disabled');
		$('#commentsTab').removeClass('video_tab_selected');
		$('#addCommentTab').removeClass('video_tab_selected');
		$('#addCommentTab').addClass('video_tab_disabled');		
		
		
		$('#UploadTabContents').show();
		$('#commentsTabContents').hide();
		$('#addCommentTabContents').hide();
		$('#debugVideo').hide();
		var videoOptions = { 
			
				dataType:  'json', 
				beforeSubmit:  CheckExtVideo,  // pre-submit callback 
				success:       showUploadResponseVideo  // post-submit callback 
			} 
			$('#videoUploadForm').ajaxForm(videoOptions);		
	}
}
function getVideo(listType,searchInput)
{	
	html='<div class="video_tab_container">'
	+'<select id="videoTypeSelect" style="width:238px;margin-left:13px;border:none;" onchange="getVideo(this.options[this.selectedIndex].value)">'
		+'<option value="mostViewed" onclick="getVideo(\'mostViewed\')">Most viewed</option>'							
		+'<option value="myVideos" >My videos</option>'
		+'<option value="friendsVideos" >Friends videos</option>'
		+'<option value="myFavorit" >Favorites</option>'								
	+'</select>'
	+'</div>'

	+'<div id="videoPart1" class="browse_videos"></div>'
	+'<div class="videos_search">'						
		+'<input id="searchVideosInput" class="videos_input_text"  type="text" onkeypress="if(onPressEnter(event))getVideo(\'search\',$(\'#searchVideosInput\').val());"/>'
		+'<div onclick="getVideo(\'search\',$(\'#searchVideosInput\').val())"><a  class="videos_submit" href="javascript:void(null)"></a></div>'						
	+'</div>'
	+'<div id="videoPart2Top" class="show_videos"></div>'						
	+'<div id="videoPart2Bottom" class="video_preview_details"></div>'
	+'<div id="videoPart3" class="comments"></div>';
	
	$('#winContent5').html(html);

	videoConut=0;
	if((myID==-1) && (listType=='myVideos' || listType=='friendsVideos' || listType=='myFavorit'))
	{
		getLogin();
		return 0;
	}
	if (listType==null) listType='mostViewed';
	
	part1='';	
	
	videoParams='videoType='+listType;
	
	if (listType=='search')
	{
		videoParams+='&searchText='+searchInput;
		$('#videoTypeSelect').append("<option value='search' onclick=\"getVideo('search','searchVideosInput')\">Search Result</option>");
	}
	else
	{
		
	}
	$('#videoTypeSelect').val(listType);
	
	$.post(URL+"/videos.php/list/index",videoParams+'&limit=0',function(data) {
		if(data.reply==1)
		{			
			if(data.message!=null)
			{
				for (i = 0; i < data.message.length; i++) {
					part1+='<div>'
						+'<div id="secectedVideoDiv'+data.message[i]['video_id']+'" onclick=" playVideo(\''+ data.message[i]['video_id']+'\',\''+ data.message[i]['video_name']+'\',\''+ data.message[i]['video_file']+'\',\''+ data.message[i]['video_total_rank']+'\',\''+ data.message[i]['video_views']+'\',\''+data.message[i]['user_name']+'\')" class="single_video">';
							
							if(data.message[i]['video_file']!=''){part1+='<img src="'+CDN_VIDEOS+'/uploaded_images/'+data.message[i]['video_file']+'1.jpg" alt="" />'}
							
							part1+='<div class="video_details">'
								+'<span class="title">'+data.message[i]['video_name']+' ';
								/*if(data.message[i]['user_name']!='' & data.message[i]['user_name']!=null){
									part1+='-- '+data.message[i]['user_name'];
								}*/
								/*+'<span>Rating:';
									for(r=0;r<data.message[i]['video_total_rank'];r++)
									{
										part1+='<img src="'+CDN_IMG+'/stars.png" alt="" />';
									}
							part1+='</span>'*/
							part1+='</span><br /></div>'
						+'</div>'		
						+'</div>';
							videoConut++;
				}
				if(data.errors=='true')
					part1+='<div class="show_more_video" id="videoResults" onclick="showMore(videoParams+\'&limit=\'+videoConut,\'/videos.php/list/index\',\'videoList\');$(\'#videoResults\').remove();">Show more</div>';
				$('#videoPart1').html(part1);
			
				playVideo(data.message[0]['video_id'], data.message[0]['video_name'], data.message[0]['video_file'], data.message[0]['video_total_rank'],data.message[0]['video_views'],data.message[0]['user_name']);
			}
			else
			{				
				$('#videoPart1').html('There are no videos');
				if(listType=='mostViewed')
					if($('#videoPart3').html(getUploadVideoHTML(1)))
					{
						$.getJSON( URL + '/videos.php/videoCategories/list',function(data)
								{			
									catlist='';
									for(i=0;i<data.message.length;i++)
										catlist+="<option value='"+data.message[i]['category_id']+"'>"+data.message[i]['category_name']+"</option>";
									$('#selectVideoCategory').html(catlist);
								});
						var videoOptions = { 
								
								dataType:  'json', 
								beforeSubmit:  CheckExtVideo,  // pre-submit callback 
								success:       showUploadResponseVideo  // post-submit callback 
							} 
							$('#videoUploadForm').ajaxForm(videoOptions);	
					}				
			}
		}
		else{
			alert("Video name is mandatory");			
		}
		},'json');	
}
function addVideoComment(videoId)
{
	if($('#videoCommentText').val()!='')
	{
		params={'commentText':$('#videoCommentText').val(),'videoId':videoId};	
		$.post(URL+"/comments.php/video/new",params,function(data) {	
			if(data.reply==1)
			{
				 ChangeCommentTab('commentsTab',videoId);		
				 $('#videoCommentText').val('');
			}
		},'json');
	}
	else
	{
		//show error message enter valu ein teat area
	}		
}
function listVideoComment(videoId)
{
	html='';
	params={'videoId':videoId};	
	$.post(URL+"/comments.php/video/list",params,function(data) {		
		if(data.reply==1)
		{
			if(data.message!=null)
			{
				html+='<div class="comments_col">';
				for(i=0;i<data.message.length;i++)
				{
					html+='<div class="comment_container">'
					+'<div class="comment_header">'
					+'<div class="comment_username">'+data.message[i]['user_name']+'</div>'
					+'<div class="comment_date">'+data.message[i]['comment_date']+'</div>'
					+'</div>'
					+'<div class="comment_body">'
					+data.message[i]['comment']
					+'</div>'
					+'</div>'

					/*html+='<div >'
					+'<div class="comment_username">'+data.message[i]['user_name']+'</div>'
					+'<div class="comment_date">'+data.message[i]['comment_date']+'</div>'
					+'<div class="comment_body" style="background-color: #FBD9DE; height:100%; padding:10px; min-height:20px;">'+data.message[i]['comment']+
					+'</div>'
					+'</div>';*/									
				}
				html+='</div>';
				$('#commentsTabContents').html(html);
			}
		}
	},'json');
}
function addVideoToFavorit(videoId)
{
	if(myID==-1)
	{
		getLogin();
		return 0;
	}else{
		params={'videoId':videoId};	
		$.post(URL+"/videos.php/edit/addToFavorit",params,function(data) {},'json');
	}
}
function editUserProfilePhoto()
{
	//document.getElementById('privacyDiv').className='settings_tab_disabled',$('#accountSettings').hide(),$('#pprivacySettings').hide(),$('#prefSettings').show()
	$('#prefDiv').removeClass('settings_tab_disabled');
	$('#passwordDiv').removeClass('settings_tab_selected');
	$('#accountDiv').removeClass('settings_tab_selected');
	$('#privacyDiv').removeClass('settings_tab_selected');
	$('#passwordDiv').removeClass('settings_tab_selected');
	
	$('#prefDiv').addClass('settings_tab_selected');
	$('#passwordDiv').addClass('settings_tab_disabled');
	$('#accountDiv').addClass('settings_tab_disabled');
	$('#privacyDiv').addClass('settings_tab_disabled');
	$('#passwordDiv').addClass('settings_tab_disabled');
	
	$('#passwordSettings').hide()
	$('#accountSettings').hide()
	$('#pprivacySettings').hide()
	$('#passwordSettings').hide()
	$('#prefSettings').show();
}
function editProfileInfo(editId)
{
	$('#personalInfoData_'+editId).slideToggle();
	$('#personalInfoInput_'+editId).slideToggle();	
}
function postProfileInfo(editId)
{
	$('#personalInfoData_'+editId).slideToggle();
	$('#personalInfoInput_'+editId).slideToggle();
	params='field='+editId+'&value='+$('#personal'+editId).val();
	$.getJSON(URL+"/accounts.php/register/updateUserField",params,function(data) {
		$('#personalData_'+editId).text($('#personal'+editId).val());
	});
}

function addToWall(userId,postTextId)
{
	params={'userId':myID,'friendId':userId,'wallText':$('#'+postTextId+userId).val()};
	$.post(URL+"/myProfile.php/addToWall/addToWall",params,function(data) {
		
		html='<div id="feed_container_" class="feed_container">'
		
		+'<div  id="feed_container_center" class="feed_container_center">'
		+'<span class="feed_date">'+now+'</span>'
		+'<br />';
		/*html+='<span class="feed_text">'
			+'<a href="javascript:void(null)" style="font-weight:bold;color:#ff7c00;text-decoration: none;"  onclick="getFriendProfile('+userId+')" >'+userName+'</a>'
			+' wrote on ';*/
								//if(myID==userId){html+='his/her';}else{html+='your';}
								
								
								
							/*html+='<span class="feed_text">'+data.friends[i]['userPhoto']+'&nbsp;';
							if(data.friends[i]['id']==data.friends[i]['sentTo']){
								html+=data.friends[i]['name']
							}else{
								if(data.friends[i]['sentTo']!=myID){
									html+=data.friends[i]['name']
								}else{
									if(data.friends[i]['sentTo']==myID){
										html+='You'
									}else{
										html+=data.friends[i]['name']
									}
								}
							}*/
							
							html+='<span class="feed_text">You wrote on ';
							
								if(myID==userId){
									html+='your';
								}else{
									html+=data.reply;
								}
							
							html+=' wall on KFC Arabia :<div class="wallTextMsg">'+$('#'+postTextId+userId).val()+'</div></span>';	
							//profileWallCount++;
										
		html+='</div>'
				
			+'</div>'	;	
	
		$('#cont_'+userId).prepend(html);
		$('#'+postTextId+userId).val('');
		
	},'json');
}
function createPhotoAlbum()
{
	params="albumName="+$('#albumName').val()+"&albumLocation="+$('#albumLocation').val()+"&albumDescription="+$('#albumDescription').val()+"&albumPrivacy="+$('input:radio[name=albumPrivacy]:checked').val();	
	$.post(URL+"/photos.php/albums/createAlbum",params,function(data) {
		if(data.reply==1)
		{
			$('#photo_left_menu_contents1').animate({ width:"0px" },2 ,'swing',function (){
				$('#photo_left_menu_contents1').css('visibility','hidden')
				generalAlbumId='';
				getPhotos('listAlbums');				
			})
			$('#img_photo_left_menu_contents1').attr('src',CDN_IMG+'/new/creat_album.gif');			
		}
		else
		{			
			if(data.errors['albumName']!=null)
				$('#createAlbumNameErrors').text(data.errors['albumName']);
			if(data.errors['userId']!=null)
				$('#createAlbumErrors').text(data.errors['userId']);
		}
	},'json');
}
function editAlbumTab(albumId)
{
	$.post(URL+"/photos.php/albums/getAlbumDetails",'albumId='+albumId,function(data) {	
		html='<div class="photos_settings_content">'
			+'<div class="photos_input_title">'
			+'<label for="edit_albumName">Name:</label> </div>'
			+'<div class="photos_input_field">'
			+'<input id="edit_albumName" class="photos_input_field_textarea" type="text" value="'+data.message['album_name']+'"/><span id="editAlbumNameErrors"></span>'
			+'</div>'
			+'<div class="photos_input_title">'
			+'<label for="edit_albumLocation">Location:</label></div>'
			+'<div class="photos_input_field">'
			+'	<input id="edit_albumLocation" class="photos_input_field_textarea" type="text" value="'+data.message['album_location']+'"/>'
			+'</div>'
			
			+'	<div style="height:180px;" class="photos_input_title">'
			+'		<label for="edit_albumDescription">Description:</label> </div>'
			+'	<div style="height:180px;float:right" class="photos_input_field">'
			+'		<textarea id="edit_albumDescription" class="photos_input_field_textarea" cols="15" rows="10">'+data.message['album_description']+'</textarea>'
			+'	</div>'
			
			+'<div>'						
			+'<div class="photos_input_title">Privacy: </div>'
			+'<div class="photos_input_field">'
			+'	<input type="radio" name="edit_albumPrivacy" id="edit_onlyMe" value="0" '
			if(data.message['album_privacy']=='0')
				html+='checked="checked"'
			html+='/>'
			+'	<label for="onlyMe"> Only Me</label><br />'
			+'	<input type="radio" name="edit_albumPrivacy" id="edit_friends" value="1"'
			if(data.message['album_privacy']=='1')
				html+='checked="checked"'
			html+='/>'
			+'	<label for="friends"> Friends</label><br />'
			+'	<input type="radio" name="edit_albumPrivacy" id="edit_everyOne" value="3" '
			if(data.message['album_privacy']=='3')
				html+='checked="checked"'
			html+='/>'
				+'<label for="everyOne"> Everyone</label> <br />'
			+'</div>'
			+'</div>'						
			+'<div><a class="photos_settings_button" href="javascript:void(null)" title="Creat Album" onclick="editPhotoAlbum()" >Edit Album</a></div>'
			+'<div id="editAlbumErrors"></div>'						
		+'</div>'
	if($('#photo_left_menu_contents2').html(html))
	{
		$('#photos_vertical_left_menu2').show();
		showLeftMenu('photo_left_menu_contents',2);
	}
	},'json');
}
function editPhotoAlbum()

{
	params="albumName="+$('#edit_albumName').val()+"&albumLocation="+$('#edit_albumLocation').val()+"&albumDescription="+$('#edit_albumDescription').val()+"&albumPrivacy="+$('input:radio[name=edit_albumPrivacy]:checked').val();	
	$.post(URL+"/photos.php/albums/editAlbum",params,function(data) {
		if(data.reply==1)
		{
			$('#photo_left_menu_contents2').animate({ width:"0px" },2 ,'swing',function (){
				$('#photo_left_menu_contents2').css('visibility','hidden')
				getPhotos('listAlbums');
			})
			$('#img_photo_left_menu_contents2').attr('src',CDN_IMG+'/new/edit_album.gif');			
		}
		else
		{			
			if(data.errors['albumName']!=null)
				$('#editAlbumNameErrors').text(data.errors['albumName']);
			if(data.errors['userId']!=null)
				$('#editAlbumErrors').text(data.errors['userId']);
		}
	},'json');
}
function listPhotoAlbums(friendId)
{
	
	$.post(URL+"/photos.php/albums/listAlbums",'friendId='+friendId,function(data) {
		if(data.reply==1&& data.message!=null)
		{
			var html="";
			if(friendId==0)
			{
			html+='<div class="photos_left_menu_all">'
				
				+'<div id="photo_left_menu_contents1" class="photo_left_menu_contents">'				
					+'<div class="photos_settings_content">'
						+'<div class="photos_input_title">'
						+'<label for="albumName">Name:</label> </div>'
						+'<div class="photos_input_field">'
						+'<input id="albumName" class="photos_input_field_textarea" type="text" /><span id="createAlbumNameErrors"></span>'
						+'</div>'
						+'<div class="photos_input_title">'
						+'<label for="albumLocation">Location:</label></div>'
						+'<div class="photos_input_field">'
						+'	<input id="albumLocation" class="photos_input_field_textarea" type="text" />'
						+'</div>'
						
						+'	<div style="height:180px;" class="photos_input_title">'
						+'		<label for="albumDescription">Description:</label> </div>'
						+'	<div style="height:180px;float:right" class="photos_input_field">'
						+'		<textarea id="albumDescription" class="photos_input_field_textarea" cols="15" rows="10"></textarea>'
						+'	</div>'
						
						+'<div>'						
						+'<div class="photos_input_title">Privacy: </div>'
						+'<div class="photos_input_field">'
						+'	<input type="radio" name="albumPrivacy" id="onlyMe" value="0"/>'
						+'	<label for="onlyMe"> Only Me</label><br />'
						+'	<input type="radio" name="albumPrivacy" id="friends" value="1"/>'
						+'	<label for="friends"> Friends</label><br />'
						+'	<input type="radio" name="albumPrivacy" id="everyOne" value="3" checked="checked"/>'
							+'<label for="everyOne"> Everyone</label> <br />'
						+'</div>'
						+'</div>'						
						+'<div><a class="photos_settings_button" href="javascript:void( null)" title="Creat Album" onclick="createPhotoAlbum();" >Create Album</a></div>'
						+'<div id="createAlbumErrors"></div>'						
					+'</div>'					
				+'</div>'			
				
				+'<div id="photo_left_menu_contents2" class="photo_left_menu_contents">'
						
						
				+'</div>'				
				
				+'<div class="photos_album_left_tab">'
				
				+'<div class="photos_vertical_left_menu">'				
				+'<div class="photos_top_corner"></div>'
				+'<div class="photos_left_tab_center">'
				+'<img  id="img_photo_left_menu_contents1" src="'+CDN_IMG+'/new/creat_album.gif" onclick="showLeftMenu(\'photo_left_menu_contents\',1)"/>'
				+'</div>'				
				+'<div class="photos_bottom_corner"></div>'
				+'</div>'
				
				+'<div style="display:none;" id="photos_vertical_left_menu2" class="photos_vertical_left_menu">'				
				+'<div class="photos_top_corner"></div>'
				+'<div class="photos_left_tab_center">'
				+'<img id="img_photo_left_menu_contents2" src="'+CDN_IMG+'/new/edit_album.gif" onclick="showLeftMenu(\'photo_left_menu_contents\',2)"/>'
				+'</div>'				
				+'<div class="photos_bottom_corner"></div>'
				+'</div>'	
				
				+'</div>'
				
				+'</div>';	
			}			
			for(i=0;i<data.message.length;i++)
			{
				albumDesc=data.message[i]['album_description'].substring(0,38)
				if(data.message[i]['album_description'].length>38 )
					albumDesc+='<br/>'+data.message[i]['album_description'].substring(38,76)
				if(data.message[i]['album_description'].length>76 )
					albumDesc+='<br/>'+data.message[i]['album_description'].substring(76,114)
				html+='<div class="photos_album_container">'
					if(friendId==0)
					{
						html+='	<div class="photos_actions_container">'
							+'	<div class="delete_album" onclick="deleteConfirmation('+data.message[i]['album_id']+',\'album\')">Delete</div>'
							+'	<div class="edite_album" onclick="editAlbumTab('+data.message[i]['album_id']+')">Edit</div>'
						+'</div>'
					}				
					html+='<div class="photos_album_cover" onclick="openAlbum(\''+data.message[i]['album_id']+'\','+friendId+')">'
					
					+'<div class="photo_thumb2">'
					if(data.message[i]['album_cover']!=''&&data.message[i]['album_cover']!=null)
						html+='<img src="'+CDN_PHOTOS+'/'+data.message[i]['album_id']+'/thumb/'+data.message[i]['album_cover']+'"/>'
					else
						html+='<img src="'+CDN_IMG+'/new/album_cover.gif"/>'
					html+='</div>'
						
					html+='</div>'
					+'<div class="photos_album_details">'				
						+'<a class="photos_album_title" href="javascript:void(null)" onclick="openAlbum(\''+data.message[i]['album_id']+'\','+friendId+')">'
						+data.message[i]['album_name']
						+'</a><br />'
					//	+'12 photos<br />'
						//+'<div style="width:200px;height:30px;">'
							+ albumDesc
						//+'</div>'
						+'<br />'
						+'Created :'+data.message[i]['creationDate']+'<br />'
						+'Last Updated :'+data.message[i]['updateDate']+'<br />'
					+'</div>'
				+'</div>';				
				//html+=data.message[i]['album_name']+"  <a onclick=\"deleteAlbum('"+data.message[i]['album_id']+"')\">Delete</a><br/>";
			}
			$('#photosAlbumContaintsDiv').html(html);
		}
	},'json');
}
function CheckExtPhoto(formData, jqForm, options) {	
	var errors=0;
	var exists=0;
	$('#createPhotoErrors').hide()
	for(i=1;i<9;i++)
	{
		ext = $("#photoFile"+i).val();
		if($('#photoFile'+i).val().length>3){	
			ext = ext.substring(ext.length-3,ext.length);
			ext = ext.toLowerCase();
			 if((ext != 'jpg') && (ext != 'gif')&& (ext != 'png')){
					$('#createPhotoErrors').append('<h4>Please select a proper photo file in Photo File '+i+'<br/>jpg, gif, png<h4>').fadeIn(500);
					errors++;
				}
		}
		else
		{
			exists++;
		}
	}
	if(myID==-1)
	{
		$('#createPhotoErrors').append('<h4>Please sign in first ..<h4>').fadeIn(500);
		errors++;
	}		
	if(exists==8){	
		$('#createPhotoErrors').append('<h4>Please select a file before submission ...<h4>').fadeIn(500);
		errors++;
	}
	if(errors!=0)
	{
		return false;
	}
	else
	{
		$('#photoUploadFormTab').hide();
		$('#photoUploadLoaderImage').show();
		return true;
	}
}
function showUploadResponsePhoto(data){
	//alert(data.error)
	$('#createPhotoErrors').show();
	$('#createPhotoErrors').html('<h4><br/>The photo file has been successfully uploaded ..</h4>');
	$('#photoUploadLoaderImage').hide();
	$('#img_photo_left_menu_contents3').attr('src',CDN_IMG+'/new/add_photo.gif');
	$('#photo_left_menu_contents3').animate({ width:"0px"},500 ,'swing',function (){
		$('#photo_left_menu_contents3').css('visibility','hidden');
		$('#photos_vertical_left_menu2').hide();
		getPhotos('listphotos');				
	})
	
}
function listAlbumPhotos(friendId)
{
	$.post(URL+"/photos.php/photos/listAlbumPhotos",'friendId='+friendId,function(data) {
		if(data.reply==1&& data.message!=null)
		{
			html='';
			if(friendId==0)
			{
				html+='<div class="photos_left_menu_all">'
				+'<div id="photo_left_menu_contents3" class="photo_left_menu_contents">'
				+'<div class="photos_settings_content">'
				+'<div id="photoUploadFormTab"><form action="'+URL+'/photos.php/photos/New" method="post" id="photoUploadForm" enctype="multipart/form-data" >'			
				for(i=1;i<9;i++)
				{
					html+='<div class="photos_input_title">'
					+'<label for="photoFile">Photo File '+i+'</label> </div>'
					+'<div class="photos_input_field">'
					+'<input class="photos_input_field_textarea" type="file"  value="" id="photoFile'+i+'" name="photoFile'+i+'"/>'
					+'</div>'
				}
				html+='<div><input class="photos_settings_button" type="submit" value="Add Photos"/></div>'			
					+'<span>Allowed files.(jpg, gif, png)</span>'
				+'</form></div>'			
				+'<br/><div id="createPhotoErrors" style="display:none;"></div>'			
				+'<div  id="photoUploadLoaderImage" style="display:none;text-align:center;padding-top:100px;">'
				+'<img src="'+CDN_IMG+'/img_loader.gif">'
				+'</div>'
				+'</div>'
				+'</div>'				
				+'<div class="photos_album_left_tab">'				
				+'<div class="photos_vertical_left_menu">'				
				+'<div class="photos_top_corner"></div>'
				+'<div class="photos_left_tab_center">'
				+'<img  id="img_photo_left_menu_contents3" src="'+CDN_IMG+'/new/add_photo.gif" onclick="showLeftMenu(\'photo_left_menu_contents\',3)"/>'
				+'</div>'				
				+'<div class="photos_bottom_corner"></div>'
				+'</div>'				
				+'</div>'
				+'</div>'
			}			
			//html+="<div style='margin-left:45px;>";
			html+='<div class="photo_thumb_container">'
				+'<ul class="photo_thumb_ul">'
				
			for(i=0;i<data.message.length;i++)
			{
				ifNext=0;
				if (i==0)
					ifNext=2;
				else if (i==data.message.length-1)
					ifNext=1;
				if (data.message.length==1)
					ifNext=3;			
				
				html+='<li class="photo_thumb_li"><div class="photo_thumb" onclick="showBigPhoto(\'photosAlbumContaintsDiv\',\''+CDN_PHOTOS+"/"+data.message[i]['album_id']+"/thumb1/"+data.message[i]['photo_file']+'\',\''+data.message[i]['photo_file']+'\','+data.message[i]['photo_id']+','+ifNext+','+friendId+')">'
					    	+'<img src="'+CDN_PHOTOS+"/"+data.message[i]['album_id']+"/thumb/"+data.message[i]['photo_file']+'" />'
					    +'</div>'
					    +'</li>'
			}
			html+='</ul>'
			html+="</div>"
			//	+'</div>'		
			if($('#photosAlbumContaintsDiv').html(html))
			{		
				var photoOptions = { 			
						dataType:  'json', 
						beforeSubmit:  CheckExtPhoto,   
						success:       showUploadResponsePhoto  
					} 
					$('#photoUploadForm').ajaxForm(photoOptions);		
			}
		}
	},'json');
}

function deleteConfirmation(ItemId,type)
{	
	html='<div id="deleteConfirmation">'
	 +'<div  class="photos_delete_confirmation"><div>Are you sure you want to proceed ?</div>'
	 +'<div style="width:200px;float:left;margin-left:130px;margin-top:15px">'
	 +' <div style="float:left;margin-right:35px;cursor:pointer;"><img alt="Yes" src="'+CDN_IMG+'/new/confirm_delete.gif" onclick="deleteItem('+ItemId+',\''+type+'\')"/></div>'		
	 +' <div style="float:left;margin-right:35px;cursor:pointer;"><img alt="No" src="'+CDN_IMG+'/new/reject_delete.gif" onclick="controlFullScreen(\'deleteConfirmation\', \'hide\')"/></div>'
	 +' </div>'
	 +'</div>'
	 +'</div>'
	 controlFullScreenHTML(html,'show');
}
function deleteItem(ItemId,type)
{
	if(type=='photo')
	{
		$.post(URL+"/photos.php/photos/delete",'photoId='+ItemId,function(data) {
			getPhotos('listphotos');				
		},'json');
	}
	else if(type=='album')
	{
		$.post(URL+"/photos.php/albums/delete",'albumId='+ItemId,function(data) {
			getPhotos('listAlbums');				
		},'json');
	}	
	else if(type=='friend')
	{
		if($('#win3'+ItemId).attr('id') )
		{
			$('#win3'+ItemId).remove();
		}
		deleteFriend(ItemId);
	}	
	controlFullScreen('deleteConfirmation', 'hide');		
}
function deleteAlbum(albumId)
{
	$.post(URL+"/photos.php/albums/delete",'albumId='+albumId,function(data) {},'json');
}
//JavaScript Document
var theCounter1=0;
var theCounter2=0;
var theCounter3=0;
var counterSearch=0;
var profileFeedCount=0;
var profileWallCount=0;
var videoConut=0;
function showMore(toPost, Link,type,userId){
	var finalText='';
	$.post(URL+Link,toPost,function(data){
		if(data.message!=null)
		{
			if(type=='videoList')
			{				
				theDiv='#videoPart1';
				for (i = 0; i < data.message.length; i++) {
					finalText+='<div>'
						+'<div id="secectedVideoDiv'+data.message[i]['video_id']+'" onclick=" playVideo(\''+ data.message[i]['video_id']+'\',\''+ data.message[i]['video_name']+'\',\''+ data.message[i]['video_file']+'\',\''+ data.message[i]['video_total_rank']+'\',\''+ data.message[i]['video_views']+'\',\''+ data.message[i]['user_name']+'\')" class="single_video">';
							
							if(data.message[i]['video_file']!=''){finalText+='<img src="'+CDN_VIDEOS+'/uploaded_images/'+data.message[i]['video_file']+'2.jpg" alt="" />'}
							
							finalText+='<div class="video_details">'
								+'<span class="title">'+data.message[i]['video_name']+'</span><br />'
								/*+'<span>Rating:';
									for(r=0;r<data.message[i]['video_total_rank'];r++)
									{
										finalText+='<img src="'+CDN_IMG+'/stars.png" alt="" />';
									}
									finalText+='</span>'*/
							+'</div>'
						+'</div>'		
						+'</div>';
						videoConut++;
				}	
				if(data.errors=='true')
					finalText+='<div class="show_more_video" id="videoResults" onclick="showMore(videoParams+\'&limit=\'+videoConut,\'/Videos/List/Index\',\'videoList\');$(\'#videoResults\').remove();">Show more</div>';
			}
			else if(type=='friendsFeeds'){				
				 theDiv='#friendsFeeds';
				 if(data.friends!=null){
					for(h=0; h<data.friends.length ;h++){
						
						finalText+='<div class="feed_container"><div class="feed_container_center"><span class="feed_date">'+data.friends[h]['date']+'</span><br/><div class="feed_text">'+data.friends[h]['user']+data.friends[h]['friend']+'</div></div></div>';	
						theCounter1++;
					}				
			}
				if(data.message[1]=="true"){finalText+='<div class="show_more" id="feedsResults" onclick="showMore({ userID :myID ,theCounter:theCounter1},\'/feeds.php/view/viewFeeds/\',\'friendsFeeds\');$(\'#feedsResults\').remove();">Show more</div>';
				}
			}			
		}
		if(data.friends!=null){
			if(type=='profileFeeds'||type=='profileWall' )
			{
				theDiv="#cont_"+userId;				
				for(i=0;i<data.friends.length;i++)
				{
					finalText+='<div id="feed_container_'+i+'" class="feed_container">'
							
							+'<div  id="feed_container_center'+i+'" class="feed_container_center">'
							+'<span class="feed_date">'+data.friends[i]['date']+'</span>'
							+'<br />';
					
					
					
					
					
					if(type=='profileWall')	
					{
						/*finalText+='<span class="feed_text">'+data.friends[i]['userPhoto']+'&nbsp;'+data.friends[i]['name']+' wrote on ';
								if(data.friends[i]['id']==data.friends[i]['sentTo']){finalText+='his/her';}else{finalText+='your';}
								finalText+=' wall on KFC Arabia :<div class="wallTextMsg">'+data.message[i]+'</div></span>';
						profileWallCount++;*/
						
							finalText+='<span class="feed_text">'+data.friends[i]['userPhoto']+'&nbsp;';
							if(data.friends[i]['id']==data.friends[i]['sentTo']){
								finalText+=data.friends[i]['name']
							}else{
								if(data.friends[i]['sentTo']!=myID){
									finalText+=data.friends[i]['name']
								}else{
									if(data.friends[i]['sentTo']==myID){
										finalText+='You'
									}else{
										finalText+=data.friends[i]['name']
									}
								}
							}
							
							finalText+=' wrote on ';
							if(data.friends[i]['id']==data.friends[i]['sentTo']){
								finalText+='his/her';
							}else{
								if(data.friends[i]['sentTo']!=myID){
									finalText+='your';
								}else{
									finalText+=data.friends[i]['myData'];
								}
							}
							finalText+=' wall on KFC Arabia :<div class="wallTextMsg">'+data.message[i]+'</div></span>';
							profileWallCount++;
					}
					
					
					
					
					
					
					if(type == 'profileFeeds')
					{
						finalText+='<span class="feed_text">'+data.friends[i]['user']+data.friends[i]['friend']+'</span>';
						profileFeedCount++;
					}
					else if (type=='requests')
					{
						finalText+='<span class="feed_text">'+data.friends[i]['name']+'has added you as a friend on</span> <br/><span class="feed_text">KFC Arabia.</span>';							
						finalText+='<div class="request_action">'
							finalText+='<div class="accept_request" onclick="acceptFriendRequest('+i+','+data.friends[i]['user_id']+','+data.friends[i]['friend_id']+',\''+data.friends[i]['name']+'\');">Accept</div>'
							finalText+='<div class="reject_request" onclick="ignoreFriendRequest('+i+','+data.friends[i]['user_id']+','+data.friends[i]['friend_id']+');">Reject</div>'
						finalText+='</div>'
					}							
					finalText+='</div>'
							
						+'</div>';						
				}
				if(type=='profileFeeds')
				{
					if(data.message[1]=="true")
						finalText+='<div class="show_more" id="feedsResults_'+userInfo['user_id']+'" onclick="showMore({ userID :'+userInfo['user_id']+' ,theCounter:profileFeedCount},\'/feeds.php/view/viewFeeds/\',\'profileFeeds\','+userInfo['user_id']+');$(\'#feedsResults_'+userInfo['user_id']+'\').remove();">Show more</div>';
				}
				else if(type=='profileWall')
				{
					if(data.reply=="true")
					finalText+='<div class="show_more" id="wallResults_'+userInfo['user_id']+'" onclick="showMore({ userID :'+userInfo['user_id']+' ,theCounter:profileWallCount},\'/myProfile/myWall/myWall\',\'profileWall\','+userInfo['user_id']+');$(\'#wallResults_'+userInfo['user_id']+'\').remove();">Show more</div>';								
				}				
			}			
			else if(Link=='/friends.php/list/allFriends/'){
				var theDiv='#myFriends';
				for(h=0; h<data.friends.length ;h++){
					finalText+='<div id="friend'+data.friends[h]['id']+'" class="feed_container"><div class="feed_container_center"><div   class="delete_btn"></div><div class="friend_avatar"><img width="50px" height="50px" src="'+IMG_URL+data.friends[h]['friendPhoto']+'" alt="'+data.friends[h]['name']+'"/></div><div class="friend_overview"><div class="friend_name"><a href="javascript:null();" onclick="getFriendProfile('+data.friends[h]['id']+')" title="" >'+data.friends[h]['name']+'</a></div><div class="friend_status">'+data.friends[h]['fPost']+'</div></div></div></div>';	
					theCounter3++;
				}				
				if(data.message=="true"){
					finalText+='<div  class="show_more" id="friendsResults" onclick="showMore({ userID :myID ,theCounter:theCounter3},\'/friends.php/list/allFriends/\');$(\'#friendsResults\').remove();">Show more</div>';
				}
			}					
		}		
		$(theDiv).append(finalText);
    },'json');
}
function sendRequest(toPost, Link, callBack,type){
	$.post( URL+Link , toPost ,function(data){
		eval(callBack);	
	},type); 
 }
function searchFriend(toPost, Link, callBack,type){
	 	theDiv="#searchFriends";
		searchValue=$('#friendSearch').val();
		var finalText='';
	    $.post(URL+Link,toPost,function(data){
		if(data.friends!=null){
			for(h=0; h<data.friends.length ;h++){
				finalText+='<div id="friendSearch'+data.friends[h]['id']+'" class="feed_container"><div class="feed_container_center"><div class="friend_avatar" onclick="getFriendProfile('+data.friends[h]['id']+')" ><img src="'+IMG_URL+data.friends[h]['fPhoto']+'" width="50px" height="50px" alt="'+data.friends[h]['name']+'"/></div><div class="friend_overview"><div class="friend_name"><a href="javascript:void(null);" title="" onclick="getFriendProfile('+data.friends[h]['id']+')" >'+data.friends[h]['name']+'</a></div><div class="friend_status">';
				if(data.friends[h]['rel']==1){
					finalText+='Alredy a friend';
				}else if(data.friends[h]['rel']==2){
					finalText+='A friendship request between you and this user.';
				}else{
					finalText+='<span style="cursor:pointer" onclick="$(\'#friendSearch'+data.friends[h]['id']+'\').remove();sendRequest({ userid : '+myID+' , friendid : '+data.friends[h]['id']+'},\'/friends.php/requestFriend/addFriends\',\'\',\'json\');">Add to my friends</span>';
				}				
				finalText+='</div></div></div></div>';
				counterSearch++;
			}
			if(data.message=="true"){finalText+='<div  class="show_more" id="moreResults" onclick="searchFriend({ userID :myID ,friendSearch:searchValue,counterSearch:counterSearch},\'/friends.php/searchFriends/searchFriends/\',\'\',\'json\');$(\'#moreResults\').remove();">Show more</div>';
			}
		}else{
				finalText+='<br/><div class="feed_container"><div class="feed_container_center"><br/><div class="feed_text">You don\'t have any friends yet. Look for your friends now on KFC Arabia or invite your friends using the e-mail contact importer. </div><br/></div></div>';				
			}
		//if(counterSearch==0){
			//$(theDiv).html(finalText);
		//}else{
			$(theDiv).append(finalText);
		//}
    },type);	
 } 
 var loadWithAjax={
  loadContent: function (id){ 
  loadWithAjax.listFriends(id);
  },
  listFriends: function (id) {
	var theDiv=Array("#friendsFeeds","","#myFriends","","","","","","","","","accountSettings");
	var links=Array(URL+"/feeds.php/view/viewFeeds/userID/"+myID+"/__/"+Math.random(),
				URL+"/myProfile.php/myWall/myWall/userID/"+myID+"/__/"+Math.random(),
				URL+"/friends.php/list/allFriends/userID/"+myID+"/__/"+Math.random(),
				URL+"/friends.php/requestFriend/requestFriend/userID/"+myID+"/__/"+Math.random(),
				URL+"/friends.php/searchFriends/searchFriends/userID/"+myID+"/__/"+Math.random(),
				URL+"/friends.php/friendDetails/friendDetails/userID/"+myID+"/__/"+Math.random(),
				URL+"/notification.php/view/view/userID/"+myID+"/__/"+Math.random(),
				"","","","",
				URL+"/settings.php/update/userSettings/userID/"+myID+"/__/"+Math.random());

  $.getJSON(links[id],function(data){
	var finalText="";
	if(id==0){
		$('#theUserPhoto').attr("src", IMG_URL+data.reply[0])
		if(data.friends!=null){
			for(h=0; h<data.friends.length ;h++){
				finalText+='<div class="feed_container"><div class="feed_container_center"><span class="feed_date">'+data.friends[h]['date']+'</span><br/><div class="feed_text"><a href="javascript:void(null);" title="" onclick="getFriendProfile('+data.friends[h]['id']+')" >'+data.friends[h]['user']+'</a>'+data.friends[h]['friend']+'</div></div></div>';
			theCounter1++;	
			}
		}else{
				finalText+='<br/><div class="feed_container"><div class="feed_container_center"><br/><div class="feed_text"> No new feeds yet .</div><br/></div></div>';
				
			}
		if(data.message[1]=="true"){finalText+='<div  class="show_more" id="feedsResults" onclick="showMore({ userID :myID ,theCounter:theCounter1},\'/feeds.php/view/viewFeeds/\',\'friendsFeeds\');$(\'#feedsResults\').remove();">Show more</div>';
		}
	}
	
	if(id==1){
		if(data.friends!=null){
			for(h=0; h<data.friends.length ;h++){
				finalText+='<span style="color:green;">'+data.friends[h]['name']+"</span> <span style='color:maroon;'>"+data.message[h] +"</span><span style='color:green;'>   "+myID +"</span><br/><br/>";
				theCounter2++;
			}
		}
		finalText+='<div  class="show_more" id="nana2" onclick="showMore(theCounter2,links[id],id);$(\'#nana2\').remove();">Show more</div>';
	}

	if(id==2){
		if(!data.friends){
				finalText+='<br/><div class="feed_container"><div class="feed_container_center"><br/><div class="feed_text">You don\'t have any friends yet. Look for your friends now on KFC Arabia or invite your friends using the e-mail contact importer. </div><br/></div></div>';
		}
		else{		
			if(data.friends[0]['id']!=null){
				for(h=0; h<data.friends.length ;h++){
					if(data.friends[h]['fPost']==null){data.friends[h]['fPost']='';}
					finalText+='<div id="friend'+data.friends[h]['id']+'" class="feed_container"><div class="feed_container_center"><div ><img src="'+CDN_IMG+'/new/delete_user_small.png" alt="Delete Friend" title="Delete Friend" class="getFriendPhotosImg" onclick="deleteConfirmation('+data.friends[h]['id']+',\'friend\')" /></div><div class="friend_avatar" onclick="getFriendProfile('+data.friends[h]['id']+')"><img width="50px" height="50px" src="'+IMG_URL+data.friends[h]['friendPhoto']+'" alt="'+data.friends[h]['name']+'"/></div><div class="friend_overview"><div class="friend_name"><a href="javascript:void(null);" title="" onclick="getFriendProfile('+data.friends[h]['id']+')" >'+data.friends[h]['name']+'</a></div><div class="friend_status">'+data.friends[h]['fPost']+'</div></div></div></div>';
					theCounter3++;
			}
		}else{
				finalText+='<br/><div class="feed_container"><div class="feed_container_center"><br/><div class="feed_text">You don\'t have any friends yet. Look for your friends now on KFC Arabia or invite your friends using the e-mail contact importer. </div><br/></div></div>';				
			}
		if(data.message=="true"){finalText+='<div  class="show_more" id="friendsResults" onclick="showMore({ userID :myID ,theCounter:theCounter3},\'/friends.php/list/allFriends/\');$(\'#friendsResults\').remove();">Show more</div>';
		}		
		}
	}
	if(id==3){
		if(data.friends!=null){
			thePath1="friends.php/list/allFriends/userID/"+myID;
			thePath2="friends.php/requestFriend/requestFriend/userID/"+myID;
			for(m=0; m<data.friends.length ;m++){
				finalText+='<span style="color:green;">'+data.friends[m]['name'] + "</span> <span style='color:maroon;cursor:pointer;' onclick='sendRequest({ userid : "+myID+" , friendid : "+data.friends[m]['id']+"},\"/friends.php/requestFriend/acceptFriend\",\"loadWithAjax.loadContent(3)\",\"json\");' >Accept friend</span>  -  <span style='color:maroon;cursor:pointer;' onclick='sendRequest({ userid : "+myID+" , friendid : "+data.friends[m]['id']+"},\"/friends.php/requestFriend/ignorFriend\",\"loadWithAjax.loadContent(3)\",\"json\");'>Ignor</span><br/><br/>";
			}
		}
	}	
	if(id==4){
		if(data.friends!=null){
			for(h=0; h<data.friends.length ;h++){
				finalText+='<span style="color:maroon;">'+data.friends[h]['id']+'/'+data.friends[h]['name'] + "</span> <span style='color:blue;cursor:pointer;' onclick='sendRequest({ userid : "+myID+" , friendid : "+data.friends[h]['id']+"},\"/friends.php/requestFriend/addFriends\",\"loadWithAjax.loadContent(4)\",\"json\");' >Add to my friends</span><br/><br/>";
			}
		}
	}	
	if(id==5){
		if(data.friends!=null){
			finalText+='<span style="color:maroon;">FullName: '+data.friends[0]['fullname']+"</span> <br/><span style='color:maroon;'>NickName: "+data.friends[0]['nickname']+"</span><br/><br/>";
		}
	}	
	if(id==11){
		//if(data.friends['email']!=null){
			//$('#settingUserEmail').val(data.friends['email']);
			$('#settingUsername').val(data.friends['name']);
			//$('#settingQuestion option:selected').selectedIndex=data.friends['question'];
			$('#settingQuestion').val(data.friends['question']);
			$('#settingAnswer').val(data.friends['answer']);
			$('#theUserPhotoSettings').attr("src", IMG_URL+data.friends['usPhoto'])
		//}
	}	
	finalText+="";
	$(theDiv[id]).html(finalText);
    });
  }
}  	
 function deleteFriend(FriendId)
 {
	 sendRequest({'userid':myID,'friendid':FriendId},'/friends.php/deleteFriend/deleteFriend', '','json');
	 $('#friend'+FriendId).remove();
 }
 function submitAllSettings(){
 	var data2={'userID':myID
 			,'settingUsername':$('#settingUsername').val()
 			,'settingQuestion':$('#settingQuestion').val()
 			,'settingAnswer':$('#settingAnswer').val()};
 			
 	if(user_name_validation('settingUsername')) {
 	sendRequest(data2, '/settings.php/update/updateAccount', '$("#updateSettingsMess").text(data.message).fadeIn();','json');
 	}
 }
 function submitPassword(){
 	var data2={'userID':myID
 			,'settingOldPassword':$('#settingOldPassword').val()
 			,'user_password':$('#user_password').val()};
 			
 	if(password_validation('settingOldPassword')  && password_validation('user_password')  && re_password_validation('user_re_password','user_password') ) {
 	sendRequest(data2, '/settings.php/update/updatePassword', '$("#passwordSettingsMess").text(data.message).fadeIn();','json');
 	}
 }


 function submitPrivacy(){
 	var data={'userID':myID
 			,'profileSelect':$('#profileSelect').val()
 			,'searchSelect':$('#searchSelect').val()
 			,'blogSelect':$('#blogSelect').val()
 			,'photoSelect':$('#photoSelect').val() 
 			,'vedioSelect':$('#vedioSelect').val()};
 			
 	sendRequest(data, '/settings.php/update/updatePrivacy', '$("#privacyMessage").text(data.message).fadeIn();','json');
 }
 function submitPhoto(){
 	sendRequest({'userID':myID , 'uploadedFile':$('#uploadedFile').val() }, '/settings.php/upload/uploadUserPhoto', '','json'); 	
 }
 function handelFriendRequest(){
 	sendRequest({'userID':myID , 'uploadedFile':$('#uploadedFile').val() }, '/settings.php/upload/uploadUserPhoto', '','json');
 	$('.inner_notification').empty();
 	$('#not_win').slideToggle();
 }
 function viewNotifications(uid){
	//$('#notfMainDiv').css("display", "block");
	$.getJSON( URL + '/notification.php/view/viewPoints','userID='+uid,function(data)
	{		
		notifRow=''; 
		if(data.friends=='' || data.friends==null){
			notifRow=''; 
		}else{
			notifRow='<div class=inner_notification>'+data.friends+'</div>'; 	
		}
		if(data.message==null){
			data.message=0;
		}
		else
		{
			$('.not_content').html('<div class=inner_notification>You have "'+data.message+'" points</div>'+notifRow)
		}
			
	});
	$.getJSON( URL + '/feeds.php/view/notifFeeds','userID='+uid+'&theCont=0&feeds_rel=1',function(data)
	{	
		var finalText='';
		if(data.friends!=null){
			for(h=0; h<data.friends.length ;h++){
			finalText+='<div class="inner_notification">'+data.friends[h]['user']+' '+data.friends[h]['friend']+'</div>';
			}
			$('.not_content').append(finalText);
		}
			
	});
}

function getFriendProfile(friendId)
{
	if(friendId==myID)
	{
		showWindow(1);
		return;
	}
	if($('#win3'+friendId).attr('id') )
	{
		if(!($('#win3'+friendId).css("display")=="block")){			
			$('#win3'+friendId).css("display", "block");
		}
		else
			raiseMyIndex('win3'+friendId);
	}
	else
	{
		html='<div class="friendProfileWin" id="win3'+friendId+'" onmousedown="raiseMyIndex(this.id)" onmouseup="removeDraggable(this.id)">'
		+'<div>'
			+'<div class="top_center" onmousedown="makeDraggable(\'win3'+friendId+'\')" onmouseup="removeDraggable(\'win3'+friendId+'\')">'
				+'<div class="winTitle">Friend Profile</div>'
				+'<div class="win_controls" onclick="hideWindow(\'3'+friendId+'\')">'
					+'<img src="'+CDN_IMG+'/new/close.png" alt="Close window" title="Close" /></div>'
				
			+'</div>'
			+'<div class="top_left">'
			+'</div>'
			+'<div class="top_right">'
			+'</div>'
		+'</div>'
		+'<div id="winContent3'+friendId+'" class="win_content">'
		
		+'</div>'
		+'<div class="footer">'
			+'<div class="bottom_left">'
			+'</div>'
			+'<div class="bottom_center">'
			+'</div>'
			+'<div class="bottom_right">'
			+'</div>'
		+'</div>'
		+'</div>';		
		$('#containment-wrapper').append(html);
		getProfile('feeds',friendId);
	}	
	raiseMyIndex('win3'+friendId);
}
function loadGames()
{
	html='';
	$.getJSON(URL+"/games.php/list/listGames",'',function(data) {
		if(data.message!=null)
		{
			html+='<div class="games_browse">';		
			for(i=0;i<data.message.length;i++)
			{
				html+='<div class="games_browse_left_col"><img onclick=\'loadGame("'+ data.message[i]['game_object']+'","'+data.message[i]['game_enabled']+'")\' src="'+CDN_IMG+'/games/'+data.message[i]['game_image']+'" alt="" /></div>';
			}
			
			html+='</div>'
				+'<div id="playGame" class="games_show" style="color:#999999;font-weight:bold;font-size:32px;text-align:center"><span style="color:#ffffff;">&nbsp;<br/>&nbsp;<br/>&nbsp;<br/>&nbsp;<br/></span>Choose your preferred game from the left menu</div>';
				$('#winContent8').html(html);
		}
		
	});
}
function loadGame(gameObject,gOption)
{	
if(gOption==1){
	$('#playGame').html(gameObject);
}else{
	window.open(gameObject, 'GameWindow', 'width=610,height=440,scrollbars=yes');
}
	//window.open('http://www.miniclip.com/games/monster-trucks-nitro/en/webgame.php', '123', 'width=600,height=4,scrollbars=yes');

}
function getPhotos(type,friendId)
{
	if(friendId==null)friendId=0;
	first=true;
	if(type==null){
		type='listAlbums';
		generalAlbumId='';
	}
	//alert(generalAlbumId);
	html='<div class="photos_tab_nav">'	
		+'<div '
		if (type=='listAlbums')
			html+=' class="photos_tab_selected"'
		else
			html+='class="photos_tab_disabled"'
				
		html+=' onclick="getPhotos(\'listAlbums\','+friendId+');">Albums</div>'
	
			if(generalAlbumId!='')
			{
				html+='<div '
				if (type=='listphotos')
					html+='class="photos_tab_selected"'
				else
					html+='class="photos_tab_disabled"'
						
				html+=' onclick="getPhotos(\'listphotos\','+friendId+');">Photos</div>'
			}	
		html+='</div>'
		+'<div class="photos_tab_content" id="photosAlbumContaintsDiv"></div>';
	$('#winContent3').html(html);
	if (friendId==0)
		$('#winTitle_3').text('My Photo Albums')
	else
		$('#winTitle_3').text("Friend's Photos")		
		
	if (type=='listAlbums')
		listPhotoAlbums(friendId);	
	else if (type=='listphotos')
		listAlbumPhotos(friendId);
}
function getRegisterationForm()
{
	html='<div id="toHideLater"><div><form class="register_form" action="javascript:void(null)" method="post">'
	+'<fieldset class="register_fieldset"><legend class="register_legend">Login information</legend>'
	
	+'<div class="register_row"><label for="userName">Full Name:</label></div>'
	+'<div class="register_row" ><input  class="register_input" type="text" name="userName" id="userName" onblur="user_name_validation(this.id)" /></div>'
	+'<div id="userName_error_text" class="discreption">At least 4 charcters</div>'
	
	+'<div class="register_row"><label for="userEmail">E-mail :</label></div>'
	+'<div class="register_row" ><input class="register_input" type="text" name="userEmail" id="userEmail" onblur="email_validation(this.id)"/></div>'
	+'<div class="discreption" id="userEmail_error_text">Unique e-mail </div>'
	
							
	+'<div class="register_row"><label for="RegUserPassword">Password:</label></div>'
	+'<div class="register_row"><input class="register_input" type="password" name="RegUserPassword" id="RegUserPassword" onblur="password_validation(this.id)"/></div>'
	+'<div id="RegUserPassword_error_text" class="discreption">At least 6 charcters </div>'

	+'<div class="register_row"><label for="userConfirmPassword">Retype Password:</label></div>'
	+'<div class="register_row"><input class="register_input" type="password" name="userConfirmPassword" id="userConfirmPassword" onblur="re_password_validation(this.id,\'RegUserPassword\')" /></div>'
	+'<div  id="userConfirmPassword_error_text" class="discreption">Retype the same password</div>'						


	+'<div class="register_row"><label for="userSecurityQuestion" >Security Question:</label></div>'				
	+'<div class="register_row"><select class="register_select" name="userSecurityQuestion" id="userSecurityQuestion">'
		+'<option value="1">What\'s your favorite book?</option>'
		+'<option value="2">Who is your favorite Hero?</option>'
		+'<option value="3">What\'s your favorite Movie or Car?</option>'
	+'</select></div>'
	+'<div class="register_row"></div>'
	
	+'<div class="register_row"><label for="userSecurityAnswer">Security Answer:</label></div>'
	+'<div class="register_row"><input  class="register_input" type="text" name="userSecurityAnswer" id="userSecurityAnswer" /> </div>'
	+'<div class="register_row"></div>'
	
	+'<div class="register_row"><input class="register_input" type="button" onclick="registerNewUser()"" value="Register" style="width:68px;height:26px" id="register_btn"/></div>'
	+'</form>'
	+'</fieldset></div>';
	$('#winContent0').html(html);
}
function inviteFriends(provider)
{
	html=''
		html='<div id="'+provider+'Inviter">'
		+'<center id="'+provider+'Inviter_center"><br/><br/><br/>'
		+'<div id="'+provider+'Inviter_center_div">'
			+'<div style="float:left;margin-left:25%;_margin-left:0%">'
				+'<a href="javascript:void(null)" title="" onclick="controlFullScreen(\''+provider+'Inviter\',\'hide\');"><img style="float:right" src="'+CDN_IMG+'/new/close.png" alt="" /></a><br/>'
			
			+'<iframe style="margin-right:25px;" border="0" scroll="no" src="'+URL+'/inviter.php/inviter/index?provider_box='+provider+'"></iframe>'
			+'</div>'
		+'</div>'
		+'</center>'
		+'</div>';	
	//if($('#containment-wrapper').append(html))
		controlFullScreenHTML(html,'show');
}

function getFriends()
{
	html='<div class="user_left_col">'
	+'<div class="user_photo_friends"><img  id="theUserPhoto" src="" width="50px" height="50px" alt="" /></div>'
	+'<div class="friends_vertical_menu">'
		+'<ul>'
			+'<li><a class="selected" id="friendsFeedLink" href="javascript:void(null)" title="" onclick="friendsFeedsClick()">Friends Feeds</a></li>'
			+'<li><a id="myFriendsLink" href="javascript:void(null)" title="" onclick="myFriendClick()" >My Friends</a></li>'
			+'<li><a id="inviteFriendsLink" href="javascript:void(null)" title="" onclick="inviteFriendsClick()">Invite Friends</a></li>'
			+'<li><a id="inviterLink" href="javascript:void(null)" title="" onclick="inviterClick()">Inviter</a></li>'
		+'</ul>'
	+'</div>'
	+'</div>'
	+'<span class="user_name" id="selectedTitle">Friends Feed</span>'
	+'<div class="friends_search">'
	+'<input class="friends_input_text" onkeypress="if(onPressEnter(event))searchFriendClick();" onfocus="if(this.value==\'Find friends on KFC Club\')this.value=\'\';" onblur="if(this.value==\'\')this.value=\'Find friends on KFC Club\';" value="Find friends on KFC Club" type="text" id="friendSearch" name="friendSearch" />'	
	+'<div>'	
	+'<a class="friends_submit" href="javascript:void(null)" >'
	+'<img alt="search" src="'+CDN_IMG+'/new/search_friends.gif" name="search_but" onclick="searchFriendClick();" /></a></div>'
	+'</div>'
	+'<div id="friendsFeeds" class="friends_right_col"></div>'
	+'<div id="myFriends" class="friends_right_col_disable"></div>'
	+'<div id="searchFriends" class="friends_right_col_disable" ></div>'
	+'<div id="inviteFriends" class="friends_right_col_disable">'
	+'<div class="friends_networks">'
	+'	<div id="yahooLogo" class="network" onclick="inviteFriends(\'yahoo\')"></div>'
	+'	<div id="yahooWin" class="friends_right_col_disable"></div>'
	+'	<div id="hotmailLogo" class="network" onclick="inviteFriends(\'hotmail\')"></div>'
	+'	<div id="hotmailWin" class="friends_right_col_disable"></div>'
	+'	<div id="facebookLogo" class="network" onclick="inviteFriends(\'facebook\')"></div>'
	+'	<div id="facebookWin" class="friends_right_col_disable"></div>'
	+'	<div id="gmailLogo" class="network" onclick="inviteFriends(\'gmail\')"></div>'
	+'	<div id="gmailWin" class="friends_right_col_disable"></div>'
	+'</div>'
	+'</div>'
	+'<div id="inviterFriends" class="friends_right_col_disable">'
	+'<div class="friends_networks">'
	+'	<div class="friendWallTextMsg" style="font-size:13px;">Send an invitation e-mail to all your friends , just put their e-mails separated by (;) and click Send</div>'
	+'	<div style="float:left;width:100%;height:170px;position:relative"><textarea id="friendsTextarea" class="wallTextArea" style="height: 120px;width:400px;"></textarea>'
	+'<div class="wallpost_friends_btn" style="margin-left:-20px;margin-top:-20px;" onclick="validateTextarea()">Send</div><br/><br/><br/><div style="display:none" class="friendWallTextMsg" id="emailSentResponce"></div>'
	+'</div></div>'
	+'</div>';
	if($('#winContent2').html(html))	
	{
		loadWithAjax.loadContent(0);
	}	
}
function searchFriendClick()
{
	if((document.getElementById('friendSearch').value!='Find friends on KFC Club')&& (document.getElementById('friendSearch').value!='') && (document.getElementById('friendSearch').value!=' '))
	{
		$('#searchFriends').html('');
		counterSearch=0;
		searchFriend({ 'userID' :myID ,'friendSearch':$('#friendSearch').val(),'counterSearch':counterSearch},'/friends.php/searchFriends/searchFriends/','','json');
		$('#selectedTitle').html('Search Friends');
		document.getElementById('myFriendsLink').className='';
		document.getElementById('inviterLink').className=''
		document.getElementById('friendsFeedLink').className='';
		document.getElementById('inviteFriendsLink').className='';
		document.getElementById('searchFriends').className='friends_right_col';
		document.getElementById('myFriends').className='friends_right_col_disable';
		document.getElementById('friendsFeeds').className='friends_right_col_disable';
		document.getElementById('inviteFriends').className='friends_right_col_disable'
		document.getElementById('inviterFriends').className='friends_right_col_disable'
	}	
}
function inviteFriendsClick()
{	
	document.getElementById('inviteFriendsLink').className='selected'
	document.getElementById('myFriendsLink').className=''
	document.getElementById('friendsFeedLink').className=''
	document.getElementById('inviterLink').className=''
		
	document.getElementById('myFriends').className='friends_right_col_disable'
	document.getElementById('searchFriends').className='friends_right_col_disable'
	document.getElementById('friendsFeeds').className='friends_right_col_disable'
	document.getElementById('inviterFriends').className='friends_right_col_disable'
	document.getElementById('inviteFriends').className='friends_right_col'
	document.getElementById('selectedTitle').innerHTML='Invite Friends'
}
function inviterClick()
{	
	document.getElementById('inviterLink').className='selected'
	document.getElementById('myFriendsLink').className=''
	document.getElementById('friendsFeedLink').className=''
	document.getElementById('inviteFriendsLink').className=''
		
	document.getElementById('myFriends').className='friends_right_col_disable'
	document.getElementById('searchFriends').className='friends_right_col_disable'
	document.getElementById('friendsFeeds').className='friends_right_col_disable'
	document.getElementById('inviteFriends').className='friends_right_col_disable'
	document.getElementById('inviterFriends').className='friends_right_col'
	document.getElementById('selectedTitle').innerHTML='Inviter'
}

function myFriendClick()
{	
	document.getElementById('myFriendsLink').className='selected'
	document.getElementById('inviteFriendsLink').className=''
	document.getElementById('friendsFeedLink').className=''
	document.getElementById('inviterLink').className=''
		
	document.getElementById('myFriends').className='friends_right_col'
	document.getElementById('friendsFeeds').className='friends_right_col_disable'
	document.getElementById('searchFriends').className='friends_right_col_disable'
	document.getElementById('inviteFriends').className='friends_right_col_disable'
	document.getElementById('inviterFriends').className='friends_right_col_disable'
	document.getElementById('selectedTitle').innerHTML='My Friends';
	loadWithAjax.loadContent(2);
}
function friendsFeedsClick()
{
	document.getElementById('friendsFeedLink').className='selected'
	document.getElementById('myFriendsLink').className=''
	document.getElementById('inviteFriendsLink').className=''
	document.getElementById('inviterLink').className=''
	
	document.getElementById('myFriends').className='friends_right_col_disable'
	document.getElementById('friendsFeeds').className='friends_right_col'
	document.getElementById('searchFriends').className='friends_right_col_disable'
	document.getElementById('inviteFriends').className='friends_right_col_disable'
	document.getElementById('inviterFriends').className='friends_right_col_disable'
	document.getElementById('selectedTitle').innerHTML='Friends Feeds'
	loadWithAjax.loadContent(0);
}
function getLogin()
{
	html='<div id="logInMsg"><center id="logInMsg_win">'	
	+'<div id="logInMsg_body">'
	+'<div id="logInMsg_image">'
		+'<img class="png" src="'+CDN_IMG+'/logout_home.gif" alt="" /></div>'
		+'<div id="logInMsg_content">'
		+'<div id="LoginFormDiv">'
		+'<form style="display: block" id="loginForm" action="javascript:void(null)" method="post">'			
			+'<div class="login_elements_container">'			
				+'<div style="text-align:right; margin-right:60px;_margin-right:10px">'
					+'<a style="font-family:Trebuchet MS;color:#fff;text-decoration:none;font-weight:bold;*margin-right:50px;" href="javascript:void(null)" title="Close" onclick="controlFullScreen(\'logInMsg\',\'hide\');">x</a>'				+'</div>'
				+'<div class="login_input_title">'
				+'	<label for="loginUserEmail">E-mail :</label></div>'
				+'<div class="login_input_div">'
				+'	<input type="text" id="loginUserEmail" name="loginUserEmail" /></div>'
				+'	<div class="login_error_msg" id="loginUserEmail_error_text"></div>'
				+'</div>'
				+'<div class="login_elements_container">'
				+'	<div class="login_input_title">'
				+'		<label for="loginUserPassword">Password:</label></div>'
				+'	<div class="login_input_div">'
				+'		<input type="password" id="loginUserPassword" onkeypress="if(onPressEnter(event))doLogin()" /></div>'
				+'	<div class="login_error_msg" id="loginUserPassword_error_text"></div>'
				+'</div>'				
				+'<div class="login_elements_container" style="padding-right:0px;float:left"><input type="hidden" id="loginUserGroup" name="loginUserGroup" value="users">'
				+'	<div class="login_win_btn" style="margin-left:0px;*margin-left:-45px;width:65px;margin-right:100px;" id="userLogin" onclick="controlFullScreen(\'logInMsg\',\'hide\');showWindow(\'0\')">Register</div>'
				+'	<div class="login_win_btn" onclick="doLogin()" style="float:right;margin-right:5px;_margin-right:50px;margin-left:2px">Login</div>'

				+'	<div class="login_error_msg">'
				+'		<a href="javascript:void(null)" title="" onclick="show_hide(\'LoginFormDiv\',\'ForgotFormDiv\')">Forgot Your Password?</a></div>'
				+'	<div class="reg_error_text" id="login_error"></div>'
				+'	<div style="display:none;" id="login_ok">Logged in ok</div>'
			+'</div>'				
		+'</form>'
		+'	</div>'			
		+'	<div id="ForgotFormDiv" style="display:none;">'
		+'		<div class="login_elements_container">'
			
		+'		<div style="text-align:right; margin-right:60px;_margin-right:10px">'
		+'			<a style="font-family:Trebuchet MS;color:#fff;text-decoration:none;font-weight:bold;*margin-right:50px;" href="javascript:void(null)" title="" onclick="controlFullScreen(\'logInMsg\',\'hide\');">x</a>'
		+'		</div>'
		+'			<div class="login_input_title">'
		+'				<label for="forgotUserEmail">E-mail :</label></div>'
		+'			<div class="login_input_div">'
		+'				<input type="text" id="forgotUserEmail"/></div>'
		+'			<div class="login_error_msg" id="forgotUserEmail_error_text"></div>'
		+'		</div>'				
		+'		<div class="login_elements_container">'
		+'			<div class="login_win_btn" style="width:110px;float:right;margin-right:100px;_margin-right:20px;*margin-right:50px;margin-top:20px" onclick="Reset_password()">Reset Password</div>'										
		+'		</div>'
		+'	</div>'			
		+'	<div id="ChangeFormDiv" style="display:none;">'
		+'		<div class="login_elements_container">'
		+'			<div class="login_input_title">'
		+'				<label for="changeUserEmail">E-mail :</label></div>'
		+'			<div class="login_input_div">'
		+'				<input type="text" id="changeUserEmail"/></div>'
		+'			<div class="login_error_msg" id="changeUserEmail_error_text"></div>'
		+'		</div>'				
		+'		<div class="login_elements_container">'
		+'			<div class="login_input_title">'
		+'				<label for="changeUserPassword">Password:</label></div>'
		+'			<div class="login_input_div">'
		+'				<input type="password" id="changeUserPassword" /></div>'
		+'			<div class="login_error_msg" id="changeUserPassword_error_text"></div>'
		+'		</div>'
		+'		<div class="login_elements_container">'
		+'			<div class="login_input_title">'
		+'				<label for="changeUserConfirmPassword">Confirm Password:</label></div>'
		+'			<div class="login_input_div">'
		+'				<input type="password"  id="changeUserConfirmPassword" /></div>'
		+'			<div class="login_error_msg" id="changeUserConfirmPassword_error_text"></div>'
		+'		</div>'
		+'		<div class="login_elements_container">'
		+'			<div class="login_win_btn" style="width:110px;" onclick="changePassword()">Change Password</div>'					
		+'		</div>'
		+'	</div>'			
		+'</div>'
	+'</div>'
	+'</center></div>';
	if($('body').append(html))
	{
		controlFullScreen('logInMsg','show')		 
	}
}
function getMessages(tab)
{
	if(tab==null)tab='inbox';
	
	html='<div class="messages_tab_nav">'
		 	
			+'<div  class="'
		 	if(tab=='newMessage')	
		 		html+='message_tab_selected'
		 	else
		 		html+='message_tab_disabled'		 	
		 	html+='" onclick="getMessages(\'newMessage\')">New Message</div>'
		 	
		 	+'<div class="'
		 	if(tab=='inbox')	
		 		html+='message_tab_selected'
		 	else
		 		html+='message_tab_disabled'		 	
		 	html+='" onclick="getMessages(\'inbox\')">Inbox</div>'
		 		
		 	+'<div class="'
		 	if(tab=='outbox')	
		 		html+='message_tab_selected'
		 	else
		 		html+='message_tab_disabled'		 	
		 	html+='" onclick="getMessages(\'outbox\')">Outbox</div>'
		 		
		 	+'<div class="'
		 	if(tab=='deleteMessage')	
		 		html+='message_tab_selected'
		 	else
		 		html+='message_tab_disabled'		 	
		 	html+='" onclick="getMessages(\'deleteMessage\')">Deleted Messages</div>'		 		
		 		
	 	+' </div>'
	 	+' <div class="message_content" id="message_content_id">'
	 	
	
	html+='</div>'
	 	
	 	
	if($('#winContent7').html(html))
	{
		if(tab=='newMessage')
	 	{
			getNewMessage()
	 	}
		else if(tab=='inbox')
	 	{	
	 		listMessages(1);
	 	}
		else if(tab=='outbox')
	 	{	
	 		listMessages(2);
	 	}
		else if(tab=='deleteMessage')
	 	{	
	 		listMessages(3);
	 	}
		
	}
}
var textarr;
function add_userid_in_to(f_id)
{
	var ch=$('#user_ids').val()			
	
		if (ch=='*' || ch=='')
		{
			ch=f_id+",";
		}
		else
		{
			if(ch.indexOf(f_id)==-1)			
				ch=ch+f_id+",";
		}		
	$('#user_ids').val(ch);	
	
}
function delete_usernameFormTo_message(friendId) {
	$('#user_name_id_'+friendId).remove();
	$('#user_ids').val($('#user_ids').val().replace(','+friendId,''));	
}
function addUsernameInTo(f_id,f_name)
{	
	ids_id=$('#user_ids').val();	
	add_userid_in_to(f_id);	
	//display choosed user names in the texbox.	
	f_nameDiv="<div id='user_name_id_"+f_id+"' class='message_usernames' >"+f_name+"<img onclick='delete_usernameFormTo_message("+f_id+")' src='"+CDN_IMG+"/new/DeleteContact.png' style='vertical-align:middle;cursor:pointer;'/></div>";	
	$('#messageToInput').before(f_nameDiv);
	//if(textarr.length==0)else $('#messageToInput').before(textarr.toString()+','+f_name+',');					
	$('#messageToInput').val('');	
	//$('#friends_show_menu').slideUp();	
}
function openMessage(msgId,msgSubject,msgBody,msgDate,senderName,reciverName,type,next,read)
{
	html='<div class="message_open">'
		+'<div class="message_header">'
//		+'<div class="message_header_photo"><img class="message_header_photo_img" src="'+CDN_IMG+'/new/kochely.jpg" alt="Sender Name"/></div>'
		+'<span><strong>From: </strong>'
		if(type==1 || type==3){html+=senderName;}else{html+=reciverName;}
		html+='</span><br/>'
		+'<span><strong>To: </strong>'
		if(type==1 || type==3){html+=reciverName;}else{html+=senderName;}
		html+='</span><br/>'
		+'<span><strong>Subject: </strong>'+msgSubject+'</span><br/>'
		+'<span><strong>Date: </strong>'+msgDate+'</span><br/>'
		+'</div>'	
		+'<div class="messages_body">'	
		+'<pre>'
		+msgBody
		+'</pre>'		
		+'</div>'
		
		+'<div class="message_actions">'		
			+'<div class="message_btn" onclick="deleteMessage('+msgId+','+type+')">Delete</div>'
			+'<div class="message_btn" onclick="getReplayMessage(\''+senderName+'\',\''+msgSubject+'\',\''+msgBody+'\')">Reply</div>'
		
			if(next==2 ||next==3 )
				html+='<div class="message_btn_disable" style="float:right">Next</div>'
			else
				html+='<div class="message_btn" style="float:right" onclick="getNextMessage('+msgId+','+type+',\'next\')">Next</div>'
					
			if(next==1 ||next==3 )
				html+='<div class="message_btn_disable" style="float:right">Prev.</div>'
			else
				html+='<div class="message_btn" style="float:right" onclick="getNextMessage('+msgId+','+type+',\'prev\')">Prev.</div>'
				
		html+='</div>'
	
		+'</div>'
	if($('#message_content_id').html(html))
	{
		if(read=='0')
		{
			$.post(URL+'/messages.php/list/readMessage','msgId='+msgId+'&type='+type,function(data) {
				viewNotifications(myID)
			},'json');
		}		
	}
	
}

function getNextMessage(msgId,type,next)
{
	$.post(URL+'/messages.php/list/getNextMessage','msgId='+msgId+'&next='+next+'&type='+type,function(data) {
		if(data.message!=null)
		{
			if(type==1 || type==3){
				senderName=data.message['senderName'];
				reciverName=data.message['reciverName'];
			}else{
				reciverName=data.message['senderName'];
				senderName=data.message['reciverName'];
			}
			ifNext=0;
			if(data.errors=="false" && next=='next')
				ifNext=2;
			else if(data.errors=="false" && next=='prev')
				ifNext=1;			
			openMessage(data.message['message_id'],data.message['message_subject'],data.message['message_body'],data.message['message_date'],senderName,reciverName,type,ifNext,data.message['message_read']);
		}		
	},'json');
}
function getFriendsList(searchText)
{	
	textarr=searchText.split(",");
	text1=textarr.pop();
	//if(text1!='')
	//{
		params="searchText="+text1;
		html='';
		$.post(URL+'/friends.php/list/listSearchFriends',params,function(data) {
			if(data.message!=null ||data.message!='')
			{
				for(i=0;i<data.message.length;i++)
				{
					//alert(data.message[i]['user_id'])
					html+="<div id='"+data.message[i]['user_id']+"' class='messageFriendUsername' onclick=\"addUsernameInTo("+data.message[i]['user_id']+",'"+data.message[i]['user_name']+"')\">"+data.message[i]['user_name']+"</div>";
				}
				divHeight=22*data.message.length;
				if (divHeight>110)divHeight='110'
				$('#friends_show_menu').css('height',divHeight+'px');
			}
			else
			{
				html="No match";
			}
			$('#friends_show_menu').html(html);
			
			$('#friends_show_menu').slideDown();
		},'json');
	//}
}
function getFriendsListReply(searchText)
{	
	textarr=searchText.split(",");
	text1=textarr.pop();
	//if(text1!='')
	//{
		params="searchText="+text1;
		html='';
		$.post(URL+'/friends.php/list/listSearchFriends',params,function(data) {
			if(data.message!=null ||data.message!='')
			{
				for(i=0;i<data.message.length;i++)
				{
					addUsernameInTo(data.message[i]['user_id'],data.message[i]['user_name']);
					html+="<div id='"+data.message[i]['user_id']+"' class='messageFriendUsername' onclick=\"addUsernameInTo("+data.message[i]['user_id']+",'"+data.message[i]['user_name']+"')\">"+data.message[i]['user_name']+"</div>";
				}
				divHeight=22*data.message.length;
				if (divHeight>110)divHeight='110'
				$('#friends_show_menu').css('height',divHeight+'px');
			}
			else
			{
				html="No match";
			}
			$('#friends_show_menu').html(html);
			
			//$('#friends_show_menu').slideDown();
		},'json');
	//}
}
function getNewMessage()
{	
	 
	html='<div class="message_elements_container"> '
		+' <div class="message_input_title"><label for="messageTo" >Send To</label></div>'
		+"<input type='hidden' name='user_ids' id='user_ids' value=''/>"
		
		//To.
		+"<div class='message_input_field'>"
		//+"<input autocomplete='off' type='text' id='messageTo' style='width:400px;'  value='' onkeyup=\"getFriendsList($(this).val())\" />"
		+"<div class='divLikeInput'id='messageTo' onclick=\"$('#messageToInput').focus()\"><input id='messageToInput' type='text' value=''  onkeyup=\"getFriendsList($(this).val())\"/></div>"

		//menu to show and hide
		+"<div style='position:relative;'><div style='position:absolute;left:0px;top:0px;'>"
		+"<div id='friends_show_menu' class='toTextboxSlideDiv'>Type in the Textbox.</div>"
		+"<div><img id='friends_show_img' src='"+CDN_IMG+"/new/wlip_closed.png' style='width:400px;' onclick=\"$('#friends_show_menu').slideToggle()\"/></div>"
		+"</div>"//END of menu.
		+"</div></div>"//END of "To" textbox.
			
		//	+'<div class="message_input_field"><input type="text" id="messageTo" /></div>'
			+'</div>'
			
			+'<div class="message_elements-container">'
			+'<div class="message_input_title"><label for="messageSubject">Subject</label></div>'
			+'<div class="message_input_field"><input type="text" id="messageSubject" /></div>'
			+'</div>'
	 
			+'<div class="message_elements-container">'
			+'<div class="message_input_title"><label for="messageBody">Message</label></div>'
			+'<div class="message_input_field" style="height:200px;"><textarea id="messageBody""></textarea></div>'
			+'</div>'
	 
			+'<div class="message_elements-container">'
			+'<div class="message_input_field">'
			+'<input type="button" id="message_btn" onclick="sendMessage()" value="Send Message" />'
			+'</div>'
			+'<div id="message_error_message"></div>'
			+'</div>'	
	$('#message_content_id').html(html);
	getFriendsList('');
}
function getReplayMessage(theTo,theSubject,theBody)
{	
	 
	html='<div class="message_elements_container"> '
		+' <div class="message_input_title"><label for="messageTo" >Send To</label></div>'
		+"<input type='hidden' name='user_ids' id='user_ids' value=''/>"
		
		//To.
		+"<div class='message_input_field'>"
		//+"<input autocomplete='off' type='text' id='messageTo' style='width:400px;'  value='' onkeyup=\"getFriendsList($(this).val())\" />"
		+"<div class='divLikeInput'id='messageTo' onclick=\"$('#messageToInput').focus()\"><input id='messageToInput' type='text' value=''  onkeyup=\"getFriendsList($(this).val())\"/></div>"

		//menu to show and hide
		+"<div style='position:relative;'><div style='position:absolute;left:0px;top:0px;'>"
		+"<div id='friends_show_menu' class='toTextboxSlideDiv'>Type in the Textbox.</div>"
		+"<div><img id='friends_show_img' src='"+CDN_IMG+"/new/wlip_closed.png' style='width:400px;' onclick=\"$('#friends_show_menu').slideToggle()\"/></div>"
		+"</div>"//END of menu.
		+"</div></div>"//END of "To" textbox.
			
		//	+'<div class="message_input_field"><input type="text" id="messageTo" /></div>'
			+'</div>'
			
			+'<div class="message_elements-container">'
			+'<div class="message_input_title"><label for="messageSubject">Subject</label></div>'
			+'<div class="message_input_field"><input type="text" id="messageSubject" value="'+theSubject+'"/></div>'
			+'</div>'
	 
			+'<div class="message_elements-container">'
			+'<div class="message_input_title"><label for="messageBody">Message</label></div>'
			+'<div class="message_input_field" style="height:200px;"><textarea id="messageBody"">\n\r\n\r'+theBody+'</textarea></div>'
			+'</div>'
	 
			+'<div class="message_elements-container">'
			+'<div class="message_input_field">'
			+'<input type="button" id="message_btn" onclick="sendMessage()" value="Send Message" />'
			+'</div>'
			+'<div id="message_error_message"></div>'
			+'</div>'	
	$('#message_content_id').html(html);
	//addUsernameInTo(data.message[i]['user_id'],data.message[i]['user_name'])
	getFriendsListReply(theTo);
}

function sendMessage()
{
	//alert($('#user_ids').val())
	if($('#user_ids').val()=='')
	{
		$('#message_error_message').html("Please enter a valid friend name in To field.");	
	}
	else
	{
		params={"subject": $('#messageSubject').val(),"body": $('#messageBody').val(),"to": $('#user_ids').val()}
		$.post(URL+'/messages.php/new/new',params,function(data) {
			getMessages('inbox');
		},'json');
	}
}

function listMessages(type,count,more)
{
	if(count==null)
		count=0;
	if(more==null)more=0;
	$.post(URL+'/messages.php/list/index','type='+type+'&count='+count,function(data) {
		html='';
		if(data.message!=null)
		{
			if(more!=1)
			{
				html+="<input type='hidden' id='checked_boxes' value='*'/>"					
				html+='<div class="message_table_container">'									 	
				html+="<input id='message_btn2' type='button' value='Delete Selected' onclick=\"deleteMessages($('#checked_boxes').val(),"+type+");\" />"				 							
				html+='<div class="message_table">'
				+'<div class="message_table_td_1 message_header_from"><input type="checkbox" id="check_select_all" onclick="checkbox_select_all(\'check_select_all\');"/></div>'
				+'<div class="message_table_td_2 message_header_from">';
				if(type==2){
					html+='To';
				}else{
					html+='From';
				}				
				html+='</div>'
				+'<div class="message_table_td_3 message_header_from">Subject</div>'
				+'<div class="message_table_td_4 message_header_from">Date</div>'
				+'</div>'
				+'<div class="message_table2">'
				+'<div id="message_table_id" class="message_table">'				
			}
			for(i=0;i<data.message.length;i++)
			{				
				ifNext=0;
				if (i==0)
					ifNext=1;
				else if (i==data.message.length-1)
					ifNext=2;
				if (data.message.length==1)
					ifNext=3;							
				msgBodyarr=data.message[i]['message_body'].split('\n')				
				msgBody=msgBodyarr.join('<br>');
				if(data.message[i]['message_read']=='0')
					bgcolor='#DDF8FE'
				else
					bgcolor='#fff'
				html+=' <div class="message_new">'
						+'<div class="message_table_td_1" style="background-color:'+bgcolor+'">'
							+'<input type="checkbox" class="checkbox_messages" id="'+data.message[i]['message_id']+'" onclick=" checked_boxes(\'checked_boxes\',\''+data.message[i]['message_id']+'\')"/>'
						+'</div>'
						+'<div class="message_table_td_2" style="background-color:'+bgcolor+'" ';
						
			if(type==2){
			html+=' onclick="getFriendProfile('+ data.message[i]['message_reciver_id']+')">'+data.message[i]['senderName'];
			}else{
			html+=' onclick="getFriendProfile('+ data.message[i]['message_user_id']+')">'+data.message[i]['senderName'];
			}
						
						html+='</div>'
						+'<div class="message_table_td_3" style="background-color:'+bgcolor+'" onclick="openMessage('+data.message[i]['message_id']+',\''+data.message[i]['message_subject']+'\',\''+msgBody+'\',\''+data.message[i]['date']+'\',\''+data.message[i]['senderName']+'\',\''+data.message[i]['reciverName']+'\','+type+','+ifNext+',\''+data.message[i]['message_read']+'\')">'
						+data.message[i]['message_subject']+'</div>'
						+'<div class="message_table_td_4"style="background-color:'+bgcolor+'">'+data.message[i]['date']+'</div>'
					+'</div>'	
					count++;
			}
			if(more!=1)
			{
				html+='</div>'
				 +'</div>'			 
				+'</div>'
			}			
		}
		showMoreHTML='<div id="showMoreMessageId" class="show_more_messages" onclick="listMessages('+type+','+count+',1);$(this).remove();" >Show More</div>'
		if(more==1)		
		{
			if($('#message_table_id').append(html))
			{
				if (data.errors) 
					$('#message_btn2').before(showMoreHTML);		
			}
		}
		else
		{
			if($('#message_content_id').html(html))
			{
				if (data.errors) 
					$('#message_btn2').before(showMoreHTML);
			}
		}				
	},'json');
}
function deleteMessages(ms_ids,type)
{		
	if (ms_ids!='' && ms_ids!='*')
	{
		ms_ids=ms_ids.substring(0,ms_ids.length-1);	// to remove the last ","	
		$.post(URL+'/messages.php/delete/index','type='+type+'&messageIds='+ms_ids,function(data) {
			if(type==1)
				typetext='inbox';
			else if(type==2)
				typetext='outbox';
			else if(type==3)
				typetext='deleteMessage';			
			getMessages(typetext);
		},'json');
	}	
}
function deleteMessage(msgId,type)
{
	$.post(URL+'/messages.php/delete/index','type='+type+'&messageIds='+msgId,function(data) {
		if(type==1)
			typetext='inbox';
		else if(type==2)
			typetext='outbox';
		else if(type==3)
			typetext='deleteMessage';		
		getMessages(typetext);
	},'json');
}
function checkbox_select_all(ch_id)
{	
	var inputarr=document.getElementsByTagName("input");
	if($('#'+ch_id).attr('checked'))
	{
		for(i=0;i<inputarr.length;i++)
		{
			if (inputarr[i].className=="checkbox_messages")
			{
				inputarr[i].checked=true;				
				checked_boxes('checked_boxes',inputarr[i].id);					
			}
		 }			
	}
	else
	{
		for(i=0;i<inputarr.length;i++)
		{
			if (inputarr[i].className=="checkbox_messages")
			{
				inputarr[i].checked=false;				
				checked_boxes('checked_boxes',inputarr[i].id);					
			}
		 }		
	}
}
function checked_boxes(input_name,check_id)
{	
	var ch=$('#'+input_name).val();			
	if ($('#'+check_id).attr('checked'))
	{
		if (ch=='*')
		{
			ch=check_id+",";
		}
		else
		{
			ch=ch+check_id+",";
		}		
	}
	else
	{		
		if(ch.indexOf(check_id)!=-1)
			ch=ch.replace(check_id+",","");		
	}	
	$('#'+input_name).val(ch);			
}
function openAlbum(albumId,friendId)
{
	$.post(URL+'/photos.php/albums/openAlbum','albumId='+albumId,function(data){
		generalAlbumId=albumId;
		getPhotos('listphotos',friendId);		
	},'json');
}
function showLeftMenu(menuId,id)
{
	if($('#'+menuId+id).css('width')=='0px')
	{
		if (id==1){
			$('#'+menuId+'2').animate({ width:"0px" },2,'swing',function (){$('#'+menuId+'2').css('visibility','hidden')})
			$('#img_'+menuId+'2').attr('src',CDN_IMG+'/new/edit_album.gif');
			$('#img_'+menuId+id).attr('src',CDN_IMG+'/new/creat_album_selected.gif');
		}
		else if (id==2){
			$('#'+menuId+'1').animate({ width:"0px" },2 ,'swing',function (){$('#'+menuId+'1').css('visibility','hidden')})
			$('#img_'+menuId+'1').attr('src',CDN_IMG+'/new/creat_album.gif');
			$('#img_'+menuId+id).attr('src',CDN_IMG+'/new/edit_album_selected.gif');
		}
		else if(id==3)
		{
			$('#img_'+menuId+id).attr('src',CDN_IMG+'/new/add_photo_selected.gif');
		}		
		$('#'+menuId+id).css('visibility','visible');
		$('#'+menuId+id).animate({ width:"505px"},500 ,'swing')				
	}
	else if($('#'+menuId+id).css('width')=='505px')
	{
		if(id==1)
		{
			$('#img_'+menuId+id).attr('src',CDN_IMG+'/new/creat_album.gif');
		}
		else if(id==2)
		{
			$('#img_'+menuId+id).attr('src',CDN_IMG+'/new/edit_album.gif');
		}
		else if(id==3)
		{
			$('#img_'+menuId+id).attr('src',CDN_IMG+'/new/add_photo.gif');			
		}		
		$('#'+menuId+id).animate({ width:"0px"},500 ,'swing',function (){
			$('#'+menuId+id).css('visibility','hidden')
			if (id==2)
			{
				$('#photos_vertical_left_menu2').hide();
			}			
		})		
	}	
}
function showBigPhoto(divId,imgSrc,photoFile,photoId,next,friendId) {
	if(next==null)
		next=0;
		
	html='<div style="padding-left:30px"><div class="big_photo_tumb">'
		+'<img src="'+imgSrc+'" />' 	
	+'</div></div>'
	
	+'<div class="photos_task_bar">'
	html+='<a href="javascript:void(null)" onclick="change_background(\''+imgSrc.replace('/thumb1','')+'\');">Set as background</a>'
	if(friendId==0)
	{
		html+='<a href="javascript:void(null)" onclick="SetAlbumCover(\''+photoFile+'\')">Set as album cover</a>'
		html+='<a href="javascript:void(null)" onclick="deleteConfirmation(\''+photoId+'\',\'photo\')" style="margin:0px 40px 0px 60px;">Delete</a>'
	}
		
		if(next==2 ||next==3)
			html+='<a href="javascript:void(null)"  style="color:#ccc;">Prev</a>';
		else
			html+='<a href="javascript:void(null)" onclick="getNextPhoto('+photoId+',\'next\','+friendId+')">Prev</a>';
		
		if(next==1 ||next==3 )
			html+='<a href="javascript:void(null)"  style="color:#ccc;">Next</a>';
		else
			html+='<a href="javascript:void(null)" onclick="getNextPhoto('+photoId+',\'prev\','+friendId+')\">Next</a>';
		
	html+='</div>';
	$('#'+divId).html(html);	
}
function getNextPhoto(photoId,next,friendId)
{
	$.post(URL+'/photos.php/photos/getNextPhoto','photoId='+photoId+'&next='+next,function(data) {
		if(data.message!=null)
		{
			ifNext=0;
			if(data.errors=="false" && next=='next')
				ifNext=2;
			else if(data.errors=="false" && next=='prev')
				ifNext=1;
			showBigPhoto('photosAlbumContaintsDiv',CDN_PHOTOS+"/"+data.message['album_id']+"/thumb1/"+data.message['photo_file'],data.message['photo_file'],data.message['photo_id'],ifNext,friendId);
		}		
	},'json');
}
function SetAlbumCover(photoFile)
{
	$.post(URL+'/photos.php/photos/setAlbumCover','photoFile='+photoFile,function(data){},'json');
}
function getFriendPhotos(friendId)
{
	showWindow(3);
	getPhotos('listAlbums',friendId)
}
function draw_menu(){}
function drawBannerItems(){
	$.getJSON( URL + '/cpanel.php/banner/bannerHomeList',function(data)
		{			
			catlist='';
			if(data.message!=null){
			for(i=0;i<data.message.length;i++){
				catlist+='<li class="slider1Image"><a  href="'+data.message[i]['banner_name']+'" target="_blank" ><img src="'+CDN_BANNER+'/'+data.message[i]['banner_img']+'"/></a><span style="background-color:transparent"></span></li>';
			}
			catlist+='<div class="clear slider1Image"></div>';
			$('#general_banner').attr('class','');
			if(data.friends==1){
				$('#general_banner').addClass('banner');
			}else if(data.friends==2){
				$('#general_banner').addClass('banner_top');
			}else if(data.friends==3){
				$('#general_banner').addClass('banner_left');
			}
			
			$('#slider1Content').html(catlist);
		
		$('#slider1').s3Slider({
            timeOut: 4000 
        });
			}
		});
	
}
function onPressEnter(e)
{
	var keynum;
	var keychar;
	var numcheck;
	
	if(window.event) // IE
	  {
	  keynum = e.keyCode;
	  }
	else if(e.which) // Netscape/Firefox/Opera
	  {
	  keynum = e.which;
	  }
	  if (keynum==13)
	  {
		return true;
	  }
	  return false;
}
function doAccountDiv(){
	document.getElementById('accountDiv').className='settings_tab_selected';
	document.getElementById('passwordDiv').className='settings_tab_disabled';
	$('#passwordSettings').hide();
	document.getElementById('prefDiv').className='settings_tab_disabled';
	$('#accountSettings').show();
	$('#prefSettings').hide();	
	
}
function doPasswordDiv(){
	document.getElementById('passwordDiv').className='settings_tab_selected';
	document.getElementById('prefDiv').className='settings_tab_disabled';
	document.getElementById('accountDiv').className='settings_tab_disabled';
	$('#accountSettings').hide(),$('#passwordSettings').show();
	$('#prefSettings').hide()
	
}

function doPrefDiv(){
	document.getElementById('prefDiv').className='settings_tab_selected';
	document.getElementById('passwordDiv').className='settings_tab_disabled';
	$('#passwordSettings').hide();
	document.getElementById('accountDiv').className='settings_tab_disabled';
	$('#accountSettings').hide();
	$('#prefSettings').show()
}
function dateSeparte(actualDate){
	var bDate=actualDate;
	mySplitDate=bDate.split('-');
	sYear=mySplitDate[0];
	sMonth=mySplitDate[1];
	sDay=mySplitDate[2];
	
	var html='<select id="syear" onchange="doNewDate()">';
	for(var s=1900;s<2010;s++){
		html+='<option ';
		if(s==sYear){html+=' selected="selected"';}
		html+='>'+s+'</option>';
	}
	html+=' </select>&nbsp;<select id="smonth" onchange="doNewDate()">';
	
	for(var s=1;s<13;s++){
		html+='<option ';
		if(s==sMonth){html+=' selected="selected"';}
		html+='>'+s+'</option>';
	}
	html+=' </select>&nbsp;<select id="sday" onchange="doNewDate()">';
	
	for(var s=1;s<32;s++){
		html+='<option ';
		if(s==sDay){html+=' selected="selected"';}
		html+='>'+s+'</option>';
	}
	
	return html;
	
}
function doNewDate(){
	var bDay=$('#syear').val()+'-'+$('#smonth').val()+'-'+$('#sday').val();
	$('#personaluser_birth_date').val(bDay);
	//alert($('#personaluser_birth_date').val());
	
}

function validateTextarea(){
	theValues=$('#friendsTextarea').val();
	textarr=theValues.split(";");
	arrLength=textarr.length;
	for(var mn=0;mn<arrLength;mn++){
		if ((textarr[mn].search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) == -1){
			alert('('+textarr[mn]+') is not a valid email address.');
			return false;
		}
	}
	
	$.post(URL+'/friends.php/searchFriends/inviter','userid='+myID+'&emailArr='+textarr,function(data){
		$('#emailSentResponce').css("display", "block");
		$('#emailSentResponce').text(data.friends);
		
		},'json');
}

function checkForVideo(vOption,videoId){
	
	if(myID==-1)
	{
		getLogin();
		return 0;
	}else{
		if(vOption==1){
			$('#uploadTab').removeClass('video_tab_selected').addClass('video_tab_disabled');ChangeCommentTab('addCommentTab',videoId)	
		}else if(vOption==2){
			ChangeCommentTab('uploadTab',videoId);$('#uploadTab').removeClass('video_tab_disabled').addClass('video_tab_selected')
		}
	}	
	
	
}