// JavaScript Document
//** Need above for browser detection
var ns4 = (document.layers);
var ns6 = (!document.all && document.getElementById);
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById && !window.opera);
var op6 = (window.opera && document.getElementById);
var safari = ((document.childNodes) && (!document.all) && (!navigator.taintEnabled) && (!navigator.accentColorName));
var orig_midHt;					//original mid section height, used when we resize
var topElem = "topBarGrey";		// top element
var midElem = "midTable";		// mid section
var footElem = "footerMenu";	// footer section
//** These are the itim Function **//
//var itimswf = "itim_0.1.2";
//var itimswf = "itim_2";
//var itimswf = "itim_3";
var itimswf = "itim_4";
var itimvidswf = "vid_player3";
//var cameraswf = "webcam3b";
var cameraswf = "webcam7b";

var server_name = "www.2waystar.com";

//var server_name = "38.98.53.52";

var baseUrl = "http://www.2waystar.com/itimworld/";

/**
var getNewMesUrl = baseUrl+"con_scripts/getNewMessage.php";		// url for checking for new messages
var get_camera_url = baseUrl+"get_camera_filename.php";

var getNewMesUrl = "http://"+server_name+"/itimworld/con_scripts/getNewMessage.php";		// url for checking for new messages
var get_camera_url = "http://"+server_name+"/itimworld/get_camera_filename.php";
**/

var getNewMesUrl = baseUrl+"con_scripts/getNewMessage.php";		// url for checking for new messages
var get_camera_url = baseUrl+"get_camera_filename.php";

var getNewMesUrl = "http://"+server_name+"/itimworld/con_scripts/getNewMessage.php";		// url for checking for new messages
var get_camera_url = "http://"+server_name+"/itimworld/get_camera_filename.php";

var camera_pic = "";
var camera_pic_wd;
var camera_pic_ht;
var camera_thumb_wd;
var camera_thumb_ht;

var lostConnection; 		//this is one when you lose connection

var next_pic_num;			// this is the number of thumbnails
var thumb_attr;

//alert settings
var alert_itim_newtop = 20;
var alert_itim_newleft = 600;
var alert_itim_topspacer = 40;
var alert_itim_leftspacer = 0;
//var top_spacer_limit = 220;



var itim_newtop = 90;
var itim_newleft = 190;
var itim_topspacer = 10;
var itim_leftspacer = 10;
var top_spacer_limit = 220;
var winOpened = 'none';
var pic_image_main = baseUrl+"tim_images/03-20-2008_13-07-12-soccer12.jpg";
var picwd_main = 273;
var picht_main = 268;
var itimnum_main;

/** ie adds the scroll bars to the width of the total screen */
var iescrollwd = 21;
var iescrollht = 0;

//alert('hey kid we are in '+cameraswf);


/**
if(safari){
	alert("this is safari browswer")
}else if(ns4){
	alert("this is safari browswer")
}else {
	alert("this is probably ie browswer")
}
*/


/**
* 
* IndexOf fix for IE browser
*
* Because we use indexof and IE does not support it, we must check first to see 
* it exist, if it does not, we will create a prototype function so it works	


if (!Array.indexOf) {
  Array.prototype.indexOf = function (obj, start) {
    for (var i = (start || 0); i < this.length; i++) {
      var newobj = this[i];
	  if (newobj == obj) {
        return i;
      }
    }
  }
}
*/


// preloads images and flash
function preloadflash(flashLoc) {
	myflash01 = new Image(); 
	//myflash01.src = flashLoc;
	alert("wecam = "+myflash01.src);
	
}

function startFullPreload(url) {
			//alert("preloading "+url);
			this.preloadFrame = new Object ();	// JavaScript native Object
			this.preloadFrame.datatype = 'iframe';
			//this.preload.w = ;
			//this.preload.h = ;
			this.preload.src = url;
		
}




function updateBarItim(itimnum){
	
	var newitim = "";
	writeDiv('iTim_temp', newitim);	
	moveDivCenter(id);
	
}

function startNewItim(){
	
	var newitim = "&nbsp;</div>";
	writeDiv('iTim_temp', newitim);	
	moveDivCenter(id);
	
}

function getItimConvIdContact(cid){
	var getUrl = baseUrl+"con_scripts/itim_createconversation.php?cid="+cid;
	var func = "startItim";
	
	//alert("about to get "+getUrl+" and func = "+func);
	ajaxGetUrlFunction(getUrl, func);
	
	
}

function getItimConvIdCell(cellnum){
	var getUrl = baseUrl+"con_scripts/itim_createconversation.php?send_email_num="+cellnum;
	var func = "startItim";
	
	//alert("about to get "+getUrl+" and func = "+func);
	ajaxGetUrlFunction(getUrl, func);
	
	
	
	
}

function updatePersonal_itim(){
	var firstname = escape(document.getElementById('firstname').value);
	var middlename = escape(document.getElementById('middlename').value);
	var lastname = escape(document.getElementById('lastname').value);
	
	
	var url = baseUrl+"con_scripts/ajaxupdatesettings.php?changeprofile=1&firstname="+firstname+"&middlename="+middlename+"&lastname="+lastname;
	//alert('updating personal - first:'+firstname+' and mid: '+middlename+' and lastname : '+lastname+'\n\nurl = '+url);
	var loadingComment = "Saving";
	ajaxGetUrlBasicComment(url, loadingComment);
	if(middlename != ''){
		var realname = firstname+' '+middlename+' '+lastname;	
	}else{
		var realname = firstname+' '+lastname;
	}
	writeDiv('gen_real_name', realname);
}

function updatePassword_itim(){
	
	
	var curr_pwd = escape(document.getElementById('curr_pwd').value);
	var temp_pwd = escape(document.getElementById('temp_pwd').value);
	var newpwd = escape(document.getElementById('newpwd').value);
	
	
	var url = baseUrl+"con_scripts/ajaxupdatesettings.php?changepwd=1&newpwd="+newpwd+"&temp_pwd="+temp_pwd+"&curr_pwd="+curr_pwd;
	//alert('updating personal - curr_pwd:'+curr_pwd+' and curr: '+ temp_pwd+' and new : '+newpwd+'\n\nurl = '+url);
	var loadingComment = "Saving";
	ajaxGetUrlBasicComment(url, loadingComment, 1, 'pwd_error');
	//alert('updating password');
	
	
}

function updateMobile_itim(){
	//alert('updating mobile');
	
	var cellphone = escape(document.getElementById('cellphone').value);
	var carrier = escape(document.getElementById('carrier').value);
	//var phonetype = escape(document.getElementById('phonetype').value);
	
	if(document.getElementById('phonetype_iphone').checked == true ){
		var phonetype = 'iphone';
	}else if(document.getElementById('phonetype_blackberry').checked == true ){
		var phonetype = 'blackberry';
	}else if(document.getElementById('phonetype_sidekick').checked == true ){
		var phonetype = 'sidekick';
	}else if(document.getElementById('phonetype_other').checked == true ){
		var phonetype = 'other';
	}

	
	
	if(cellphone > 1000000000){
		
		
		
		
		
		var url = baseUrl+"con_scripts/ajaxupdatesettings.php?changemobile=1&cellphone="+cellphone+"&phonetype="+phonetype+"&carrier="+carrier;
		//alert('updating personal \nurl = '+url);
		var loadingComment = "Saving";
		ajaxGetUrlBasicComment(url, loadingComment);
		var content = cellphone+' /  '+carrier+' / Type:'+phonetype;
		writeDiv('gen_mobile', content);
		
	}else{
		writeDiv('mobile_error', 'Error: Phone must be a 10-digit number');
		
		
	}
	
}


function showOpenItims(){
	
	
	
}

function showItimContacts(){
	
	
	
}


function showAllItims(){
	
	
	
}

function showItimFriends(){
	
	
	
}

function updateBg_itim(){
	alert('updating bg');

}


function updateNotifications_itim(){
	
	if(document.getElementById('emailalert').checked == false ){
		var emailalert = 0;
	}else{
		var emailalert = 1;
		
	}
	
	if(document.getElementById('mobilealert').checked == false ){
		var mobilealert = 0;
	}else{
		var mobilealert = 1;
		
	}
	
	
	if((mobilealert == 1)&&(emailalert == 1)){
		var content = "sms + email";
		
	}else if(mobilealert == 1){
		var content = "sms only";
		
	}else if(emailalert == 1){
		var content = "email only";
	}else{
		var content = "none";
		
		
	}
	
	//alert('updating alerts');
	var url = baseUrl+"con_scripts/ajaxupdatesettings.php?changenotifications=1&mobilealert="+mobilealert+"&emailalert="+emailalert;
	//alert('updating notifications -and email: '+emailalert+' and new : '+mobilealert+'\n\nurl = '+url);
	var loadingComment = "Saving";
	ajaxGetUrlBasicComment(url, loadingComment);
	//alert('updating password');
	
	writeDiv('gen_notifications', content);
}


function changeSettings(newsettings){
	
	var defHt = 420;
	var topset = 0;
	var maindiv = 'generalSettings';
	var allSettings = new Array('majorsettings', 'profilesettings', 'pwdsettings', 'mobilesettings', 'bgsettings', 'notificationsettings');
	
	//hide all 
	//alert(' newsettings is '+newsettings+' len = '+allSettings.length);
	for(var i = 0; i < allSettings.length; i++){
		
		if(allSettings[i] == newsettings){
			
			//var newtop = (((i*defHt) + 10) * -1);
			//alert(' setting is '+newsettings);
			//moveDivTop(maindiv, newtop);
			
			showDiv(allSettings[i]);
		}else{
			//alert(' Hideing '+allSettings[i]);
			hideDiv(allSettings[i]);
			
				
			
		}
		
		
	}
	
	
	//move the current one
	
	
}



//alert('line 98');
function createNewItim(cellnum, from, tempmsg){
	//alert("New - starting itim for :\ncellnum:"+cellnum+"\n From: "+from);
	var from = "";
	startItimCell(cellnum, from, tempmsg);
		//_root.is_firstsend = 1;
	//_root.tempMessage = "hello uyi";
	//_root.tempCellnum =s "3102565569";
	//_root.tempCellfrom = "James Bond";
	/**
	if(im_id > 0){
		
		
	}else{
		
		
	}
	*/
	
}

//alert('line 119');
function createNewItimIM( im_id){
	var temp_i_c_id = friendIcidStatusArray[im_id][0];
	//alert("IM mes:\nimid = "+im_id+"\nicid = "+temp_i_c_id+" \n array = "+friendIcidStatusArray[im_id]);
	if(temp_i_c_id > 0){
		startItimIM(temp_i_c_id);
	}else if(im_id > 0){
		getIcidIM(im_id);
		//getItimConvIdFriend(im_id);
	}else{
		
		
	}
	
}



/**
* GetIMicid
*
* get the icid for a conversation using the friend user id. the tim id is gotten from the session ino
*/
function getIcidIM(friend_user_id){
	var getUrl = baseUrl+"con_scripts/getIcid_aj.php?send=1&cellnum3=**********&receiver_user_id="+friend_user_id+"&message_type=2";
	//var func = "startItimBar";
	var func = "startItimBar";
	
	//alert("about to get "+getUrl+" and func = "+func);
	ajaxGetUrlFunction(getUrl, func);
	
	
}

function parseTemp(){
	
	var func = "parseNewMes";
	//alert('url = '+getNewMesUrl+'\n\nfunc = '+func);
	ajaxGetUrlAndFunc(getNewMesUrl, func);	
	
	
	
}



/**
*
* parses content received by getNewmessage
*
*/

function parseNewMes(str){
	//alert('output = '+str);
	//var str = "&newmes_0=68-_-_-6614352461-_-_-1-_-_-113-_-_-Jan 14, 2009-_-_-12:25 PM-_-_-950-_-_-Tiffani Hill-_-_-Yes what's up it dont think you are nuts why are you so meain-_-_-:_._._:&friend_0=8-_-_-Daddy-_-_-avatars/daddy_sm.jpg-_-_-1-_-_-7-_-_-47&friend_1=1-_-_-Money+Penny-_-_-avatars/avatar2.jpg-_-_-0-_-_-2-_-_-1";	
	var mainarr = str.split(":_._._:");
	var newMesarr = mainarr[0];
	var friendarr = mainarr[1];
	
	// parse new message and make the alert
	var mesarr = newMesarr.split("&");
	
	for(var i = 0; i < mesarr.length; i++){
		if(mesarr[i].length > 0){
			var currMesarr = mesarr[i].split("-_-_-");
			var temp_i_c_id_arr = currMesarr[0].split("=");
			var temp_i_c_id = temp_i_c_id_arr[1];
			var cellnum = currMesarr[1];
			var is_reply = currMesarr[2];
			var totalmsg = currMesarr[3];
			var msgdate = currMesarr[4];
			var msgtime = currMesarr[5];
			var temp_mes_id = currMesarr[6];
			var name = currMesarr[7];
			var message = currMesarr[8];
			var attachment = currMesarr[9];
			var re = /(.{20}).+/;
			message = message.replace(re, "$1...");
			
			var temp_msgdate = msgdate+" "+msgtime;
			// Now check if we have already gotten this and closed it
			//newMessageArray[mes_id] = new Array('i_c_id', 'message', 'sender', 'is_closed');
			
			
			
			if(newMessageArray[temp_mes_id]){
				if(newMessageArray[temp_mes_id][3] != 1){
					//perform the alert and add to 	
					startItimAlert(temp_i_c_id, message, name, temp_mes_id, temp_msgdate);
					newMessageArray[temp_mes_id][3] = 1;
				}
			}else{
				//add alert and perform 
				startItimAlert(temp_i_c_id, message, name, temp_mes_id, temp_msgdate);
				newMessageArray[temp_mes_id] = new Array(temp_i_c_id, message, name, '1', temp_msgdate);
			}
		}
		
		
	}
	//alert('parse arr array = '+newMessageArray);
	
	//Now update the friends stuff by setting fr_online_".$fr_id. to visible is online or hidden if is not online
	//&friend_0=8-_-_-Daddy-_-_-avatars/daddy_sm.jpg-_-_-0-_-_-7-_-_-47&friend_1=1-_-_-Money+Penny-_-_-avatars/avatar2.jpg-_-_-0-_-_-2-_-_-1";	
	var frarr = friendarr.split("&");
	
	for(var i = 0; i < frarr.length; i++){
		if(frarr[i].length > 0){
			var currFrarr = frarr[i].split("-_-_-");
			
			var is_online = currFrarr[3];
			var fr_id = currFrarr[4];
			var is_online_divId = "fr_online_"+fr_id;
			//alert('fr array = '+currFrarr+'\nonline = '+is_online+'\ndivid = '+is_online_divId);
			if(is_online == 1){
				var newFrDiv=document.getElementById(is_online_divId);
				var newFrStyle=newFrDiv.style;
				newFrStyle.visibility = "visible";
								
			}else{
				var newFrDiv=document.getElementById(is_online_divId);
				var newFrStyle=newFrDiv.style;
				newFrStyle.visibility = "hidden";
								
			}
				
		}
		
	}
	
	
	
}


/**
*
* closealertarr updates the alert to show whether it has been closed or not so we don't keep showing it even when a new message is not received but we are getting the previous one
*
*/
function closeAlertArr(temp_mes_id, temp_value){
	newMessageArray[temp_mes_id][3] = temp_value;
	//alert('close alert arr array = '+newMessageArray);
	
	
	
}


/**
* GetIMicid
*
* get the icid for a conversation using the friend user id. the tim id is gotten from the session ino
*/
function getIcidIM(friend_user_id){
	var getUrl = baseUrl+"con_scripts/getIcid_aj.php?send=1&cellnum3=**********&receiver_user_id="+friend_user_id+"&message_type=2";
	//var func = "startItimBar";
	var func = "startItimBar";
	
	//alert("about to get "+getUrl+" and func = "+func);
	ajaxGetUrlFunction(getUrl, func);
	
	
}


//alert('line 148');
function getItimConvIdFriend(friend_user_id){
	var getUrl = baseUrl+"con_scripts/itim_createconversation.php?receiver_user_id="+friend_user_id;
	var func = "startItim";
	
	//alert("about to get "+getUrl+" and func = "+func);
	ajaxGetUrlFunction(getUrl, func);
	
	
}


/** Default Functions **/

function moveDiv(id, newtop, newleft)
{
	var newDiv=document.getElementById(id);
	var newStyle=newDiv.style;
	//alert("about to show menu for "+id+" and var = "+newDiv);
	newStyle.top=newtop +"px";
	newStyle.left=newleft +"px";
	newStyle.visibility = "visible";	
	
	
}

function moveDivTop(id, newtop)
{
	var newDiv=document.getElementById(id);
	var newStyle=newDiv.style;
	//alert("about to show menu for "+id+" and var = "+newDiv);
	newStyle.top=newtop +"px";
	newStyle.visibility = "visible";	
	
	
}


function removeDiv (id)
{
	var newDiv=document.getElementById(id);
	var newStyle=newDiv.style;
	//winOpened = 'none';
	newStyle.top = "-2000px";
	newStyle.visibility = "hidden";
}
//alert('line 183');
function closeDivIcid(i_c_id){
	
	var curr_itimnum = icidArray[i_c_id];
	var divId = "bar_iTim_"+curr_itimnum;
	//alert('removing '+divId);
	closeDiv(curr_itimnum);
	if(currentItimWinArray.length > 0){
		setItimSelected();
	}
	
	document.getElementById('open_itims').removeChild(document.getElementById(divId));
	
	//remove the cellnumItimnumArray[tempcell] entry or set it to 0
	var tempcell = cellnumIcidArray[i_c_id];
	cellnumItimnumArray[tempcell] = 0;
}
	
function changeItimClass(divId, itimnum){
		var tempfname = "iTim_"+itimnum;
		var lastindex = currentItimWinArray.length - 1;
		var fname = currentFnameArray[lastindex];
		//check if this is the current window
		//alert("okay array fname = "+fname+" and tempfname = "+tempfname);
		if(fname != tempfname){
			changeClass(divId, 'itim_bar');	
			
		}
	
}


//this function adds a active toolbar itim to the toolbar

function addItimToolbar(itimnum){
	//create div with id bar_iTim_+itimnum
	
	//add class
	var content = "";

	var selectIndex = currentFnameArray.length - 1;
	for(var i = 0; i < currentFnameArray.length; i++){
			var tempcon = "";
			var fname = currentFnameArray[i];
			var fnamearr = fname.split("_");
			var tempitimnum = fnamearr[1];
			var temp_i_c_id = itimnumArray[tempitimnum];
			var avatar = icidAvatarArray[temp_i_c_id];
			var cellName = icidCellNameArray[temp_i_c_id];
			
			
			
			//trim cellName
			if(cellName.length > 15){
				var re = /(.{13}).+/;
				cellName = cellName.replace(re, "$1...");
				//alert('replaced cellname =  '+cellName);
			}
			var cellNum = cellnumIcidArray[temp_i_c_id];
			//alert('itimnum = '+itimnum+' \n\ntempicid = '+temp_i_c_id+'\n\n'+itimnumArray+'\n\ntempitimnum = '+tempitimnum+'\ncellnuame='+cellName+'\ncellnum = '+cellNum);
			var divId = "bar_"+fname;
			
			var newMsgId = "newdot_"+fname;
			//alert("okay array fname = "+fname+" and tempfname = "+fnamearr+" \ndiv id ="+divId+"\n\narray = "+currentFnameArray);
		
			if(i != selectIndex){
				tempcon = "   <div id=\""+divId+"\" class=\"itim_bar\" style=\"height:35px; margin-right:2px; margin-left:2px; position:relative; overflow:hidden;\" onMouseOver=\"changeDivHeight(this.id, 55); showDiv(this.id+'_close'); changeClass(this.id, 'itim_bar_open');\" onMouseOut=\"changeDivHeight(this.id, 35); hideDiv(this.id+'_close'); changeItimClass(this.id, "+tempitimnum+")\">";
											
								
				
			}else{
				tempcon = "   <div id=\""+divId+"\" class=\"itim_bar_open\" style=\"height:35px; margin-right:2px; margin-left:2px; position:relative; overflow:hidden;\" onMouseOver=\"changeDivHeight(this.id, 55); showDiv(this.id+'_close'); changeClass(this.id, 'itim_bar_open');\" onMouseOut=\"changeDivHeight(this.id, 35); hideDiv(this.id+'_close'); changeItimClass(this.id, "+tempitimnum+")\">";
				//var temp_i_c_id = itimnumArray[itimnum];
				//alert(' about to hide icid='+temp_i_c_id);
				
				// check if this is an IM, if cellnum is not > 0 then it is an IM
				if(cellNum > 0){
					hideDiv('new_alltim_'+temp_i_c_id);
				}
				hideDiv('newMsgAllMain');
			}
			var oldcon = content;
			//content = tempcon + "<div class=\"menuLink\" style=\" margin-left:5px; margin-top:5px; height:25px; z-index:10; position:relative;\" ><table width=\"150\" height=\"25\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">	<tr>	<td width=\"132\" valign=\"top\" >		<a href=\"javascript:void(0)\" onClick=\"startItimBar("+temp_i_c_id+"); setItimClass(this.id, "+tempitimnum+");\"><img src=\""+avatar+"\" alt=\"a_sm\" width=\"25\" height=\"25\" border=\"0\" style=\"float:left; margin-right: 3px;\"></a><a href=\"javascript:void(0)\" onClick=\"startItimBar("+temp_i_c_id+"); setItimClass(this.id, "+tempitimnum+");\" title=\""+cellNum+"\">"+cellName+"  </a>	  </td>			<td width=\"18\" valign=\"top\"><div id=\""+newMsgId+"\" style=\"visibility:hidden\"><img src=\"images/greendot.png\" alt=\"new_msg\" width=\"16\" height=\"16\"></div></td>			</tr>	  </table>	 	</div>		<div id=\""+divId+"_close\" style=\" visibility:hidden; position:relative;\">		<table width=\"155\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">		  <tr><td width=\"129\" valign=\"middle\" style=\"font-size:10px;text-align:right; z-index:9; position:relative; margin-right:5px\">	  <a href=\"a\"  style=\" font-family:Verdana, Arial, Helvetica, sans-serif;\">close itim </a>  </td>  <td width=\"26\" align=\"right\">				<a href=\"javascript:void(0)\" onClick=\"closeDivIcid("+temp_i_c_id+"); document.getElementById('open_itims').removeChild(document.getElementById('"+divId+"'));\">  <img src=\"icons_main/close.png\" alt=\"close itim\" width=\"16\" height=\"16\" border=\"0\" ></a> </td>	</tr>	  </table>	</div>	</div>"+oldcon;
				
				
			content = tempcon + "<div class=\"menuLink\" style=\" margin-left:5px; margin-top:5px; height:25px; z-index:10; position:relative;\" ><table width=\"150\" height=\"25\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">	<tr>	<td width=\"132\" valign=\"top\" >		<a href=\"javascript:void(0)\" onClick=\"startItimBar("+temp_i_c_id+"); setItimClass(this.id, "+tempitimnum+");\"><img src=\""+avatar+"\" alt=\"a_sm\" width=\"25\" height=\"25\" border=\"0\" style=\"float:left; margin-right: 3px;\"></a><a href=\"javascript:void(0)\" onClick=\"startItimBar("+temp_i_c_id+"); setItimClass(this.id, "+tempitimnum+");\" title=\""+cellNum+"\">"+cellName+"  </a>	  </td>			<td width=\"18\" valign=\"top\"><div id=\""+newMsgId+"\" style=\"visibility:hidden\"><img src=\"images/greendot.png\" alt=\"new_msg\" width=\"16\" height=\"16\"></div></td>			</tr>	  </table>	 	</div>		<div id=\""+divId+"_close\" style=\" visibility:hidden; position:relative;\">		<table width=\"155\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">		  <tr><td width=\"129\" valign=\"middle\" style=\"font-size:10px;text-align:right; z-index:9; position:relative; margin-right:5px\">	  <a href=\"javascript:void(0)\" onClick=\"closeDivIcid("+temp_i_c_id+");\"  style=\" font-family:Verdana, Arial, Helvetica, sans-serif;\">close itim </a>  </td>  <td width=\"26\" align=\"right\">				<a href=\"javascript:void(0)\" onClick=\"closeDivIcid("+temp_i_c_id+"); \">  <img src=\"icons_main/close.png\" alt=\"close itim\" width=\"16\" height=\"16\" border=\"0\" ></a> </td>	</tr>	  </table>	</div>	</div>"+oldcon;	
			
		}
		content = content+"<P><div>&nbsp;</div><P></p>";
		//alert("okay content = "+content+ "\nand oldcon = "+oldcon);
		//writeDiv('open_itims', "");
		//alert("con is blank");
		writeDiv('open_itims', content);
	
	
}


//collapse a div and open it
/**
*
*	divid is the id to be open and collapse,
*	buttonId is the button that is clicked to collapse the div
*	collapseheight = height of div when it is collapse
*	openheight = height of div when open
*	collapse content = content in div when collapse
*	setopen = 1 means you should force open, 2 is force close
*
*/

var collapseContent = "<a href=\"javascript:void(0)\" onClick=\"collapseAndOpenDiv('open_itims', this.parentNode.id, 0, 215, collapseContent, openContent, 2)\" title=\"Collapse\"><img src=\"icons_main/down_exp.gif\" alt=\"collapse\" width=\"9\" height=\"6\" border=\"0\"></a>";
var openContent = "<a href=\"javascript:void(0)\" onClick=\"collapseAndOpenDiv('open_itims', this.parentNode.id, 0, 215, collapseContent, openContent, 1)\" title=\"Expand\"><img src=\"icons_main/left_exp.gif\" alt=\"expand\" width=\"6\" height=\"9\" border=\"0\"></a>";


var collapseContent2 = "<a href=\"javascript:void(0)\" onClick=\"collapseAndOpenDiv('all_itims', this.parentNode.id, 0, 120, collapseContent2, openContent2, 2)\" title=\"Collapse\"><img src=\"icons_main/down_exp.gif\" alt=\"collapse\" width=\"9\" height=\"6\" border=\"0\"></a>";
var openContent2 = "<a href=\"javascript:void(0)\" onClick=\"collapseAndOpenDiv('all_itims', this.parentNode.id, 0, 120, collapseContent2, openContent2, 1)\" title=\"Expand\"><img src=\"icons_main/left_exp.gif\" alt=\"expand\" width=\"6\" height=\"9\" border=\"0\"></a>";

var collapseContent3 = "<a href=\"javascript:void(0)\" onClick=\"collapseAndOpenDiv('friends', this.parentNode.id, 0, 100, collapseContent3, openContent3, 2)\" title=\"Collapse\"><img src=\"icons_main/down_exp.gif\" alt=\"collapse\" width=\"9\" height=\"6\" border=\"0\"></a>";
var openContent3 = "<a href=\"javascript:void(0)\" onClick=\"collapseAndOpenDiv('friends', this.parentNode.id, 0, 100, collapseContent3, openContent3, 1)\" title=\"Expand\"><img src=\"icons_main/left_exp.gif\" alt=\"expand\" width=\"6\" height=\"9\" border=\"0\"></a>";

var collapseContent4 = "<a href=\"javascript:void(0)\" onClick=\"collapseAndOpenDiv('myContacts', this.parentNode.id, 0, 100, collapseContent4, openContent4, 2)\" title=\"Collapse\"><img src=\"icons_main/down_exp.gif\" alt=\"collapse\" width=\"9\" height=\"6\" border=\"0\"></a>";
var openContent4 = "<a href=\"javascript:void(0)\" onClick=\"collapseAndOpenDiv('myContacts', this.parentNode.id, 0, 100, collapseContent4, openContent4, 1)\" title=\"Expand\"><img src=\"icons_main/left_exp.gif\" alt=\"expand\" width=\"6\" height=\"9\" border=\"0\"></a>";



function collapseAndOpenDiv(divId, buttonId, collapseHeight, openHeight, collapseContent, openContent, setOpen){
	var C_el = document.getElementById(divId);
	var oldht = C_el.offsetHeight;
	//alert(' about to test collapse oldht = '+oldht+' and openHeight = '+openHeight+' and buttondiv = '+buttonId+'\ncollht = '+collapseHeight+' and setopn = '+setOpen);
	if((oldht == collapseHeight)||(setOpen == 1)){
		//means it is closed, go ahead and open it
		
		//EXPAND IT
		changeDivHeight(divId, openHeight);
		showDiv(divId);
		
		//writeDiv(buttonId, '');
		//alert('expanding '+divId+);
		
		writeDiv(buttonId, collapseContent);
		
	}else if((oldht == openHeight)||(setOpen == 2)){
		//COLLAPSE IT
		//alert('collpainging '+divId+' and ht = '+collapseHeight);
		if(collapseHeight < 1){
		
			collapseHeight = 1;
		}
		changeDivHeight(divId, collapseHeight);
		hideDiv(divId);
		writeDiv(buttonId, openContent);
	}else{
		//alert('No set open - collpainging '+divId);
		//COLLAPSE IT
		// default to close the div	
		// debug for ie , cannot set height to 0 must be 1
		if(collapseHeight < 1){
		
			collapseHeight = 1;
		}
		changeDivHeight(divId, collapseHeight);
		hideDiv(divId);
		writeDiv(buttonId, openContent);
	}
	
	resizeMidSection();
}

/**
*	 this starts the routine interval checkers
*
*/
function startChecker(){
	//setInterval ( "startItimAlert('47', 'Hello uyi', 'Uyi Ogbeide')", 10000 );
	setInterval ( "checkNewMsgAndFriend()", 10000 );

	
	
}



/**
*
*	This is to accept = 1 or ignore (accept = 0)
*
*
*/

function itimAcceptFriendRequest(friend_user_id, accept, divId){
	
	alert(" Add New Friend id = "+friend_user_id+" and accept = "+accept+ " and div id = "+divId );	
	
	if(accept > 0){
		
	}else{
		accept = 0;	
	}
	if(friend_user_id > 0){
		var url = baseUrl+"acceptFriendRequest.php?friend_user_id="+friend_user_id+"&accept="+accept+"&friendrequest=1";
		
		alert(" okay url = "+url);
		//alert('updating personal - first:'+firstname+' and mid: '+middlename+' and lastname : '+lastname+'\n\nurl = '+url);
		var loadingComment = "Sending Friend Request";
		
		
		ajaxGetUrlBasicComment(url, loadingComment);
		num_of_reqs--;
		var divcon = 'You have <span style="font-weight:bold; color:#000000;">'+num_of_reqs+'</span>	friend requests';
		writeDiv("topTitle", divcon);
		var hostDivId = "mainContentSection";
		removeDivInDiv(divId, hostDivId);
		
		
	}

}



/**
*
*	This add new friend from search results
*
*
*/

function itimAddNewFriend(friend_user_id, my_user_id, buttondivId){
	
	//alert(" Add New Friend id = "+friend_user_id+" and my id = "+my_user_id+ " and div id = "+buttondivId );	
	
	var divcon = '<div class="sentItimButton" > Request Sent :)  </div>';
	writeDiv(buttondivId, divcon);
	var url = baseUrl+"sendFriendRequest.php?sendrequest=1&friend_user_id="+friend_user_id;
	//alert(" okay url = "+url);
	//alert('updating personal - first:'+firstname+' and mid: '+middlename+' and lastname : '+lastname+'\n\nurl = '+url);
	var loadingComment = "Sending Friend Request";
	
	
	ajaxGetUrlBasicComment(url, loadingComment);
	
	

}


/**
*
*	This add new friend from search results
*
*
*/
function itimStartConversation(friend_user_id, my_user_id){
	
	alert(" Starting Conversation with id = "+friend_user_id+" and my id = "+my_user_id);	
	
}



function itimGoToMyAccount(my_user_id){
	
	alert(" Going to my account with and my id = "+my_user_id);	
	
}




/**
*	 this checks if a new message is received by calling the appropriate url
*	also check the friends online status and updates the friendIcidStatusArray[friend_id] = new array(icid, onlinestatus, name)
*
*
*/
function checkNewMsgAndFriend(){
	
	//first call the url http://www.2waystar.com/itimworld/con_scripts/getNewMessage.php
	var newurl = baseUrl+"con_scripts/getNewMessage.php";
	parseTemp();
	
	// check if newmessagearray[mes_id][3] == 1, if it is not do the alert
	// startItimAlert('47', 'Hello uyi', 'Uyi Ogbeide')
	////newMessageArray[mes_id] = new Array('i_c_id', 'message', 'sender', 'is_closed');
	
	//parse it and update newmessagearray and friendsarray arrays
	
	
	// then use for loop thru the friendarray and reset the css of the online guys for the blue dot.
	
	// now we are done
	
}

/** 
* logMeOut logs you out
*	it is typically called by the flash application freesmsreply_im looking for mainlogout = 1
*
*/

function logMeOut(){
	//alert('okay son logginh you out');
	location.href='login.php?login_elsewhere=1';	
	
	
}


// shows the green dot next to the bar itim
function showNewMsg(itimnum){
	var lastIndex = currentFnameArray.length - 1;
	var tempFname = "iTim_"+itimnum;
	if(tempFname != currentFnameArray[lastIndex]){
		itimnumNewmsgArray[itimnum] = 1;
		showDiv("newdot_iTim_"+itimnum);	
		showDiv("newMsgAll");
		//trace("wow adding itm = "+itimnum+" and array = "+itimnumNewmsgArray);
	}
}


function removeNewMsg(itimnum){
	itimnumNewmsgArray[itimnum] = 0;
	
	hideDiv("newdot_iTim_"+itimnum);	
	var msgtotal = totalNewMsg();
	//trace("wow removing itm = "+itimnum+"\ntotal msg = "+msgtotal+" and array = "+itimnumNewmsgArray);
	if(msgtotal > 0){
		
	}else{
		hideDiv("newMsgAll");	
	}
}

function totalNewMsg(){
	var total = 0;
	for(var i = 0; i < currentFnameArray.length; i++){
		if(	itimnumNewmsgArray > 0){
			total = total + itimnumNewmsgArray[i];
		}
	}
	return total;
	
}

function setItimSelected(){
	var lastIndex = currentFnameArray.length - 1;
	var fname = currentFnameArray[lastIndex];
	var divId = "bar_"+fname;
	changeClass(divId, 'itim_bar_open');
}


/** load ajax setup pages */
function loadAddPicture(itimnum){
	writeDiv('addPicture_holder', '');
	//var i_c_id = 68;
	var content = '<iframe src="addpic.php?itimnum='+itimnum+'" style=" border-width:0; overflow:hidden;" width="660px" height="480" frameborder="0"></iframe>';	
	//alert(' iframe = '+content);
	writeDiv('addPicture_holder', content);
	
}


/** load ajax setup pages */
function loadAddAvatar(){
	writeDiv('addAvatar_holder', '');
	//var i_c_id = 68;
	var content = '<iframe src="addavatar.php" style=" border-width:0; overflow:hidden;" width="660px" height="480" frameborder="0"></iframe>';	
	//alert(' iframe = '+content);
	writeDiv('addAvatar_holder', content);
	
}



function setAvatar(picloc, wd, ht){
	
	
	var defwd = 125;
	var defht = 157;
	
	if((wd/ht) > (defwd/defht)){
		// match the height
		var finalht = defht;
		//var finalwd = defht/ht * defwd;
		var finalwd = defht/ht * wd;
		finalwd = Math.round(finalwd);
		var diffleft = (finalwd - defwd)/2;
		var centerStyle = " style=\"position:relative; left:-"+diffleft+"px;\" ";
	
	}else{
		//match the wd
		
		var finalwd = defwd;
		//var finalht = defwd/wd * defht;
		var finalht = defwd/wd * ht;
		finalht = Math.round(finalht);
		
		var difftop = (finalht - defht)/2;
		var centerStyle = " style=\"position:relative; top:-"+difftop+"px;\" ";
	}
	
	
	
	var divCon = '<img alt="my avatar" src="'+picloc+'" width="'+finalwd+'" border="0" height="'+finalht+'" '+centerStyle+' >';
	//alert('hey div is '+divCon);
	writeDiv('myavatardiv', divCon);
	
	var url = baseUrl+"con_scripts/editAvatar.php?changeavatar=1&picloc="+picloc;
	//alert(" okay url = "+url);
	//alert('updating personal - first:'+firstname+' and mid: '+middlename+' and lastname : '+lastname+'\n\nurl = '+url);
	var loadingComment = "Saving";
	
	
	ajaxGetUrlBasicComment(url, loadingComment);
	
	//writeDiv('gen_real_name', realname);	
	
}



function loadCamera(){
	writeDiv('myCamera_Holder', '');
	
	var cameraname = "simpleCamera";
	var cid = "cam1";
	var fvars = "" ;
	/**
	'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0',
		'width', '300',
		'height', '400',
		'src', 'webcam3b',
		'quality', 'high',
		'pluginspage', 'http://www.adobe.com/go/getflashplayer',
		'align', 'middle',
		'play', 'true',
		'loop', 'true',
		'scale', 'showall',
		'wmode', 'window',
		'devicefont', 'false',
		'id', 'webcam3b',
		'bgcolor', '#ffffff',
		'name', 'webcam3b',
		'menu', 'true',
		'allowFullScreen', 'false',
		'allowScriptAccess','sameDomain',
		'movie', 'webcam3b',
		'salign', ''
	*/
	
	
	var swfOut = AC_FL_RunContent_uyi('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0','width','300','height','400','src',cameraswf,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie', cameraswf, 'name', cameraswf, 'id', cameraswf, 'wmode', 'window','allowScriptAccess','sameDomain');
	
	//var swfOut = AC_FL_RunContent_uyi('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','300','height','400','src',cameraswf,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie', cameraswf, 'name', cameraname, 'id', cid, 'wmode', 'opaque','allowScriptAccess','sameDomain', 'swLiveConnect','true','flashVars', fvars);

	
	
	writeDiv('myCamera_Holder', swfOut);
	
	
}


function loadHistory(i_c_id){
	
	writeDiv('myHistory_holder', '');
	//var i_c_id = 68;
	var content = '<iframe src="history.php?i_c_id='+i_c_id+'&getHis=1&firstdate=1" style=" border-width:0; overflow:hidden;" width="865px" height="480" frameborder="0"></iframe>';	
	//alert(' iframe = '+content);
	writeDiv('myHistory_holder', content);
	
}

function loadSettings(){
	writeDiv('mySettings_holder', '');
	//var i_c_id = 68;
	var content = '<iframe src="updatesettings.php" style=" border-width:0; overflow:hidden;" width="780px" height="480" frameborder="0"></iframe>';	
	//alert(' iframe = '+content);
	writeDiv('mySettings_holder', content);
	
}

function showHistory(i_c_id){
	loadBackfade();
	loadHistory(i_c_id);
	moveDivCenter('myHistory');	
	winOpened = 'myHistory';
	
}

function showSettings(){
	//alert('hey settings show');
	loadBackfade();
	loadSettings(); 
	
	moveDivCenter('mySettings');
	winOpened = 'mySettings';
}

function setItimClass(divId, itimnum){
		var tempfname = "iTim_"+itimnum;
		
		//check if this is the current window
		
		for(var i = 0; i < currentFnameArray.length; i++){
			var fname = currentFnameArray[i];
			var divId = "bar_"+fname;
			//alert("okay array fname = "+fname+" and tempfname = "+tempfname+" \ndiv id ="+divId);
		
			if(fname != tempfname){
				changeClass(divId, 'itim_bar');	
				
			}else{
				if(!safari){
					
					changeClass(divId, 'itim_bar_open');	
				}else{
					changeClass(divId, 'itim_bar_open');
				}
				
			}
			
			
		}
		
		
	
}

function findIndexOf(searchItem, checkarray){
	//alert('for ie check for == '+searchItem+' in == '+checkarray);
	for (var i = 0; i < checkarray.length; i++) {
      var currObj = checkarray[i];
	  if(currObj == searchItem){
		  
		return i;  
	  }
	  
	  /**
	  if (checkarray[i] == searchItem) {
        return i;
      }
	  */
    }	
	
	
	
}
function closeDiv(itimnum){
	
	//var blank = "";
	//writeDiv('iTim_div_'+itimnum, blank);
	//removeDiv('boxHandle'+itimnum);
	//alert("b4 removal array: "+currentFnameArray+"\narray: "+currentItimWinArray);
	//removeDivInDiv("iTim_div_"+itimnum, "iTimHolder"+itimnum);
	writeDiv("iTim_div_"+itimnum, '');			//added this because the flash swf is still there when you close it, we want it gone.
	//alert("just removed itiom "+itimnum);
	removeDivInDiv("iTimHolder"+itimnum, "midSection");
	// remove from arrays
	// please use findIndexOf because it does not conflict with dragging
	if((ie4)||(ie5)){
		var remIndex = findIndexOf('boxHandle'+itimnum, currentItimWinArray);
	}else{
		var remIndex = currentItimWinArray.indexOf('boxHandle'+itimnum);
		
	}
	//alert("after remove remIndex = "+remIndex+" divindiv array: "+currentFnameArray+"\narray: "+currentItimWinArray);
	if(remIndex >= 0){
		currentItimWinArray.splice(remIndex, 1);
		currentFnameArray.splice(remIndex, 1);
		
		
	}
	if(currentItimWinArray.length > 0){
		var lastindex = currentItimWinArray.length - 1;
		var itimid = currentItimWinArray[lastindex];
		var fname = currentFnameArray[lastindex];
		//alert("okay lst index = "+lastindex+"\nitim Id = "+itimid+"\nwind fname = "+fname);
		itimWinToFocus(itimid, fname);
		removeFlashAlertNewmes(fname);
		//alert("JUST SET mad focus uiyi");
		thisMovie(fname).focus();
		//currentItimWinArray.push(id)
		//lastFname = currentFname
		//currentFnameArray.push(movieName)	
		
	}
		
	//alert("After removal array: "+currentFnameArray+"\narray: "+currentItimWinArray);
	
	
}

function animFavNewMessage( sent_by, newMessage, avatar, itimnum){
	
	//alert(" You have a message from "+sent_by+"\n\n"+newMessage+" and "+avatar);
	// Removes ending whitespaces

	
	//var re = /(.*?)\s+<fon/;
	//sent_by.replace(re, "$1");
	//alert(" You have a message from "+sent_by+"\n\n"+newMessage+" and "+avatar);
	/**
	if(ns4){
		alert("this is ns4 - firefox")
	}else if(ns6){
		alert("this is ns6")
	}else if(ie4){
		alert("internet explorer 4")
	}else if(ie5){
		alert("ie.e 5")
	}else if(op6){
		alert("opera windows")
	}
	*/
	
	showNewMsg(itimnum);
	
	var icoarr = new Array("favicons/favicon_4.ico", "favicons/favicon_mbw.ico", avatar);
	var titlearr = new Array("New iTim!!", sent_by+" Says:", newMessage);
	if((ie4) || (ie5)){
		//alert("we are in ie - "+top.document.title);
		//top.document.title = "No way";
		f_index = 0;
		//blinkTitle();
		var newtitle = document.title;
		//changeTitle(titlearr, f_index, 2000);
		//document.title = "uyi figures";
		//alert("favicon here = "+newtitle);
		document.title = titlearr[0]; 
		blinkTitle();
		favicon.animateIE(icoarr, titlearr, 2000);
	}else{
		//alert("we are mozillar");
		//blinkTitle();
		favicon.animate(icoarr, titlearr, 2000);
	}
	favNewMes = 1;				// must be reset by itim in focus
	
}


var blinkTitle = function(){
	
	top.document.title = (!document.title || document.title == '* New Message Waiting! *')? 'New Message Waiting!' : '* New Message Waiting! *';
	blinkTimer = window.setTimeout("blinkTitle()", 2000);
	//alert(" Now title = "+document.title+" changes ");
}

function changeTitle(msgarr, f_index, speed)
{
	//var msg  = "Your message here --- hscripts.com";
	var speed = 500;
	
	//f_index = 0;

	f_index = (f_index+1) % msgarr.length;
	var masg = msgarr[f_index];
	document.title = masg;
	timerX = window.setTimeout("titlebar("+msgarr+", "+f_index+", "+speed+")",speed);
	//alert(" Now title = "+document.title+" and findex  = "+f_index+"\narray = "+msgarr);
}


/** lost connection
*
*/
function lostConnection(){
	
	
}


/** start itim with just cellnum and from, itim will get the icid by itself
*
*/

function startItimCell(tempcell, tempfrom, tempmsg){
	//alert("crazy, u got "+tempcell+"\nfrom="+tempfrom+"\nmsg: "+tempmsg);
	//var newtop = 100;
	//var newleft = 200;
	var cellitimnum = cellnumItimnumArray[tempcell];
	//alert("temp cell top sitimnum "+itimnum+" and fname = "+cellitimnum);
	if(cellitimnum > 0){
		//var i_c_id = itimnumArray[cellitimnum];
		//alert(" hey cellitimnum = "+cellitimnum);	
		
		
		var fname = 'iTim_'+cellitimnum;
		var box_id = "boxHandle"+cellitimnum;
		//alert('fname = '+fname+' and array is '+currentFnameArray);
		
		if((ie4)||(ie5)){
			var remIndex = findIndexOf(fname, currentFnameArray);
		}else{
			//var remIndex = currentItimWinArray.indexOf('boxHandle'+itimnum);
			var remIndex = currentFnameArray.indexOf(fname);
		}
		//var remIndex = currentFnameArray.indexOf(fname);
		// check if fname is open
		if(remIndex >= 0){
				//alert('okay it exist = '+fname+' and box = '+box_id);
				itimWinToFocus(box_id, fname);
								
		}
		
		var end = 1;
		return end;	
	}else{
		
			
	}
	
	
	if(itim_newtop < top_spacer_limit){
		itim_newtop = itim_newtop + itim_topspacer;	
		itim_newleft = itim_newleft + itim_leftspacer;
		var newtop = itim_newtop;
		var newleft = itim_newleft;
	}else{
		itim_newtop = 98 + itim_topspacer;	
		itim_newleft = 198 + itim_leftspacer;		
		var newtop = itim_newtop;
		var newleft = itim_newleft;
	}
	//alert("new top = "+newtop);
	itimnum++;
	var itim2 = itimnum + 1;
	//var tempid = getElementById("tempBox");
	topIndex++;
	var swf_vars = "'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','405','height','425','src','itim_0.1.0','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','itim_0.1.0', 'name', 'iTim_"+itimnum+"', 'id', 'iTim_"+itimnum+"', 'wmode', 'transparent','allowScriptAccess','sameDomain', 'swLiveConnect','true' ";
	var fvars = "is_firstsend=1&tempMessage="+tempmsg+"&tempCellnum="+tempcell+"&tempCellfrom="+tempfrom+"&itimnum="+itimnum+"&winfocus=1&blinkingbarStatus=onfocus";
	var fname = 'iTim_'+itimnum;
	var fid = 'iTim_'+itimnum;
	//var swfOut = AC_FL_RunContent_uyi('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','405','height','425','src','itim_0.1.0','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','itim_0.1.0', 'name', fname, 'id', fid, 'wmode', 'transparent','allowScriptAccess','sameDomain', 'swLiveConnect','true','flashVars', fvars);
	
	var swfOut = AC_FL_RunContent_uyi('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','405','height','425','src', itimswf ,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie', itimswf, 'name', fname, 'id', fid, 'wmode', 'transparent','allowScriptAccess','sameDomain', 'swLiveConnect','true','flashVars', fvars);
	
	//alert("okay = fvars = "+fvars+ " and out = "+swfOut);
	//var content = "<div id=\"boxHandle"+itimnum+"\" class=\"box\"   onClick=\"itimWinToFocus(this.id, '"+fname+"')\" style=\"width:405px; height:435px; position: absolute;  z-index:"+topIndex+"\"><div id='iTim_div_"+itimnum+"' style='position:relative; z-index:10;'>"+swfOut+"</div><div id=\"handle"+itimnum+"\" class=\"handle\"  style=\"width:390px; z-index:20; position:relative; top:-425px;  \">&nbsp;</div> </div>";
	var content = "<div id=\"boxHandle"+itimnum+"\" class=\"box\"   onMouseDown=\"itimWinToFocus(this.id, '"+fname+"')\" style=\"width:405px; height:435px; position: absolute;  z-index:"+topIndex+"\"><div id='iTim_div_"+itimnum+"' style='position:relative; z-index:10;'>"+swfOut+"</div><div id=\"handle"+itimnum+"\" class=\"handle\"  style=\"width:390px; z-index:20; position:relative; top:-425px;  \">&nbsp;</div> </div>";
	if(currentFnameArray.length > 0){
		var lastIndex = currentFnameArray.length - 1;
		//alert("Removing focus -- array = "+currentFnameArray);
		removeFlashFocus(currentFnameArray[lastIndex])
	}
	writeDivInDiv("iTimHolder"+itimnum, "midSection", content)
	//lastItimWin = currentItimWin
	//currentItimWin = "boxHandle"+itimnum
	
	
	
	
	
	//lastFname = currentFname
	//currentFname = fname
	
	//lastItimWin = currentItimWin
	//currentItimWinArray.push("iTim_div_"+itimnum)
	currentItimWinArray.push("boxHandle"+itimnum)
	//lastFname = currentFname
	currentFnameArray.push(fname)
	
	//alert("starting new array: "+currentFnameArray+"\narray: "+currentItimWinArray);
	if(currentFnameArray.length > 1){
		var pen = currentFnameArray.length - 2
		// second to the last item in array
		var lastFname = currentFnameArray[pen]
		//alert("ok removing focus in "+lastFname+" and penultimate ="+pen+" \narray: "+currentFnameArray)
		setOnfocus(lastFname, 0)
	}
	
	var boxHandle = document.getElementById("boxHandle"+itimnum)
  	group = drag.createSimpleGroup(boxHandle, document.getElementById("handle"+itimnum))
	moveDiv('boxHandle'+itimnum, newtop, newleft)
	//alert("itimnum "+itimnum+" and fname = "+fname);
	//setCellnumArray(tempcell, itimnum);
	//addItimToolbar(itimnum)
	thisMovie(fname).focus();
	
	
}





function getAndSetCameraPic(){
	

	// get url get_camera_filename.php and set the var camera_pic
	//alert("url = "+get_camera_url);
	ajaxGetUrlSetVarsFunc(get_camera_url, "setCameraPic");	
	
	
	
	
	
	
	
	
}



function setCameraPic(){
	
	
	if(camera_pic != ""){
		setPicMain(camera_pic, camera_pic, camera_pic_wd, camera_pic_ht);	
		
		
		
		
		// insert the thumbnail
		var content = "<div id=\"pic"+next_pic_num+"\" class=\"outPicItim\" ><table width=\"130\" height=\"97\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border: #CCCCCC 0px solid; width:130px; height:97px;\"><tr><td align=\"center\" valign=\"middle\"><a href=\"javascript:void(0)\" onClick=\"setPicMain('"+camera_pic+"', '"+camera_pic+"', '186', '160')\" onMouseOver=\"showPicMouse(this.parentNode.parentNode.parentNode.parentNode.parentNode.id, 'overPicItim');\" onMouseOut=\"showPicMouse(this.parentNode.parentNode.parentNode.parentNode.parentNode.id, 'outPicItim');\" title=\"Add This Pic iTim\"><img src=\""+camera_pic+"\" alt=\"photos\" width=\""+camera_thumb_wd+"\" height=\""+camera_thumb_ht+"\" border=\"0\" style=\"margin:5px;\"></a> </td></tr></table></div>";
		
		
		next_pic_num++;
		
		var photo_container = document.getElementById('photos');
		// Create a new <li> element for to insert inside <ul id="myList">
		var new_element = document.createElement('div');
		new_element.innerHTML = content;
		photo_container.insertBefore(new_element, photo_container.firstChild);
		//alert("inserting pic"+next_pic_num+"\n\n"+content);
		
		// close the camera window
	}
	
	removeDiv('backfade'); 
	removeDiv('myCamera'); 
	winOpened = 'none';
	
}

/**
*
*
*/
function setPicMain(pic_image, disp_newpic, disp_wd, disp_ht){
	pic_image_main = pic_image;
	avatarWd = disp_wd;
	avatarHt = disp_ht;
	var content = '<img src="'+disp_newpic+'" alt="timimage" width="'+disp_wd+'" height="'+disp_ht+'" style="margin:2px;">';
	writeDiv("addpicholder", content);
	//alert('picmain = '+pic_image_main+' and pic = '+disp_newpic);
	
	
	
}


function setPicAvatar(pic_image, disp_newpic, disp_wd, disp_ht){
	pic_image_main = pic_image;
	avatarWd = disp_wd;
	avatarHt = disp_ht;
	var content = '<img src="'+disp_newpic+'" alt="timimage" width="'+disp_wd+'" height="'+disp_ht+'" style="margin:2px;">';
	writeDiv("addpicholder", content);
	//alert('picmain = '+pic_image_main+' and pic = '+disp_newpic);
	
	
	
}


function addImageMain(){
	var newpic = pic_image_main;
	var itimnum = itimnum_main;
	var fname = 'iTim_'+itimnum;
	var fid = 'iTim_'+itimnum;
	//pic_image_main = newpic;
	var pic_image = newpic;
	//var pic_image = baseUrl+"tim_images/03-20-2008_06-43-50-66.jpg";
	//var pic_image = baseUrl+"tim_images/03-20-2008_13-07-12-soccer12.jpg";
	var picwd = 273;
	var picht = 268;
	//alert("pic image main = "+pic_image_main+" and ht = "+picht_main+ ' itimnum =  '+itimnum);
	addImage2Itim(itimnum, pic_image_main, picwd_main, picht_main);
}


function addImage(itimnum){
	
	//alert('okayu adding itim = '+itimnum);
	loadBackfade();
	loadAddPicture(itimnum);  
	moveDivCenter('addPicture');
	winOpened = 'addPicture';
	/**
	var fname = 'iTim_'+itimnum;
	var fid = 'iTim_'+itimnum;
	
	//var pic_image = baseUrl+"tim_images/03-20-2008_06-43-50-66.jpg";
	var pic_image = baseUrl+"tim_images/03-20-2008_13-07-12-soccer12.jpg";
	var picwd = 273;
	var picht = 268;
	addImage2Itim(itimnum, pic_image, picwd, picht);
	*/
	
}



function addImageOld(itimnum){
	var fname = 'iTim_'+itimnum;
	var fid = 'iTim_'+itimnum;
	
	//var pic_image = baseUrl+"tim_images/03-20-2008_06-43-50-66.jpg";
	var pic_image = baseUrl+"tim_images/03-20-2008_13-07-12-soccer12.jpg";
	var picwd = 273;
	var picht = 268;
	addImage2Itim(itimnum, pic_image, picwd, picht);
}


/**
*
* resets itim globals like the base domain
*
*/
function resetItimBaseUrl(itimnum, base_url_main){
	
	/**
	var fname = 'iTim_'+itimnum;
	//alert('itin='+fname+' and url = '+base_url_main);
	flashID = thisMovie(fname);
	flashID.SetVariable( "base_url_main", base_url_main);
	flashID.SetVariable( "base_url2", base_url_main);
	//flashID.SetVariable( "base_url2", base_url_main);
	**/
	
	
	
}


//this changes the avatar
function addAvatarMain(wd, ht){
	var newpic = pic_image_main;
	//alert("okay the newpic = "+newpic+" and wd = "+wd);
	
	setAvatar(newpic, wd, ht);
}


function addImage2Itim(itimnum, pic_image, picwd, picht){
	var fname = 'iTim_'+itimnum;
	var picwd_disp_def = 140;
	var picht_disp_def = 160;
	var picwd_sm_def = 45;
	var picht_sm_def = 50;
	
	
	
	flashID = thisMovie(fname);
	
	// make the necessary adjustments for proper pic display
	if(picwd > 0){
		if(picwd > picht){
			picwd_sm = picwd_sm_def;
			picht_sm = (picht/picwd) * picht_sm_def;
			picwd_disp = picwd_disp_def;
			picht_disp = (picht/picwd) * picht_disp_def;
			
		}else{
			picht_sm = picht_sm_def;
			picwd_sm = (picwd/picht) * picwd_sm_def;
			picht_disp = picht_disp_def;
			picwd_disp = (picwd/picht) * picwd_disp_def;
			
			
		}
		//alert("picwd_sm = "+picwd_sm+"\npicht_sm = "+picht_sm+"\npicwd_disp = "+picwd_disp+"\npicht_disp = "+picht_disp+"\n");
		flashID.SetVariable( "picwd_sm", picwd_sm);
		flashID.SetVariable( "picht_sm", picht_sm);
		flashID.SetVariable( "picwd_disp", picwd_disp);
		flashID.SetVariable( "picht_disp", picht_disp);
		
	}
	
	
	//alert("flashid = "+flashID);
	
	
	flashID.SetVariable( "pic_image", pic_image);
	flashID.SetVariable( "attach_img", 1);
	
	
	
	
}

function setCellnumArray(cellnum, itimnum){
	if((cellnum > 0)&&(itimnum > 0)){
		//cellnumIcidArray[cellnum] = i_c_id;
		cellnumItimnumArray[cellnum] = itimnum;
	}
	//alert('okay cellnum array is\n\njus added '+cellnum+' and itimnum = '+itimnum);
	
	
}



function setIcidArray(i_c_id, itimnum, tempcell, avatar, cellName){
	if(cellName.length > 0 ){
		var oldcname = cellName;
		var re = /'/;
		cellName = cellName.replace(re, "\$1");
		//alert('old = '+oldcname+' \nreplaced cellname =  '+cellName);
	}
	if((i_c_id > 0)&&(itimnum > 0)){
		icidArray[i_c_id] = itimnum;
		itimnumArray[itimnum] = i_c_id;
		icidAvatarArray[i_c_id] = avatar;
		cellnumIcidArray[i_c_id] = tempcell;
		icidCellNameArray[i_c_id] = cellName;
		//alert(" avatar array = "+avatar+"\n\ncellnamearr = "+cellName);
		setCellnumArray(tempcell, itimnum);
		addItimToolbar(itimnum, tempcell);
		//cellnumIcidArray[cellnum] = i_c_id;
		//cellnumItimnumArray[cellnum] = itimnum;
	}
	
	//alert('okay icid array is '+icidArray+'\n\njus added '+i_c_id+' and itimnum = '+itimnum);
	
	
	
}


function startItimBar(i_c_id){
	// check if fname is already open
	var remIndex;
	
	var curr_itimnum = icidArray[i_c_id];
	
	var fname = 'iTim_'+curr_itimnum;
	var box_id = "boxHandle"+curr_itimnum;
	if(curr_itimnum > 0){
		if((ie4)||(ie5)){
			var remIndex = findIndexOf(fname, currentFnameArray);
		}else{
			//var remIndex = currentItimWinArray.indexOf('boxHandle'+itimnum);
			var remIndex = currentFnameArray.indexOf(fname);
		}
		
		//remIndex = currentFnameArray.indexOf(fname);
		//remIndex= "25";
		//alert(" Found\narray = "+currentFnameArray+" and remindex = "+remIndex);
	}
	//alert('hey sonb '+remIndex+' and inm = '+curr_itimnum+'\narray = '+currentFnameArray);
	
	// check if fname is open
	
	if(remIndex >= 0){
			//alert('okay it exist = '+fname+' and box = '+box_id);
			itimWinToFocus(box_id, fname);
			
			
	}else{
		//alert('okay not exist = '+fname+' and box = '+box_id+'\n\n'+currentFnameArray);
		startItim(i_c_id);	
	}
	//alert('loading add pic itim = '+curr_itimnum);
	
	
}


function closeWinOpened(){
	
	if(winOpened != 'none'){
		removeDiv('backfade'); 
		removeDiv(winOpened); 
		winOpened = 'none';	
	}
}

function getFnameForIcid(i_c_id){
	var resFname;
	var selectIndex = currentFnameArray.length - 1;
	for(var i = 0; i < currentFnameArray.length; i++){
			var fname = currentFnameArray[i];
			var fnamearr = fname.split("_");
			var tempitimnum = fnamearr[1];
			var temp_i_c_id = itimnumArray[tempitimnum];
			if(i_c_id == temp_i_c_id){
				resFname = fname;	
				i = currentFnameArray.length;
				return resFname;
			}
	}
	return resFname;
}


function getFnameForIcidAndCheck(i_c_id){
	var resFname = "a";
	var selectIndex = currentFnameArray.length - 1;
	for(var i = 0; i < currentFnameArray.length; i++){
			var fname = currentFnameArray[i];
			var fnamearr = fname.split("_");
			var tempitimnum = fnamearr[1];
			var temp_i_c_id = itimnumArray[tempitimnum];
			if(i_c_id == temp_i_c_id){
				resFname = fname;	
				i = currentFnameArray.length;
				//send command to checknow to fname
				
				checkForNewMessageNow(resFname);
				//alert('just send New message to '+resFname);
				return resFname;
			}
	}
	return resFname;
}

function startItimAlert(temp_i_c_id, message, from, temp_mes_id, temp_msgdate){
	var itimalert = "alertItim_"+temp_i_c_id;
	topIndex++;
	
	//** really important try closing an alert like this one before opening, in case the same person sent another mes
	
	try {
		flashID = thisMovie(movieName);
	
		//alert("fadeflash flashid = "+flashID.id+" for "+window.document[movieName]+ " and name = "+movieName);
		flashID.SetVariable( "setbgalpha", alpha);
		flashID.SetVariable( "changebgalpha", 1);
	} catch (e) { //alert('error son - ')
	
	}
	var newFname = "a";
	if(temp_i_c_id > 0){
		newFname = getFnameForIcidAndCheck(temp_i_c_id);
		//alert(' Okay fname array = '+currentFnameArray+'\n\n and icid = '+temp_i_c_id+' and Fname = '+newFname+'\n\n');
	}
	//alert("crazy, u got "+i_c_id+" and flvpath = "+flvpath+" and sender = "+sender);
	//var newtop = 100;
	//var newleft = 200;
	//alert('>>> newfname = '+newFname);	
	if(newFname.length < 3){
		//alert('start alert newfname = '+newFname);
		showDiv('newMsgAllMain');
		if(alert_itim_newtop < top_spacer_limit){
			alert_itim_newtop = alert_itim_newtop + alert_itim_topspacer;	
			alert_itim_newleft = alert_itim_newleft + alert_itim_leftspacer;
			var newtop = alert_itim_newtop;
			var newleft = alert_itim_newleft;
		}else{
			alert_itim_newtop = 28 + alert_itim_topspacer;	
			alert_itim_newleft = 600 + alert_itim_leftspacer;		
			var newtop = alert_itim_newtop;
			var newleft = alert_itim_newleft;
		}
		//alert("new top = "+newtop);
		itimnum++;
		var itim2 = itimnum + 1;
		//var tempid = getElementById("tempBox");
		topIndex++;
		var fname = 'iTim_'+itimnum;
		var fid = 'iTim_'+itimnum;
		//var alertOut = "heloo";
		var alertOut = "<div id=\"showAlert_"+temp_i_c_id+"\" style=\"position:relative; width:240px; height:150px; border:#99CC00 1px none; background-image: url(images/alerts_bg.png); background-repeat:no-repeat; background-position:top; z-index:45; \" ><div style=\"height:15px;\">&nbsp;</div><div id=\"alertTitle\" style=\"color:#FFFFFF; text-align:center; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; width:180px; margin-left:25px; position:relative;\">Text from "+from+"</div><div id=\"alerttext\" style=\"color:#FFFFFF; font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; width:200px; margin-top:10px; margin-left:18px; height:20px; overflow:hidden;\">Says: "+message+"</div><div style=\"color:#FFFFFF; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; width:200px; margin-top:10px; margin-left:15px;\"><table height=\"35\" cellspacing=\"5\"><tr><td width=\"95\" align=\"center\" valign=\"middle\"><div id=\"closealert\" class=\"closeAlert\" onMouseDown=\"closeAlertArr("+temp_mes_id+",'1' ); closeDiv("+itimnum+");\">Close</div></td><td width=\"95\" align=\"center\" valign=\"middle\"><div id=\"closealert\" class=\"replyAlert\" onMouseDown=\"closeWinOpened(); startItimBar('"+temp_i_c_id+"');hideDiv('newMsgAllMain'); closeDiv("+itimnum+");\">Reply</div></td></tr></table></div><div id=\"showAlert_date_"+temp_i_c_id+"\" style=\"color:#FFFFFF; text-align:center; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:8px; width:180px; margin-left:25px; margin-top:-7px\">"+temp_msgdate+"</div></div>";
		
		//var content = "<div id=\"boxHandle"+itimnum+"\" class=\"box\"   onMouseDown=\"//itimWinToFocus(this.id, '"+fname+"')\" style=\"width:240px; height:150px; position: absolute; border:#ff3399 1px solid;  z-index:"+topIndex+"\"><div id='iTim_div_"+itimnum+"' style='position:relative; z-index:10;'>"+alertOut+"</div><div id=\"handle"+itimnum+"\" class=\"handle\"  style=\"width:390px; z-index:20; position:relative; top:-165px; border:#ccdd55 1px solid;  \">&nbsp;</div> </div>";
		var content = "<div id=\"boxHandle"+itimnum+"\" class=\"box\" style=\"width:240px; height:150px; position: absolute;  z-index:"+topIndex+"\"><div id='iTim_div_"+itimnum+"' style='position:relative; z-index:10; overflow:hidden;'>"+alertOut+"</div><div id=\"handle"+itimnum+"\" class=\"handle\"  style=\"width:240px; z-index:20; position:relative; height:50px; top:-135px; border:#ccdd55 0px solid; cursor:move;  \">&nbsp;</div> </div>";
		if(currentFnameArray.length > 0){
			var lastIndex = currentFnameArray.length - 1;
			//alert("Removing focus -- array = "+currentFnameArray);
			removeFlashFocus(currentFnameArray[lastIndex])
		}
		writeDivInDiv("iTimHolder"+itimnum, "midSection", content)
		//lastItimWin = currentItimWin
		//currentItimWin = "boxHandle"+itimnum
		
		
		
		
		
		//lastFname = currentFname
		//currentFname = fname
		
		//lastItimWin = currentItimWin
		//currentItimWinArray.push("iTim_div_"+itimnum)
		/**
		currentItimWinArray.push("boxHandle"+itimnum)
		//lastFname = currentFname
		currentFnameArray.push(fname)
		
		//alert("starting new array: "+currentFnameArray+"\narray: "+currentItimWinArray);
		if(currentFnameArray.length > 1){
			var pen = currentFnameArray.length - 2
			// second to the last item in array
			var lastFname = currentFnameArray[pen]
			//alert("ok removing focus in "+lastFname+" and penultimate ="+pen+" \narray: "+currentFnameArray)
			setOnfocus(lastFname, 0)
		}
		**/
		var boxHandle = document.getElementById("boxHandle"+itimnum)
		group = drag.createSimpleGroup(boxHandle, document.getElementById("handle"+itimnum))
		moveDiv('boxHandle'+itimnum, newtop, newleft)
		//addItimToolbar(itimnum)
		//alert("JUST SET mad focus uiyi");
		//setIcidArray(i_c_id, itimnum);
		document.getElementById("showAlert_"+temp_i_c_id).focus();
		
		
	}
	
}

//starts IM
function startItimIM(i_c_id){
		//alert('okay i am starting friend id '+i_c_id);
		startItimBar(i_c_id); 
		//hideDiv('new_alltim_50');   
		hideDiv('newMsgAllMain');
	
}

function startItim(i_c_id){
	//alert("crazy, u got "+i_c_id);
	//var newtop = 100;
	//var newleft = 200;
	
	
	if(itim_newtop < top_spacer_limit){
		itim_newtop = itim_newtop + itim_topspacer;	
		itim_newleft = itim_newleft + itim_leftspacer;
		var newtop = itim_newtop;
		var newleft = itim_newleft;
	}else{
		itim_newtop = 98 + itim_topspacer;	
		itim_newleft = 198 + itim_leftspacer;		
		var newtop = itim_newtop;
		var newleft = itim_newleft;
	}
	//alert("new top = "+newtop);
	itimnum++;
	var itim2 = itimnum + 1;
	//var tempid = getElementById("tempBox");
	topIndex++;
	var swf_vars = "'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','405','height','425','src','itim_0.1.0','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','itim_0.1.0', 'name', 'iTim_"+itimnum+"', 'id', 'iTim_"+itimnum+"', 'wmode', 'transparent','allowScriptAccess','sameDomain', 'swLiveConnect','true' ";
	var fvars = "i_c_id="+i_c_id+"&itimnum="+itimnum+"&winfocus=1&blinkingbarStatus=onfocus";
	var fname = 'iTim_'+itimnum;
	var fid = 'iTim_'+itimnum;
	//var swfOut = AC_FL_RunContent_uyi('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','405','height','425','src','itim_0.1.0','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','itim_0.1.0', 'name', fname, 'id', fid, 'wmode', 'transparent','allowScriptAccess','sameDomain', 'swLiveConnect','true','flashVars', fvars);
	
	var swfOut = AC_FL_RunContent_uyi('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','405','height','425','src', itimswf ,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie', itimswf, 'name', fname, 'id', fid, 'wmode', 'transparent','allowScriptAccess','sameDomain', 'swLiveConnect','true','flashVars', fvars);
	
	//alert("okay = fvars = "+fvars+ " and out = "+swfOut);
	//var content = "<div id=\"boxHandle"+itimnum+"\" class=\"box\"   onClick=\"itimWinToFocus(this.id, '"+fname+"')\" style=\"width:405px; height:435px; position: absolute;  z-index:"+topIndex+"\"><div id='iTim_div_"+itimnum+"' style='position:relative; z-index:10;'>"+swfOut+"</div><div id=\"handle"+itimnum+"\" class=\"handle\"  style=\"width:390px; z-index:20; position:relative; top:-425px;  \">&nbsp;</div> </div>";
	var content = "<div id=\"boxHandle"+itimnum+"\" class=\"box\"   onMouseDown=\"itimWinToFocus(this.id, '"+fname+"')\" style=\"width:405px; height:435px; position: absolute;  z-index:"+topIndex+"\"><div id='iTim_div_"+itimnum+"' style='position:relative; z-index:10;'>"+swfOut+"</div><div id=\"handle"+itimnum+"\" class=\"handle\"  style=\"width:390px; z-index:20; position:relative; top:-425px;  \">&nbsp;</div> </div>";
	if(currentFnameArray.length > 0){
		var lastIndex = currentFnameArray.length - 1;
		//alert("Removing focus -- array = "+currentFnameArray);
		removeFlashFocus(currentFnameArray[lastIndex])
	}
	writeDivInDiv("iTimHolder"+itimnum, "midSection", content)
	//lastItimWin = currentItimWin
	//currentItimWin = "boxHandle"+itimnum
	
	
	
	
	
	//lastFname = currentFname
	//currentFname = fname
	
	//lastItimWin = currentItimWin
	//currentItimWinArray.push("iTim_div_"+itimnum)
	currentItimWinArray.push("boxHandle"+itimnum)
	//lastFname = currentFname
	currentFnameArray.push(fname)
	
	//alert("starting new array: "+currentFnameArray+"\narray: "+currentItimWinArray);
	if(currentFnameArray.length > 1){
		var pen = currentFnameArray.length - 2
		// second to the last item in array
		var lastFname = currentFnameArray[pen]
		//alert("ok removing focus in "+lastFname+" and penultimate ="+pen+" \narray: "+currentFnameArray)
		setOnfocus(lastFname, 0)
	}
	
	var boxHandle = document.getElementById("boxHandle"+itimnum)
  	group = drag.createSimpleGroup(boxHandle, document.getElementById("handle"+itimnum))
	moveDiv('boxHandle'+itimnum, newtop, newleft)
	//addItimToolbar(itimnum)
	//alert("JUST SET mad focus uiyi");
	//setIcidArray(i_c_id, itimnum);
	thisMovie(fname).focus();
	//alert('loading add pic itim = '+itimnum);
	//loadAddPicture(itimnum);
	
	
}

/*
*
* set the class for the border when you put your mouse over a pic
*
*/

function showPicMouse(picId, mclass){
	//alert('hey changing id of '+picId);
	var picIdDiv = document.getElementById(picId);
	changeClass(picId, mclass);
}

	
	



function startVideo(i_c_id, flvpath, sender){
	var flvpath = "tim_video_flv/"+flvpath;
	
	//alert("crazy, u got "+i_c_id+" and flvpath = "+flvpath+" and sender = "+sender);
	//var newtop = 100;
	//var newleft = 200;
	
	
	if(itim_newtop < top_spacer_limit){
		itim_newtop = itim_newtop + itim_topspacer;	
		itim_newleft = itim_newleft + itim_leftspacer;
		var newtop = itim_newtop;
		var newleft = itim_newleft;
	}else{
		itim_newtop = 98 + itim_topspacer;	
		itim_newleft = 198 + itim_leftspacer;		
		var newtop = itim_newtop;
		var newleft = itim_newleft;
	}
	//alert("new top = "+newtop);
	itimnum++;
	var itim2 = itimnum + 1;
	//var tempid = getElementById("tempBox");
	topIndex++;
	var embedtext = "<div>Nice worku</div>";
	var linktext = escape("testing");
	var backtoitimtext = "Back to "+sender;
	var swf_vars = "'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','405','height','425','src','itim_0.1.0','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','itim_0.1.0', 'name', 'iTim_"+itimnum+"', 'id', 'iTim_"+itimnum+"', 'wmode', 'transparent','allowScriptAccess','sameDomain', 'swLiveConnect','true' ";
	var fvars = "i_c_id="+i_c_id+"&autobegin=1&itimnum="+itimnum+"&flvpath="+flvpath+"&embedtext="+embedtext+"&backtoitimtext="+backtoitimtext+"&linktext="+linktext+"&blinkingbarStatus=onfocus";
	var fname = 'iTim_'+itimnum;
	var fid = 'iTim_'+itimnum;
	//var swfOut = AC_FL_RunContent_uyi('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','405','height','425','src','itim_0.1.0','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','itim_0.1.0', 'name', fname, 'id', fid, 'wmode', 'transparent','allowScriptAccess','sameDomain', 'swLiveConnect','true','flashVars', fvars);
	
	var swfOut = AC_FL_RunContent_uyi('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','405','height','425','src', itimvidswf ,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie', itimvidswf, 'name', fname, 'id', fid, 'wmode', 'transparent','allowScriptAccess','sameDomain', 'swLiveConnect','true','flashVars', fvars);
	
	//alert("okay = fvars = "+fvars+ " and out = "+swfOut);
	//var content = "<div id=\"boxHandle"+itimnum+"\" class=\"box\"   onClick=\"itimWinToFocus(this.id, '"+fname+"')\" style=\"width:405px; height:435px; position: absolute;  z-index:"+topIndex+"\"><div id='iTim_div_"+itimnum+"' style='position:relative; z-index:10;'>"+swfOut+"</div><div id=\"handle"+itimnum+"\" class=\"handle\"  style=\"width:390px; z-index:20; position:relative; top:-425px;  \">&nbsp;</div> </div>";
	var content = "<div id=\"boxHandle"+itimnum+"\" class=\"box\"   onMouseDown=\"itimWinToFocus(this.id, '"+fname+"')\" style=\"width:405px; height:335px; position: absolute;  z-index:"+topIndex+"\"><div id='iTim_div_"+itimnum+"' style='position:relative; z-index:10;'>"+swfOut+"</div><div id=\"handle"+itimnum+"\" class=\"handle\"  style=\"width:390px; z-index:20; position:relative; top:-395px;  \">&nbsp;</div> </div>";
	if(currentFnameArray.length > 0){
		var lastIndex = currentFnameArray.length - 1;
		//alert("Removing focus -- array = "+currentFnameArray);
		removeFlashFocus(currentFnameArray[lastIndex])
	}
	writeDivInDiv("iTimHolder"+itimnum, "midSection", content)
	//lastItimWin = currentItimWin
	//currentItimWin = "boxHandle"+itimnum
	
	
	
	
	
	//lastFname = currentFname
	//currentFname = fname
	
	//lastItimWin = currentItimWin
	//currentItimWinArray.push("iTim_div_"+itimnum)
	currentItimWinArray.push("boxHandle"+itimnum)
	//lastFname = currentFname
	currentFnameArray.push(fname)
	
	//alert("starting new array: "+currentFnameArray+"\narray: "+currentItimWinArray);
	if(currentFnameArray.length > 1){
		var pen = currentFnameArray.length - 2
		// second to the last item in array
		var lastFname = currentFnameArray[pen]
		//alert("ok removing focus in "+lastFname+" and penultimate ="+pen+" \narray: "+currentFnameArray)
		setOnfocus(lastFname, 0)
	}
	
	var boxHandle = document.getElementById("boxHandle"+itimnum)
  	group = drag.createSimpleGroup(boxHandle, document.getElementById("handle"+itimnum))
	moveDiv('boxHandle'+itimnum, newtop, newleft)
	//addItimToolbar(itimnum)
	//alert("JUST SET mad focus uiyi");
	//setIcidArray(i_c_id, itimnum);
	thisMovie(fname).focus();
	
	
	
}


function startItimInit(i_c_id){
	//alert("crazy, u got "+i_c_id);
	var newtop = 50;
	var newleft = 220;
	itimnum++;
	
	var itim2 = itimnum + 1;
	var bbar = "onfocus";
	//var tempid = getElementById("tempBox");
	topIndex++;
	var swf_vars = "'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','405','height','425','src','itim_0.1.0','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','itim_0.1.0', 'name', 'iTim_"+itimnum+"', 'id', 'iTim_"+itimnum+"', 'wmode', 'transparent','allowScriptAccess','sameDomain', 'swLiveConnect','true' ";
	var fvars = "i_c_id="+i_c_id+"&itimnum="+itimnum+"&winfocus=1&blinkingbarStatus=onfocus";
	var fname = 'iTim_'+itimnum;
	
	//alert("New itimnum "+itimnum+" and fname = "+fname);
	var fid = 'iTim_'+itimnum;
	var swfOut = AC_FL_RunContent_uyi('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','405','height','425','src', itimswf,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie', itimswf, 'name', fname, 'id', fid, 'wmode', 'transparent','allowScriptAccess','sameDomain', 'swLiveConnect','true','flashVars', fvars);
	//alert("okay = fvars = "+fvars+ " and out = "+swfOut);
	//var content = "<div id=\"boxHandle"+itimnum+"\" class=\"box\"   style=\"width:405px; height:435px; position: absolute;  z-index:"+topIndex+"\"><div id='iTim_div_"+itimnum+"' onClick=\"itimWinToFocus(this.id, '"+fname+"')\" style='position:relative; z-index:10;'>"+swfOut+"</div><div id=\"handle"+itimnum+"\" class=\"handle\"  style=\"width:390px; z-index:20; position:relative; top:-425px;  \">&nbsp;</div> </div>";
	var content = "<div id=\"boxHandle"+itimnum+"\" class=\"box\" onMouseDown=\"itimWinToFocus(this.id, '"+fname+"')\" style=\"width:405px; height:435px; position: absolute;  z-index:"+topIndex+"\"><div id='iTim_div_"+itimnum+"' style='position:relative; z-index:10;'>"+swfOut+"</div><div id=\"handle"+itimnum+"\" class=\"handle\"  style=\"width:390px; z-index:20; position:relative; top:-425px;  \">&nbsp;</div> </div>";
	
	
	writeDivInDiv("iTimHolder"+itimnum, "midSection", content)
	//lastItimWin = currentItimWin
	
	currentItimWinArray.push("boxHandle"+itimnum)
	//currentItimWinArray.push("iTim_div_"+itimnum)
	//lastFname = currentFname
	currentFnameArray.push(fname)
	//alert("first INIT array: "+currentFnameArray+"\narray: "+currentItimWinArray);
	 var boxHandle = document.getElementById("boxHandle"+itimnum)
  	group = drag.createSimpleGroup(boxHandle, document.getElementById("handle"+itimnum))
	moveDiv('boxHandle'+itimnum, newtop, newleft)
	//alert("JUST SET mad focus uiyi " +itimnum);
	//addItimToolbar(itimnum)
	//setIcidArray(i_c_id, itimnum)
	thisMovie(fname).focus();
	//alert('INIT loading add pic itim = '+itimnum);
	//loadAddPicture(itimnum);
	
	//alert("2 starting new array: "+currentFnameArray+"\narray: "+currentItimWinArray);
}

function writeDivInDiv(newDivId, hostDivId, content){
	var tempDiv =document.createElement("div")
	tempDiv.setAttribute("id", newDivId)
	document.getElementById(hostDivId).appendChild(tempDiv)
	//alert(" create div = "+newDivId+" in div = "+hostDivId);
	writeDiv(newDivId, content);
	
	
}


function removeDivInDiv(divId, hostDivId) {
  var d = document.getElementById(hostDivId);
  
  var olddiv = document.getElementById(divId);
  
  //alert("removing id = "+olddiv.id+ " from host "+d.id);
  if(d.hasChildNodes()){
  	d.removeChild(olddiv);
  }
}


function showPhoto(url){
	alert('showing photo = '+url);	
	
}

function showPhoto(user_id){
	alert('AGet photo for id='+user_id);	
	
}

function muteAll2(movieName){
	flashID = thisMovie(movieName);
	//alert("flashid = "+flashID);
	flashID.SetVariable( "uyitest", 1);

	
}

function checkForNewMessageNow(movieName){
	
	flashID = thisMovie(movieName);
	//alert("flashid = "+flashID);
	flashID.getNewMessageNow();


	
}

function fadeFlashBG(movieName, alpha){
	//alert("about to fade movieName - "+movieName);
	
	//sometimes it is trying to fade a non flash swf
	try {
			flashID = thisMovie(movieName);
		
			//alert("fadeflash flashid = "+flashID.id+" for "+window.document[movieName]+ " and name = "+movieName);
			flashID.SetVariable( "setbgalpha", alpha);
			flashID.SetVariable( "changebgalpha", 1);
		} catch (e) { //alert('error son - ')
		
		}
	/**
		flashID = thisMovie(movieName);
		
		alert("fadeflash flashid = "+flashID.id+" for "+window.document[movieName]+ " and name = "+movieName);
		flashID.SetVariable( "setbgalpha", alpha);
		flashID.SetVariable( "changebgalpha", 1);
	**/

	
}

function setOnfocus(movieName, is_on_focus){
	flashID = thisMovie(movieName);
	
	//alert("set on focus flashid = "+flashID.id+" for "+window.document[movieName]+ " and name = "+movieName);
	if(is_on_focus == 1){
		var blinkingbarStatus = "onfocus";
		var winfocus = 1;
	}else{
		var blinkingbarStatus = "nofocus";
		var winfocus = 0;
		
	}
	//flashID.SetVariable( "blinkingbarStatus", blinkingbarStatus);
	flashID.SetVariable( "winfocus", winfocus);
	

	
}

// This removes the flashing top bar when the window is set in focus after receiveing a message
function removeFlashAlertNewmes(movieName){
	//alert("JUST SET mad focus uiyi newmes");
	flashID = thisMovie(movieName);
	var blinkingbarStatus = "onfocus";
	var winfocus = 1;
	var changeWinfocus = 1;
	flashID.SetVariable( "alertNewmes", 0);
	//flashID.SetVariable( "blinkingbarStatus", blinkingbarStatus);
	flashID.SetVariable( "winfocus", winfocus);
	flashID.SetVariable( "changeWinfocus", changeWinfocus);
}

// This removes the flashing top bar when the window is set in focus after receiveing a message
function removeFlashFocus(movieName){
	//alert("removing flash focus hey movie name = "+movieName);
	if(movieName){
		//alert("--> Movie exists = "+movieName);
		flashID = thisMovie(movieName);
		var blinkingbarStatus = "nofocus";
		var winfocus = 0;
		var changeWinfocus = 1;
		//alert("--> Movie exists = "+movieName+ " and changewinfocus = "+changeWinfocus);
		flashID.SetVariable( "alertNewmes", 0);
		//flashID.SetVariable( "blinkingbarStatus", blinkingbarStatus);
		flashID.SetVariable( "winfocus", winfocus);
		flashID.SetVariable( "changeWinfocus", changeWinfocus);
	}
}


function itimWinToFocus(id, movieName){
	
	// Make it the top index
	//alert(" you clicked id = "+id+"\n moviename = "+movieName);
	
	var lastIndex = currentItimWinArray.length - 1; 
	//alert(" you clicked id = "+id+"\narry="+currentItimWinArray[lastIndex]+"\n BCOS array: "+currentItimWinArray+"\n moviename = "+movieName);
	if(currentItimWinArray[lastIndex] != id){
		//alert("currentItim was = "+currentItimWinArray[lastIndex]+" and new id = "+id+" and lastFname = "+currentFnameArray[lastIndex]+"\n\nArray = "+currentItimWinArray+" and count ="+lastIndex)
		removeFlashFocus(currentFnameArray[lastIndex])
		var elem = document.getElementById(id)
		topIndex++
		elem.style.zIndex = topIndex
		//currentItimWin = id;
		
		removeFlashAlertNewmes(movieName)
		//removeFlashFocus(currentFnameArray[lastIndex], 0)
		
		if((ie4)||(ie5)){
			var remIndex = findIndexOf(id, currentItimWinArray);
		}else{
			//var remIndex = currentItimWinArray.indexOf('boxHandle'+itimnum);
			var remIndex = currentItimWinArray.indexOf(id);
		}
		
		//var remIndex = currentItimWinArray.indexOf(id);
		if(remIndex >= 0){
			currentItimWinArray.splice(remIndex, 1);
			currentFnameArray.splice(remIndex, 1);
			
			
		}
		//itimWinToFocus(id, movieName)
		currentItimWinArray.push(id)
		//lastFname = currentFname
		currentFnameArray.push(movieName)
		// set focus
		//alert("settgin focus son");
		thisMovie(movieName).focus();
		
		
		
		
		// remove newmsg if it exists on this itim
		var fnamearr = movieName.split("_");
		var tempitimnum = fnamearr[1];
		removeNewMsg(tempitimnum);
		
		
		//change the toolbar class
		//alert('setting class');
		var divId = "bar_"+movieName;
		setItimClass(divId, tempitimnum);
		
	
	
	
	
	
	}
	// stop blinking favicon
	if(favNewMes == 1){
		favNewMes = 0;
		favicon.change("favicons/favicon_4.ico", "iTim World -  Send and Receive Text Messages Online - And Instant Messenger");
	}
	
	//alert("JUST SET mad focus uiyi itimwin focua");
	thisMovie(movieName).focus();
	//alert(" you clicked id = "+id+"\n moviename = "+movieName+' and loading = '+tempitimnum);
	//loadAddPicture(tempitimnum);
}


/**
*
* this mutes all the itims in the 
*
*/
function muteAlliTims(){
	
	
	
	if(currentFnameArray.length > 0){
		
		var content = '<a href="javascript:void(0)" onClick="unmuteAlliTims();" title="UnMute All iTims"><img src="../icons_main/sound.png" alt="Mute All iTims" width="16" height="16" border="0"></a>	';
		writeDiv('muteallicon', content);
		for(var i = 0; i < currentFnameArray.length; i++){
	
			var movieName = currentFnameArray[i];
			//alert("fname array = "+currentFnameArray+"\n\nfname = "+movieName);
			//alert("Removing focus -- array = "+currentFnameArray);
			muteAll(movieName);
		}
	
	}
		
	
	
	
		
		
		
	
	
	
}


/**
*
* this unmutes all the itims in the 
*
*/
function unmuteAlliTims(){
	if(currentFnameArray.length > 0){
		
		var content = '<a href="javascript:void(0)" onClick="muteAlliTims();" title="Mute All iTims"><img src="../icons_main/sound_mute.png" alt="Mute All iTims" width="16" height="16" border="0"></a>	';
		writeDiv('muteallicon', content);
		
		for(var i = 0; i < currentFnameArray.length; i++){
	
			var movieName = currentFnameArray[i];
			//alert("fname array = "+currentFnameArray+"\n\nfname = "+movieName);
			unmuteAll(movieName);
		}
		
		
	}
	
	
	
	
}


function muteAll(movieName){
	flashID = thisMovie(movieName);
	//alert("flashid = "+flashID);
	flashID.muteSoundAlert();

	
}

function unmuteAll(movieName){
	flashID = thisMovie(movieName);
	flashID.unmuteSoundAlert();

	
}

function thisMovie(movieName) {
	//alert('your browser is '+navigator.appName);
    var flash_id;
	
	if (navigator.appName.indexOf("Microsoft") != -1) {
        flash_id = window[movieName]
    }
    else {
        flash_id = document[movieName]
    }
	
	// did below because flash_id is sometimes and array of objects (nodelist) instead of an object, so we get the last value or index[1]
	// thats because first element in the nodeList is the OBJECT, the second is the EMBED
	var tempflashID = flash_id;
	if((tempflashID.length > 0)&&(flash_id.id == undefined)){
		for(var i = 0; i < tempflashID.length; i++){
			
			//alert("Now we have item = "+tempflashID[i].id + " and tempid = "+tempflashID.id);	
			if((tempflashID.id == undefined)&&(tempflashID[i].id != undefined)){
				flash_id = tempflashID[i];
				//i = tempflashID.length;
				
			}
		}
		
	}
	return flash_id;
	
}
//removes div and changes content of  cid
function removeDivContent (id, cid, content)
{
	var newDiv=document.getElementById(id);
	var newStyle=newDiv.style;
	newStyle.top = "-2000px";
	newStyle.visibility = "hidden";
	var newcDiv=document.getElementById(cid);
	newcDiv.innerHTML = content;
}

function loadBackfade()
{
	var id = "backfade";
	var sTop = 0;	
	sTop = document.body.scrollTop;
	var newtop = 0 + sTop;
	var newleft = 0;
	//alert("hey backfade");
	//var wd = document.getElementById('banner').offsetWidth;
	var wd = document.getElementById('pagetop').offsetWidth;
	var ht = getScreenHeight();
	var newDiv=document.getElementById(id);
	var newStyle=newDiv.style;
	//alert("about to show menu for "+id+" and var = "+newDiv);
	if((ie4)||(ie5)){
		wd = wd - iescrollwd;
		ht = ht - iescrollht;
	}
	//alert('width = '+wd+' and ht = '+ht);
	newStyle.top=newtop +"px";
	newStyle.left=newleft +"px";
	newStyle.width=wd +"px";
	newStyle.height=ht +"px";
	//topZ++;
	//newStyle.zIndex = topZ;
	
	topIndex++;
	newStyle.zIndex = topIndex;
	newStyle.visibility = "visible";	
	
	
}



function getElementHeight(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op6) { 
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	} 
}

function getElementWidth(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.width;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op6) {
			xPos = elem.style.pixelWidth;
		} else {
			xPos = elem.offsetWidth;
		}
		return xPos;
	}
}


function getScreenWidth(){
	var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  return myWidth;
}

function getScreenHeight(){
	var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  return myHeight;
}

function resizeMonitor(){
	resizeMidSection();
	
}

function init_iTimpage(){
	
	//alert('ht = '+midElem);
	orig_midHt = getElementHeight(midElem);
	
	
	
	resizeMidSection();
	
	
}

function resizeMidSection(){
	var sHt;
	var topHt;
	var midHt;
	var footerHt;
	
	
	var sHt = getScreenHeight();
	
	
	
	//alert("okay top = "+topElem.id);
	var topHt = getElementHeight(topElem);
	var footerHt = getElementHeight(footElem);
	//var midHt = getElementHeight(midElem);
	
	var tempMid = sHt - (topHt + footerHt);
	var midHt = getElementHeight(midElem);
	//move the footer down by increasing the middle one
	if(tempMid > orig_midHt){
		var newHt = sHt - (topHt + footerHt);
		document.getElementById("midTable").style.height = newHt + "px";
		//alert('new heit = '+newHt);
	}
	
	//alert(' okey midHt = '+midHt+' and tempMid = '+tempMid); 
	//move the footer down by increasing the middle one
	if(tempMid > midHt){
		var newHt = sHt - (topHt + footerHt);
		document.getElementById("midTable").style.height = newHt + "px";
		//alert('new heit = '+newHt);
	}
	
	//alert("uyi just resize = Screen ="+sHt+" and tempMid = "+tempMid+ " bcos topHt = "+topHt+" and footer = "+footerHt+ "  and midHt = "+midHt+" --  so we resized mid to "+document.getElementById("midTable").style.offsetHeight);
}



	
function moveDivCenter(id){
	var ht = getScreenHeight();
	//alert(" B4 winOpended = "+winOpened);
	
	if(id != 'loadingX'){		//No need to add the progress report.... it is removed when loading is completed
		winOpened = id;
	}
	//var myHt = document.getElementById(id).scrollHeight;
	var wd = getScreenWidth();
	var sTop = 0;
	sTop = document.body.scrollTop;
	
	var myHt = document.getElementById(id).offsetHeight/2;
	var newtop = sTop + (ht/2) - (document.getElementById(id).offsetHeight/2);
	//alert("top = "+sTop+" and newtop = "+newtop);
	var newleft = (wd/2) - (document.getElementById(id).offsetWidth/2);
	//topZ++;
	topIndex++;
	document.getElementById(id).style.zIndex = topIndex;
	moveDiv(id, newtop, newleft);
	//document.getElementById('new_pwd').focus();
	//alert(" after winOpended = "+winOpened);
	
	
}


function wCenter(id){
	var ht = getScreenHeight();
	//alert(" B4 winOpended = "+winOpened);
	
	//var myHt = document.getElementById(id).scrollHeight;
	var wd = getScreenWidth();
	var myHt = document.getElementById(id).offsetHeight/2;
	var newtop = document.getElementById(id).offsetTop;
	var newleft = (wd/2) - (document.getElementById(id).offsetWidth/2);
	//topZ++;
	//document.getElementById(id).style.zIndex = topZ;
	moveDiv(id, newtop, newleft);
	//alert(" newleft = "+newleft+" and width = "+wd+" and top = "+newtop);
	
	
}

//This captures key pressed events

function keyPressHandler(e) {
  var kC  = (window.event) ?    // MSIE or Firefox?
			 event.keyCode : e.keyCode;
  var Esc = (window.event) ?   
			27 : e.DOM_VK_ESCAPE // MSIE : Firefox
  if(kC==Esc){
	 //alert("Esc pressed and kC = "+kC+" and winopened = "+winOpened);
	 if((winOpened != "none")&&(winOpened != "")){
		removeDiv('backfade'); 
		
		if(winOpened == 'changeProfile'){
			reset_pro_oldvalues();
		}else if(winOpened == 'changeLocation'){
			reset_addr_oldvalues();
		}else if(winOpened == 'changeAvatar'){
			reset_img_oldvalues();
		}
		removeDiv(winOpened);
		winOpened = "none";
	 }
  }else{
	  //alert(" You pressed "+kC);
  }
}

function writeDiv(divId, content){
	//alert("div id = "+divId);
	el = document.getElementById(divId);
	el.innerHTML = content;	
	
	
}



/**
*
*	basic ajax url call, no var or functions are called
*
*/
function ajaxGetUrlBasicComment(url, loadingComment, writeError, errorDiv){
	var xml_file = url;
	var percent = '...5%';
	writeDiv('loadingdiv', loadingComment+percent);
	//moveDiv('loadingX', '280', '390'); 
	moveDivCenter('loadingX');
	//switchZ('loadingX');
	setTimeout('removeDiv(\'loadingX\')', 10000);
	//alert("this is the url "+xml_file);
	
	var predivId = "preload_img";
	if (document.getElementById) {
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
		
	}else{
		//alert("No X connection here");
	}
	if (x){
		
		x.onreadystatechange = function(){
		
			//alert('we have x '+x.readyState);
			
			if(x.readyState == 1){
				percent = '...25%';
				writeDiv('loadingdiv', loadingComment+percent);
			}else if(x.readyState == 2){
				percent = '...45%';
				writeDiv('loadingdiv', loadingComment+percent);
			}else if(x.readyState == 3){
				percent = '...75%';
				writeDiv('loadingdiv', loadingComment+percent);
					
			}
				
			
			if (x.readyState == 4 && x.status != 200){
				//alert('connection lost');
			}else if (x.readyState == 4 && x.status == 200){
				//alert(" okay loaded your image - "+xml_file);
				//el = document.getElementById(predivId);
				//el.innerHTML = x.responseText;
				
				var content = x.responseText;
				percent = '...100%';
				writeDiv('loadingdiv', loadingComment+percent);
				//el = document.getElementById('loadingdiv');
				//el.innerHTML = "Loading COMPLETE";
				//alert('this is content '+el.innerHTML);
				//var img_sn_div = document.getElementById('load_image_by_sn');
				//img_sn_div.innerHTML = content;
				if(writeError == 1){
					error_el = document.getElementById(errorDiv);
					error_el.innerHTML = x.responseText;
					setTimeout('writeDiv(\''+errorDiv+'\', \'\')', 5000);
					
				}
				
				setTimeout('removeDiv(\'loadingX\')', 1000);
				removeDiv('backfade');
				//removeDiv('loadingX');
				//alert("con = "+content);
				
				//return content;
				//removeDiv('loadingX');
			}else{
				//alert('readystate = '+x.readyState);
			}
		}
		x.open("GET", xml_file, true);
		x.send(null);
	}
	
}




/**
*
* 	this sets the vars return eg url return &camera_pic=test+2.jpg&cool=me&
*	it sets it like flash eg camera_pic = "test 2.jpg", var cool = "me";
*
*/

function ajaxGetUrlSetVarsFunc(url, func){
	var xml_file = url;
	
	//var predivId = "preload_img";
	if (document.getElementById) {
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
		
	}else{
		//alert("No X connection here");
	}
	if (x){
		//alert('we have x '+x);
		x.onreadystatechange = function(){
			if (x.readyState == 4 && x.status == 200){
				//alert(" okay loaded your image - "+xml_file);
				//el = document.getElementById(predivId);
				//alert("output = " + x.responseText);
				var strvars = x.responseText.split("&");
				var re = /\s+/;
				//alert( "strvars = ---"+strvars+"--- and the len = "+strvars.length);
				
				for(var j = 0; j < strvars.length; j++){
					//alert(" j is ="+j+" and str = "+strvars[j]);
					if(strvars[j] != ""){
						
						strvars[j] = strvars[j].replace(re, "");
						var pairs = strvars[j].split("=");
						pairs[1] = unescape(pairs[1]);
						//alert("strvars - setting: "+pairs[0]+" = "+pairs[1]+";");
						if(pairs[0] != ""){
							eval(pairs[0]+" = '"+pairs[1]+"';");
						}
						//alert("camera pic = "+camera_pic+" and b4 = "+pairs[1]);
					}
						
					
				}
				
				if(func !=  ""){
					//alert("runiing func = "+func);
					eval(func+"();");
				}else{
					//alert("No func = "+i_c_id);	
				}
				
				//setTimeout('removeDiv(\'loadingX\')', 1000);
				//removeDiv('loadingX');
				//alert("con = "+content);
				
				//return content;
				//removeDiv('loadingX');
			}else{
				//alert('readystate = '+x.readyState);
			}
		}
		x.open("GET", xml_file, true);
		x.send(null);
	}
	
	
	
	
}




/**
*
* 	this sets the vars return eg url return &camera_pic=test+2.jpg&cool=me&
*	it sets it like flash eg camera_pic = "test 2.jpg", var cool = "me";
*
*/

function ajaxGetUrlSetVars(url){
	var xml_file = url;
	
	//var predivId = "preload_img";
	if (document.getElementById) {
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
		
	}else{
		//alert("No X connection here");
	}
	if (x){
		//alert('we have x '+x);
		x.onreadystatechange = function(){
			if (x.readyState == 4 && x.status == 200){
				//alert(" okayf loaded your image - "+xml_file);
				//el = document.getElementById(predivId);
				//alert("output = " + x.responseText);
				var strvars = x.responseText.split("&");
				//alert( "strvars = "+strvars+" and the len = "+strvars.length);
				
				for(var j = 0; j < strvars.length; j++){
					//alert(" j is ="+j+" and str = "+strvars[j]);
					if(strvars[j] != ""){
						var pairs = strvars[j].split("=");
						pairs[1] = unescape(pairs[1]);
						//alert("strvars = "+pairs[0]+" = "+pairs[1]+";");
						eval(pairs[0]+" = '"+pairs[1]+"';");	
						//alert("camera pic = "+camera_pic+" and b4 = "+pairs[1]);
					}
						
					
				}
				//setTimeout('removeDiv(\'loadingX\')', 1000);
				//removeDiv('loadingX');
				//alert("con = "+content);
				
				//return content;
				//removeDiv('loadingX');
			}else{
				//alert('readystate = '+x.readyState);
			}
		}
		x.open("GET", xml_file, true);
		x.send(null);
	}
	
	
	
	
}



/** 
*
*	this gets a url and then runs the function using array of varArr as inputs 
*
*	Example:
*	var varArr = new Array("98", "divId");
*	var func = "getDiv"
*	where function getDiv(num, divName){....
*/


function ajaxGetUrlRunFunction(url, func, varArr, useOutput){
	var xml_file = url;
	
	//var predivId = "preload_img";
	if (document.getElementById) {
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
		
	}else{
		//alert("No X connection here");
	}
	if (x){
		//alert('we have x '+x);
		x.onreadystatechange = function(){
			if (x.readyState == 4 && x.status == 200){
				//alert(" okay loaded your image - "+xml_file);
				//el = document.getElementById(predivId);
				//el.innerHTML = x.responseText;
				if(varArr.length > 0){
					var funcvars = varArr.join(", ");		
				}else if(useOutput == 1){
					var funcvars = x.responseText;	
				}
				
				//alert(" ok icid = "+i_c_id);
				if(funcvars != ""){
					eval(func+"("+funcvars+");");
				}else{
					//alert("No icid = "+funcvars);	
				}
				//setTimeout('removeDiv(\'loadingX\')', 1000);
				//removeDiv('loadingX');
				//alert("con = "+content);
				
				//return content;
				//removeDiv('loadingX');
			}else{
				//alert('readystate = '+x.readyState);
			}
		}
		x.open("GET", xml_file, true);
		x.send(null);
	}
	
}


/**
*
*	ajaxgeturlandfunc runs a the url and gets the output then runs the function using the output from the url as the var for the function
*
*/


function ajaxGetUrlAndFunc(url, func){
	var xml_file = url;
	//writeDiv('loadingdiv', 'Loading Images...');
	//moveDiv('loadingX', '280', '390'); 
	//moveDivCenter('loadingX');
	//switchZ('loadingX');
	//setTimeout('removeDiv(\'loadingX\')', 10000);
	//alert("this is the url "+xml_file);
	
	var predivId = "preload_img";
	if (document.getElementById) {
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
		
	}else{
		//alert("No X connection here");
	}
	if (x){
		//alert('we have x '+x);
		x.onreadystatechange = function(){
			if (x.readyState == 4 && x.status != 200){
				
				if(lostConnection == 4){
					lostConnection = 0;
					alert("Internet Connection Lost.\nPlease Check your connection. Thanks ;)  "+x.status);
				}else{
					if(lostConnection > -1){
						
						lostConnection++;
					}else{
						lostConnection = 0;	
					}
					
				}
			}else if (x.readyState == 4 && x.status == 200){
				//alert(" okay loaded your image - "+xml_file);
				//el = document.getElementById(predivId);
				//el.innerHTML = x.responseText;
				lostConnection = 0;
				var tempoutputstr = x.responseText;
				var outputstrArr = tempoutputstr.split('&EOF');		//we need eof because responsetext adds spaces to the end
				var outputstr = outputstrArr[0];
				//var evalstr = 'alert("'+outputstr+'");';
				//alert('evelstr = '+evalstr);
				//var fullName = 'Joe';
   				//var mySentence = eval('"My name is " + fullName;');
				//eval(evalstr);
				
				//var outputstr = "&newmes_0=41-_-_-5628893802-_-_-1-_-_-11-_-_-Jan 16, 2009-_-_-01:21 PM-_-_-975-_-_-5628893802-_-_-Yes-_-_-:_._._:&friend_0=8-_-_-Daddy-_-_-avatars/daddy_sm.jpg-_-_-0-_-_-7-_-_-47&friend_1=1-_-_-Money+Penny-_-_-avatars/avatar2.jpg-_-_-0-_-_-2-_-_-1";
				
				
				//alert('output = '+outputstr);
				
				eval(func+"('"+outputstr+"');");
				
				//setTimeout('removeDiv(\'loadingX\')', 1000);
				//removeDiv('loadingX');
				//alert("con = "+content);
				
				//return content;
				//removeDiv('loadingX');
			}else{
				//alert('readystate = '+x.readyState);
			}
		}
		x.open("GET", xml_file, true);
		x.send(null);
	}
	
}





function ajaxGetUrlFunction(url, func, varArr){
	var xml_file = url;
	//writeDiv('loadingdiv', 'Loading Images...');
	//moveDiv('loadingX', '280', '390'); 
	//moveDivCenter('loadingX');
	//switchZ('loadingX');
	//setTimeout('removeDiv(\'loadingX\')', 10000);
	//alert("this is the url "+xml_file);
	
	var predivId = "preload_img";
	if (document.getElementById) {
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
		
	}else{
		//alert("No X connection here");
	}
	if (x){
		//alert('we have x '+x);
		x.onreadystatechange = function(){
			if (x.readyState == 4 && x.status == 200){
				//alert(" okay loaded your image - "+xml_file);
				//el = document.getElementById(predivId);
				//el.innerHTML = x.responseText;
				
				var i_c_id = x.responseText;
				//alert(" ok icid = "+i_c_id);
				if(i_c_id > 0){
					eval(func+"("+i_c_id+");");
				}else{
					alert("No icid = "+i_c_id);	
				}
				//setTimeout('removeDiv(\'loadingX\')', 1000);
				//removeDiv('loadingX');
				//alert("con = "+content);
				
				//return content;
				//removeDiv('loadingX');
			}else{
				//alert('readystate = '+x.readyState);
			}
		}
		x.open("GET", xml_file, true);
		x.send(null);
	}
	
}


function ajaxGetUrl(url){
	var eofurl = 0;
	var xml_file = url;
	writeDiv('loadingdiv', 'Loading...');
	//moveDiv('loadingX', '280', '390'); 
	moveDivCenter('loadingX');
	el = document.getElementById('loadingdiv');
	//el.innerHTML = "Loading...";
	//switchZ('loadingX');
	
	//setTimeout('removeDiv(\'loadingX\')', 10000);
	//alert("this is the url "+xml_file+"\n\na_uid = "+currAlertId);
	
	var predivId = "preload_img";
	if (document.getElementById) {
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
		
	}else{
		//alert("No X connection here");
	}
	if (x){
		//alert('we have x '+x);
		x.onreadystatechange = function(){
			if (x.readyState == 4 && x.status == 200){
				//alert(" okay loaded your image - "+xml_file);
				//el = document.getElementById(predivId);
				//el.innerHTML = x.responseText;
				
				var content = x.responseText;
				
				el = document.getElementById('loadingdiv');
				//el.innerHTML = "Loading...";
				
				//var avatar_el = document.getElementById('avatar');
				//avatar_el.innerHTML = "<img src=\""+avatar_new+"\" alt=\"avatar\" width=\"92\" height=\"92\" style=\"border:#000000 1px solid; margin-right:10px;\">";
				
				//removeDiv('loadingX');
				//alert("con = "+content);
				if(winOpened != "none"){
					//alert('winopened = '+winOpened);
					if(winOpened == 'changeProfile'){
						if(content.indexOf("updated") == 0){
							nickname_js = nickname_new;
							firstname_js = fname_new;
							lastname_js = lname_new;
							dphone_js = dphone_new;
							email_js = email_new;	
							el.innerHTML = "<strong>Saving Complete</strong>";
							setTimeout('removeDiv(\'loadingX\')', 1000);
							setTimeout('removeDiv(\'backfade\')', 1000);
							setTimeout('removeDiv(\''+winOpened+'\')', 1000);
							winOpened = "none";
							//alert(" loading complete - "+content+" and firstname = "+firstname_js);
						}else if(content.indexOf("cell_not_num") == 0){
							el.innerHTML = "<strong><font color=\"#FF0000\">Invalid cellphone number</font></strong>";
							setTimeout('removeDiv(\'loadingX\')', 1000);
							alert("Please enter a numeric cellphone number \nEx: 3105551212");
							document.profile_form.defphone.focus();
							document.profile_form.defphone.select();
						}else if(content.indexOf("taken_nick") == 0){
							el.innerHTML = "<strong><font color=\"#FF0000\">Nickname taken</font></strong>";
							setTimeout('removeDiv(\'loadingX\')', 1000);
							alert("Sorry, "+nickname_new+" is already taken\nPlease choose another nickname.");
							document.profile_form.nickname.focus();
							document.profile_form.nickname.select();
						}
					}else if(winOpened == 'changeLocation'){
						if(content.indexOf("updated") == 0){
							home_address = address_new;
							home_city = city_new;
							home_state = state_new;
							home_zip = zip_new;
							var newAddr = document.addr_form.address_hm.value+" "+document.addr_form.home_city.value+" "+document.addr_form.home_state.value+" "+document.addr_form.home_zip.value;
							writeNewMap(newAddr);
							el.innerHTML = "<strong>Saving Complete</strong>";
							setTimeout('removeDiv(\'loadingX\')', 5000);
							setTimeout('removeDiv(\'backfade\')', 5000);
							setTimeout('removeDiv(\''+winOpened+'\')', 5000);
							winOpened = "none";
							//alert(" loading complete - "+content+" and firstname = "+home_address);
						}else if(content.indexOf("invalid") == 0){
							el.innerHTML = "<strong><font color=\"#FF0000\">Address Not Found</font></strong>";
							setTimeout('removeDiv(\'loadingX\')', 1000);
							alert("your address was not found \nPlease re-enter your address");
							document.addr_form.address_hm.focus();
							
						}
					}else if(winOpened == 'changeAvatar'){
						if(content.indexOf("no_avatar") == 0){
							el.innerHTML = "<strong><font color=\"#FF0000\">No Avatar was uploaded</font></strong>";
							setTimeout('removeDiv(\'loadingX\')', 1000);
							alert("No Image was added.\n Please Try Again");
						}else{
							el.innerHTML = "<strong>Saving Complete</strong>";
							avatar_js = content;
							//alert('avatar = '+avatar_js+' and content = '+content);
							avatar_el = document.getElementById('avatar');
							avatar_el.innerHTML = "<a href=\"javascript:void(0)\" onClick=\"loadBackfade(); img_oldvalues();  moveDivCenter('changeAvatar');  getSocialImages();\" ><img src=\""+avatar_js+"\" alt=\"avatar\" width=\"92\" height=\"92\" style=\"border:#000000 1px solid; margin-right:10px;\"></a>";
							setTimeout('removeDiv(\'loadingX\')', 1000);
							setTimeout('removeDiv(\'backfade\')', 1000);
							setTimeout('removeDiv(\''+winOpened+'\')', 1000);
							winOpened = "none";
						}
					}else if(winOpened == 'changePwd'){
						if(content.indexOf("updated") == 0){
							el.innerHTML = "<strong>Saving Complete</strong>";
							setTimeout('removeDiv(\'loadingX\')', 1000);
							setTimeout('removeDiv(\'backfade\')', 1000);
							setTimeout('removeDiv(\''+winOpened+'\')', 1000);
							winOpened = "none";
						}
					}else if(winOpened == 'createCustomAlert'){
						//alert("Hey this is = "+url+"\ncontent = "+content);
						if((content != "")&&(eofurl != 1)){
							//alert("New Hey this is = currAlertId="+currAlertId);
							eofurl = 1;
						
							//removeAlert(currAlertId);
							if(is_wizard == 1){
								is_wizard = 0;
								removeDivComplete('alertWizard');
							}
							
							var el_alert = document.getElementById('myMAlerts');
							var div_alert = el_alert.innerHTML;
							
							//var el_alert = document.getElementById('myMAlerts');
							if(!content.indexOf("nocellphone") == 0){
								el_alert.innerHTML = content+div_alert;
								el.innerHTML = "<strong>Saving Complete</strong>";
							}else{
								alert('Error: No Cellphone number. Please add a cellphone in your profile \( it is in your home section.\) ');	
								el.innerHTML = "<strong>No Cellphone Number Saved</strong>";
							}
							//el_alert.innerHTML = div_alert;
							//alert("Div = "+div_alert);
							
							setTimeout('removeDiv(\'loadingX\')', 1000);
							setTimeout('removeDiv(\'backfade\')', 1000);
							setTimeout('removeDiv(\''+winOpened+'\')', 1000);
							winOpened = "none";
							document.create_alert_form.next_hours.value = "";
							document.create_alert_form.url_link.value = "";
							document.create_alert_form.setoff.value = "";
							document.create_alert_form.title.value = "";
							document.create_alert_form.desc.value = "";
						}
					}else if(winOpened == 'editCustomAlert'){
						//alert("Hey this is = "+url+"\ncontent = "+content+"\ncurrAlertId="+currAlertId);
						if((content != "")&&(eofurl != 1)){
							//alert("Hey this is = currAlertId="+currAlertId);
							eofurl = 1;
						
							removeAlert(currAlertId);
							var el_alert = document.getElementById('myMAlerts');
							var div_alert = el_alert.innerHTML;
							
							//var el_alert = document.getElementById('myMAlerts');
							
							el_alert.innerHTML = content+div_alert;
							//el_alert.innerHTML = div_alert;
							//alert("Div = "+div_alert);
							el.innerHTML = "<strong>Saving Complete</strong>";
							setTimeout('removeDiv(\'loadingX\')', 1000);
							setTimeout('removeDiv(\'backfade\')', 1000);
							setTimeout('removeDiv(\''+winOpened+'\')', 1000);
							winOpened = "none";
							document.edit_alert_form.next_hours.value = "";
							document.edit_alert_form.url_link.value = "";
							document.edit_alert_form.setoff.value = "";
							document.edit_alert_form.title.value = "";
							document.edit_alert_form.desc.value = "";
						}
						//createRssAlert
					}else if((winOpened == 'createRssAlert')||(winOpened == 'createBlogAlert')){
						//alert("Hey this is = "+url+"\ncontent = "+content);
						if((content != "")&&(eofurl != 1)){
							//alert("New Hey this is = currAlertId="+currAlertId);
							eofurl = 1;
							if(is_wizard == 1){
								is_wizard = 0;
								removeDivComplete('alertWizard');
							}
						
							//removeAlert(currAlertId);
							var el_alert = document.getElementById('myMAlerts');
							var div_alert = el_alert.innerHTML;
							
							//var el_alert = document.getElementById('myMAlerts');
							if(!content.indexOf("nocellphone") == 0){
								if(winOpened == 'createRssAlert'){
									memRsslink = document.create_rss_alert_form.urlrss.value;	
								}else{
									memRsslink = document.create_blog_alert_form.urlrss.value;	
								
								}
								
								el_alert.innerHTML = content+div_alert;
								el.innerHTML = "<strong>Saving Complete</strong>";
								setTimeout('removeDiv(\''+winOpened+'\')', 1000);
								setTimeout('removeDiv(\'loadingX\')', 1000);
								setTimeout('loadBackfade()', 1000);
								setTimeout('moveDivCenter(\'createAlertKey\')', 1000);
								memRsslink = document.create_rss_alert_form.urlrss.value;	
								
							}else{
								alert('Error: No Cellphone number. Please add a cellphone in your profile \( it is in your home section.\) ');	
								el.innerHTML = "<strong>No Cellphone Number Saved</strong>";
								setTimeout('removeDiv(\''+winOpened+'\')', 1000);
								setTimeout('removeDiv(\'backfade\')', 1000);
								winOpened = "none";
							}
							//el_alert.innerHTML = content+div_alert;
							
							//el_alert.innerHTML = div_alert;
							//alert("Div = "+div_alert);
							//el.innerHTML = "<strong>Saving Complete</strong>";
							//setTimeout('removeDiv(\'loadingX\')', 1000);
							//setTimeout('removeDiv(\'backfade\')', 1000);
							//setTimeout('removeDiv(\''+winOpened+'\')', 1000);
							//winOpened = "none";
							document.create_rss_alert_form.next_hours.value = "";
							document.create_rss_alert_form.urlrss.value = "";
							document.create_rss_alert_form.setoff.value = "";
							document.create_rss_alert_form.title.value = "";
							document.create_rss_alert_form.desc.value = "";
							document.create_blog_alert_form.next_hours.value = "";
							document.create_blog_alert_form.urlrss.value = "";
							document.create_blog_alert_form.setoff.value = "";
							document.create_blog_alert_form.title.value = "";
							document.create_blog_alert_form.desc.value = "";
						}
					}else if(winOpened == 'editRssAlert'){
						//alert("Hey this is = "+url+"\ncontent = "+content+"\ncurrAlertId="+currAlertId);
						if((content != "")&&(eofurl != 1)){
							//alert("Hey this is = currAlertId="+currAlertId);
							eofurl = 1;
						
							removeAlert(currAlertId);
							var el_alert = document.getElementById('myMAlerts');
							var div_alert = el_alert.innerHTML;
							
							//var el_alert = document.getElementById('myMAlerts');
							
							el_alert.innerHTML = content+div_alert;
							//el_alert.innerHTML = div_alert;
							//alert("Div = "+div_alert);
							el.innerHTML = "<strong>Saving Complete</strong>";
							setTimeout('removeDiv(\'loadingX\')', 1000);
							setTimeout('removeDiv(\'backfade\')', 1000);
							setTimeout('removeDiv(\''+winOpened+'\')', 1000);
							winOpened = "none";
							document.edit_rss_alert_form.next_hours.value = "";
							document.edit_rss_alert_form.url_link.value = "";
							document.edit_rss_alert_form.setoff.value = "";
							document.edit_rss_alert_form.title.value = "";
							document.edit_rss_alert_form.desc.value = "";
						}
						//createRssAlert
					}else if(winOpened == 'setAlertKey'){
						//alert("Hey this is = "+url+"\ncontent = "+content);
						if(content.indexOf("updated") == 0){
							
							el.innerHTML = "<strong>Saving Complete</strong>";
							document.setkeyform.setkey.value = "";
							memRsslink = "";
							setTimeout('removeDiv(\'loadingX\')', 1000);
							setTimeout('removeDiv(\'backfade\')', 1000);
							setTimeout('removeDiv(\''+winOpened+'\')', 1000);
							winOpened = "none";
							
						}else if(content.indexOf("keyexists") == 0){
							removeDiv('loadingX');
							alert('The mKey "'+ document.setkeyform.setkey.value+'" already exists.\nPlease choose a different mKey');
							document.setkeyform.setkey.focus();
						}else if(content.indexOf("spacefound") == 0){
							removeDiv('loadingX');
							alert('No Spaces Allowed. The mKey "'+ document.setkeyform.setkey.value+'" contains spaces.\nPlease create your mKey without spaces \n\nEx: tc4');
							document.setkeyform.setkey.focus();
						}else if(content.indexOf("keyhasno4") == 0){
							removeDiv('loadingX');
							alert('The mKey "'+ document.setkeyform.setkey.value+'" does not end with the number 4.\nPlease add a 4 to the end of your mKey.\nEx: '+document.setkeyform.setkey.value+'4');
							document.setkeyform.setkey.focus();
							
						}
						
						
						//createRssAlert
					}
				
	
												
				 }
				//return content;
				//removeDiv('loadingX');
			}else{
				//alert('readystate = '+x.readyState);
			}
		}
		x.open("GET", xml_file, true);
		x.send(null);
	}
	
}


function ajaxGetUrlBasic(url){
	var xml_file = url;
	writeDiv('loadingdiv', 'Loading Images...');
	//moveDiv('loadingX', '280', '390'); 
	moveDivCenter('loadingX');
	//switchZ('loadingX');
	setTimeout('removeDiv(\'loadingX\')', 10000);
	//alert("this is the url "+xml_file);
	
	var predivId = "preload_img";
	if (document.getElementById) {
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
		
	}else{
		//alert("No X connection here");
	}
	if (x){
		//alert('we have x '+x);
		x.onreadystatechange = function(){
			if (x.readyState == 4 && x.status == 200){
				//alert(" okay loaded your image - "+xml_file);
				//el = document.getElementById(predivId);
				//el.innerHTML = x.responseText;
				
				var content = x.responseText;
				
				el = document.getElementById('loadingdiv');
				el.innerHTML = "Loading COMPLETE";
				//alert('this is content '+el.innerHTML);
				var img_sn_div = document.getElementById('load_image_by_sn');
				img_sn_div.innerHTML = content;
				setTimeout('removeDiv(\'loadingX\')', 1000);
				//removeDiv('loadingX');
				//alert("con = "+content);
				
				//return content;
				//removeDiv('loadingX');
			}else{
				//alert('readystate = '+x.readyState);
			}
		}
		x.open("GET", xml_file, true);
		x.send(null);
	}
	
}


function ajaxGetUrlSilent(url){
	var xml_file = url;
	writeDiv('loadingdiv', 'Loading Images...');
	//moveDiv('loadingX', '280', '390'); 
	//moveDivCenter('loadingX');
	//switchZ('loadingX');
	setTimeout('removeDiv(\'loadingX\')', 10000);
	//alert("this is the url "+xml_file);
	
	var predivId = "preload_img";
	if (document.getElementById) {
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
		
	}else{
		//alert("No X connection here");
	}
	if (x){
		//alert('we have x '+x);
		x.onreadystatechange = function(){
			if (x.readyState == 4 && x.status == 200){
				//alert(" okay loaded your image - "+xml_file);
				//el = document.getElementById(predivId);
				//el.innerHTML = x.responseText;
				
				var content = x.responseText;
				
				el = document.getElementById('loadingdiv');
				el.innerHTML = "Loading COMPLETE";
				//alert('this is content '+el.innerHTML);
				var img_sn_div = document.getElementById('load_image_by_sn');
				//img_sn_div.innerHTML = content;
				setTimeout('removeDiv(\'loadingX\')', 1000);
				//removeDiv('loadingX');
				//alert("con = "+content);
				
				//return content;
				//removeDiv('loadingX');
			}else{
				//alert('readystate = '+x.readyState+'\nx-status= '+x.status);
			}
		}
		x.open("GET", xml_file, true);
		x.send(null);
	}
	
}


function ajaxGetUrlAvatar(url){
	var xml_file = url;
	writeDiv('loadingdiv', 'Loading...');
	//moveDiv('loadingX', '280', '390'); 
	moveDivCenter('loadingX');
	el = document.getElementById('loadingdiv');
				//el.innerHTML = "Loading...";
	//switchZ('loadingX');
	//setTimeout('removeDiv(\'loadingX\')', 10000);
	//alert("22--Avatar url "+xml_file);
	
	var predivId = "preload_img";
	if (document.getElementById) {
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
		
	}else{
		//alert("No X connection here");
	}
	if (x){
		//alert('we have x '+x);
		x.onreadystatechange = function(){
			if (x.readyState == 4 && x.status == 200){
				//alert(" okay loaded your image - "+xml_file);
				//el = document.getElementById(predivId);
				//el.innerHTML = x.responseText;
				
				var content = x.responseText;
				
				el = document.getElementById('loadingdiv');
				el.innerHTML = "Complete...";
				if(s_net != "none"){
					if(content.indexOf("no_avatar") == 0){
						el.innerHTML = "<strong>No Avatar Found</strong>";
						setTimeout('removeDiv(\'loadingX\')', 1000);
						
						alert("No Avatar was Found. Please Check the your web address and make sure you selected the right site.");
					}else{
						//alert("this is the image "+content);
						changeAvatar(content);
						el.innerHTML = "<strong>Found Your Avatar</strong>";
						setTimeout('removeDiv(\'loadingX\')', 1000);
					
						
					}
				}
				
				//var avatar_el = document.getElementById('avatar');
				//avatar_el.innerHTML = "<img src=\""+avatar_new+"\" alt=\"avatar\" width=\"92\" height=\"92\" style=\"border:#000000 1px solid; margin-right:10px;\">";
				
				//removeDiv('loadingX');
				//alert("con = "+content);
				
				//return content;
				//removeDiv('loadingX');
			}else{
				//alert('In baby - readystate = '+x.readyState+' and status = '+x.status);
			}
		}
		x.open("GET", xml_file, true);
		x.send(null);
	}
	
}



function setPwd(pwd){
	var url = "updateUser.php?setpwd=1&newpwd="+pwd;
	//alert("url = "+url);
	ajaxGetUrl(url);
}

function setProfile(nickname, fname, lname, dphone, email){
	
	var url = "updateUser.php?setprofile=1&nickname="+nickname+"&firstname="+fname+"&lastname="+lname+"&defphone="+dphone+"&email="+email;
	//alert("url = "+url);
	ajaxGetUrl(url);
}

function setNewProfile(){
	nickname_new = document.profile_form.nickname.value;
	fname_new = document.profile_form.firstname2.value;
	lname_new = document.profile_form.lastname.value;
	dphone_new = "1"+document.profile_form.defphone.value;
	email_new = document.profile_form.email.value;
	if(dphone_new.length != 11){
		alert('Cellphone must be 10 digits.');
		document.profile_form.defphone.focus();
	}else{
		setProfile(nickname_new, fname_new, lname_new, dphone_new, email_new);
	}
}
function setNewPwd(){
	if(document.pwd_form.new_pwd.value != ''){
		if(document.pwd_form.new_pwd.value == document.pwd_form.re_pwd.value){
		
			setPwd(document.pwd_form.new_pwd.value);	
		}else{
			alert("Passwords do not match\nPlease re-enter passwords again");
			document.pwd_form.new_pwd.focus();
		}
	}else{
		alert("You must enter a password");
		document.pwd_form.new_pwd.focus();
	}
}

function pro_oldvalues(){
	nickname_js = document.profile_form.nickname.value;
	firstname_js = document.profile_form.firstname2.value;
	lastname_js = document.profile_form.lastname.value;
	dphone_js = document.profile_form.defphone.value;
	email_js = document.profile_form.email.value;
	
	//alert("Old first = "+firstname_js);
	
	
}

function reset_pro_oldvalues(){
	document.profile_form.nickname.value = nickname_js;
	document.profile_form.firstname2.value = firstname_js;
	document.profile_form.lastname.value = lastname_js;
	document.profile_form.defphone.value = dphone_js;
	document.profile_form.email.value = email_js;
		
}

function addr_oldvalues(){
	home_address = document.addr_form.address_hm.value;
	home_city = document.addr_form.home_city.value;
	home_state = document.addr_form.home_state.value;
	home_zip = document.addr_form.home_zip.value;
	
}

function reset_addr_oldvalues(){
	document.addr_form.address_hm.value = home_address;
	document.addr_form.home_city.value = home_city;
	document.addr_form.home_state.value = home_state;
	document.addr_form.home_zip.value = home_zip;
	
}

function img_oldvalues(){
	document.search_email_sn.search_email.value = document.profile_form.email.value;
	var avatar_el = document.getElementById('avatar');
	avatar_js = avatar_el.innerHTML;
	
}

function reset_img_oldvalues(){
	var ava_el = document.getElementById('img_hold');
	ava_el.innerHTML = avatar_js;
	
}



// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function getScrollingPosition(){
	var position = [0, 0];

	if (typeof window.pageYOffset != 'undefined'){
		position = [
       		window.pageXOffset,
       		window.pageYOffset
   		];
 	}else if (typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0){
		position = [
       		document.documentElement.scrollLeft,
       		document.documentElement.scrollTop
   		];
 	}else if (typeof document.body.scrollTop != 'undefined'){
   		position = [
       		document.body.scrollLeft,
       		document.body.scrollTop
		];
 	}
	alert("position = "+position);
 	return position;
}

function init() {
	window.onblur = register;
	window.oncontextmenu = register;
	window.onerror = register;
	window.onfocus = register;
	window.onscroll = register;
	window.onresize = register;
	window.onunload = function (e) {alert('Unload event'); register(e)};
	window.onclick = register;
	window.onmousedown = register;
	window.onmouseup = register;
	register(event);
}

function writeNewMap(newAddr){
	var escAddr = escape(newAddr);
	var mapurl = "http://www.411sms.com/map2_411sms.swf?address="+escAddr+"&myevent=My%20Location&";
	//alert('new address = '+escAddr+' and \nurl =\n'+mapurl);
	var map_el = document.getElementById('yMap');
	map_el.innerHTML = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"340\" height=\"240\" align=\"middle\"><param name=\"allowScriptAccess\" value=\"sameDomain\" /><param name=\"movie\" value=\""+mapurl+"\" /><param name=\"quality\" value=\"high\" /><param name=\"bgcolor\" value=\"#ffffff\" /><embed src=\""+mapurl+"\" quality=\"high\" bgcolor=\"#ffffff\" width=\"340\" height=\"240\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></object>";
	
}

function setNewAddr(){
	if(document.addr_form.address_hm.value != ''){
		//alert('this is new addr='+newAddr);
		setLocation();
	}else{
		alert("You must enter an address");
		document.addr_form.address_hm.focus();
	}
}

function setLocation(){
	address_new = escape(document.addr_form.address_hm.value);
	city_new = escape(document.addr_form.home_city.value);
	state_new = document.addr_form.home_state.value;
	zip_new = document.addr_form.home_zip.value
	var url = "updateUser.php?setaddress=1&address="+address_new+"&tcity="+city_new+"&tzip="+zip_new+"&tstate="+state_new;
	//var url = "updateUser.php?setprofile=1&nickname="+nickname+"&firstname="+fname+"&lastname="+lname+"&defphone="+dphone+"&email="+email;
	//alert("url = "+url);
	ajaxGetUrl(url);
}

function changeClass(divId, cName){
	//alert("changing class of "+divId+" to "+cName);
	document.getElementById(divId).className = cName;	
}

function changeAvatar(img){
	//alert('image is = '+img);
	avatar_new = img;
	var img_el = document.getElementById('img_hold');
	img_el.innerHTML = "<img src=\""+img+"\" alt=\"avatar\" width=\"92\" height=\"92\" style=\"border:#000000 1px solid; margin-right:10px;\">";
	
	
	
}

function changeAndRemoveLoadingX(content, timex){
	//alert('Loading X content = '+content);
	el = document.getElementById('loadingdiv');
	el.innerHTML = "<strong>Uploading Complete</strong>";
	setTimeout('removeDivContent(\'loadingX\', \'loadingdiv\', \'Loading...\')', timex);	
	
	
	
}

function RemoveDivTimed(id, timex){
	//alert("removign = "+id);
	setTimeout('removeDiv(\''+id+'\')', timex);	
	
	
	
}

function saveNewAvatar(){
	//var avatar_el = document.getElementById('avatar');
	//avatar_el.innerHTML = "<img src=\""+avatar_new+"\" alt=\"avatar\" width=\"92\" height=\"92\" style=\"border:#000000 1px solid; margin-right:10px;\">";
	var url = "updateUser.php?setavatar=1&avatar="+avatar_new;
	//var url = "updateUser.php?setprofile=1&nickname="+nickname+"&firstname="+fname+"&lastname="+lname+"&defphone="+dphone+"&email="+email;
	//alert("url = "+url);
	ajaxGetUrl(url);
	
	//removeDiv('backfade'); 
	//removeDiv('changeAvatar');
	
	
}



function getpdfUrl(){
	var email_js = document.profile_form.email.value;
	var url_avatar = document.get_ava_url.url_ava.value;
	
	url_avatar = escape(url_avatar);
	var s_net = document.get_ava_url.s_net_type.value;
	var get_url_avatar = "http://www.411sms.com/findAvatarByUrl.php?url="+url_avatar+"&email="+email_js+"&s_net="+s_net;
	
	//alert("url is "+get_url_avatar);
	
	ajaxGetUrlAvatar(get_url_avatar);
}

function getAvatarUrl(){
	var email_js = document.profile_form.email.value;
	var url_avatar = document.get_ava_url.url_ava.value;
	
	url_avatar = escape(url_avatar);
	var s_net = document.get_ava_url.s_net_type.value;
	var get_url_avatar = "http://www.411sms.com/findAvatarByUrl.php?url="+url_avatar+"&email="+email_js+"&s_net="+s_net;
	
	//alert("url is "+get_url_avatar);
	
	ajaxGetUrlAvatar(get_url_avatar);
}



function createCustomAlert(){
	var next_hours = document.create_alert_form.next_hours.value;
	var url_link = document.create_alert_form.url_link.value;
	url_link = escape(url_link);
	var setoff = document.create_alert_form.setoff.value;
	setoff = escape(setoff);
	var alert_title = document.create_alert_form.title.value;
	alert_title = escape(alert_title);
	var alert_desc = document.create_alert_form.desc.value;
	alert_desc = escape(alert_desc);
	var create_alert_url = "http://www.411sms.com/updateUser.php?createalert=1&alert_type=custom&link="+url_link+"&next_hours="+next_hours+"&setoff="+setoff+"&title="+alert_title+"&desc="+alert_desc;
	
	//alert("url is "+create_alert_url);
	
	ajaxGetUrl(create_alert_url);
}

function createRssAlert(){
	var next_hours = document.create_rss_alert_form.next_hours.value;
	
	var url_link = document.create_rss_alert_form.urlrss.value;
	url_link = escape(url_link);
	var setoff = document.create_rss_alert_form.setoff.value;
	setoff = escape(setoff);
	//alert("hey here's next = "+next_hours+"\nsetoff = "+setoff);
	var alert_title = document.create_rss_alert_form.title.value;
	alert_title = escape(alert_title);
	var alert_desc = document.create_rss_alert_form.desc.value;
	alert_desc = escape(alert_desc);
	
	var create_alert_url = "http://www.411sms.com/updateUser.php?create_rss_alert=1&alert_type=rss&urlrss="+url_link+"&next_hours="+next_hours+"&setoff="+setoff+"&title="+alert_title+"&desc="+alert_desc;
	//var create_alert_url = "http://www.411sms.com/updateUser.php?createalert=1&alert_type=custom&link="+url_link+"&next_hours="+next_hours+"&setoff="+setoff+"&title="+alert_title+"&desc="+alert_desc;
	
	//alert("url is "+create_alert_url);
	
	ajaxGetUrl(create_alert_url);
}


function createBlogAlert(){
	var next_hours = document.create_blog_alert_form.next_hours.value;
	
	var url_link = document.create_blog_alert_form.urlrss.value;
	url_link = escape(url_link);
	var setoff = document.create_blog_alert_form.setoff.value;
	setoff = escape(setoff);
	//alert("hey here's next = "+next_hours+"\nsetoff = "+setoff);
	var alert_title = document.create_blog_alert_form.title.value;
	alert_title = escape(alert_title);
	var alert_desc = document.create_blog_alert_form.desc.value;
	alert_desc = escape(alert_desc);
	
	var create_alert_url = "http://www.411sms.com/updateUser.php?create_rss_alert=1&alert_type=rss&urlrss="+url_link+"&next_hours="+next_hours+"&setoff="+setoff+"&title="+alert_title+"&desc="+alert_desc;
	//var create_alert_url = "http://www.411sms.com/updateUser.php?createalert=1&alert_type=custom&link="+url_link+"&next_hours="+next_hours+"&setoff="+setoff+"&title="+alert_title+"&desc="+alert_desc;
	
	//alert("url is "+create_alert_url);
	
	ajaxGetUrl(create_alert_url);
}


function editRssAlert(){
	var next_hours = document.edit_rss_alert_form.next_hours.value;
	var url_link = document.edit_rss_alert_form.urlrss.value;
	url_link = escape(url_link);
	var setoff = document.edit_rss_alert_form.setoff.value;
	setoff = escape(setoff);
	var alert_title = document.edit_rss_alert_form.title.value;
	alert_title = escape(alert_title);
	var alert_desc = document.edit_rss_alert_form.desc.value;
	alert_desc = escape(alert_desc);
	
	var create_alert_url = "http://www.411sms.com/updateUser.php?create_rss_alert=1&alert_type=rss&urlrss="+url_link+"&next_hours="+next_hours+"&setoff="+setoff+"&title="+alert_title+"&desc="+alert_desc;
	
	//alert("url is "+create_alert_url);
	
	ajaxGetUrl(create_alert_url);
}


function editCustomAlert(){
	var next_hours = document.edit_alert_form.next_hours.value;
	var url_link = document.edit_alert_form.url_link.value;
	url_link = escape(url_link);
	var setoff = document.edit_alert_form.setoff.value;
	setoff = escape(setoff);
	var alert_title = document.edit_alert_form.title.value;
	alert_title = escape(alert_title);
	var alert_desc = document.edit_alert_form.desc.value;
	alert_desc = escape(alert_desc);
	var create_alert_url = "http://www.411sms.com/updateUser.php?createalert=1&alert_type=custom&link="+url_link+"&next_hours="+next_hours+"&setoff="+setoff+"&title="+alert_title+"&desc="+alert_desc;
	
	//alert("url is "+create_alert_url);
	
	ajaxGetUrl(create_alert_url);
}

function saveAlertKey(){
	var newkey = document.setkeyform.setkey.value;
	memRsslink = "http://rss.slashdot.org/Slashdot/slashdot";
	var keycommand = escape(memRsslink);
	var save_key_url = "http://www.411sms.com/updateUser.php?addAlertKey=1&key="+newkey+"&command="+keycommand;
	
	//alert("url is "+save_key_url);
	
	ajaxGetUrl(save_key_url);
	
	
	
}

function updateCustomAlert(){
	var next_hours = document.create_alert_form.next_hours.value;
	var url_link = document.create_alert_form.url_link.value;
	url_link = escape(url_link);
	var setoff = document.create_alert_form.setoff.value;
	setoff = escape(setoff);
	var alert_title = document.create_alert_form.title.value;
	alert_title = escape(alert_title);
	var alert_desc = document.create_alert_form.desc.value;
	alert_desc = escape(alert_desc);
	var create_alert_url = "http://www.411sms.com/updateUser.php?createalert=1&alert_type=custom&link="+url_link+"&next_hours="+next_hours+"&setoff="+setoff+"&title="+alert_title+"&desc="+alert_desc;
	
	//alert("url is "+create_alert_url);
	
	ajaxGetUrl(create_alert_url);
}


function fillAlert(a_uid, a_setoff, a_freq){
	var aTitleId = document.getElementById('aTitle_'+a_uid);
	var aDescId = document.getElementById('aDesc_'+a_uid);
	var aLinkId = document.getElementById('aLink_'+a_uid);
	
	document.edit_alert_form.title.value = aTitleId.innerHTML;
	document.edit_alert_form.desc.value = aDescId.innerHTML;
	
	//alert("setoff is "+document.edit_alert_form.next_hours.value+"\nuid="+a_uid);
	document.edit_alert_form.next_hours.value = a_freq;
	document.edit_alert_form.setoff.value = a_setoff;
	document.edit_alert_form.url_link.value = aLinkId.innerHTML;
	currAlertId = a_uid;
	//alert("setoff is "+document.edit_alert_form.next_hours.value+"\nuid="+currAlertId);
	
}


function fillRssAlert(a_uid, a_setoff, a_freq, a_rssLink){
	var aTitleId = document.getElementById('aTitle_'+a_uid);
	var aDescId = document.getElementById('aDesc_'+a_uid);
	document.edit_rss_alert_form.title.value = aTitleId.innerHTML;
	document.edit_rss_alert_form.desc.value = aDescId.innerHTML;
	document.edit_rss_alert_form.next_hours.value = a_freq;
	//alert("Rss setoff is "+document.edit_rss_alert_form.next_hours.value+"\nuid="+a_uid+"\nfreq = "+a_freq);
	
	document.edit_rss_alert_form.setoff.value = a_setoff;
	document.edit_rss_alert_form.urlrss.value =  a_rssLink;
	currAlertId = a_uid;
	//alert("setoff is "+document.edit_alert_form.next_hours.value+"\nuid="+currAlertId);
	
}







//Lets us tell it the first content
function changeAndRemoveMainLoadingX(first_content, timex){
	//alert('Loading X content = '+first_content);
	el = document.getElementById('loadingdiv');
	el.innerHTML = first_content;
	setTimeout('removeDivContent(\'loadingX\', \'loadingdiv\', \'Loading...\')', timex);	
	
	
	
}

function getSocialImages(){
	//email_new = document.profile_form.email.value;
	if(first_load_image != 1){
		var socImgUrl = "http://www.411sms.com/findAvatar.php?email="+document.search_email_sn.search_email.value;
		//alert('email is = '+document.profile_form.email.value+'\nurl = '+socImgUrl);
		ajaxGetUrlBasic(socImgUrl);
	}else{
		first_load_image = 0;
	}
	
}
function getSocialImagesInit(){
	//email_new = document.profile_form.email.value;
	
	var socImgUrl = "http://www.411sms.com/findAvatar.php?email="+document.profile_form.email.value;
	//alert('email is = '+document.profile_form.email.value+'\nurl = '+socImgUrl);
	ajaxGetUrlBasic(socImgUrl);
	setTimeout('removeDivContent(\'loadingX\', \'loadingdiv\', \'Loading...\')', 1);
	
	
}

function removeAlertConfirm(a_uid){
	var aTitleId = document.getElementById('aTitle_'+a_uid);
	var answer = confirm("Delete Alert: "+aTitleId.innerHTML+"?")
	if (answer){
		scaleDownRemove(a_uid);
		//removeAlert(a_uid);
	}else{
		//alert("Thanks for sticking around!")
	}
}

function removeDivComplete(alertId){
	var alertIdDiv = document.getElementById(alertId);
	alertIdDiv.innerHTML = "";
	changeClass(alertId, 'mAlert_Remove');
}

function removeAlert(a_uid){
	var alertId = "alert_"+a_uid;
	var alertIdDiv = document.getElementById(alertId);
	alertIdDiv.innerHTML = "";
	changeClass(alertId, 'mAlert_Remove');
	var delete_alert_url = "http://www.411sms.com/updateUser.php?deletealert=1&alert_keeper_uid="+a_uid;
	
	//alert("url is "+delete_alert_url);
	
	ajaxGetUrlSilent(delete_alert_url);
	
}

function removePDF(docuid){
	var alertId = "pdf_"+docuid;
	var alertIdDiv = document.getElementById(alertId);
	alertIdDiv.innerHTML = "";
	changeClass(alertId, 'mAlert_Remove');
	var delete_alert_url = "http://www.2waystar.com/savePdf.php?delpdf=1&docuid="+docuid;
	
	//alert("url is "+delete_alert_url);
	
	ajaxGetUrlSilent(delete_alert_url);
	
}






function deactivateAlert(a_uid){
	
	var deactivate_alert_url = "http://www.411sms.com/updateUser.php?deactivate_alert=1&alert_keeper_uid="+a_uid;
	
	//alert("url is "+deactivate_alert_url);
	var deCon = "<a href=\"javascript:void(0)\" onClick=\"activateAlert('9');\" style=\"text-decoration:none;\">activate</a> | view now | send | share ";
	var deCon = "<a href=\"javascript:void(0)\" onClick=\"activateAlert('"+a_uid+"');\" ><img src=\"icons_main/clock_add.png\" alt=\"a\" width=\"16\" height=\"16\" border=\"0\"> activate</a> | <img src=\"icons_main/phone.png\" alt=\"cell\" width=\"16\" height=\"16\"><a href=\"viewalert.php?a_uid="+a_uid+"\" target=\"_blank\">view/send</a> | <img src=\"icons_main/email_go.png\" alt=\"share\" width=\"16\" height=\"16\"><a href=\"javascript:void(0)\" onClick=\"shareAlert('"+a_uid+"');\" > share</a>";
	var alertIdDiv = document.getElementById('act_'+a_uid);
	alertIdDiv.innerHTML = deCon;
	
	ajaxGetUrlSilent(deactivate_alert_url);
	
}

function activateAlert(a_uid){
	
	var activate_alert_url = "http://www.411sms.com/updateUser.php?activate_alert=1&alert_keeper_uid="+a_uid;
	
	//alert("url is "+activate_alert_url);
	var deCon = "<a href=\"javascript:void(0)\" onClick=\"deactivateAlert('9');\" style=\"text-decoration:none;\">deactivate</a> | view now | send | share ";
	var deCon = "<a href=\"javascript:void(0)\" onClick=\"deactivateAlert('"+a_uid+"');\" ><img src=\"icons_main/clock_stop.png\" alt=\"a\" width=\"16\" height=\"16\" border=\"0\"> deactivate</a> | <img src=\"icons_main/phone.png\" alt=\"cell\" width=\"16\" height=\"16\"><a href=\"viewalert.php?a_uid="+a_uid+"\" target=\"_blank\">view/send</a> | <img src=\"icons_main/email_go.png\" alt=\"share\" width=\"16\" height=\"16\"><a href=\"javascript:void(0)\" onClick=\"shareAlert('"+a_uid+"');\" > share</a>";
	var alertIdDiv = document.getElementById('act_'+a_uid);
	alertIdDiv.innerHTML = deCon;
	ajaxGetUrlSilent(activate_alert_url);
	
}

function addAlert(a_uid){
	
	var add_alert_url = "http://www.411sms.com/updateUser.php?addalert=1&alert_keeper_uid="+a_uid;
	
	alert("url is "+add_alert_url);
	//var deCon = "<a href=\"javascript:void(0)\" onClick=\"deactivateAlert('9');\" style=\"text-decoration:none;\">deactivate</a> | view now | send | share ";
	//var alertIdDiv = document.getElementById('act_'+a_uid);
	//alertIdDiv.innerHTML = deCon;
	
	var el_alert = document.getElementById('myMAlerts');
	var div_alert = el_alert.innerHTML;
	//var el_alert = document.getElementById('myMAlerts');
	
	el_alert.innerHTML = "<div class=\"mAlert\" id=\"alert_34\"><div style=\"margin:5px;\"><div style=\"margin-bottom:5px;\"><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr> <td width=\"8%\" height=\"21\"><img src=\"webicons/411sms_favicon.gif\" alt=\"a\" width=\"16\" height=\"16\"></td><td width=\"71%\" style=\"font-weight:bold; color:#333333; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;\">Virgo Horoscope </td><td width=\"12%\">edit</td><td width=\"9%\"><A HREF=\"javascript:void(0)\" onclick=\"removeAlert('alert_34', '30');\" title=\"Delete This Alert\"><img src=\"images5/close_exit.gif\" alt=\"exit\" width=\"16\" height=\"16\" border=\"0\"></A></td></tr></table></div><div style=\"margin-left:5px; margin-right:5px; border-bottom:5px;\">My horoscope for young male... <br></div><div style=\"margin-left:5px; margin-right:5px; border-bottom:5px; color:#999999; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;\">rss -&gt; www.zodiac.com <br></div><div style=\"margin-left:5px; margin-right:5px; border-bottom:5px; color:#999999; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;\">created by Mrgood <br></div><div><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td width=\"7%\" height=\"21\"><img src=\"icons_main/clock_add.png\" alt=\"a\" width=\"16\" height=\"16\"></td> <td width=\"93%\" style=\"color:#999999; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;\" ><div id=\"act_9\"><a href=\"javascript:void(0)\" onClick=\"activateAlert('9');\" style=\"text-decoration:none;\">activate</a> | view now | send | share </div></td></tr></table></div></div></div>"+div_alert;
	
	ajaxGetUrlSilent(add_alert_url);
	
}

function getAbsolutePosition(element) {
	var r = { x: element.offsetLeft, y: element.offsetTop };
	if (element.offsetParent) {
	  var tmp = getAbsolutePosition(element.offsetParent);
	  r.x += tmp.x;
	  r.y += tmp.y;
	}
	//alert("r = "+r.x);
	return r;
};


function shareAlert(a_uid){
	
	var alertIdDiv = document.getElementById('act_'+a_uid);
	var offY = alertIdDiv.offsetTop;
	var offsets = getAbsolutePosition(alertIdDiv);
	var leftDisp = offsets.x + 220;
	var topDisp = offsets.y + 3;
	//alert("offset Y = "+offY+" and offsets = "+offsets.x);
	winOpened = 'shareAlert';
	var aTitleId = document.getElementById('aTitle_'+a_uid);
	
	var shareAlertDivTitleId = document.getElementById('shareAlertDivTitle');
	shareAlertDivTitleId.innerHTML = "Share: "+aTitleId.innerHTML;
	var shareButtonId = document.getElementById('shareButton');
	shareButtonId.innerHTML = "<input name=\"Submit60\" type=\"submit\" id=\"Submit60\" onClick=\"sendtoEmail('"+a_uid+"'); return false;\" value=\"Send to Email\">";
	var shareBookmarkId = document.getElementById('shareBookmark');
	shareBookmarkId.innerHTML = "<span class=\"snap_nopreview\"><a rel=\"nofollow\" href=\"http://www.addthis.com/bookmark.php?pub=techcrunch&amp;url=http://www.411sms.com/addnewalert.php?a_uid="+a_uid+"\" onClick=\"window.open('http://www.addthis.com/bookmark.php?pub=411sms.com&url=http%3A%2F%2Fwww.411sms.com%2Faddnewalert.php%3Fa_uid%3D"+a_uid+"', 'addthis', 'scrollbars=yes,menubar=no,width=620,height=420,resizable=yes,toolbar=no,location=no,status=no,screenX=200,screenY=100,left=200,top=100'); return false;\" title=\"Bookmark using any bookmark manager!\" target=\"_blank\"><img src=\"http://s3.addthis.com/button1-bm.gif\" alt=\"AddThis Social Bookmark Widget\" border=\"0\" height=\"16\" width=\"125\"></a></span>";
	
	
	
	//alert("offset Y = "+offY+" and offsets = "+offsets.y+"\nTITLE = "+shareAlertDivTitleId.innerHTML);
	moveDiv('shareAlert', topDisp, leftDisp);
	document.shareForm.share_email.focus();
	//alertIdDiv.innerHTML = deCon;
	//ajaxGetUrlSilent(activate_alert_url);
	
}

function sendtoEmail(a_uid){
	//alert("ok starting alert uid = "+a_uid);
	var aTitleId = document.getElementById('aTitle_'+a_uid);
	var aTitle = escape(aTitleId.innerHTML);
	var aDescId = document.getElementById('aDesc_'+a_uid);
	var aDesc = escape(aDescId.innerHTML);
	var send_email_url = "http://www.411sms.com/sendalerttofriend.php?friendemail="+document.shareForm.share_email.value+"&a_uid="+a_uid+'&aTitle='+aTitle+'&aDesc='+aDesc+'&sendmes=1';
	var send_email_url = "http://www.411sms.com/sentalerttofriend.php?a_uid="+a_uid+"&aTitle="+aTitle+"&aDesc="+aDesc+"&friendemail="+document.shareForm.share_email.value+"&sendmes=1";
	
	ajaxGetUrlSilent(send_email_url);
	moveDivCenter('loadingX');
	el = document.getElementById('loadingdiv');
	el.innerHTML = "Sharing COMPLETE";
				
	setTimeout('removeDiv(\'loadingX\')', 1000);
	setTimeout('removeDiv(\'shareAlert\')', 1000);
	//alert("email url = "+send_email_url);
	
	
	
	
	
	
	
	
}

function minimizeAlert(a_uid){
	
	var C_el = document.getElementById('aCollapse_'+a_uid);
	var oldht = C_el.offsetHeight;
	//C_el.style.height = 25;
	newht = 25;
	//alert("ok collapsed to 20 == "+C_el.offsetHeight);
	aEditId = document.getElementById('aMini_'+a_uid);
	aEditId.innerHTML = "<a href=\"javascript:void(0)\" onclick=\"maximizeAlert("+a_uid+", "+oldht+");\" title=\"maximize\"><img src=\"images3/left_exp.gif\" alt=\"d\" width=\"6\" height=\"9\" border=\"0\"></a>";
	doHeightChangeMem('aCollapse_'+a_uid, oldht, newht,10,10,1);
	
}

function scaleDown(a_uid){
	var C_el = document.getElementById('aCollapse_'+a_uid);
	var oldht = C_el.offsetHeight;
	var newht = 0;
	
	//alert("div = aCollapse_"+a_uid+" Oldht = "+oldht+"  and changing to "+newht);
	doHeightChangeMem('aCollapse_'+a_uid, oldht, newht,3,3,1);	
	
}

function startDownload(docuid){
	//loadBackfade(); 
	//moveDivCenter('downloadPDF'); 
	var dlUrl = "pdfdownloader.php?download=1&docuid="+docuid;
	document.getElementById('dl_iframe').innerHTML = "<iframe src=\""+dlUrl+"\" frameborder=\"0\" width=\"100%\" height=\"260px\"></iframe>";
	//setTimeout('removeDiv(\'loadingX\')', 1000);
	//setTimeout('removeDiv(\'downloadPDF\')', 1000);
}

function scaleDownRemove(a_uid){
	var C_el = document.getElementById('aCollapse_'+a_uid);
	var oldht = C_el.offsetHeight;
	var newht = 0;
	
	//alert("div = aCollapse_"+a_uid+" Oldht = "+oldht+"  and changing to "+newht);
	doHeightChangeMemRem(a_uid, oldht, newht,3,3,1);	
	
}

function remDelPDF(docuid){
	var P_el = document.getElementById('pdf_'+docuid);
	var oldht = P_el.offsetHeight;
	var newht = 0;
	
	//alert("div = aCollapse_"+a_uid+" Oldht = "+oldht+"  and changing to "+newht);
	var pdf_div_id = "pdf_"+docuid;
	
	doHeightChangeMemRemPDF(docuid, oldht, newht,3,3,1);
	var p_elStyle = P_el.style;
	p_elStyle.lineHeight = "0px";
	p_elStyle.height = "0px";
	
	
}

function maximizeAlert(a_uid, oldht){
	
	var C_el = document.getElementById('aCollapse_'+a_uid);
	var maxoldht = C_el.offsetHeight;
	var maxnewht = oldht;
	//alert("Max ok collapsed to 20 == "+maxnewht);
	aEditId = document.getElementById('aMini_'+a_uid);
	aEditId.innerHTML = "<a href=\"javascript:void(0)\" onclick=\"minimizeAlert("+a_uid+");\" title=\"minimize\"><img src=\"images3/down_exp.gif\" alt=\"d\" width=\"9\" height=\"6\" border=\"0\"></a>";
	doHeightChangeMem('aCollapse_'+a_uid,maxoldht,  maxnewht, 5,5,1);
	
}


/**
*
* section for showing stuff and hiding using style
*
*/

function changeDivHeight(divId, newht){
	var C_el = document.getElementById(divId);
	
	C_el.style.height = newht + "px";
	
	
}

function changeDivWidth(divId, newht){
	var C_el = document.getElementById(divId);
	
	C_el.style.width = newht + "px";
	
	
}


function changeDivHeight(divId, newht){
	var C_el = document.getElementById(divId);
	
	C_el.style.height = newht + "px";
	
	
}

function clearDivHeight(divId){
	var C_el = document.getElementById(divId);
	
	C_el.style.height = "";
	
	
}


function showDiv(divId){
	//alert('showing div = '+divId);
	var C_el = document.getElementById(divId);
	C_el.style.visibility = "visible";
	
	
}

function hideDiv(divId){
	//alert('hiding == '+divId);
	var C_el = document.getElementById(divId);
	C_el.style.visibility = "hidden";
	
	
}

function showMiniDiv(a_uid){
	var C_el = document.getElementById('aMini_'+a_uid);
	C_el.style.visibility = "visible";
	
	
}

function hideMiniDiv(a_uid){
	var C_el = document.getElementById('aMini_'+a_uid);
	C_el.style.visibility = "hidden";
	
	
}

function doHeightChangeMem(elemId,startHeight,endHeight,steps,intervals,powr) { 
	var elem = document.getElementById(elemId);
	//alert("Elem = "+elem);
    if (elem.widthChangeMemInt){
		window.clearInterval(elem.widthChangeMemInt);
	}
	var actStep = 0;
    elem.heightChangeMemInt = window.setInterval(
	function() { 
		
	  elem.currentHeight = easeInOut(startHeight,endHeight,steps,actStep,powr);
	  //elem.currentHeight = 20;
	
	  elem.style.height = elem.currentHeight + "px"; 
	  actStep++;
	  //alert("Div= "+elem+" actstep = "+actStep+" and steps = "+steps+"\ncHt = "+elem.currentHeight);
	  if (actStep > steps) {
			//alert("Must close now");
			window.clearInterval(elem.heightChangeMemInt);
	  }else{
		  //alert("Div= "+elem+" actstep = "+actStep+" and steps = "+steps+"\ncHt = "+elem.currentHeight+"\noldht = "+endHeight);
	  }
		  
	} 
	,intervals);
	
}


function doHeightChangeMemRem(a_uid,startHeight,endHeight,steps,intervals,powr) { 
	var elem = document.getElementById('aCollapse_'+a_uid);
	//alert("Elem = "+elem);
    if (elem.widthChangeMemInt){
		window.clearInterval(elem.widthChangeMemInt);
	}
	var actStep = 0;
    elem.heightChangeMemInt = window.setInterval(
	function() { 
		
	  elem.currentHeight = easeInOut(startHeight,endHeight,steps,actStep,powr);
	  //elem.currentHeight = 20;
	
	  elem.style.height = elem.currentHeight + "px"; 
	  actStep++;
	  //alert("Div= "+elem+" actstep = "+actStep+" and steps = "+steps+"\ncHt = "+elem.currentHeight);
	  if (actStep > steps) {
			//alert("Must close now");
			window.clearInterval(elem.heightChangeMemInt);
			removeAlert(a_uid);
	  }else{
		  //alert("Div= "+elem+" actstep = "+actStep+" and steps = "+steps+"\ncHt = "+elem.currentHeight+"\noldht = "+endHeight);
	  }
		  
	} 
	,intervals);
	
}


function doHeightChangeMemRemPDF(docuid,startHeight,endHeight,steps,intervals,powr) { 
	var elem = document.getElementById('pdf_'+docuid);
	//alert("Elem = "+elem);
    if (elem.widthChangeMemInt){
		window.clearInterval(elem.widthChangeMemInt);
	}
	var actStep = 0;
    elem.heightChangeMemInt = window.setInterval(
	function() { 
		
	  elem.currentHeight = easeInOut(startHeight,endHeight,steps,actStep,powr);
	  //elem.currentHeight = 20;
	
	  elem.style.height = elem.currentHeight + "px"; 
	  actStep++;
	  //alert("Div= "+elem+" actstep = "+actStep+" and steps = "+steps+"\ncHt = "+elem.currentHeight);
	  if (actStep > steps) {
			//alert("Must close now "+docuid);
			window.clearInterval(elem.heightChangeMemInt);
			removePDF(docuid);
			//removeAlert(a_uid);
	  }else{
		  //alert("Div= "+elem+" actstep = "+actStep+" and steps = "+steps+"\ncHt = "+elem.currentHeight+"\noldht = "+endHeight);
	  }
		  
	} 
	,intervals);
	
}


function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) { 
    var delta = maxValue - minValue; 
    var stepp = minValue+(Math.pow(((1 / totalSteps) * actualStep), powr) * delta); 
    return Math.ceil(stepp);
	//var stepp = minValue - 1;
	//return stepp;
} 

function loadWizard(){
	if(loadedWizard == 1){
		//alert("loaded already - LW="+loadedWizard);
		removeDivComplete('alertWizard');
	}else{
		//alert("NOT loaded already - LW="+loadedWizard);
	}
	var el_alert = document.getElementById('myMAlerts');
	var wiz_alert = document.getElementById('alertWizard');
	var div_alert = el_alert.innerHTML;
	var wizContent = "<div id=\"alertWizard\"><div class=\"round_rect2\" style=\"margin-bottom: 10px;\"><div class=\"rr_top\" style=\"overflow: hidden; height: 15px;\"><div class=\"rr_top_right\"></div></div><div class=\"rr_content\"><div class=\"rr_content_right\"><div id=\"aCollapse_254x\" style=\"overflow:hidden;\"><div style=\"position: relative; margin-bottom: 5px;\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"260\"><tbody><tr><td height=\"21\" width=\"8%\"><img src=\"icons_main/wand.png\" alt=\"fav\" width=\"16\" height=\"16\" border=\"0\" style=\"margin-right:5px; float:left;\"></td><td style=\"font-weight: bold; color: rgb(51, 51, 51); font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 11px;\" width=\"69%\"><div id=\"aTitle_154\">Alert Creation Wizard  </div></td> <td width=\"7%\"><div class=\"clickLinkEdit\"></div></td> <td width=\"7%\" align=\"right\" valign=\"middle\">&nbsp;</td> <td align=\"right\" width=\"9%\"><a href=\"javascript:void(0)\" onClick=\"removeDivComplete('alertWizard'); loadedWizard = 0;\" title=\"Remove Wizard\" alt=\"Remove Wizard\"><img src=\"images5/close_exit.gif\" alt=\"exit\" border=\"0\" height=\"16\" width=\"16\"></a></td></tr></tbody></table></div><div> <object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"260\" height=\"120\" title=\"wizard\"><param name=\"movie\" value=\"flash/alertwiz4.swf\"><param name=\"quality\" value=\"high\"><param name=\"wmode\" value=\"opaque\"><param name=\"wizard\" value=\"false\"><embed src=\"flash/alertwiz4.swf\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" wmode=\"opaque\" wizard=\"false\" width=\"260\" height=\"120\"></embed></object></div></div></div></div><div class=\"rr_bottom\"><div class=\"rr_bottom_left\"><div class=\"rr_bottom_right\" style=\"height: 5px;\"></div></div></div> </div></div>";

	el_alert.innerHTML = wizContent+div_alert;	
	loadedWizard = 1;
	
}

//docCt is the number of documents this person has now
function addDocs(pdfname, pdffile, imgpdffile, pc, picwd, picht, pdftitle, docCt, docUid){
	//docCt = docCt + 5;
	//alert("doc count is now "+docCt);
	var docname = pdftitle;
	pdfuid_array.push(docUid);
	var d_off = docCt - 1;
	// update the array of all the pdfs
	allpdf_array[d_off] = new Array();
	allpdf_array[d_off][0] = pdffile;
	allpdf_array[d_off][1] = pdftitle;
	allpdf_array[d_off][2] = docUid;
	allpdf_array[d_off][3] = pc;
	allpdf_array[d_off][4] = picwd;
	allpdf_array[d_off][5] = picht;
	allpdf_array[d_off][6] = pdfname;
	allpdf_array[d_off][7] = imgpdffile;
	
	
	var addpdf_el = document.getElementById('editdocs');
	
	
	//addpdf_el.innerHTML= "<div id=\"pdf_"+docUid+"\" style=\" margin-top:10px;  height:20px;\"><a href=\"javascript:void(0)\" onClick=\"PassFlashPdf('"+pdfname+"', '"+pdffile+"', '"+imgpdffile+"', "+pc+", "+picwd+", "+picht+", '"+pdftitle+"', "+docUid+"); changeSel('pdficon_"+docCt+"');\"><DIV id=\"pdficon_"+docCt+"\" style=\"float:left; margin-right:5px;\"><img src=\"icons_main/page_white_text.png\" height=\"16px\" width=\"16px\" border=\"0\" alt=\"fav\"></div><div style=\"float:left\">"+pdftitle+"</div> </a><div style=\"float:right; margin-right:3px;\"></div><div style=\"float:right; margin-right:5px;\"><a href=\"javascript:void(0)\" onClick=\"deletePDF('"+docUid+"', '"+pdftitle+"'); \"><img src=\"images5/close_exit.gif\" alt=\"delete\" width=\"16\" height=\"16\" border=\"0\"></a></div></div>"+addpdf_el.innerHTML;	
	
	//addpdf_el.innerHTML = "<div id=\"pdf_"+docUid+"\" style=\" margin-top:10px; clear:both; height:20px;\"><DIV id=\"pdficon_2\" style=\"float:left; margin-right:5px; \"><a href=\"javascript:void(0)\" onClick=\"PassFlashPdf('"+pdfname+"', '"+pdffile+"', '"+imgpdffile+"', "+pc+", "+picwd+", "+picht+", '"+pdftitle+"', "+docUid+"); changeSel('pdficon_"+docCt+"');\"><DIV id=\"pdficon_"+docCt+"\" style=\"float:left; margin-right:5px;\"><img src=\"icons_main/page_edit.png\" height=\"16\" width=\"16\" border=\"0\" alt=\"fav\" style=\"margin-left:5px;\"></a></div><div style=\"float:left\"><a href=\"javascript:void(0)\" onClick=\"PassFlashPdf('"+pdfname+"', '"+pdffile+"', '"+imgpdffile+"', "+pc+", "+picwd+", "+picht+", '"+pdftitle+"', "+docUid+"); changeSel('pdficon_"+docCt+"');\" style=\"color:#5A5E61;\">shortcode </a></div><div style=\"float:right; margin-right:3px;\"></div> <div style=\"float:right; margin-right:5px;\"><a href=\"javascript:void(0)\" onClick=\"deletePDF('"+docUid+"', '"+pdftitle+"'); \"><img src=\"images5/exit_12x12.gif\" alt=\"delete\" width=\"12\" height=\"12\" name=\"Delete\" border=\"0\" style=\"margin-top:4px\"></a></div> </div>"+addpdf_el.innerHTML;
	
	//addpdf_el.innerHTML= "<div id=\"pdf_"+docUid+"\" style=\" margin-top:10px;  height:20px;\"><a href=\"javascript:void(0)\" onClick=\"PassFlashPdf('"+pdfname+"', '"+pdffile+"', '"+imgpdffile+"', "+pc+", "+picwd+", "+picht+", '"+pdftitle+"', "+docUid+"); changeSel('pdficon_"+docCt+"');\"><DIV id=\"pdficon_"+docCt+"\" style=\"float:left; margin-right:5px;\"><img src=\"icons_main/page_white_text.png\" height=\"16px\" width=\"16px\" border=\"0\" alt=\"fav\"></div><div style=\"float:left\">"+pdftitle+"</div> </a><div style=\"float:right; margin-right:3px;\"></div><div style=\"float:right; margin-right:5px;\"><a href=\"javascript:void(0)\" onClick=\"deletePDF('"+docUid+"', '"+pdftitle+"'); \"><img src=\"images5/exit_12x12.gif\" alt=\"delete\" width=\"12\" height=\"12\" border=\"0\" style=\"margin-top:4px\"></a></div></div>"+addpdf_el.innerHTML;
	
	addpdf_el.innerHTML= "<div id=\"pdf_"+docUid+"\" style=\" margin-top:10px;  height:20px;\"><DIV id=\"pdficon_"+docCt+"\" style=\"float:left; margin-right:5px;\"><a href=\"javascript:void(0)\" onClick=\"PassFlashPdf('"+pdfname+"', '"+pdffile+"', '"+imgpdffile+"', "+pc+", "+picwd+", "+picht+", '"+pdftitle+"', "+docUid+"); changeSel('pdficon_"+docCt+"');\"><img src=\"icons_main/page_white_text.png\" height=\"16px\" width=\"16px\" border=\"0\" alt=\"fav\"></a></div><div style=\"float:left\"><a href=\"javascript:void(0)\" onClick=\"PassFlashPdf('"+pdfname+"', '"+pdffile+"', '"+imgpdffile+"', "+pc+", "+picwd+", "+picht+", '"+pdftitle+"', "+docUid+"); changeSel('pdficon_"+docCt+"');\">"+pdftitle+"</a></div> <div style=\"float:right; margin-right:3px;\"></div><div style=\"float:right; margin-right:5px;\"><a href=\"javascript:void(0)\" onClick=\"deletePDF('"+docUid+"', '"+pdftitle+"'); \"><img src=\"images5/exit_12x12.gif\" alt=\"delete\" width=\"12\" height=\"12\" border=\"0\" style=\"margin-top:4px\"></a></div></div>"+addpdf_el.innerHTML;
	PassFlashPdf(pdfname, pdffile, imgpdffile, pc, picwd, picht, pdftitle, docUid);
	
	changeSel('pdficon_'+docCt);
	
}

function editPdf(pdfname, pdffile, imgpdffile, pc, picwd, picht, pdftitle, docUid){
	//alert('image is = '+img);
	//avatar_new = img;
	var pdf_el = document.getElementById('pdfeditor');
	//alert("ok starting update with pdfname = "+pdfname);
	pdf_el.innerHTML = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"1500\" height=\"1500\" title=\"pdfzoom\"> <param name=\"movie\" value=\"pdfzoom16.swf?pdfname="+pdfname+"&pdf_file="+pdffile+"&img_pdf_file="+imgpdffile+"&pc="+pc+"&picwd="+picwd+"&picht="+picht+"&pdftitle="+pdftitle+"\"> <param name=\"quality\" value=\"high\">	<param name=\"wmode\" value=\"transparent\"> <embed src=\"pdfzoom16.swf?pdfname="+pdfname+"&pdf_file="+pdffile+"&img_pdf_file="+imgpdffile+"&pc="+pc+"&picwd="+picwd+"&picht="+picht+"&pdftitle="+pdftitle+"&docuid="+docUid+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"1500\" height=\"1500\" wmode=\"transparent\"></embed>  </object>";
	//pdf_el.innerHTML = "hello <P><P> ok<P>";
	var newStyle=pdf_el.style;
	//alert("Flash = \n"+pdf_el.innerHTML);
	if(picwd > 800){
		var wd = picwd;
	}else{
		var wd = 800;
	}
	var ht = picht + 110;
	newStyle.width=wd +"px";
	newStyle.height=ht +"px";
	
	
	var pdftitle_el = document.getElementById('titlePdf');
	pdftitle_el.innerHTML = "<img src=\"icons_main/page_white_acrobat.png\" alt=\"home\" width=\"16\" height=\"16\" style=\"margin-right:5px; float:left;\">"+pdftitle;
	
	
	
	
}



function PassFlashPdf(pdfname, pdffile, imgpdffile, pc, picwd, picht, pdftitle, docUid){
    
	//alert("HEY Flash added pdfname = \n"+pdfname);
	var pdfMovie=getFlashMovieObject("pdfflash");
    pdfMovie.SetVariable("pdfname", pdfname);
	pdfMovie.SetVariable("pdf_file", pdffile);
	pdfMovie.SetVariable("img_pdf_file", imgpdffile);
	pdfMovie.SetVariable("pc", pc);
	pdfMovie.SetVariable("picwd", picwd);
	pdfMovie.SetVariable("picht", picht);
	pdfMovie.SetVariable("pdftitle", pdftitle);
	pdfMovie.SetVariable("docuid", docUid);
	pdfMovie.SetVariable("newDoc", 1);
	/**
	
	//Got rid of this because it doesn't work with ie
	window.document.pdfflash.SetVariable("pdfname", pdfname);
	window.document.pdfflash.SetVariable("pdf_file", pdffile);
	window.document.pdfflash.SetVariable("img_pdf_file", imgpdffile);
	window.document.pdfflash.SetVariable("pc", pc);
	window.document.pdfflash.SetVariable("picwd", picwd);
	window.document.pdfflash.SetVariable("picht", picht);
	window.document.pdfflash.SetVariable("pdftitle", pdftitle);
	window.document.pdfflash.SetVariable("docuid", docUid);
	window.document.pdfflash.SetVariable("newDoc", 1);
	**/
	//alert('its over son');
	
	var pdf_el = document.getElementById('pdfeditor');
	var newStyle=pdf_el.style;
	
	if(picwd > 800){
		var wd = picwd;
	}else{
		var wd = 800;
	}
	var ht = picht + 110;
	newStyle.width=wd +"px";
	newStyle.height=ht +"px";
	
	
	var pdftitle_el = document.getElementById('titlePdf');
	pdftitle_el.innerHTML = "<img src=\"icons_main/page_white_acrobat.png\" alt=\"home\" width=\"16\" height=\"16\" style=\"margin-right:5px; float:left;\">"+pdftitle;
	edit_docuid = docUid; 
	

}


function changeSel(pdficonId){
	
	
	//alert("changing "+pdficonId+" TO ="+selPdf+"==");	
	if(selPdf != pdficonId){
		var pdficon_el = document.getElementById(pdficonId);
		if(pdficon_el){
			pdficon_el.innerHTML = "<img src=\"icons_main/page_edit.png\" height=\"16\" width=\"16\" border=\"0\" alt=\"fav\" style=\"margin-left:5px;\" >";
			var unsel_el = document.getElementById(selPdf);
			unsel_el.innerHTML = "<img src=\"icons_main/page_white_text.png\" height=\"16\" width=\"16\" border=\"0\" alt=\"fav\"  >";
			selPdf = pdficonId;
			//alert("changing - "+pdficonId+" to "+pdficon_el.innerHTML); 
			//alert("changing "+pdficonId+" bcos it is not ="+selPdf+"==");	
		}
	}else{
		//alert("cannot change "+pdficonId+" bcos it is not ="+selPdf+"==");
	}
	
	
	
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

//this function loads the sections of the pages on the screen after the page as loaded
function pageLoaded(){
	//alert("Cool Page loaded now");
	//moveDiv('mainP', -74, 0);
	//changeClass('mainP', 'mainPloaded')
	//alert('hey son uyi');
	var newmDiv=document.getElementById('mainP');
	var newmStyle=newmDiv.style;
	//alert("about to show menu for "+id+" and var = "+newDiv);
	newmStyle.filter = "Alpha(Opacity=100)"; //for IE 
	removeDiv('loadingX');
	removeDiv('backfade');
	//setTimeout('removeDiv(\'loadingX\')', 1000);
	//setTimeout('removeDiv(\'backfade\')', 1000);
	if(j_docuid > 1){	
		//alert("-- loading the first = "+j_docname);
		PassFlashPdf(j_pdfname, j_pdffile, j_imgpdffile, j_pagecount, j_picwd, j_picht, j_docname, j_docuid); 
		changeSel('pdficon_'+j_docCt);
	}else{
		//alert("No first = "+j_docname);
	}
		
	newmStyle.opacity = 1; //for FF
	
	//moveDiv('mainP', newtop, newleft);
	//moveDiv(id, newtop, newleft)
	//alert("now pdfuid_array = "+pdfuid_array);
	
	
}

//This is called by flash to save old
function saveOldPdfFlash(docuid, editver){
	//alert('Saving Old Ok I will save it in a Doc-'+docuid+' as version '+editver);
	save_docuid = docuid;
	save_editver = editver;
	winOpened = "saveoldPDF";
	var save_old_pdf_url = "http://www.2waystar.com/savePdf.php?saveold=1&docuid="+docuid+"&editver="+editver;
	if(editver > 0){
		//alert("saving = id-"+docuid+"\n\nurl is "+save_old_pdf_url);
	
		ajaxGetUrlPDF(save_old_pdf_url);
	}else{
		//alert("Nothing to Save. \nNo changes have being made to your PDF document");
		winOpened = "none";
	}
	
	
	
	
}

function sharePdfFlash(docuid){
	alert('Sharing Ok I will save it in a Doc-'+docuid);
	
	
	//ajaxGetUrlSilent(dl_url);
	
	
	
	
	
}

function combinePdfFlash(docuid){
	
	loadBackfade();  
	moveDivCenter('combinePDF');
	winOpened = "combinePDF";
	
	
	
}


function closeWindow(winref){
	if(winref){
		winref.close();
	}
}
function downloadPdfFlash(docuid){
	//alert('Download Ok I will save it in a Doc-'+docuid);
	startDownload(docuid);
	//var dl_url = "http://www.2waystar.com/downloader.php?delpdf=1&docuid="+docuid;
	//var dl_url = "http://www.google.com";
	
	//dlRef = window.open(dl_url,'mywin','left=20,top=20,width=100,height=100,toolbar=0,resizable=0');
	//dlRef.moveTo(-300,-300);
	//setTimeout('closeWindow(dlRef)', 5000);
	setTimeout('dlRef.close()', 5000);
	//alert("url is "+dl_url);
	
	
	
	
	
}

function saveNewPdfFlash(docuid, editver){
	//alert('Saving New\nPlease tell me Docname\n\nOk I will save it in a Doc-'+docuid+' as version '+editver);
	loadBackfade();  
	moveDivCenter('savenewPDF');
	save_docuid = docuid;
	save_editver = editver;
	document.save_new_PDF.newdocname.value = "";
	document.save_new_PDF.newdocname.focus();
	
	
	
}

function deletePDF(docuid, pdftitle){
	//var aTitleId = document.getElementById('aTitle_'+a_uid);
	var answer = confirm("Delete PDF: "+pdftitle+"?")
	if (answer){
		
		var old_pdfuid_array = pdfuid_array;
		var old_allpdf_array = allpdf_array;
		for(var i = 0; i < pdfuid_array.length; i++){
			if(pdfuid_array[i] == docuid){
				// remove it from the array using splice
				//alert("there are "+allpdf_array.length+" elements in allpdf \n\n"+allpdf_array+"\n\nBefore \n"+old_allpdf_array);
				pdfuid_array.splice(i, 1); 
				allpdf_array.splice(i, 1); 
				//alert("Now there are "+allpdf_array.length+" and below "+allpdf_array);
				var lastoff = allpdf_array.length - 1;
				var nextpdfarr = allpdf_array[lastoff];
			
				//alert("UYI there are "+allpdf_array.length+" elements in allpdf and next = "+nextpdfarr[6]);
				//alert("now pdfuid_array = "+pdfuid_array+" and next docuid = "+nextpdfarr+"\n\nAll pdf = "+allpdf_array);
				if(edit_docuid == docuid){
					// if you delete one that you are working on, it should move to the next one	
					var d_pdffile = nextpdfarr[0];
					var d_docname = nextpdfarr[1];
					var d_docuid = nextpdfarr[2];
					var d_pagecount = nextpdfarr[3];
					var d_picwd = nextpdfarr[4];
					var d_picht = nextpdfarr[5];
					var d_pdfname = nextpdfarr[6];
					var d_imgpdffile = nextpdfarr[7];
					//alert("you delete a doc you were working on so I am gointo remvoe it\nSince next doc = "+nextdocuid+"\narray = "+nextpdfarr);
			
			
					
					PassFlashPdf(d_pdfname, d_pdffile, d_imgpdffile, d_pagecount, d_picwd, d_picht, d_docname, d_docuid); 
					var newdocCt = allpdf_array.length;
					changeSel('pdficon_'+newdocCt);
					
				}
			}
			
		}
		remDelPDF(docuid);
			
		//removeAlert(a_uid);
	}else{
		//alert("Thanks for sticking around!")
	}
}

// used by flash to delete a file that it could not make an image of
function deleteCorruptedPDF(docuid){
	var old_pdfuid_array = pdfuid_array;
	var old_allpdf_array = allpdf_array;
	for(var i = 0; i < pdfuid_array.length; i++){
		if(pdfuid_array[i] == docuid){
			// remove it from the array using splice
			//alert("there are "+allpdf_array.length+" elements in allpdf \n\n"+allpdf_array+"\n\nBefore \n"+old_allpdf_array);
			pdfuid_array.splice(i, 1); 
			allpdf_array.splice(i, 1); 
			//alert("Now there are "+allpdf_array.length+" and below "+allpdf_array);
			var lastoff = allpdf_array.length - 1;
			var nextpdfarr = allpdf_array[lastoff];
		
			//alert("UYI there are "+allpdf_array.length+" elements in allpdf and next = "+nextpdfarr[6]);
			//alert("now pdfuid_array = "+pdfuid_array+" and next docuid = "+nextpdfarr+"\n\nAll pdf = "+allpdf_array);
			if(edit_docuid == docuid){
				// if you delete one that you are working on, it should move to the next one	
				var d_pdffile = nextpdfarr[0];
				var d_docname = nextpdfarr[1];
				var d_docuid = nextpdfarr[2];
				var d_pagecount = nextpdfarr[3];
				var d_picwd = nextpdfarr[4];
				var d_picht = nextpdfarr[5];
				var d_pdfname = nextpdfarr[6];
				var d_imgpdffile = nextpdfarr[7];
				//alert("you delete a doc you were working on so I am gointo remvoe it\nSince next doc = "+nextdocuid+"\narray = "+nextpdfarr);
		
		
				
				PassFlashPdf(d_pdfname, d_pdffile, d_imgpdffile, d_pagecount, d_picwd, d_picht, d_docname, d_docuid); 
				var newdocCt = allpdf_array.length;
				changeSel('pdficon_'+newdocCt);
				
			}
		}
		
	}
	remDelPDF(docuid);
	
}



function saveNewPDF(docuid, pdftitle, editver){
	
	if(!(editver > 0)){
		editver = "";
	}
		
	pdftitle = escape(pdftitle);
	var save_pdf_url = "http://www.2waystar.com/savePdf.php?savenew=1&docuid="+docuid+"&docname="+pdftitle+"&editver="+editver;
	
	
	if(pdftitle != ""){
		//alert("url is "+save_pdf_url);
	
		ajaxGetUrlPDF(save_pdf_url);
	}else{
		alert("You must enter a title for your PDF document");
		document.save_new_PDF.newdocname.focus();
	}
}


function PassFlashSavePdf(){
    
	//alert("HEY setting you just saved Flash added pdfname");
	var pdfMovie=getFlashMovieObject("pdfflash");
    pdfMovie.SetVariable("oldSaveDoc", 1);
	

}


function ajaxGetUrlPDF(url){
	var eofurl = 0;
	var xml_file = url;
	writeDiv('loadingdiv', 'Loading...');
	//moveDiv('loadingX', '280', '390'); 
	moveDivCenter('loadingX');
	el = document.getElementById('loadingdiv');
	//el.innerHTML = "Loading...";
	//switchZ('loadingX');
	
	//setTimeout('removeDiv(\'loadingX\')', 10000);
	//alert("this is the url "+xml_file+"\n\na_uid = "+currAlertId);
	
	var predivId = "preload_img";
	if (document.getElementById) {
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
		
	}else{
		//alert("No X connection here");
	}
	if (x){
		//alert('we have x '+x);
		x.onreadystatechange = function(){
			if (x.readyState == 4 && x.status == 200){
				//alert(" okay loaded your image - "+xml_file);
				//el = document.getElementById(predivId);
				//el.innerHTML = x.responseText;
				
				var content = x.responseText;
				
				el = document.getElementById('loadingdiv');
				//el.innerHTML = "Loading...";
				
				//var avatar_el = document.getElementById('avatar');
				//avatar_el.innerHTML = "<img src=\""+avatar_new+"\" alt=\"avatar\" width=\"92\" height=\"92\" style=\"border:#000000 1px solid; margin-right:10px;\">";
				
				//removeDiv('loadingX');
				//alert("con = "+content);
				if(winOpened != "none"){
					//alert('winopened = '+winOpened);
					if(winOpened == 'savenewPDF'){
						//alert("hey this is content - "+content);
						var new_pdf_arr = content.split("uyi_uyi");
						
						var conres = new_pdf_arr[1];
						var conindex = conres.indexOf("updated");
						//alert("REST - ok I am in - array="+new_pdf_arr+" and conres = "+conres+" and index = "+conindex);
						if(conres.indexOf("updated") == 0){
						
							
							
							var docUid = new_pdf_arr[10];
							var pdfname = new_pdf_arr[2];
							var pdffile = new_pdf_arr[3];
							var imgpdffile = new_pdf_arr[4];
							var pc = new_pdf_arr[5];
							var picwd = new_pdf_arr[6];
							var picht = new_pdf_arr[7];
							var pdftitle = new_pdf_arr[8];
							var docCt = new_pdf_arr[9];
							addDocs(pdfname, pdffile, imgpdffile, pc, picwd, picht, pdftitle, docCt, docUid);
								
							el.innerHTML = "<strong>Saving Complete</strong>";
							setTimeout('removeDiv(\'loadingX\')', 1000);
							setTimeout('removeDiv(\'backfade\')', 1000);
							setTimeout('removeDiv(\''+winOpened+'\')', 1000);
							winOpened = "none";
							//alert(" loading complete - "+content+" and firstname = "+firstname_js);
						}else if(content.indexOf("cell_not_num") == 0){
							el.innerHTML = "<strong><font color=\"#FF0000\">Invalid cellphone number</font></strong>";
							setTimeout('removeDiv(\'loadingX\')', 1000);
							alert("Please enter a numeric cellphone number \nEx: 3105551212");
							document.profile_form.defphone.focus();
							document.profile_form.defphone.select();
						}else if(content.indexOf("taken_nick") == 0){
							el.innerHTML = "<strong><font color=\"#FF0000\">Nickname taken</font></strong>";
							setTimeout('removeDiv(\'loadingX\')', 1000);
							alert("Sorry, "+nickname_new+" is already taken\nPlease choose another nickname.");
							document.profile_form.nickname.focus();
							document.profile_form.nickname.select();
						}
					}else if(winOpened == 'saveoldPDF'){
						//alert("hey this is content - "+content);
						var new_pdf_arr = content.split("uyi_uyi");
						
						var conres = new_pdf_arr[1];
						var conindex = conres.indexOf("updated");
						//alert("Save OLd REST - ok I am in - array="+new_pdf_arr+" and conres = "+conres+" and index = "+conindex);
						if(conres.indexOf("updated") == 0){
						
							
							
							var docUid = new_pdf_arr[10];
							//alert("removed  - "+save_docuid+" and new uid = "+docUid);
						
							var pdfname = new_pdf_arr[2];
							var pdffile = new_pdf_arr[3];
							var imgpdffile = new_pdf_arr[4];
							var pc = new_pdf_arr[5];
							var picwd = new_pdf_arr[6];
							var picht = new_pdf_arr[7];
							var pdftitle = new_pdf_arr[8];
							var docCt = new_pdf_arr[9];
							addDocs(pdfname, pdffile, imgpdffile, pc, picwd, picht, pdftitle, docCt, docUid);
							remDelPDF(save_docuid);
							
							//PassFlashSavePdf();	
							el.innerHTML = "<strong>Saving Complete</strong>";
							setTimeout('removeDiv(\'loadingX\')', 1000);
							//setTimeout('removeDiv(\'backfade\')', 1000);
							//setTimeout('removeDiv(\''+winOpened+'\')', 1000);
							winOpened = "none";
							//alert(" loading complete - "+content+" and firstname = "+firstname_js);
						}else if(content.indexOf("invalid") == 0){
							el.innerHTML = "<strong><font color=\"#FF0000\">Address Not Found</font></strong>";
							setTimeout('removeDiv(\'loadingX\')', 1000);
							alert("your address was not found \nPlease re-enter your address");
							document.addr_form.address_hm.focus();
							
						}
					}
				
	
												
				 }
				//return content;
				//removeDiv('loadingX');
			}else{
				//alert('readystate = '+x.readyState);
			}
		}
		x.open("GET", xml_file, true);
		x.send(null);
	}
	
}

