// 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));


//firefox = mozilla/5.0 (windows nt 6.1; wow64; rv:9.0) gecko/20100101 firefox/9.0
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
var is_firefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
if((is_chrome)||(is_firefox)){
	safari = false;	
}

if(safari == true){
	
	
}

//alert(' ischrom = '+is_chrome+' and safari = '+safari+' and firefox = '+is_firefox+' and browser = '+navigator.userAgent.toLowerCase());
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
var addMyMediaType = 0;	//1=add to itim, 2 = myavatar, 3 = contact_avatar
var updateAvatar = 0;
var socket;		//love this socket
var is_socket_connected = 0;
var is_checker_on = 0;
var is_checker_once_on = 0;
var socket_should_reconnect = 0;
var disconnect_count = 0;
var reconnect_max = 3; 		// its 3 per minute, so 5 minutes. if greater, logout

var openingIcidWinArr = new Array();	//this is used to detect win in the process of opening

var gAuthLevel = 0;		//google chrome auth level, 1 = paid, 2 = free with ads
var prev_con_name = '';
var prev_con_i_c_id = 0;
var prev_con_avatar = '';
//var fav_group_id = 0;


var curr_long = "";
var curr_lat = "";
var lostConnectionLogout = 0;
//** These are the itim Function **//
//var itimswf = "itim_0.1.2";
//var itimswf = "itim_2";
//var itimswf = "itim_3";
//var itimswf = "itim_4";
//var itimswf = "itim_6";
//var itimswf = "itim_8";
//var itimswf = "itim_9";

var itimswf = "itim_10";
var itimswf_safari = "itim_6c";		//safari can't handle overlayed scroll-y
var mp3swf = "mp3player";
//var itimswf = "itim_5";
//var itimswf = "itim_9_basic";
var itimvidswf = "vid_player3";
//var cameraswf = "webcam3b";
//var cameraswf = "webcam7b";

//
var cameraswf = "webcam9";



if(location.hostname == 'www.2waystar.com'){
	
	var server_name = "www.2waystar.com";
	
	//var server_name = "38.98.53.52";
	//alert('url = '+location.pathname+' and hostname = '+location.hostname+' href = '+location.href);
	var baseUrl = "http://www.2waystar.com/itimworld/";	
		
}else{
	
	var server_name = "www.itimworld.com";
	
	//var server_name = "38.98.53.52";
	//alert('url = '+location.pathname+' and hostname = '+location.hostname+' href = '+location.href);
	var baseUrl = "http://www.itimworld.com/";	
	
	
}


//send the baseUrl as base_url_main for flash to use
var sessId;


/**
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 editAddressbookUrl = baseUrl+"con_scripts/addressbookWidget.php";		// url for checking for 

var getIcidUrl = baseUrl+"con_scripts/getIcidAjax.php";		// url for checking for new messages
var itim_mp3_url_prefix = baseUrl+"tim_audio_mp3/";

var timsenderUrl = baseUrl+"con_scripts/timsenderwidget.php";		// url for checking for new messages


var timsenderGroupUrl = baseUrl+"con_scripts/timsenderallwidgetgroup.php";		// url for checking for new
var timreadUrl = baseUrl+"con_scripts/itimReadStatusApp.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 updateInAppUrl = baseUrl+"updateInApp.php";
var clearIcidUrl = baseUrl+"con_scripts/clearIcid.php";				//deletes allitim entry and clears the convo
var editGroupUrl = baseUrl+"con_scripts/editGroupXML.php";				//edits existing group
var createGroupUrl = baseUrl+"con_scripts/createGroupXML.php";				//creates new  group




var rotation_deg = 0;

var newContactAvatar= '';	//when you change a contact avatar, this is set to it until you save. it is cleared when you delete or cancel or close
var isStartNewOpened = 0;
var isStartNewIMOpened = 0;
var checkIntervalId;		// used to start and stop
var checkIntervalIdOnce;
var shakeIntervalId;
var swfIntervalId;
var reconIntervalId;
var reconOn = 0;
var shakeUnit;
var lostConnCount = 0;
var topOpenedIcid = 0;
var firstCheck = 1;
var fadingConvo = 0;
var itim_nickname = '';
var itim_user_id;		//user_id
var fav_group_id;
var isadmin = 0;
var newAttachment = '';		//attachment when createing a new message
var newAudio = '';
var newcellnum = '';
var newnickname = '';
var new_icid;
var new_avatar;
var new_group_id;
var new_group_type;
var new_itim_version;
var new_admin_group = 0;
var new_mes_type;
var new_form_opened = 0;
var nosend = 0;			//is 1 when u open a contact after geticid
var camera_pic = "";
var camera_pic_wd;
var camera_pic_ht;
var camera_thumb_wd;
var camera_thumb_ht;
var allitimcasenum = 1;		//counts all the new itims added
var isAllMuted = 0;

var use_drag_drop = 0;	//this allows drag and drop of files, it is set by addpicmain.php

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;

//time between checking for msgs
//var timeCheck = 10000;
var timeCheck = 20000;
var firstTimeCheck = 5000;
//var timeCheck = 60000;

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;
var newitim_main = 0;

/** ie adds the scroll bars to the width of the total screen */
var iescrollwd = 21;
var iescrollht = 0;


var curr_bg;
var prev_curr_bg;

var curr_bg_pos;
var prev_bg_pos;

var curr_bg_repeat;
var prev_bg_repeat;
var unsavedBg = 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;
      }
    }
  }
}
*/


//added this so we can search for array stuff
 if (!Array.prototype.indexOf)
  {

       Array.prototype.indexOf = function(searchElement /*, fromIndex */)

    {


    "use strict";

    if (this === void 0 || this === null)
      throw new TypeError();

    var t = Object(this);
    var len = t.length >>> 0;
    if (len === 0)
      return -1;

    var n = 0;
    if (arguments.length > 0)
    {
      n = Number(arguments[1]);
      if (n !== n)
        n = 0;
      else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0))
        n = (n > 0 || -1) * Math.floor(Math.abs(n));
    }

    if (n >= len)
      return -1;

    var k = n >= 0
          ? n
          : Math.max(len - Math.abs(n), 0);

    for (; k < len; k++)
    {
      if (k in t && t[k] === searchElement)
        return k;
    }
    return -1;
  };

}





// preloads images and flash
function preloadflash(flashLoc) {
	myflash01 = new Image(); 
	//myflash01.src = flashLoc;
	alert("wecam = "+myflash01.src);
	
}
function preloadMyImages(picArr, picArrDim, maxct){
	
	if (document.images){
	
		var i = 0;
		var tempct = picArr.length;
		
		if(maxct > 0){
			
			
			if(tempct < maxct){
				
				maxct = tempct;	
			}
			

		}else{
			
			maxct = tempct;	
		}
		
		//alert('Yes loaded ct = '+maxct+' and pc arr = '+picArrDim[0]);
		var k = 1;
		
		var imgloader = function(i,picPath,picWd,picHt,attr) {
			//alert('woah i = '+i);
			
			//var picPathThumb = searchAndReplace (picPath, "tim_images/", "tim_images_thumbs/");
			var picPathThumb = picPath;
			var imgcon = "<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\"><img src=\""+picPathThumb+"\" "+attr+" title=\"Add This Pic iTim\" alt=\"Add This Pic iTim\"  border=\"0\" style=\"margin:5px;cursor:pointer;\" onClick=\"setPicMain('"+picPath+"', '"+picPath+"', '"+picWd+"', '"+picHt+"')\" onMouseOver=\"showPicMouse(this.parentNode.parentNode.parentNode.parentNode.parentNode.id, 'overPicItim');\" onMouseOut=\"showPicMouse(this.parentNode.parentNode.parentNode.parentNode.parentNode.id, 'outPicItim');\"> </td></tr></table>";
				
				
				
			//var imgcon = "<img src=\""+picArr[i]+"\" width=\""+picArrDim[i][0]+"\" height=\""+picArrDim[i][1]+"\" alt=\"photos\"  border=\"0\" style=\"margin:5px;\">";
			var clickDiv = "pic"+i;
				
				
			//alert('just clickdiv = '+clickDiv+' image ocn = ');
			
			if(divIdExists(clickDiv) == 1){	
				writeDiv(clickDiv, imgcon);
			
			
			}
			//alert('just clickdiv = '+clickDiv+' and  wrote div con '+imgcon);
			
			
		}
		
		
		for(i=0; i<=maxct; i++){ 
			//preload_image_object.src = picArr[i];
		 	
		 	
			//alert('loading img = '+picArr[i] );
			if(typeof(picArr[i]) != "undefined"){
				var image = new Image();
				image.src = picArr[i];
				var picPath = picArr[i];
				var picWd = picArrDim[i][0];
				var picHt = picArrDim[i][1];
				var attr = picArrDim[i][2];
				image.onload = imgloader(i,picPath,picWd,picHt,attr);
				
			}
			
		}
		
		//alert('hey done and cid = '+clickDiv);
		
	}else{
		
			//alert('NONE loaded = '+picArr);
		
	}

}


function preloadImages(picArr, picArrDim, maxct, maxWd, maxHt){
	
	
   alert('preload begin and maxct = '+maxct);
	
	if (document.images){
		preload_image_object = new Image();
		
		var i = 0;
		var tempct = picArr.length;
		
		if(maxct > 0){
			
			
			if(tempct < maxct){
				
				maxct = tempct;	
			}
			

		}else{
			
			maxct = tempct;	
		}
		
		for(i=0; i<=maxct; i++){ 
			//preload_image_object.src = picArr[i];
		 	
		 	
			
			
			var image = new Image();
			image.onload = function() {
				alert('loadcomplete img = '+picArr[i] );
				var imgcon = "<img src=\""+picArr[i]+"\" width=\""+picArrDim[i][0]+"\" height=\""+picArrDim[i][1]+"\" alt=\"photos\"  border=\"0\" style=\"margin:5px;\">";
				var clickDiv = "clickpic"+i;
				
				
				writeDiv('clickDiv', imgcon);
				
				alert('just wrote div con '+imgcon);
			};
			image.src = picArr[i];

			
			
			
		}
	}

       
  
	
	
}

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);
	
}



//contact stuff
//gets the i_c_id for a contact c_id
function saveContact(con_id, con_icid){
	//var getUrl = baseUrl+"con_scripts/itim_createconversation.php?cid="+cid;
	
	//$firstname", "$lastname", "$newfrom", "$email", "$note, $newcell
	var firstname = escape(document.getElementById('contact_fname').value);
	var lastname = escape(document.getElementById('contact_lname').value);
	if((firstname == '')&&(lastname == '')){
		//echo error, must have a 
		alert('You must add a first or last name before you can save a contact. Please add one and save');
		
		document.getElementById('contact_fname').focus;
		return false;
	}
	
	
	
	var newcell = escape(document.getElementById('contact_phone').value);
	
	if((newcell > 0)&&(newcell.length > 9)){
		
	}else{
		//echo error, must have a 
		alert('You must add a 10 digit number before you can save. Please add one and save');
		
		document.getElementById('contact_phone').focus;
		return false;
	}
	
	var email = escape(document.getElementById('contact_email').value);
	
	
	if(con_id > 0){
	 	var mode = "&updatecontact=1";	
	
	}else{
		
	 	var mode = "&addnewcontact=1";	
		con_id = 0;
	}
	
	
	
	if(con_icid > 0){
	 	
	}else{
		
	 	con_icid = 0;
	}
	var avatarsetting = "&updateAvatar=0";	
	var avatarpicloc = '';
	if(newContactAvatar != ''){
		
		var avatarsetting = "&updateAvatar=1";
		avatarpicloc = newContactAvatar;	
	}



	var getUrl = editAddressbookUrl+"?"+mode+avatarsetting+"&newfrom="+itim_nickname+"&firstname="+firstname+"&lastname="+lastname+"&newcell="+newcell+"&email="+email+"&contacts_id="+con_id+"&long="+curr_long+"&lat="+curr_lat+"&picloc="+avatarpicloc+"&con_icid="+con_icid+"&id="+parent.itim_user_id+"&sessID="+parent.sessId;
	//alert("save stri = "+getUrl);
	var func = "saveConComplete";
	
	//alert("about to get "+getUrl+" and func = "+func);
	//ajaxGetUrlFunction(getUrl, func);
	var status = "saving in progress. please wait...<img src=\"images_iphone/loader.gif\" alt=\"saving...\" width=\"32\" height=\"32\" border=\"0\" style=\" margin-left:4px;\">";
	changeClass('con_status', 'con_status_saving');
	writeDiv('con_status', status);
	showDiv('con_status');
	ajaxGetUrlAndFunc(getUrl, func);	
	
	
}

function saveConComplete(str){
	str = unescape(str);
	//str = echo $contacts_id.":-_-:".$i_c_id.":-_-:".$newcell.":-_-:".$addnewcontact;
	//alert("delete stri = "+getUrl);
	var conarr = str.split(":-_-:");
	//alert("con = "+str+" and conarr = "+conarr); 
	if(conarr.length > 1){
		changeClass('con_status', 'con_status');
		var status = "Saving Complete :)";
		writeDiv('con_status', status);
		showDiv('con_status');
		var new_con_id = conarr[0];
		var new_con_icid = conarr[1];
		if((new_con_id > 0)&&(new_con_icid > 0)){
			
			var con_save_buttons = "<div class=\"contact_div\"><div id=\"delete_con\" class=\"delete_div\" title=\"delete this contact\" onClick=\"deleteContact('"+new_con_id+"');\">Delete</div></div><div class=\"contact_div\"><div id=\"save_con\" class=\"save_div\" title=\"save this contact\" onClick=\"saveContact('"+new_con_id+"', '"+new_con_icid+"');\">Save</div></div>";
					
			writeDiv('con_buttons', con_save_buttons);
			
			//disable the phone contact_phone
			//.disabled = true;
			document.getElementById('contact_phone').disabled = true;
			
			insertNewContactElem(new_con_id, new_con_icid);
			//contactObjArray[1] = {i_c_id:785825, firstname:'peater', lastname:'', avatar:'avatars/nopic_sm.jpg', con_id:509672, email:'', phone:'3105552414', lat:-118.2569396, long:'34.0498741'};
			
			
		}
		
		
	}
	
	
}

function deleteContact(con_id){
	
	
	if(con_id > 0){
	 	var mode = "&deletecon=1";	
		var getUrl = editAddressbookUrl+"?updatecontact=1"+mode+"&contacts_id="+con_id;
		//alert("delete stri = "+getUrl);
		var func = "deleteConComplete";
	
		//alert("about to get "+getUrl+" and func = "+func);
		//ajaxGetUrlFunction(getUrl, func);
		ajaxGetUrlAndFunc(getUrl, func);	
	
	
	}
	
	
}

function deleteConComplete(str){
	str = unescape(str);
	//str = echo $contacts_id.":-_-:".$i_c_id.":-_-:".$newcell.":-_-:".$addnewcontact;
	//alert("delete stri = "+getUrl);
	var conarr = str.split(":-_-:");
	//alert("delete con = "+str); 
	if(conarr.length > 1){

		var new_con_id = conarr[0];
		if(new_con_id > 0){
			removeNewContactElem(new_con_id);
		
			//alert('done must remoce now');
			removeDiv('addShowProfile'); winOpened = 'none';removeDiv('backfade');
		
		}
	}
	
	
}



function makeContact(firstname, lastname, i_c_id, avatar, con_id, email, phone, lat, long) {
    this.firstname = firstname;
    this.lastname = lastname;
	this.i_c_id = i_c_id;
    this.avatar = avatar;
	this.con_id = con_id;
    this.email = email;
	this.phone = phone;
    this.lat = lat;
	this.long = long;
	
	contactIcidInfoArray[phone] = new Array(i_c_id, firstname, lastname, avatar, con_id, email, lat, long);
   
}

//this is how you loop thru an object of keys
function loopThruKeys(){


	var validation_messages = {
		"key_1": {
			"your_name": "jimmy",
			"your_msg": "hello world"
		},
		"key_2": {
			"your_name": "billy",
			"your_msg": "foo equals bar"
		}
	}


	for (var key in validation_messages) {
	   var obj = validation_messages[key];
	   for (var prop in obj) {
		  alert(prop + " = " + obj[prop]+" and the obj name = "+obj.your_name);
	   }
	}	
	
	
}

function loopThruObjectArray(objarray){
	
	

	for (var key in objarray) {
	   var obj = objarray[key];
	   alert("this contact firstname = "+obj.firstname+" and lastname = "+obj.lastname+" and icid = "+obj.i_c_id);
	   /*
	   for (var prop in obj) {
		  alert(prop + " = " + obj[prop]+" and the obj name = "+obj.your_name);
	   }
	   
	   */
	}	
		
	
	
	
}


function sortByFirstName(a, b) {
    var x = a.FirstName.toLowerCase();
    var y = b.FirstName.toLowerCase();
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}


function sortByLastNameThenFirst(a, b) {
    
	var m = a.LastName.toLowerCase();
    var n = b.LastName.toLowerCase();
	
	
	
	
	
	
	if(m < n){
		return -1;	
	}else if(m > n){
		return 1;	
	}else{
		//when they have the same last name
		//we need to sort by their firstname	
		var x = a.FirstName.toLowerCase();
    	var y = b.FirstName.toLowerCase();
		return ((x < y) ? -1 : ((x > y) ? 1 : 0));
	}
	
	
}


function sortByLastNameThenFirstReverse(a, b) {
    
	var m = a.lastname.toLowerCase();
    var n = b.lastname.toLowerCase();
	
	
	
	
	
	
	if(m > n){
		return -1;	
	}else if(m < n){
		return 1;	
	}else{
		//when they have the same last name
		//we need to sort by their firstname	
		var x = a.firstname.toLowerCase();
    	var y = b.firstname.toLowerCase();
		return ((x > y) ? -1 : ((x < y) ? 1 : 0));
	}
	
	
}



function sortItimByLastNameThenFirst(a, b) {
    
	var m = a.lastname.toLowerCase();
    var n = b.lastname.toLowerCase();
	
	
	
	
	
	
	if(m < n){
		return -1;	
	}else if(m > n){
		return 1;	
	}else{
		//when they have the same last name
		//we need to sort by their firstname	
		var x = a.firstname.toLowerCase();
    	var y = b.firstname.toLowerCase();
		return ((x < y) ? -1 : ((x > y) ? 1 : 0));
	}
	
	
}




//this inserts the new contact into the page
function insertNewContactElem(con_id, con_i_c_id){
	
	var firstname = escape(document.getElementById('contact_fname').value);
	var lastname = escape(document.getElementById('contact_lname').value);
	var email = escape(document.getElementById('contact_email').value);
	
	
	var phone = escape(document.getElementById('contact_phone').value);
	var nickname = itim_nickname;
	var long = curr_long;
	var lat = curr_lat;
	var avatar = newContactAvatar;
	if((con_id > 0)&&(con_i_c_id > 0)){
		//alert('about to insert fname = '+firstname+' and avatar = '+avatar);
		//(i_c_id, firstname, lastname, avatar, con_id, email, lat, long);
		//contactIcidInfoArray[phone] = new Array(con_i_c_id, firstname, lastname, avatar, con_id, email, lat, long);
		contactObjArray[contactObjArray.length++] = new makeContact(firstname, lastname, con_i_c_id, avatar, con_id, email, phone, lat, long);
		
		
		var allitim_name_divid = "allitim_name_"+con_i_c_id;
		//alert(' hey div id = '+allitim_name_divid);
		if(divIdExists(allitim_name_divid) == 1){
			
			
			var newContent = document.getElementById(allitim_name_divid).innerHTML;
			
			var hrefarr = newContent.split('>');
			
			if(hrefarr.length > 1){
				
				var fullname = firstname+' '+lastname;
				fullname = ucwords(fullname.toLowerCase());
				var repContent = hrefarr[0]+'>'+fullname+'</a>';
				//alert('writing new cont = '+repContent);	
				writeDiv(allitim_name_divid, repContent);
			}
			
			
			//update the avatar
			if((typeof(avatar) != "undefined")&&(avatar != '')){
	
				var imgId = "avatar_"+con_i_c_id;
				if(divIdExists(imgId) == 1){
			
					var imgobj=document.getElementById(imgId);
					imgobj.src=avatar;
					
				}
			
			}
			
			
		}
		
		
		buildContactBox();
		
		
		
	}
	
}



//this inserts the new contact into the page
function removeNewContactElem(con_id){
	
	var phone = escape(document.getElementById('contact_phone').value);
	
	
	
	//delete contactIcidInfoArray[phone];
	
	if(con_id > 0){
		//alert('about to insert fname = '+firstname+' and avatar = '+avatar);
		//(i_c_id, firstname, lastname, avatar, con_id, email, lat, long);
		//contactIcidInfoArray[phone] = new Array(con_i_c_id, firstname, lastname, avatar, con_id, email, lat, long);
	
		//remove cellinfo
		var cellinfo = contactIcidInfoArray[phone];
	
		var temp_icid = cellinfo[0];
		
		//allitim_name_786043" style="margin-top: 3px;"><a href="javascript:void(0)" onclick="startItimBar(786043); hideDiv('new_alltim_786043');   hideDiv('newMsgAllMain');" title="13105554714: 1msg" style="font-weight: normal; width: 155px; font-size: 14px;">adam</a></div>
		
		var allitim_name_divid = "allitim_name_"+temp_icid;
		//alert(' hey div id = '+allitim_name_divid);
		if(divIdExists(allitim_name_divid) == 1){
			
			
			var newContent = document.getElementById(allitim_name_divid).innerHTML;
			
			var hrefarr = newContent.split('>');
			
			if(hrefarr.length > 1){
				
				var repContent = hrefarr[0]+'>'+phone+'</a>';
				alert('writing new cont = '+repContent);	
				writeDiv(allitim_name_divid, repContent);
			}
			
		}
		
		
		
		delete contactIcidInfoArray[phone];
		//
		var maxct = contactObjArray.length;
		for(var i = 0; i < maxct; i++){	
			var temp_con_id = contactObjArray[i].con_id;	
			//alert('checking arr conid='+temp_con_id+' to the deleete contid = '+con_id);
			if(temp_con_id == con_id){
				
				//splice it out array
				contactObjArray.splice(i, 1);
				i = maxct;
				
			
				
			}
			
			
		
		}
		buildContactBox();
		
		//get the icid for the number and change the allitim box
		
	}
	
}




function createNewContactElem(firstname, lastname, con_id, phone, nickname, lat, long){
	


	var confullname = firstname+" "+lastname;
	var fullname = firstname+" <b>"+lastname+"</b>";
	fullname = ucwords(fullname.toLowerCase());
	fullname = trim(fullname);
	confullname = trim(confullname);
	

	var contactElem = "<div id=\"contact_"+con_id+"\"><table width=\"220px;\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td width=\"86%\"><div style=\"margin-left:10px; margin-right:5px; margin-top:5px; margin-bottom:5px;\"><div class=\"menuLink\"> <a href=\"javascript:void(0)\" onclick=\"createNewItim('"+phone+"', '"+nickname+"');\" title=\""+phone+"\">"+fullname+"</a> </div></div></td><td width=\"14%\"><a href=\"javascript:void(0)\" onClick=\"showContactLocation('"+confullname+"', '"+long+"', '"+lat+"'); \"><img src=\"icons_main/map_go.png\" alt=\"where you met\"  title=\"where you met\" width=\"16\" height=\"16\" border=\"0\" ></a></td></tr></table></div>"; 	

	return contactElem;
	
}



function buildContactBox(){
	//first sort the contacts
	contactObjArray.sort(sortItimByLastNameThenFirst);	
	writeDiv('myContacts', '');
	var content = "";
	var nickname = itim_nickname;
	for (var key in contactObjArray) {
	   var obj = contactObjArray[key];
	   var fname = obj.firstname;
	   var lname = obj.lastname;
	   var con_id = obj.con_id;
	   var phone = obj.phone;
	   var lat = obj.lat;
	   var long = obj.long;
	   //alert("this contact firstname = "+obj.firstname+" and lastname = "+obj.lastname+" and icid = "+obj.i_c_id);
	
		var contactElem = createNewContactElem(fname, lname, con_id, phone, nickname, lat, long);
		content += contactElem;
	
	}
	
	writeDiv('myContacts', content);
	
}


function capitaliseFirstLetter(string)
{
    return string.charAt(0).toUpperCase() + string.slice(1);
}

function ucwords(string)
{
    return string.charAt(0).toUpperCase() + string.slice(1);
}





function addNewContact(){

	loadBackfade();
	loadNewProfile();
	moveDivCenter('addShowProfile');
	winOpened = 'addShowProfile';	
	initGeolocation();
	
}






//gets the i_c_id for a contact c_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);
	
	
}


//gets the i_c_id for a contact phone number
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 previewNewBG(new_bg, pos, repeat){
	//parent.setCurrBg();
	//alert(' parent bg = '+parent.curr_bg+' and itimuserid = '+parent.itim_user_id);
	parent.ajaxChangeBackground('tester', new_bg, pos, repeat);
	showDiv('saveBackground');
	parent.setCurrBg(new_bg, pos, repeat);
	
	parent.unsavedBg = 1;
	
}


function cancelNewBG(){
	
	parent.undoChangeBackground();
	hideDiv('saveBackground');
	parent.unsavedBg = 0;
}


function updateBg_itim(){
	
	var new_bg = parent.getCurrBg();
	parent.unsavedBg = 0;
	var new_pos = parent.curr_bg_pos;
	var new_repeat = parent.curr_bg_repeat;
	//alert('updating bg = '+new_bg);
	var mysessId = parent.getSessId();
	var myuserId = parent.getUserId();
	//alert('updating alerts');
	var url = baseUrl+"con_scripts/ajaxupdatesettings.php?changebg=1&newbg="+new_bg+"&newbgpos="+new_pos+"&newbgrepeat="+new_repeat+"&sessId="+mysessId+"&id="+myuserId;
	//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);

	hideDiv('saveBackground');

}

function addNewBgFromSettings(){
	
	//alert('add new bg');
	parent.loadBackfade();
	parent.loadAddBackground();	
	parent.moveDivCenter('addPicture'); parent.winOpened = 'addPicture';
	
	
}

function switchToPublicBg(){
	//hideDiv('uploadNewBg');
	
	
	
	var elemBgContainer = document.getElementById('addbgcontainer');
	elemBgContainer.style.height = "0px";
	var elemMyGallery = document.getElementById('bg_chooser_hold_itim_gallery');
	elemMyGallery.style.height = "0px";
	//hideDiv('bg_chooser_hold_itim_gallery');
	changeClass('itim_bg_but', 'inactiveButton');
	
	var elemPublic = document.getElementById('bg_chooser_hold_public');
	//elemPublic.style.height = "100px";
	elemPublic.style.height = "200px";
	//showDiv('bg_chooser_hold_public');
	changeClass('public_bg_but', 'currSelectedButton');
	
	
}


function switchToGallery(){
	//showDiv('uploadNewBg');
	
	var elemBgContainer = document.getElementById('addbgcontainer');
	elemBgContainer.style.height = "50px";
	
	var elemMyGallery = document.getElementById('bg_chooser_hold_itim_gallery');
	elemMyGallery.style.height = "100px";
	//showDiv('bg_chooser_hold_itim_gallery');
	changeClass('itim_bg_but', 'currSelectedButton');
	
	var elemPublic = document.getElementById('bg_chooser_hold_public');
	elemPublic.style.height = "0px";
	//hideDiv('bg_chooser_hold_public');
	changeClass('public_bg_but', 'inactiveButton');
	
	
}


function getSessId(){
	
	return sessId;	
	
}


function getUserId(){
	
	return itim_user_id;	
	
}


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 cell - starting itim for :cellnum:"+cellnum+" From: "+from);
	var cellinfo = contactIcidInfoArray[cellnum];
	
	//alert('cellinfo = '+cellinfo);
	
	var name = "";
	var newicid = 0;
	var avatarpic = '';
	if(tempmsg){
		
		//then u must send
		
	}else{
		//no msg just open the contact
			
		//first we need to get the icid
		
		//alert('cellinfo = '+cellinfo);
		
		//var cellinfo = contactIcidInfoArray[cellnum];
		
		if(cellinfo[0] > 0){
			//there is a contact and a name
			 	
			newicid = cellinfo[0];
			name = cellinfo[1]+' '+cellinfo[2];
			name = trim(name);
			avatarpic = cellinfo[3];
		}else{
			
			newicid = icidForCellnumArray[cellnum];
			
		}
		
		//var newicid = icidForCellnumArray[cellnum];



		newcellnum = escape(cellnum);
		
		//var newAttachment = '';		//attachment when createing a new message
		if(cellnum > 0){
			
			new_mes_type = 1;	
		}else{
			new_mes_type = 2;
			
		}





		
		if(newicid > 0){
		
			//alert('\ncellnum = '+cellnum+'\nmessage = '+message+'\nhey index = '+newicid+' and userid = '+itim_user_id);
			
			//send a message
			new_icid = newicid;
			
			
			
			// Check if there is an element
			var allitimdiv = "allitim_"+newicid;
			var divExists = 0;
			
			//alert('about to cheeck for it now = '+allitimdiv);
			if(divIdExists(allitimdiv) != 1){
				//alert(' no sir no div for allitim icid = '+newicid+' so add please');	
				//divExists = 1;
			
				var newmsg_esc = "...";
				var attachment = "";
				
				var time_ago = "          ";
				
				//var time_ago = "2 mins ago";
				
				//get the cellnum and the name/nickname
				
			
				var message_type = '1';
				createNewAllItim(cellnum, newmsg_esc, attachment, message_type, newicid, name, "0", time_ago, avatarpic);
				
				
				
			}else{
				//alert(' element exist for = '+allitimdiv);
				divExists = 1;	
			}
				
			
			
			
			
			
			closeDivIcid(new_icid);
			startItimBar(new_icid);			
			nosend = 0;
		}else{
			//alert('\n you must search for the icid for '+cellnum);



			var new_getIcidUrl = getIcidUrl+'?&send=1&cellnum3='+newcellnum+'&message_type='+new_mes_type;
			
			nosend = 1;
			getIcidAjax(new_getIcidUrl);

		}
	
		
		
		
	}
	
	
	//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);
		alert(' staring icid = '+temp_i_c_id);
		/**
		//check if all_itim_icid exist or create it
		var allitimdiv = "allitim_"+temp_i_c_id;
		var divExists = 0;
		
		//alert('about to cheeck for it now = '+allitimdiv);
		if(divIdExists(allitimdiv) != 1){
			//alert(' no sir no div for allitim icid = '+icid+' so add please');	
			//divExists = 1;
			createNewAllItim('', '', '', '2', temp_i_c_id, name, "0", "");
			
			
			
		}else{
			//alert(' element exist for = '+allitimdiv);
			divExists = 1;	
		}
		
		*/
		startItimBar(temp_i_c_id);
	}else if(im_id > 0){
		getIcidIM(im_id);
		//getItimConvIdFriend(im_id);
	}else{
		
		
	}
	
	
	
}



/**** used to update inapp by updateInApp.php ***/


//updateInAppurl

function updateInApp(updateUserId){
	
	var func = "parseUpdateInApp";
	//alert('url = '+getNewMesUrl+'\n\nfunc = '+func);
	
	
	var vcoinDiv=document.getElementById("vcoins_count");
	if(parseInt(vcoinDiv.innerHTML) > 0){
	
		var vcoins = parseInt(vcoinDiv.innerHTML);
	}else{
		var vcoins = 0;
	}
	
	if(document.getElementById("haspro").checked == true){
		var haspro=1;
	
	}else{
		var haspro=0;
		
	}
	if(document.getElementById("hasmms").checked == true){
		var hasmms=1;
	
	}else{
		var hasmms=0;
		
	}
	if(document.getElementById("hasvmm").checked == true){
		var hasvmm=1;
	
	}else{
		var hasvmm=0;
		
	}
	if(document.getElementById("hasanimator").checked == true){
		var hasanimator=1;
	
	}else{
		var hasanimator=0;
		
	}
	if(document.getElementById("hasvoicetext").checked == true){
		var hasvoicetext=1;
	
	}else{
		var hasvoicetext=0;
		
	}
	if(document.getElementById("hastexttalk").checked == true){
		var hastexttalk=1;
	
	}else{
		var hastexttalk=0;
		
	}
	
		
	
	var updateInAppUrlMain = updateInAppUrl+"?id="+parent.itim_user_id+"&sessID="+parent.sessId+"&updateUserId="+updateUserId+"&vcoins="+vcoins+"&haspro="+haspro+"&hasmms="+hasmms+"&hasvmm="+hasvmm+"&hasanimator="+hasanimator+"&hasvoicetext="+hasvoicetext+"&hastexttalk="+hastexttalk;
	//alert('url main = '+updateInAppUrlMain);
	ajaxGetUrlAndFunc(updateInAppUrlMain, func);	
	
	
	                     
 
	
	
}




/**
*
* parses content received by getNewmessage
*
*/

function parseUpdateInApp(str){
	str = unescape(str);

	//alert('done with update str = '+str);	
	var strarr = str.split('uyi-_-uyi');
	if(strarr[1] == 1){
		
		alert('Update Completed Successfully');	
		
		
	}else{
		
		alert('Update Failed. No such user Or You are permitted to update this feature');	
		
		
	}
	
}


function addVcoin(num){
	
	var vcoinDiv=document.getElementById("vcoins_count");
	
	if((parseInt(num)  > 0)&&(parseInt(vcoinDiv.innerHTML) > -1)){
	
		var vcoins = parseInt(vcoinDiv.innerHTML) + parseInt(num);
		writeDiv("vcoins_count", vcoins);
	}
	
	//return vcoins;	
	
	
}


/*
var clearIcidUrl = baseUrl+"con_scripts/clearIcid.php";				//deletes allitim entry and clears the convo
var editGroupUrl = baseUrl+"con_scripts/editGroupXML.php";				//edits existing group
var createGroupUrl = baseUrl+"con_scripts/createGroupXML.php";				//creates new  group
*/
//clear icid and remove from allitim
function clearConversation(i_c_id, is_clear){
	
	var clearUrl = clearIcidUrl+"?aj=1&i_c_id="+i_c_id+"&isclear="+is_clear+"&id="+itim_user_id+"&sessID="+sessId;
	//var func = "startItimBar";
	var func = "parseClearIcid";
	
	//alert("about to get "+getUrl+" and func = "+func);
	ajaxGetUrlFunction(clearUrl, func);
	
	
}

function parseClearIcid(str){
	
	
}


function addGroupMember(group_id, member_user_id, phone){
	
	/*http://2waystar.com/itimworld/con_scripts/editGroupXML.php?addMemberGroup=1&group_id=32&member_user_id=26118&phone=&tim_id=17553&deviceID=eb4f2585df79486410237b46c9f3c438c9046894&iphone_user_id=17553
	*/
	var clearUrl = editGroupUrl+"?aj=1&addMemberGroup=1&group_id="+group_id+"&member_user_id="+member_user_id+"&phone="+phone+"&tim_id="+itim_user_id+"&id="+itim_user_id+"&sessID="+sessId;
	//var func = "startItimBar";
	var func = "parseAddGroupMember";
	
	alert("about to get "+clearUrl+" and func = "+func);
	ajaxGetUrlAndFunc(clearUrl, func);
	//ajaxGetUrlFunction(clearUrl, func);
	
	
}

function parseAddGroupMember(str){
	str = unescape(str);
	var strarr = str.split(":-_-:");
	
	//alert("we got back = "+strarr);
	if(strarr[1] != ""){
		var outputarr = strarr[1].split(":-:");
		//"group_i_c_id:-_-:$i_c_id:-:$psess1:-:$group_title:-:$group_id:-:$editComplete:-:$delComplete:-:$delMemberComplete:-:$addMemberComplete:-:$isfavgroupid:-:$member_count:-:$group_avatar:-:group_i_c_id:-_-:&EOF
		
		// ,bm6o7itnnv5pr6rtt0qnem8t50,,18,0,0,0,1,0,8,,group_i_c_id
		var add_icid = outputarr[0];
		var add_psess = outputarr[1];
		var add_title = outputarr[2];
		var add_group_id = outputarr[3];
		var add_edit_complete = outputarr[4];
		var add_del_complete = outputarr[5];
		var add_delMemberComplete = outputarr[6];
		var add_addMemberComplete = outputarr[7];
		var add_isfavgroupid = outputarr[8];
		var add_member_count = outputarr[9];
		var add_group_avatar = outputarr[10];
		//alert("final = Count = "+add_member_count+" group_id = "+add_group_id+" and fave = "+fav_group_id);
		
		if(add_member_count > 0){
		
			var use_count =	add_member_count;
			
		}else{
			var use_count =	0;
		}
		
		if(add_group_id == fav_group_id){
			//alert('writing div = '+use_count);
			writeDiv('favcounter', use_count);
			
		}
		
	}
	
}


function addFavMember(fav_group_id, member_user_id, phone){
	//alert('hey fave id = '+fav_group_id);
	if(fav_group_id > 0){
		//alert("hey favce group id = "+fav_group_id+" and membernick = "+member_user_id);
		addGroupMember(fav_group_id, member_user_id, phone);
	}
}



function deleteGroupMember(group_id, member_user_id, phone){
	
	/*
	http://2waystar.com/itimworld/con_scripts/editGroupXML.php?delMemberGroup=1&group_id=32&member_user_id=26118&phone=&tim_id=17553&deviceID=eb4f2585df79486410237b46c9f3c438c9046894&iphone_user_id=17553
	*/
	var clearUrl = editGroupUrl+"?aj=1&delMemberGroup=1&group_id="+group_id+"&member_user_id="+member_user_id+"&phone="+phone+"&tim_id="+itim_user_id+"&id="+itim_user_id+"&sessID="+sessId;
	//var func = "startItimBar";
	var func = "parseDelGroupMember";
	
	//alert("about to get "+getUrl+" and func = "+func);
	//ajaxGetUrlFunction(clearUrl, func);
	ajaxGetUrlAndFunc(clearUrl, func);
	
}

function parseDelGroupMember(str){
	
	
}



/**
* 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&id="+itim_user_id+"&sessID="+sessId;
	//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);
	
	var getNewMesUrlMain = getNewMesUrl+"?id="+itim_user_id+"&sessID="+sessId;
	//alert('url main = '+getNewMesUrlMain);
	ajaxGetUrlAndFunc(getNewMesUrlMain, func);	
	
	
	
}



/**
*
* parses content received by getNewmessage
*
*/

function parseNewMes(str){
	str = unescape(str);
	is_checker_once_on = 0;
	
	
	//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-_-_-avatars/daddy_sm.jpg-_-_-music.mp3:_._._:&friend_0=8-_-_-Daddy-_-_-avatars/daddy_sm.jpg-_-_-1-_-_-7-_-_-47&friend_1=1-_-_-Money+Penny-_-_-avatars/avatar2.jpg-_-_-0-_-_-2-_-_-1";	
	
	
	//var str = "&newmes_0=19648-_-_--_-_-3-_-_-366-_-_-Jun 05, 2011-_-_-05:41 PM-_-_-19975518-_-_-itim-support -_-_-Fount-_-_--_-_-tim_images/17553_07-02-2010_09-58-16_xaua_2ipodfile.jpg-_-_-
	var mainarr = str.split(":_._._:");
	
	if(mainarr.length > 1){
		
		var newMesarr = mainarr[0];
		var friendarr = mainarr[1];
		
		if(str != ":_._._:"){
			
			//alert('output = '+str);
	
			
		}
		
		// 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 newMessageStr = mesarr[i];
				var currMesarr = mesarr[i].split("-_-_-");
				
				//alert('just split mesarr = '+currMesarr);
				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 message_type = 1;
				
				
				
				
				var titleName;
				
				var is_reply = currMesarr[2];
				var newmsg_count = 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 avatar = currMesarr[10];
				var timestamp = currMesarr[12];
				
				if(cellnum > 0){
					
					
				}else{
					
					message_type = 2;
						
				}
				
				
				var message = unescape(currMesarr[8]);
				
				var attachment = currMesarr[9];
				
				message = searchAndReplace (message, "\r", " ");
				message = searchAndReplace (message, "\n", " ");
				message = searchAndReplace (message, ":ampreg:", "&");
	
				
				var re = /(.{20}).+/;
				message = message.replace(re, "$1...");
				//alert('trimed message = '+message);
				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(temp_i_c_id > 0){
					
					
					newMessageByIcidArray[temp_i_c_id] = new Array(temp_mes_id, message, name, '1', temp_msgdate, '0');
					//sending a message deletes this or setreply for that mes_id will delete it too
					//alert('mes id = '+temp_mes_id);
					if(typeof(newMessageArray[temp_mes_id]) != "undefined"){
						//alert('hye go tepm id = '+newMessageArray[temp_mes_id]);
						if(newMessageArray[temp_mes_id][3] != 1){
							//perform the alert and add to 	
							if(typeof(name) != "undefined"){
		
								startItimAlert(temp_i_c_id, message, name, temp_mes_id, temp_msgdate, newmsg_count, message_type, cellnum, avatar, timestamp, newMessageStr);
								newMessageArray[temp_mes_id][3] = 1;
								
							}
							
						}
					}else{
						//add alert and perform 
						if(typeof(name) != "undefined"){
			
							//alert('none must create tepm id = '+newMessageArray[temp_mes_id]);
							newMessageArray[temp_mes_id] = new Array(temp_i_c_id, message, name, '1', temp_msgdate, '0');
							startItimAlert(temp_i_c_id, message, name, temp_mes_id, temp_msgdate, newmsg_count, message_type, cellnum, avatar, timestamp, newMessageStr);
							
						}
						//animFavNewMessage( sent_by, newMessage, avatar, itimnum, message_type);
					}
					
				}
			}
			
			
		}
		
		
		
	}else{
		var logoutarr = str.split(":-uyi-:"	);
		
		if(logoutarr.length > 1){
		
			if(logoutarr[1] == 'logmeout'){
				
				logMeOut('getnewmessage_failed');	
				
			}
			
		}
		
	}
	//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";
	if(typeof(friendarr) != "undefined"){
	
		
		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);
					
					if(divIdExists(newFrDiv) == 1){
						var newFrStyle=newFrDiv.style;
						newFrStyle.visibility = "visible";
					}
				}else{
					
					if(divIdExists(newFrDiv) == 1){
					
						var newFrDiv=document.getElementById(is_online_divId);
						var newFrStyle=newFrDiv.style;
						newFrStyle.visibility = "hidden";
					}				
				}
					
			}
			
		}
			
		
	}
	
	
	
	//check if we should log out
	var check = str.search(/logmeout/i);
	
	if(check > -1){
		//stop checker
		logMeOut('getnewmsg_check');	
	}
	
	
}



//http://www.2waystar.com/itimworld/con_scripts/timsenderwidget.php?send=1&my_username=jjred&message=go you&receiver_username=itim-support&tim_id=26142&attach=&picloc=&piclocid=1&receiver_user_id=17553&i_c_id=19648&message_type=2&cdummy2=2
//&send=1&cellnum3=6614352461&message=wassuppppps&cellnum22=itim-support&tim_id=17553&&attach=&picloc=&piclocid=1&i_c_id=389&message_type=1&cc=1&longitude=%28null%29&latitude=%28null%29&deviceID=eb4f2585df79486410237b46c9f3c438c9046894&iphone_user_id=17553&attach_audio=&zip=%28null%29&city=%28null%29&state=%28null%29&country=%28null%29

function sendTim(){
	
	var func = "parseSendTim";
	
	var sendmes = "";
	
	if((new_mes_type != 2)&&(new_mes_type != 3)){
		new_mes_type = 1;	
		
	}
	if(new_mes_type == 2){
		sendmes = escape(document.newitimformIM.newmessageIM.value);
	
	}else if(new_mes_type == 3){
		sendmes = escape(document.newitimformIM.newmessageIM.value);
	
	}else{
		
		sendmes = escape(document.newitimform.newmessage.value);
	
	
	}
	
	var attachMedia = 0;
	if((newAttachment == '')||(typeof(newAttachment) == "undefined")){
		attachMedia = 0;
	}else{
	
		attachMedia = 1;
	
	}


	//http://www.2waystar.com/itimworld/con_scripts/timsenderwidget.php?send=1&my_username=itim%2Dsupport&message=cool&receiver_username=jbond&tim_id=17553&attach=&picloc=&piclocid=1&receiver_user_id=26165&i_c_id=19721&message_type=2&cdummy5=5
	
	//var newgetIcidUrlMain = newgetIcidUrl+"?id="+itim_user_id+"&sessID="+sessId;
	
	var newSendTimUrl = "";
	
	/*
	new_group_id = mainarr[6];
	new_group_type = mainarr[7];
	new_admin_group = mainarr[8];
	new_itim_version = mainarr[9];
	*/
	if(new_mes_type == 3){
		


		
		newSendTimUrl = timsenderGroupUrl+"?send=1&admin_group="+new_admin_group+"&group_id="+new_group_id+"&group_type="+new_group_type+"&itim_version="+new_itim_version+"&&receiver_username="+newcellnum+"&message="+sendmes+"&my_username="+itim_nickname+"&tim_id="+itim_user_id+"&attach_audio="+newAudio+"&attach="+attachMedia+"&picloc="+newAttachment+"&piclocid=1&i_c_id="+new_icid+"&message_type="+new_mes_type+"&cc=1&id="+itim_user_id+"&sessID="+sessId;
			
			
		
		//startSendIcid(newcellnum, sendmes, newAttachment, new_mes_type, new_icid);
		
		
		changeDivWidth('sendgif', 100);
		changeDivWidth('sendgifwin', 100);
		ajaxGetUrlAndFunc(newSendTimUrl, func);	
		
		
		
		
		
		
	}else{
	
	
		
		if(new_mes_type == 1){
			newSendTimUrl = timsenderUrl+"?send=1&cellnum3="+newcellnum+"&message="+sendmes+"&cellnum22="+itim_nickname+"&tim_id="+itim_user_id+"&attach_audio="+newAudio+"&attach="+attachMedia+"&picloc="+newAttachment+"&piclocid=1&i_c_id="+new_icid+"&message_type="+new_mes_type+"&cc=1&id="+itim_user_id+"&sessID="+sessId;
		//alert('myurl = '+newSendTimUrl+'\n\nfunc = '+func);
		}else{
			newSendTimUrl = timsenderUrl+"?send=1&receiver_username="+newcellnum+"&message="+sendmes+"&my_username="+itim_nickname+"&tim_id="+itim_user_id+"&attach_audio="+newAudio+"&attach="+attachMedia+"&picloc="+newAttachment+"&piclocid=1&i_c_id="+new_icid+"&message_type="+new_mes_type+"&cc=1&id="+itim_user_id+"&sessID="+sessId;
			
			
		}
		
		startSendIcid(newcellnum, sendmes, newAttachment, new_mes_type, new_icid);
		
		
		changeDivWidth('sendgif', 100);
		changeDivWidth('sendgifwin', 100);
		ajaxGetUrlAndFunc(newSendTimUrl, func);	
		
		
		
		
		
	}
	
	
	
}



/**
*
* parses content received by getIcid
*	:-_-_-:754244-_-tom-_-19853487-_--_-:-_-_-: 
*
*	:uyi-_-_-uyi:19859781-_-May 30, 2011-_-08:06 PM:uyi-_-_-uyi:
*
*
*/

function parseSendTim(str){
	str = unescape(str);
	
	changeDivWidth('sendgif', 130);
	changeDivWidth('sendgifwin', 130);
	//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";	
	
	
	//alert('fullmainarr = '+fullmainarr);
	if(new_mes_type == 3){
	
	}else{
		var outputarr = str.split(":uyi-_-_-uyi:");
		//alert('outputarr = '+outputarr);
		var mainarr = outputarr[1].split("-_-");
		//alert('mainarr = '+mainarr);
		var lastmesid = mainarr[0];
		var lastdate = mainarr[1];
		var lasttime = mainarr[2];
		
	}
	
	
	
	if(new_mes_type == 3){
		
		removeDiv('backfade'); removeDiv('startNewItimIM'); winOpened = 'none';
		
		new_form_opened = 0;
		// start the convo here
		alert('Group Msg Sent');
		
		
		
		//closeDivIcid(new_icid);
		//startItimBar(new_icid);
		// we need to add tab to all itim here
		
		//
		
	}else if(lastmesid > 0){
		
		// remove the startnewitim
		if(new_mes_type == 2){
			removeDiv('backfade'); removeDiv('startNewItimIM'); winOpened = 'none';
		}else if(new_mes_type == 3){
			removeDiv('backfade'); removeDiv('startNewItimIM'); winOpened = 'none';
		}else{
			
			removeDiv('backfade'); removeDiv('startNewItim'); winOpened = 'none';
		
		}
		new_form_opened = 0;
		// start the convo here
		//alert('opeing icid = '+new_icid);
		
		
		
		closeDivIcid(new_icid);
		startItimBar(new_icid);
		// we need to add tab to all itim here
		
		//
		
	}else{
		alert(' Message send failed....please try again');
		
		
	}
	// make sendprogress hidden
	hideDiv('sendprogress');
	hideDiv('sendprogresswin');
	hideDiv('sendOverlay');
	
	hideDiv('sendprogresswinIM');
	hideDiv('sendOverlayIM');
	changeDivWidth('sendgif', 10);
	changeDivWidth('sendgifwin', 10);
	
	//Close startNewItim
	if(winOpened == 'startNewItim'){
		//alert('closing it now');
		removeDiv('backfade'); removeDiv('startNewItim'); winOpened = 'none';
	}else if(winOpened == 'startNewItimIM'){
		//alert('closing it now');
		removeDiv('backfade'); removeDiv('startNewItimIM'); winOpened = 'none';
	}
	
	new_form_opened = 0;
	
	
}



function divIdExists(divId){
	var divExists = 0;	
	//alert(' checking now div = '+divId);
	try {
		var myElem = document.getElementById(divId);
		if(myElem != null){
		
			divExists = 1;
		
			//alert(' writing to icid div - '+divId + ' and elem = '+myElem)
		}else{
			//alert('Null div - '+divId + ' and divexists = '+divExists+' and elem = '+myElem)
				
		}
	
	} catch (e) { 
		//alert(' icid not exist error son - '+divId)
		divExists = 0;
	}
	
	return divExists;
}



/*** Cookie related stuff ****/
function putCookie() {



//document.cookie = "username=John;expires=15/02/2003 00:00:00";
//set_cookie ( "username", "John Smith", 2003, 01, 15, "","elated.com", "secure" );

	if(document.cookie != document.cookie)
	{
		index = document.cookie.indexOf(cookie_name);
	}
	else
	{ 
		index = -1;
	}
	
	if (index == -1)
	{
		YouEntered=document.cf.cfd.value;
		document.cookie=cookie_name+"="+YouEntered+"; expires=Monday, 04-Apr-2010 05:00:00 GMT";
	}
	
	

}


function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}

function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}


function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

//sets the cookie that holds all the window locs, so you can resume if closed quickly
function setWindowLocCookie(){
	
	
	if ( itimLocationArr.length > 0 )
	{
		//alert('location = '+itimLocationArr);
	
		var cookiename = "itimwinloc_"+itim_user_id;
		if ( get_cookie ( cookiename) )
		{
			//alert('hey the window delete and cookie name = '+cookiename+' and loc = '+get_cookie ( cookiename ));
			//delete the cookie
			delete_cookie ( cookiename )
		}


		var current_date = new Date;
		var cookie_year = current_date.getFullYear ( ) + 1;
		var cookie_month = current_date.getMonth ( );
		var cookie_day = current_date.getDate ( );
		//var locstr = itimLocationArr.join('-_-');
		//alert('loc = $
		set_cookie ( cookiename, itimLocationArr, cookie_year, cookie_month, cookie_day );
	}

}


//this makes sure that only class that is on top is black bordered
function checkAllItimClass(){
	
	
	var lastIndex = itimLocationArr.length - 1;
	for(var j = 0; j < itimLocationArr.length; j++){
		var tempicid = itimLocationArr[j][0];	
	
		var allitimdivid = "allitim_"+tempicid;
		
		if(j == lastIndex){
			
			//midRightBarNewOpenFocus
			changeClass(allitimdivid, 'midRightBarNewOpenFocus');	
		}else{
		
			//	
			changeClass(allitimdivid, 'midRightBarNewOpen');
			
		}
		
		

	}
	
}



//this makes sure that only class that is on top is black bordered
function isIcidOpen(i_c_id){
	
	var isOpen = 0;
	for(var j = 0; j < itimLocationArr.length; j++){
		var tempicid = itimLocationArr[j][0];	
	
		if(tempicid == i_c_id){
			
			
			isOpen = 1;
			j = itimLocationArr.length;	
			
		}
				
		

	}
	return isOpen;
	
}
		
		
//the last on this array is the top icid that's open	
function getTopIcid(){
	
	var lastIndex = itimLocationArr.length - 1;
	
	var tempicid
	if(typeof(itimLocationArr[lastIndex]) != "undefined"){	
	
		tempicid = itimLocationArr[lastIndex][0];
	
	}
	
	if(tempicid > 0){
		
		
		
	}else{
		
		
		if(	topOpenedIcid > 0){
			
			tempicid = 	topOpenedIcid;

			
			
		}else{
			
			tempicid = 0;
			
		}

		
		
			
		
	}
	return tempicid;

	
}

function startItimsWithLoc(){
	
	
	//get all the itims
	
	var cookiename = "itimwinloc_"+itim_user_id;
	
	var tempLocArr = new Array();
	tempLocArr = get_cookie ( cookiename );	
	//alert(tempLocArr.toString);
	
	if((typeof(tempLocArr) != "undefined")&&(tempLocArr != null)){
		var tempStrArr = tempLocArr.split(')');
	
	}else{
		var tempStrArr = new Array();
		
	}
	
	//alert(tempLocArr+' and strl = '+tempStrArr);
	
	//alert('hey the window cookie name = '+cookiename+' and loc = '+get_cookie ( cookiename ));
	//startItimBar(19723); hideDiv('new_alltim_19723');   hideDiv('newMsgAllMain');
	
	for(var j = 0; j < tempStrArr.length; j++){
		
		var locitem = tempStrArr[j];
		
		
		if(locitem != ''){
		
			//alert('locitem = '+locitem);
			
			//19723,(218,50
			var locitemarr = locitem.split(',');
			
			if(locitemarr[0] == ''){
				
				//alert(' before loc = '+locitemarr);
				
				//var locitemarr = locitemarr.pop();
				locitemarr.shift();	
				//alert(' now loc = '+locitemarr);
			}
			
			
			if(locitemarr[0] > 0){
				
				var locicid = locitemarr[0];
				var loc_y = locitemarr[2];
				
				var loc_x_arr = locitemarr[1].split('(');
				var loc_x = loc_x_arr[1];
				
				
				
				//alert('okay found icid = '+locicid+' and x = '+loc_x+' and y = '+loc_y);	
				var allitimdivid = "allitim_"+locicid;
		
		
				
				if(divIdExists(allitimdivid) == 1){
						startItimBar(locicid, loc_y, loc_x); hideDiv('new_alltim_'+locicid);   hideDiv('newMsgAllMain');
						
				}
				
				//startItimBar(locicid, loc_x, loc_y); hideDiv('new_alltim_'+locicid);   hideDiv('newMsgAllMain');
				
				
			}
			
			
		}
		
	}
	checkAllItimClass();
	
	
}


//takes the content you give it and adds to the top;
function addToListTop(newContent, parentId, divIdName){
	
	
		//alert('wtiring dividname = '+divIdName+' into parent '+parentId);
		
		var main_container = document.getElementById(parentId);
		// Create a new <li> element for to insert inside <ul id="myList">
		var new_element = document.createElement('div');
		
		if((divIdName != '')||(divIdName == 'undefined')){
  			new_element.setAttribute('id',divIdName);
		
		}
		
		//new_element.innerHTML = newContent;
		main_container.insertBefore(new_element, main_container.firstChild);
		new_element.innerHTML = newContent;
}

function removeElement(divId, parentId) {

  var d = document.getElementById(parentId);

  var olddiv = document.getElementById(divId);

  d.removeChild(olddiv);

}


function moveItimToTop(divId, parentId){
	
	//alert('compare sent div = '+divId+' to allitim_755114');
	//get the parent of the div
	//var divId = "allitim_755114";
	var tmparr = divId.split('_');
	var tmpicid = 0;
	var tmpclose = "";
	if(tmparr[1] != ''){
			tmpicid = tmparr[1];
			tmpclose = "closeItim_"+tmpicid;
	}
	var movediv = document.getElementById(divId);
	//alert(' moving div = '+divId+' to top of '+parentId+' and content = '+movediv.innerHTML);
	var case_used = 0;
	var removeDivId = divId;
	var newContent = document.getElementById(divId).innerHTML;
	
	//add to top and increase case_num
	allitimcasenum++;
	var divIdName = 'case_'+allitimcasenum;
	
	
	//alert('parent node = '+movediv.parentNode.id+'\ndivid = '+movediv.id+' and divId = '+divId);
	
	addToListTop(newContent, parentId, divIdName);
	// set the attribute so it looks like this
	//<div id="allitim_19648" class="midRightBarNew" onmouseover="this.className='midRightBarNewHover'" onmouseout="this.className='midRightBarNew'">	
	
	// then remove the previous
	
	//then rename the new id
	var topdiv = document.getElementById(divIdName);
	topdiv.setAttribute('onmouseover', "if(checkVisible('"+tmpclose+"')!=1){this.className='midRightBarNewHover';}");
	topdiv.setAttribute('onmouseout', "if(checkVisible('"+tmpclose+"')!=1){this.className='midRightBarNew';}");
	
	removeElement(divId, parentId);
	
	topdiv.setAttribute('id', divId);
	
	document.getElementById(divId).className = "midRightBarNew";
	//changeClass("allitim_"+temp_i_c_id, "midRightBarNewOpenUnread");
	
	//document.getElementById(divId).className = "midRightBarNewOpen";
	
	
	
	//var objDiv = document.getElementById("your_div");
	//objDiv.scrollTop = objDiv.scrollHeight;
	//alert('about to scroll = '+document.getElementById(parentId).scrollHeight);
	//document.getElementById(parentId).scrollTop = "0px";
	//document.getElementById(parentId).scrollTop = 0;
	/*
	//get inner conten
	if(movediv.parentNode.id != parentId){
		// it is enclosed in a case	
		alert(' parent id not allitims it is '+movediv.parentNode.id);
		removeElement(movediv.parentNode.id, parentId);
	
	}else{
	
		removeElement(divId, parentId);
	
	
	}
	*/
}

//cellnum can be receiver username
function createNewAllItim(cellnum, newmsg_esc, attachment, message_type, icid, name, newmsg_count, time_ago, avatarpic, timestamp){
	
	
	
	
	if(newmsg_count > 0){
		
	}else{
		//alert(" name = "+name+" and cellnum = "+cellnum+" and newmsg_count = "+newmsg_count);
	
	}
	//alert('avatarpic = '+avatarpic);
	
	
	var avatarfolderarr = avatarpic.split('avatars/');
	if(avatarfolderarr.length > 1){
	
		//this is a picloc like avatars/sisisii_sm.jpg
		//do nothing	
	}else{
	
		var avatarsplitarr = avatarpic.split('_sm.jpg');
		if(avatarsplitarr.length > 1){
			var origpic = avatarpic;
			avatarpic = avatarsplitarr[0]+'.jpg';	
			//alert('avatarpic = '+avatarpic+' and old was '+origpic);
		}
		
	}
	
	var sendmsg = unescape(newmsg_esc);
	sendmsg = searchAndReplace (sendmsg, "\\'", "'");
	
	if(sendmsg.length > 13){
		var re = /(.{11}).+/;
		sendmsg = sendmsg.replace(re, "$1...");
		//alert('replaced cellname =  '+cellName);
	}
	//alert('name before is = '+name);
	if(typeof(name) != "undefined"){
			
		if(name.length > 13){
			var re = /(.{11}).+/;
			name = name.replace(re, "$1...");
			//alert('replaced cellname =  '+cellName);
		}

	}

	//alert('name after is = '+name);
	if(message_type != 2){
		message_type = 1;	
	}
	var title = cellnum;
	var msgtitle = cellnum;
	
	if(time_ago == ""){
		time_ago = "few secs ago";	
		
	}
	
	if(message_type == 1){
		
		if(name == ""){
			name = cellnum;
		
		}else{
			
			//title = name;
			
			title = ucwords(name.toLowerCase());
		}
		
		if(cellnum > 0){
				//search contacts to get the name
			//if u find it, title becomes the name	
			
		}
		
	}else{
		if(name != ""){
			
			
			title = name;
			msgtitle = name;
		}
			
		
	}
	var avatar = '';
	 
	if((avatarpic == '')||(typeof(avatarpic) == "undefined")){
		//avatar = avatarpic;
	}else{
	
		avatar = avatarpic;
	
		//avatar = new_avatar;
	
	}
	
	avatar = avatar.toLowerCase();
	
	//check if there is a slash tim_images/nopic.jpg
	var slasharr = avatar.split('/');
	if(slasharr.length == 2){
		
	}else if(slasharr.length == 1){
	
		
		if((avatar == '')||(typeof(avatar) == "undefined")){
			if(message_type == 1){
				avatar = "images3/avatar_cellular2.png";
				
			}else{
				avatar = "images3/avatar_bubble.png";
				
			}
			
		}else{
		
	
	
			avatar = "tim_images/"+avatar;
		}
	}else{
		avatar = '';
	}
	//alert(' avatar = '+avatar+' and arr='+slasharr);
	
	if (avatar.indexOf("nopic") != -1) {
    
		//alert('there is nopic in ='+avatar);
		avatar = '';
	
	
	}
	
	
	
	if((avatar == '')||(typeof(avatar) == "undefined")){
		if(message_type == 1){
			avatar = "images3/avatar_cellular2.png";
			
		}else{
			avatar = "images3/avatar_bubble.png";
			
		}
		
	}
	
	
	//alert(' and avatarpic = '+avatarpic+' and main avatar = '+avatar);
	
	
	var newmsgStyle = "visibility: hidden;";
	if(newmsg_count > 0){
		
		newmsgStyle = "visibility: visible;";
	}
	//var closevis = "visible";
	var closevis = "hidden";
	var newContent = "<div class=\"menuLink\" style=\"height: 45px;\">	<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"220\"><tbody><tr><td width=\"60\" valign=\"center\"><a href=\"javascript:void(0)\" onclick=\"startItimBar("+icid+"); hideDiv('new_alltim_"+icid+"');   hideDiv('newMsgAllMain');\" title=\""+msgtitle+": 1msg\"><img src=\""+avatar+"\" id=\"avatar_"+icid+"\"  alt=\""+msgtitle+"\" title=\""+title+"\" style=\"margin: 2px;\" border=\"0\" height=\"45\" width=\"45\"></a></td><td valign=\"top\" width=\"125\"><div id=\"allitim_name_"+icid+"\" style=\"margin-top: 3px;\"><a href=\"javascript:void(0)\" onclick=\"startItimBar("+icid+"); hideDiv('new_alltim_"+icid+"');   hideDiv('newMsgAllMain');\" title=\""+msgtitle+": 1msg\" style=\"font-weight: normal;  width:155px; font-size: 14px;\">"+title+"</a></div><div id=\"allitimtext_"+icid+"\" onclick=\"startItimBar("+icid+"); hideDiv('new_alltim_"+icid+"');   hideDiv('newMsgAllMain');\" style=\"font-size: 10px; font-weight: normal;\">"+sendmsg+"</div><div id=\"time_"+icid+"\" class=\"elapsed_time\">"+time_ago+"<span id=\"closeItim_"+icid+"\" style=\"margin-left: 5px; visibility: "+closevis+";\"><a href=\"javascript:void(0)\" onclick=\"closeDivIcid("+icid+");\" style=\"font-family: Verdana,Arial,Helvetica,sans-serif;\">close</a></span></div></td><td align=\"right\" width=\"55\"><div id=\"new_alltim_"+icid+"\" style=\"color: rgb(255, 153, 0); "+newmsgStyle+"\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" height=\"16\"><tbody><tr><td><div id=\"timestamp_"+icid+"\"  style=\"visibility:hidden;width:0px;height:0px;overflow:hidden;float:right;\">"+timestamp+"</div><div id=\"count_new_allitim_"+icid+"\" class=\"countNum\">"+newmsg_count+"</div></td><td align=\"right\"><img src=\"images/greendot.png\" alt=\"newmsg\" height=\"16\" width=\"16\"></td></tr></tbody></table></div></td></tr></tbody></table></div>";
	
	var parentId = "all_itims";
	var divIdName = "allitim_"+icid;
	addToListTop(newContent, parentId, divIdName);
	// set the attribute so it looks like this
	//<div id="allitim_19648" class="midRightBarNew" onmouseover="this.className='midRightBarNewHover'" onmouseout="this.className='midRightBarNew'">	
	
	// then remove the previous
	
	//then rename the new id
	var topdiv = document.getElementById(divIdName);
	topdiv.setAttribute('onmouseover', "if(checkVisible('closeItim_"+icid+"')!=1){this.className='midRightBarNewHover';}");
	topdiv.setAttribute('onmouseout', "if(checkVisible('closeItim_"+icid+"')!=1){this.className='midRightBarNew';}");
		
	document.getElementById(divIdName).className = "midRightBarNewOpen";
	
	//document.getElementById(divIdName).className = "midRightBarNew";
	
	
}


//shows google maps of where you met
function showContactLocation(fullname, long, lat){
	//http://maps.google.com/maps?f=q&q=40.703910,-73.905968%28iTim_TextPro_App:_crazylove_is_here%29
	alert(' u met '+fullname+' at '+long+', '+lat);
	
	
}






//called by itim swf when sending
// actionscript looks like 
// called by itimsender
//getURL("javascript:startSendIcid('"+_root.cellNum+"', '"+_root.newmes_esc_send+"', '"+_root.attach_img+"', '"+_root.message_type+"', '"+_root.i_c_id+"');");
//Adds Stuff to new entry to the top of the allitim section		
		
function startSendIcid(cellnum, newmsg_esc, attachment, message_type, icid){
	
	var allitimdiv = "allitim_"+icid;
	var divExists = 0;
	var name = "";
	var avatarpic = "";
	
	if(icid > 0){
	
		//delete this entry
		//newMessageByIcidArray[temp_i_c_id] = new Array(temp_mes_id, message, name, '1', temp_msgdate, '0');
			
		newMessageByIcidArray[icid] = new Array();
	}
	
	if(divIdExists(allitimdiv) != 1){
		//alert(' no sir no div for allitim icid = '+icid+' so add please');	
		//divExists = 1;
		
		
		
		if(message_type == 2){
			var nickarr = getNickForIcid(icid);
			name = nickarr[1];
			avatarpic = nickarr[3];
			
		}else{
			
			
			if(cellnum > 0){
				var cellinfo = contactIcidInfoArray[cellnum];
				if((typeof(cellinfo) != "undefined")){
					
					if(cellinfo[0] > 0){
						//there is a contact and a name
						//alert('fouund matach in '+cellinfo);
						//newicid = cellinfo[0];
						name = cellinfo[1]+' '+cellinfo[2];
						name = trim(name);
						avatarpic = cellinfo[3];
					}	
						
				}
				
				
			}	
			
		}
		//alert('avatar = '+avatarpic+' and name = '+name+' about to msg for it now = '+newmsg_esc+' and messagetype = '+message_type);
	
		var timestamp = Math.round(new Date().getTime() / 1000 );
		//current time
		var timeago = "few secs ago";
		createNewAllItim(cellnum, newmsg_esc, attachment, message_type, icid, name, "0", timeago, avatarpic, timestamp);
		
		
		
	}else{
		//alert(' element exist for = '+allitimdiv);
		divExists = 1;	
	}
	
	if(divExists == 1){
		
		
		//alert('just sent to '+cellnum+' and message = '+newmsg_esc);
		var sendmsg = unescape(newmsg_esc);
		
		if(sendmsg.length > 15){
			var re = /(.{13}).+/;
			sendmsg = sendmsg.replace(re, "$1...");
			//alert('replaced cellname =  '+cellName);
		}
		writeDiv('allitimtext_'+icid, sendmsg);
		
		moveItimToTop(allitimdiv, 'all_itims');
		var addClose = "few secs ago <span id=\"closeItim_"+icid+"\" style=\"margin-left: 5px; visibility: visible;\"><a href=\"javascript:void(0)\" onclick=\"closeDivIcid("+icid+");\" style=\"font-family: Verdana,Arial,Helvetica,sans-serif;\">close</a></span>";
		writeDiv('time_'+icid, addClose);	
		
		var timestamp = Math.round(new Date().getTime() / 1000 );
		writeDiv('timestamp_'+icid, timestamp);	
		document.getElementById('all_itims').scrollTop = 0;
		
		document.getElementById('allitim_'+icid).className = "midRightBarNewOpenFocus";
	
	}
	
	
	//move to the top
	
}

function showProfile(i_c_id, name, avatar){
	
	//alert('show profile for icid = '+i_c_id+' and name = '+name+' and avatar = '+avatar);
	
	loadBackfade();
	loadShowProfile(i_c_id, name, avatar);  
	prev_con_i_c_id = i_c_id;
	prev_con_name = name;
	prev_con_avatar = avatar;
	moveDivCenter('addShowProfile');
	winOpened = 'addShowProfile';
	
	updateAvatar = 0;
	newContactAvatar = '';
	hideDiv('con_status');
	
	
}

function resizeDim(img, target_wd, target_ht, origwd, oright){
	
	var wd = 0;
	var ht = 0;
	var outwd = 0;
	var outht = 0;
	if((origwd > 0)&&(oright > 0)){
		
		//cool, do nothing
		wd = origwd;
		ht = oright;
		
		
		
	}else{
		//get the height
		
		var dim = getImgSize(img);
		wd = dim[0];
		ht = dim[1];
			
	}
	
	
	
	if((wd == 0) || (ht == 0)){
		
		if(target_wd < target_ht){
			outwd = target_wd;
			outht = target_wd;
		}else{
			outwd = target_ht;
			outht = target_ht;
		}
		
	}else{
		
		var ratio_wd = (target_wd / wd);
		var ratio_ht = (target_ht / ht);	
		var percentage;
		if (ratio_wd < ratio_ht) {
			
			percentage = (target_wd / wd);
		} else {
			percentage = (target_ht / ht);
		}
		
		outwd = Math.round(wd * percentage);
		outht = Math.round(ht * percentage);
		
	}
	
	
	var output = new Array(outwd, outht);
	//alert('wd = '+wd+' and ht = '+ht+' and out put = '+output);
	return output;
	
}


function rotateDiv(divId, deg){
	
	//
	
	
	
}




function attachImageToMouse(imagediv){
	
	
	
	
}


function cancelRotate(){
	
	
	rotation_deg = 0;
	hideDiv('save_edit');
	
	showDiv('imageview');
	var image = document.getElementById('imageview');
	image.className = "profilePhoto";
	//hideDiv('canvasview');
	//writeDiv('canvasview', '');
	
	var canvas = document.getElementById('canvasview');
	//canvas.className = "canvasEmpty";
	
	
    var context = canvas.getContext("2d");
    //context.clearRect(0, 0, canvas.width, canvas.height);
	canvas.className = "canvasEmpty";
	
	//canvas.setAttribute('height', '0');
}



function saveRotate(){
	
	alert('rotation deg = '+rotation_deg);
	
}



function rotateLeft(){
	
	if(rotation_deg == 0){
		var image = document.getElementById('imageview');
		image.className = "profilePhoto";
	
		rotate('imageview', 'canvasview', -90);
	
		rotation_deg = -90;
	}else if(rotation_deg == -90){
		var image = document.getElementById('imageview');
		image.className = "profilePhoto";
	
		
		rotate('imageview', 'canvasview', 180);
		rotation_deg = 180;
	}else if(rotation_deg == 180){
		
		var image = document.getElementById('imageview');
		image.className = "profilePhoto";
	
		rotate('imageview', 'canvasview', 90);
		rotation_deg = 90;
	}else if(rotation_deg == 90){
		
		var image = document.getElementById('imageview');
		image.className = "profilePhoto";
	
		rotate('imageview', 'canvasview', 0);
		rotation_deg = 0;
	}
	
	
	
	//rotate('imageview', 'canvasview', -90);
	//alert('rotated left');
	showDiv('save_edit');
}


function rotateRight(){
	if(rotation_deg == 0){
	
		var image = document.getElementById('imageview');
		image.className = "profilePhoto";
	
		rotate('imageview', 'canvasview', 90);
		rotation_deg = 90;
	}else if(rotation_deg == 90){
	
		var image = document.getElementById('imageview');
		image.className = "profilePhoto";
	
	
		rotate('imageview', 'canvasview', 180);
		rotation_deg = 180;
	}else if(rotation_deg == 180){
	
		var image = document.getElementById('imageview');
		image.className = "profilePhoto";
	
		rotate('imageview', 'canvasview', -90);
		rotation_deg = -90;
	}else if(rotation_deg == -90){
		
		var image = document.getElementById('imageview');
		image.className = "profilePhoto";
	
		
		rotate('imageview', 'canvasview', 0);
		rotation_deg = 0;
	}
	
	//alert('rotated right');
	showDiv('save_edit');
}


function supports_canvas() {
  return !!document.createElement('canvas').getContext;
}

// this takes the imgId, then the  
function rotate(imgId, canvasDivId, p_deg) {
	if(document.getElementById(canvasDivId)) {
		/*
		Ok!: Firefox 2, Safari 3, Opera 9.5b2
		No: Opera 9.27
		*/
		var image = document.getElementById(imgId);
		var canvas = document.getElementById(canvasDivId);
		
		if(supports_canvas() == true){

			//alert(" supports canvas and div = "+canvasDivId);
		

		}else{
		
			//alert("Does not supports canvasdiv = "+canvasDivId);
		
		}
		
		if(divIdExists(canvasDivId) != 1){
			//alert(" Does not exist div = "+canvasDivId);
		
		}else{
			//alert(" Exists baby div = "+canvasDivId);
		
		}
		
		var canvasContext = canvas.getContext("2d");
		//alert("rotating now and image src = "+image.src+" and deg = "+p_deg);
		canvas.className = "profilePhoto";
		
		var canvasCopy = document.createElement("canvas");
	    var copyContext = canvasCopy.getContext("2d");
		
		canvasCopy.width = image.width;
        canvasCopy.height = image.height;
        copyContext.drawImage(image, 0, 0);

		
		switch(p_deg) {
			default :
			case 0 :
				canvas.setAttribute('width', image.width);
				canvas.setAttribute('height', image.height);
				canvasContext.rotate(p_deg * Math.PI / 180);
				canvasContext.drawImage(image, 0, 0, image.width, image.height);
				
				//canvasContext.drawImage(canvasCopy, 0, 0, canvasCopy.width, canvasCopy.height, 0, 0, canvas.width, canvas.height);

				
				break;
			case 90 :
				canvas.setAttribute('width', image.height);
				canvas.setAttribute('height', image.width);
				canvasContext.rotate(p_deg * Math.PI / 180);
				
				//canvasContext.scale(0.5, 0.5);
				
				canvasContext.drawImage(image, 0, -image.height, image.width, image.height);
				break;
			case 180 :
				canvas.setAttribute('width', image.width);
				canvas.setAttribute('height', image.height);
				canvasContext.rotate(p_deg * Math.PI / 180);
				
				//canvasContext.scale(0.5, 0.5);
				
				canvasContext.drawImage(image, -image.width, -image.height, image.width, image.height);
				break;
			case 270 :
			case -90 :
				canvas.setAttribute('width', image.height);
				canvas.setAttribute('height', image.width);
				canvasContext.rotate(p_deg * Math.PI / 180);
				
				//canvasContext.scale(0.8, 0.8);
				
				canvasContext.drawImage(image, -image.width, 0, image.width, image.height);
				break;
		};
	
		//showDiv(canvas);
		image.className = "canvasEmpty";
		hideDiv(imgId);
		
	} else {
		/*
		Ok!: MSIE 6 et 7
		*/
		var image = document.getElementById(imgId);
		switch(p_deg) {
			default :
			case 0 :
				image.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(rotation=0)';
				break;
			case 90 :
				image.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(rotation=1)';
				break;
			case 180 :
				image.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(rotation=2)';
				break;
			case 270 :
			case -90 :
				image.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(rotation=3)';
				break;
		};
		
	};
};


function setContactAvatar(picloc){
	
	//contact_avatar
	var conAvatarElem=document.getElementById('contact_avatar');
	conAvatarElem.src = picloc;
	
	
	addMyMediaType = 0;
	//parent.removeDiv('backfade'); 
	parent.removeDiv('addPicture'); parent.winOpened = 'addShowProfile';
	showDiv('addShowProfile');
	updateAvatar = 1;
	newContactAvatar = picloc;
	//alert('adding picloc to avatar = '+picloc);
	
	
}


function loadShowProfile(i_c_id, name, avatar){
	writeDiv('addShowProfile_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>';
	
	var dim = getImgSize(avatar);
	var wd = dim[0];
	var ht = dim[1];
	//alert('okay wd = '+wd+' and ht = '+ht+' of avatar = '+avatar);
	var target_wd = 240;
	var target_ht = 420;
	var newdim = resizeDim(avatar, target_wd, target_ht, wd, ht);
	//alert('okay wd = '+wd+' and ht = '+ht+' and newdim = '+newdim+' of avatar = '+avatar);
	
	wd = newdim[0];
	ht = newdim[1];
	
	//chec if i_c_id = 
	var phone = cellnumIcidArray[i_c_id];
	var cellName = icidCellNameArray[i_c_id];
	
	//alert("phone = -"+phone+"-  cool");
	if((typeof(phone) != 'undefined')&&(phone > 0)){
		//this is contact so we ca edit it
		var hasContact = 0;
	
	
		if(avatar == 'tim_images/'){
		
			if(phone > 0){
				message_type = 1;
				
			}else{
				message_type = 2;
				
			}
			
			if(message_type == 2){
				avatar = "images3/avatar_bubble.png";
				 
			} else {
				
				avatar = "images3/avatar_cellular2.png";
				
			}
			
			
		}
		
	
	
	
	
		
		//contactIcidInfoArray = new Array;		// array of array[cellnum] (i_c_id, firstname, lastname, avatar, con_id);
		var contactArray = contactIcidInfoArray[phone];
		//alert(" this is the contact info : "+contactArray);
		var firstname = '';
		var lastname = '';
		var con_email = '';
		
		var deleteDiv = '';
		
		if(typeof(contactArray) != 'undefined'){
			
			var con_icid = contactArray[0];
			var firstname = contactArray[1];
			//alert('firstname = '+firstname);
			if(typeof(firstname) == 'undefined'){
		
					firstname = '';
			}
			
			var lastname = contactArray[2];
			
			if(typeof(lastname) == 'undefined'){
		
					lastname = '';
			}
			
			
			var con_avatar = contactArray[3];
			
			var con_id = contactArray[4];
			
			if(typeof(con_avatar) == 'undefined'){
		
					con_avatar = '';
			}
			
			
			var con_email = contactArray[5];
			
			if(typeof(con_email) == 'undefined'){
		
					con_email = '';
			}
			//alert('cehec firstname = '+firstname);
			if((firstname == '')&&(lastname == '')){
				//NO CONTACT, SO nO DElete button
				//alert('both first and last are not filled');	
			}else{
				
				//Add delete button
				deleteDiv = "<div class=\"contact_div\"><div id=\"delete_con\" class=\"delete_div\" title=\"delete this contact\" onClick=\"deleteContact('"+con_id+"');\">Delete</div></div>";
				
				
				
			}


		}

		
		var content = "<table class=\"profileHolder\"><tr><td valign=\"top\" width=\"280\"><div><img id=\"contact_avatar\" src=\""+avatar+"\" width=\""+wd+"\" height=\""+ht+"\" class=\"profilePhoto\" onClick=\"editContactAvatarPic();\"  style=\"cursor:pointer\"></div><div  class=\"clickphoto\">click image above to change it</div></td><td valign=\"top\" align=\"left\"><div class=\"profileContactInfo\"><div id=\"con_status\" class=\"con_status\"></div><div class=\"contact_div\"><span id=\"con_fname\" class=\"contact_label\">firstname:</span> <input id=\"contact_fname\" name=\"contact_fname\" type=\"text\" size=\"20\" value=\""+firstname+"\" class=\"contact_input_field\"></div><div class=\"contact_div\"><span id=\"con_lname\" class=\"contact_label\">lastname:</span> <input id=\"contact_lname\" name=\"contact_lname\"  value=\""+lastname+"\"  type=\"text\" size=\"20\" class=\"contact_input_field\"></div><div class=\"contact_div\"><span id=\"con_phone\" class=\"contact_label\">cellphone:</span> <input id=\"contact_phone\" name=\"contact_phone\" type=\"text\" size=\"20\" value=\""+phone+"\"  disabled class=\"contact_input_field\"></div><div class=\"contact_div\"><span id=\"con_email\" class=\"contact_label\">email:</span> <input id=\"contact_email\" name=\"contact_email\"  value=\""+con_email+"\"  type=\"text\" size=\"20\" class=\"contact_input_field\"></div><div id=\"con_buttons\">"+deleteDiv+"<div class=\"contact_div\"><div id=\"save_con\" class=\"save_div\" title=\"save this contact\" onClick=\"saveContact('"+con_id+"', '"+con_icid+"');\">Save</div></div></div></div></td></tr></table>";	
	
	
	}else{
	
		var userInfoFrame = "";
		//alert(' hey adin = '+isadmin);
		if(isadmin == 1){
			//alert(' okay we ahve admin ');
			userInfoFrame = '<div style="background-image:url(images/icon_inprogress.gif); background-position:center; background-repeat:no-repeat;"><iframe src="getUserInfo.php?getNick='+name+'&getUserId=&id='+itim_user_id+'&sessId='+sessId+'" style=" border-width:0; overflow:hidden; height:400px;" width="300" height="400" frameborder="0" scrolling="no"></iframe></div>';	
			//alert(' okay we ahve admin ='+userInfoFrame);
			
		}
		
		var content = "<table class=\"profileHolder\"><tr><td valign=\"top\" width=\"280\"><div><img src=\""+avatar+"\" width=\""+wd+"\" height=\""+ht+"\" class=\"profilePhoto\" ></div><div id=\"favmember\" class=\"addtofav\" onClick=\"addFavMember('"+fav_group_id+"','"+name+"', '');\"><span class=\"posFavText\">Add to Favs</span><span class=\"posFavStar\"> <img src=\"icons_main/cool_icons/favstar.png\" width=\"36\" height=\"36\" ></span></div></td><td valign=\"top\" align=\"left\"><div class=\"profileInfo\"><div>"+name+"</div>"+userInfoFrame+"</div></td></tr></table>";	
	
	
	}
	
	//alert(' iframe = '+content);
	writeDiv('addShowProfile_holder', content);
	
}



function loadNewProfile(noclear){
	
	
	
	//this is contact so we ca edit it
	var hasContact = 0;
	var message_type = 1;
	
	
	if(noclear != 1){
		
		writeDiv('addShowProfile_holder', '');
		var avatar = "images3/avatar_cellular2.png";
		
	
		var firstname = '';
		var lastname = '';
		var con_email = '';
		
		var deleteDiv = '';
		
		var con_id = 0;
		var wd=240;
		var ht=240;
		var content = "<table class=\"profileHolder\"><tr><td valign=\"top\" width=\"280\"><div><img id=\"contact_avatar\" src=\""+avatar+"\"  width=\""+wd+"\" height=\""+ht+"\"  class=\"profilePhoto\" onClick=\"editContactAvatarPic();\" style=\"cursor:pointer\"></div><div class=\"clickphoto\">click image above to change it</div></td><td valign=\"top\" align=\"left\"><div class=\"profileContactInfo\"><div id=\"con_status\" class=\"con_status\"></div><div class=\"contact_div\"><span id=\"con_fname\" class=\"contact_label\">firstname:</span> <input id=\"contact_fname\" name=\"contact_fname\" type=\"text\" size=\"20\" value=\""+firstname+"\" class=\"contact_input_field\"></div><div class=\"contact_div\"><span id=\"con_lname\" class=\"contact_label\">lastname:</span> <input id=\"contact_lname\" name=\"contact_lname\"  value=\""+lastname+"\"  type=\"text\" size=\"20\" class=\"contact_input_field\"></div><div class=\"contact_div\"><span id=\"con_phone\" class=\"contact_label\">cellphone:</span> <input id=\"contact_phone\" name=\"contact_phone\" type=\"text\" size=\"20\" class=\"contact_input_field\"></div><div class=\"contact_div\"><span id=\"con_email\" class=\"contact_label\">email:</span> <input id=\"contact_email\" name=\"contact_email\"  value=\""+con_email+"\"  type=\"text\" size=\"20\" class=\"contact_input_field\"></div><div id=\"con_buttons\">"+deleteDiv+"<div class=\"contact_div\"><div id=\"save_con\" class=\"save_div\" title=\"save this contact\" onClick=\"saveContact('"+con_id+"');\">Save</div></div></div></div></td></tr></table>";	
	
	
		//alert(' iframe = '+content);
		writeDiv('addShowProfile_holder', content);

	}


	hideDiv('con_status');
}





function editAvatarPic(){
	
	alert(" editing pic ");	
	
}





function initGeolocation()
{
    if( navigator.geolocation )
    {          
          // Call getCurrentPosition with success and failure callbacks
          navigator.geolocation.getCurrentPosition( geosuccess, geofail );
    }
    else
    {
          //alert("Sorry, your browser does not support geolocation services.");
    }
}

 var map;
 function geosuccess(position)
 {

     var longIDText = document.getElementById('longID');
     var latIDText = document.getElementById('latID');
	 curr_long = position.coords.longitude;
	 curr_lat = position.coords.latitude;
	 //alert('currently at '+position.coords.longitude+", "+position.coords.latitude+' and '+curr_lat+","+curr_long);
	 
     //longIDText.value = position.coords.longitude;
     //latIDText.value = position.coords.latitude;
     //document.getElementById('coordSubmitID').click();
  }

  function geofail(error)
  {
         // alert("FAAAAAAAAAAIIIIIIIIIL GEO");
		  /*
          var zip_code ;
          while (true){
              // Could not obtain location

              zip_code = prompt("Please enter your current address or zip code","");


              if ( zip_code == "" ) {
                  alert(zip_code +" is not a valid address. Please try again.");
              } 
              else{
                break;
              }
          }
          var zipIDText = document.getElementById('zipID');
          zipIDText.value = zip_code;
          document.getElementById('coordSubmitID').click();
  
  		*/
  
  }


//called by itim swf when it has finished
//getURL("javascript:sendDoneIcid('"+_root.i_c_id+"', '1');");
// didSend = 1 mean it sent, 0 means it failed.	
function sendDoneIcid(icid, didSend){
	//alert('Send Comepleted messeage for icid = '+icid+' was send = '+didSend);
	
	if(didSend == 1){
		
		
	}else{
		//alert('sengin failed');
		resetRecon();
		
		lostConnection = 0;
		if(reconOn != 1){
			//alert("Sending Failed - Lost. Please Check your internet connection and try resending. Thanks ;)  ");
		
		
			var msg = "Sending Failed - Lost. Please Check your internet connection and try resending. Thanks ;)  ";
			showErrorAlert(msg);
						
		
		}
		startRecon();
		
		
		
	}
	
	
}






function getIcidAjax(newgetIcidUrl){
	
	var func = "parseGetIcid";
	//alert('url = '+newgetIcidUrl+'\n\nfunc = '+func);
	var newgetIcidUrlMain = newgetIcidUrl+"&id="+itim_user_id+"&sessID="+sessId;
	
	changeDivWidth('sendgif', 60);
	changeDivWidth('sendgifwin', 60);
	//ajaxGetUrlAndFunc(newgetIcidUrl, func);	
	ajaxGetUrlAndFunc(newgetIcidUrlMain, func);	
	
	
	
}







/**
*
* parses content received by getIcid
*	:-_-_-:754244-_-tom-_-19853487-_--_-:-_-_-: 
*
*	name-_-$last_mes_id-_-$receiver_user_id-_-$avatar:-_-_-:
*/
// nosend will just open the div after getting the icid

function parseGetIcid(str){
	str = unescape(str);
	
	changeDivWidth('sendgif', 80);
	changeDivWidth('sendgifwin', 80);
	//alert('output = '+str);
	
	// :-_-_-:1027-_-cuco-_-20040335-_-18007-_-tim_images/18007_02-26-2010_02-26-21_0i8y_2ipodfile.jpg-_-2 :-_-_-:
	
	
	
	//group msg example
	//:-_-_-:955358-_-favorite+crew-_-24516482-_--_-42026_03-04-2010_03-56-35_u6b8_2ipodfile.jpg-_-3-_-16-_-1-_--_-:-_-_-: 
		
	var fullmainarr = str.split(":-_-_-:");
	
	//alert('fullmainarr = '+fullmainarr);
	
	var outputarr = fullmainarr[1];
	//alert('outputarr = '+outputarr);
	var mainarr = outputarr.split("-_-");
	//alert('mainarr = '+mainarr);
	var newicid = mainarr[0];
	var newname = unescape(mainarr[1]);
	var newlastmesid = mainarr[2];
	var new_receiver_user_id = mainarr[3];
	var newavatar = mainarr[4];
	new_avatar = mainarr[4];
	new_group_id = mainarr[6];
	new_group_type = mainarr[7];
	new_admin_group = mainarr[8];
	new_itim_version = mainarr[9];
	
	
	
	
	var newmestype = mainarr[5];
	if(newmestype == 2){
		new_mes_type = 2;
	}else if(newmestype == 3){
		new_mes_type = 3;
	}else{
		
		
	}
	//alert(' new avatar = '+new_avatar+' and typep = '+newmestype+' and mes_type = '+new_mes_type);
	
	//var tempInfo = new Array('".$fr_i_c_id."', '".$fr_name."', '".$fr_id."', '".$fr_avatar."', '".$fr_online."'); friendInfoArray.push(tempInfo);
	
	
	if(newicid > 0){
		//add icid to icidorcelllnum
		
		if(newmestype == 2){
			
			var tempInfo = new Array(newicid, newname, 0, newavatar, 0);
			friendInfoArray.push(tempInfo);
			
		}else if(newmestype == 3){
			
			//do nothing for now
			//var tempInfo = new Array(newicid, newname, 0, newavatar, 0);
			//friendInfoArray.push(tempInfo);
			
		}else{
		
			icidForCellnumArray[newcellnum] = newicid;
		
		}
		
		new_icid = newicid;
		//alert(' new icid = '+newicid+' for cellnum = '+newcellnum+'\n and array is = '+icidForCellnumArray[newcellnum]);
		if(nosend == 1){
			closeDivIcid(new_icid);
			startItimBar(new_icid);
			nosend = 0;
		}else{
		
			sendTim();
		
		}
		
		
		
	}else if(str.length > 3){
		
		hideDiv('sendprogress');
		hideDiv('sendprogresswin');
		hideDiv('sendOverlay');
		
		hideDiv('sendprogresswinIM');
		hideDiv('sendOverlayIM');
		
		//uyienoma
		changeDivWidth('sendgif', 10);
		changeDivWidth('sendgifwin', 10);
		if(newmestype == 2){
			var nickerr = document.newitimformIM.nick.value;
			alert('@'+nickerr+' is not a valid itim nickname. Please check your spelling and try again');
			document.newitimformIM.nick.focus();
			
		}else if(newmestype == 3){
			var nickerr = document.newitimformIM.nick.value;
			alert('Group: '+nickerr+' does not exist. Please check your spelling and try again');
			document.newitimformIM.nick.focus();
			
		}else{
				
			alert(' sending failed....please try again');
		
			//alert('')
		}
		
	}else{
		hideDiv('sendprogress');
		hideDiv('sendprogresswin');
		hideDiv('sendOverlay');
		hideDiv('sendprogresswinIM');
		hideDiv('sendOverlayIM');
		
		//uyienoma
		changeDivWidth('sendgif', 10);
		changeDivWidth('sendgifwin', 10);
		alert(' sending failed....please try again');
		
		
	}
	
	
	
	
}





function checkAndRemoveAlert(temp_i_c_id){
	
	var m = openAlertsArray.length;
	//alert('copan icid = '+temp_i_c_id+' to array of alers = '+openAlertsArray);
	for(var i = 0; i < m; i++){
		var alertArr = openAlertsArray[i];
		
		if(typeof(alertArr) != 'undefined'){
			var temp_itimnum = alertArr[0];
			var temp_mes_id = alertArr[1];
		
			var check_icid = alertArr[2];
			//alert('check ic id = '+check_icid+' and compare to '+temp_i_c_id);
			if(check_icid == temp_i_c_id){
				//alert(' foudn a math for icid = '+check_icid);
				
				closeAlertArr(temp_mes_id,'1' ); 
				closeDiv(temp_itimnum);
				
			}
			
			
		}
	}
	
}






/*** Sockets, aahhhh, don't you just love it  *******/

 //alert('conn to connect');
 // Handle Receiving Stuff

/**
socket.on('message', function(data){ 
	message(data); 
});
socket.on('connect', function(){ 
	//status_update("Connected");
	socket.emit('adduser', itim_user_id); 
	
	alert(' we r connected for '+itim_user_id); 
});

socket.on('timedate', function(data){ 
	status_update("Received msg = "+data); 
});

socket.on('disconnect', function(){ 
	status_update("Disconnected"); 
});
socket.on('reconnect', function(){ 
	status_update("Reconnected");
});
socket.on('reconnecting', function( nextRetry ) { 
	status_update("Reconnecting in " + nextRetry + " seconds"); 
});
socket.on('reconnect_failed', function(){ 
	message("Reconnect Failed"); 
});

**/

// Do OUTPUT
function send(itim_event, itim_data) {
	socket.emit(itim_event, itim_data);    
	//socket.emit('message', 'Uyi Hello Server!');    


};



/*** -------------------- End of Sockets ---------------*****/





/**
*
* 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);
	//now tell the openalertarray that every thing is closed
	stopAnimTitle();
	var m = openAlertsArray.length;
	for(var i = 0; i < m; i++){
		var alertArr = openAlertsArray[i];
		
		
	
		var close_mes_id = alertArr[1];
	
		if(close_mes_id == temp_mes_id){
			
			removeByIndex(openAlertsArray, i);
			i = m;
			//var alertArr2 = new Array('0', '0');
			//openAlertsArray[i] = alertArr2;
			
			//closeAlertArr(temp_mes_id,'1' ); 
			//closeDiv(temp_itimnum);
			
		}
	
	
	}
	
	
	if(openAlertsArray.length > 0){
		
		
	}else{
		hideDiv('closeallalerts');
		
	}
	
	
}


// removes array element by index
// splices the object at that index
function removeByIndex(arrayName,arrayIndex){ 
	arrayName.splice(arrayIndex,1); 
}



/**
* 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(' newitim opened = '+new_form_opened+' and winopen = '+winOpened+' and id = '+id);
	//new_form_opened = 1;
	
	
	
	if((new_form_opened == 1)&&(id == 'backfade') && ((winOpened != 'startNewItim') && (winOpened != 'startNewItimIM')   )){
		
		//alert(' newitim opened = '+new_form_opened+' and winopen = '+winOpened+' and id = '+id);
		//alert("no way pic main = "+pic_image_main+' and win open = '+winOpened);
		if(new_mes_type == 2){
		
			loadBackfade(); topIndex++; document.getElementById('startNewItimIM').style.zIndex = topIndex; moveDiv('startNewItimIM', '250', '203'); 
			if(pic_image_main.length > 0){
				
				
			}else{
				clearNewItimIM(); 
			}
			winOpened = 'startNewItimIM';
			
		}else{
			loadBackfade(); topIndex++; document.getElementById('startNewItim').style.zIndex = topIndex; moveDiv('startNewItim', '250', '203'); 
			if(pic_image_main.length > 0){
				
				
			}else{
			
				clearNewItim(); 
			
			}
			
			winOpened = 'startNewItim';
			
		}
		
		
	}
	

}


//alert('line 183');
function closeDivIcid(i_c_id){

	var curr_itimnum = icidArray[i_c_id];
	
	
	fnameForIcid[i_c_id] = "";
	
	if(curr_itimnum > 0){
		var divId = "bar_iTim_"+curr_itimnum;
		//alert('removing '+divId+' f for icid = '+i_c_id+' and icidArray = '+icidArray);
		closeDiv(curr_itimnum);
		
		document.getElementById("allitim_"+i_c_id).className = "midRightBarNew";
	
		
		if(currentItimWinArray.length > 0){
			//setItimSelected();
		}else{
			//no itim windows
			topOpenedIcid = 0;
			
		}
		
		
	
		var divExists = 0;
		
		//alert('about to cheeck for it now = '+allitimdiv);
		if(divIdExists(divId) != 1){
			//alert('div does not exist '+divId);
			
		}else{
			
			//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;
	
		//alert('hey closing icid = closeItim_'+i_c_id);
		//hideDiv('closeItim_'+i_c_id);
	
		
		if(divIdExists('closeItim_'+i_c_id) == 1){
			//alert('hey closing icid = closeItim_'+i_c_id);
			hideDiv('closeItim_'+i_c_id);
		
		}
		//var temp_i_c_id = itimnumArray[itimnum];
			
		findAndRemoveIcidLocation(i_c_id);
	
	
	}
	//alert("closing removed itiom closeItim_"+i_c_id);
	
	
	topOpenedIcid = getTopIcid();
	//alert('top open = '+topOpenedIcid);
}

//used in old, not used in new bcos we no longer have a section for open itims,
//only all itims are used now
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){
					//alert('uyienoma hiding new msg main = new_alltim_'+temp_i_c_id);
				
					hideDiv('new_alltim_'+temp_i_c_id);
					
					var tmpcountDiv=document.getElementById("count_new_allitim_"+temp_i_c_id);
					tmpcountDiv.innerHTML = 0;
					
				}
				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");
		
		
		//6-6-10 used to have this above allitims, no need
		//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, 360, 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, 360, 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 );
	
	//if((is_checker_on != 1)&&(is_socket_connected != 1)){
		
	//alert(" okey athe user id = "+itim_user_id);	
	if((is_checker_on != 1)&&(itim_user_id > 0)){

		if(firstCheck == 1){
			checkIntervalId = setInterval ( "checkNewMsgAndFriend()", firstTimeCheck );
		}else{
			checkIntervalId = setInterval ( "checkNewMsgAndFriend()", timeCheck );
		}
		
	}
	
	is_checker_on = 1;
	
}



/**
*	 this starts the routine interval checkers
*
*/
function startCheckerOnce(){
	//setInterval ( "startItimAlert('47', 'Hello uyi', 'Uyi Ogbeide')", 10000 );
	//setInterval ( "checkNewMsgAndFriend()", 10000 );
	if(is_checker_once_on != 1){
		checkIntervalIdOnce = setInterval ( "checkNewMsgAndFriendOnce()", timeCheck );
	}
	is_checker_once_on = 1;
	
}



function stopChecker(){
	firstCheck = 0;
	clearInterval(checkIntervalId);

	//is_socket_connected = 0;
	is_checker_on = 0;
}



/**
*
*	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
	
	//only allow one check 
	
	//alert('now is checking and socket = '+is_socket_connected);
	
	if(is_socket_connected == 1){
		
		stopChecker();
		
	}
	
	//alert('trying to reconnect = '+socket_should_reconnect);
	if(socket_should_reconnect == 1){
		
		//try to reconnect	
		//alert('trying to reconnect');
		//socket = io.connect('http://91.214.110.54:8080');

	}
		
	
	
	if(firstCheck == 1){
		firstCheck = 0;
		//reset checker so it users the real check time
		stopChecker();
	
		if(is_socket_connected != 1){
	
			startChecker();
		}
	}
	
	
	
	
}




/**
*	 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 checkNewMsgAndFriendOnce(){
	
	//first call the url http://www.2waystar.com/itimworld/con_scripts/getNewMessage.php
	var newurl = baseUrl+"con_scripts/getNewMessage.php";
	parseTemp();
	clearInterval(checkIntervalIdOnce);
	//alert('trying to reconnect = '+socket_should_reconnect);
	if(socket_should_reconnect == 1){
		
		//try to reconnect	
		//alert('trying to reconnect');
		//socket = io.connect('http://91.214.110.54:8080');

	}
	
	
}


//refreshes the homepage, say you lose connection

function refreshMyHome(){
	//alert('refeshing home');
	location.href='myhome.php';	
	
	
}

/** 
* logMeOut logs you out
*	it is typically called by the flash application freesmsreply_im looking for mainlogout = 1
* logMeOut
*/

function logMeOut(errormsg){
	var redirect = 1;
	var reason = 'login_elsewhere=1';
	//alert('okay son logginh you out = '+errormsg);
	
	if(typeof(errormsg) != "undefined"){
		
		if(errormsg == 'verify_failed'){
			//alert('okay son logginh you out = '+errormsg);
	
			//redirect = 0;	
			reason = 'verfail=1';
			
		}else if(errormsg == 'lostconnection'){
			//alert('okay son logginh you out = '+errormsg);
			reason = 'lost_connection=1';
			//redirect = 0;	
			
		}else{
			
			reason = errormsg;	
		}
		
	}
	
	if(itim_user_id > 0){}else{
		//alert(' wor okay son logginh you out = '+errormsg);
		
		if(errormsg == "getnewmessage_failed"){
			
			
			redirect = 0;
			
			
		}
		
	}
	
	if(redirect == 1){
		//location.href='login.php?login_elsewhere=1&id='+itim_user_id+'&sessID='+sessId;	
		
		
		//user below
		location.href='login.php?'+reason+'&id='+itim_user_id+'&sessID='+sessId;	
	
	}
}


// 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;
	
}


//writes the text into all itim, used when they send or receive during a session

function writeAllitimText(str, i_c_id) {
	var success = 0;
	var divId = "allitimtext_"+i_c_id;
	
	try {
		var myElem = document.getElementById(divId);
		success = 1;
		//trim the msg
		if(str.length > 15){
			var re = /(.{13}).+/;
			str = str.replace(re, "$1...");
			//alert('replaced cellname =  '+cellName);
		}
		
		//alert('hey stri = '+str);
		if (typeof(str) == "undefined") {
	
			str = '...';
			//alert('str is undefined = '+str);
		}
		//alert('after stri = '+str);
		writeDiv(divId, str);
		//document.getElementById('all_itims').scrollTop = 0;
		//alert(' writing to icid div - '+divId)
	} catch (e) { 
		//alert(' icid not exist error son - '+divId)
		success = 0;
		
		//create then write
		
		
		
	}
	
	return success;
	

	
}



function setItimSelected(){
	/* no needed, no open itims sections 
	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){
	addMyMediaType = 1;
	writeDiv('addPicture_holder', '');
	writeDiv('addMediaTitle', 'iTim - Add Media');
	//var i_c_id = 68;
	var content = '<iframe src="addpicmain.php?itimnum='+itimnum+'&id='+itim_user_id+'&sessId='+sessId+'" style=" border-width:0; overflow:hidden; height:480px;" width="660" height="480" frameborder="0" scrolling="no"></iframe>';
	
	//var content = '<iframe src="addpic.php?itimnum='+itimnum+'" style=" border-width:0; overflow:hidden;" width="660px" height="480" frameborder="0"></iframe>';	
	//alert(' iframe = '+content);
	
	//set height to height:480px; 240
	var newDiv=document.getElementById('addPicture_holder');
	var newStyle=newDiv.style;
	newStyle.height="480px";
	
	writeDiv('addPicture_holder', content);
	
	
	
	
}

function loadAddNewPicture(itimnum){
	addMyMediaType = 1;
	writeDiv('addPicture_holder', '');
	writeDiv('addMediaTitle', 'iTim - Add Media');
	
	//var i_c_id = 68;
	var content = '<iframe src="addpicmain.php?addtype=1&newitim=1&id='+itim_user_id+'&sessId='+sessId+'" style=" border-width:0; overflow:hidden; height:480px;" width="660" height="480" frameborder="0" scrolling="no"></iframe>';	
	//alert(' iframe = '+content);
	
	//set height to height:480px; 240
	var newDiv=document.getElementById('addPicture_holder');
	var newStyle=newDiv.style;
	newStyle.height="480px";
	
	writeDiv('addPicture_holder', content);
	
	
	
}


function editContactAvatarPic(){
	//addMyMediaType = 3;
	//alert("editing advarar fr the contact");
	var mynum = 0;
	//loadAddPicture(mynum);
	loadAddContactAvatar();
	
}

/** load ajax setup pages */
function loadAddAvatar(){
	addMyMediaType = 2;
	//writeDiv('addAvatar_holder', '');
	writeDiv('addPicture_holder', '');
	writeDiv('addMediaTitle', 'iTim - Change Avatar');
	//var i_c_id = 68;
	
	
	var content = '<iframe src="addpicmain.php?addtype=2&id='+itim_user_id+'&sessId='+sessId+'" style="overflow:hidden; height:480px;" width="660" height="480" frameborder="0" scrolling="no"></iframe>';
	
	
	//var content = '<iframe src="addavatar.php" style=" border-width:0; overflow:hidden;" width="660px" height="480" frameborder="0"></iframe>';	
	//alert(' iframe = '+content);
	
	
	//set height to height:480px; 240
	var newDiv=document.getElementById('addPicture_holder');
	var newStyle=newDiv.style;
	newStyle.height="480px";
	
	//writeDiv('addAvatar_holder', content);
	writeDiv('addPicture_holder', content);
	
}

/** load ajax setup pages */
function loadAddContactAvatar(){
	addMyMediaType = 3;
	//writeDiv('addAvatar_holder', '');
	writeDiv('addPicture_holder', '');
	
	hideDiv('addShowProfile');
	moveDivCenter('addPicture'); winOpened = 'addPicture';
	
	//alert('adding to media title before loading');
	writeDiv('addMediaTitle', 'iTim - Change Contact Photo');
	//var i_c_id = 68;
	
	
	var content = '<iframe src="addpicmain.php?addtype=3&id='+itim_user_id+'&sessId='+sessId+'" style=" border-width:0; overflow:hidden;" width="660px" height="480" frameborder="0"></iframe>';
	
	
	//var content = '<iframe src="addavatar.php" style=" border-width:0; overflow:hidden;" width="660px" height="480" frameborder="0"></iframe>';	
	//alert(' iframe = '+content);
	
	
	//set height to height:480px; 240
	var newDiv=document.getElementById('addPicture_holder');
	var newStyle=newDiv.style;
	newStyle.height="480px";
	
	//writeDiv('addAvatar_holder', content);
	writeDiv('addPicture_holder', content);
	
}



/** load ajax setup pages */
function loadAddBackground(){
	addMyMediaType = 4;
	//writeDiv('addAvatar_holder', '');
	writeDiv('addPicture_holder', '');
	
	hideDiv('addShowProfile');
	moveDivCenter('addPicture'); winOpened = 'addPicture';
	
	//alert('adding to media title before loading');
	writeDiv('addMediaTitle', 'iTim - Add New Background');
	//var i_c_id = 68;
	
	
	var content = '<iframe src="addpicmain.php?addtype=4&id='+itim_user_id+'&sessId='+sessId+'" style=" border-width:0; overflow:hidden;" width="660px" height="480" frameborder="0"></iframe>';
	
	
	//var content = '<iframe src="addavatar.php" style=" border-width:0; overflow:hidden;" width="660px" height="480" frameborder="0"></iframe>';	
	//alert(' iframe = '+content);
	
	
	//set height to height:480px; 240
	var newDiv=document.getElementById('addPicture_holder');
	var newStyle=newDiv.style;
	//newStyle.height="250px";
	
	
	//writeDiv('addAvatar_holder', content);
	writeDiv('addPicture_holder', content);
	
}






function setAvatar(picloc, wd, ht){
	
	
	//alert('hey pic div is ht = '+ht+' and wd = '+wd);
		
	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;\" ";
	}
	
	
	
	if(divIdExists('myavatardiv2') != 1){
	
		var divCon = '<img id="itim_avatar" class="itim_avatar" alt="my avatar" src="'+picloc+'" width="'+finalwd+'" border="0" height="'+finalht+'" '+centerStyle+' >';
		//alert('hey div is '+divCon);
		
		
		
		writeDiv('myavatardiv', divCon);
		
	}else{
	
	
		var defwd = 140;
		var defht = 160;
	
	
		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);
		
			if(finalwd > defwd){
							
				finalwd = defwd;
				finalht = defwd/wd * ht;
				finalht = Math.round(finalht);
				
				
				if(finalht > defht){
					
					finalht = defht;
				}	
				
				
			}

		
			//alert(' Cool pic div is ht = '+ht+' and wd = '+finalwd+' and ht = '+finalht);
			
			
			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);
		
		
			//alert('hey pic div is ht = '+ht+' and wd = '+finalwd+' and ht = '+finalht);
		
			
			if(finalht > defht){
						
				finalht = defht;
			}
			
			var difftop = (finalht - defht)/2;
			var centerStyle = " style=\"position:relative; top:-"+difftop+"px;\" ";
		}
			

			
		var divAvatarId = 'myavatardiv2';
		var C_el = document.getElementById(divAvatarId);
		imageurl = "url("+picloc+")";
		C_el.style.backgroundImage  = imageurl;
		
		
		changeClass(divAvatarId, 'itim_avatar_main');
		//alert('hey pic div is '+picloc+' and wd = '+finalwd+' and ht = '+finalht);
		
		
		C_el.style.width = finalwd+"px";
		C_el.style.height = finalht+"px";
	}
	
	
	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);	
	
}




//called before loadCamera bcos loadcam uses domain 2waystar
//and get he user_id from session, so we set it when we are not in the 2waystar domain
function set2waystarUserId(){
	
	var fixCameraUrl = "http://www.2waystar.com/itimworld/import_jpeg_fix.php?id="+parent.itim_user_id+"&sessId="+parent.sessId;
	var func = "doNothingBro";
	alert('fixurl = '+fixCameraUrl+' and userid = '+parent.itim_user_id);
	ajaxGetUrlAndFunc(fixCameraUrl, func); 
		
	
}
	

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', ''
	*/
	
	//webcam9.swf?uploadUrl=http://itimworld.com/import_jpeg.php
	var fvars = "uploadUrl="+baseUrl+"import_jpeg.php";
				
				
		//alert('flashvar = '+fvars);		
	
	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','flashVars', fvars);
	
	
	//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);

	/*
	if(location.hostname != 'www.2waystar.com'){
		alert(' not 2waystar');
		set2waystarUserId();
			
	}else{
	
		alert(' crazy, it is 2waystar');	
		
	}
	*/
	writeDiv('myCamera_Holder', swfOut);
	
	
}

function loadSelectedMedia(picloc){
	//alert('picloc = '+picloc);
	var title = 'iTim - Use this Media? ';
	writeDiv('myMediaTitle', title);
	writeDiv('myMedia_Holder', '');
	var wd = 300;
	var ht = 400;
	
	
	var imgOut = '<img src="'+picloc+'" width="'+wd+'" height="'+ht+'" alt="Click Use below to select"><div class="selectPicBottomTab"><div class="cancelSelectPic" onClick="removeDiv(\'backfade\'); removeDiv(\'myMedia\'); winOpened = \'none\';">Cancel</div><div class="useSelectPic" onClick="useMediaForItim(\''+picloc+'\'); ">Use</div></div>';
	writeDiv('myMedia_Holder', imgOut);
	
	
	
	
}


function useMediaForItim(picloc){
	
	pic_image_main = picloc;
	//alert('parent type = '+parent.addMyMediaType );
	if(parent.addMyMediaType == 1){
		//alert('pic = '+picloc);
		parent.pic_image_main = pic_image_main; parent.newitim_main = newitim_main; parent.itimnum_main = itimnum_main; parent.addImageMain();parent.removeDiv('backfade'); parent.removeDiv('addPicture'); parent.winOpened = 'none';
	}else if(parent.addMyMediaType == 2){
		//changing my avatar
		var image = new Image();
		image.src = picloc;		//attempt to preload it
		var avatarWd = 0;
		var avatarHt = 0;
		
		
		var avatarWd = image.width;
		var avatarHt = image.height;
			
		parent.pic_image_main = pic_image_main; parent.itimnum_main = itimnum_main; parent.addAvatarMain(avatarWd, avatarHt);parent.removeDiv('backfade'); parent.removeDiv('addPicture'); parent.winOpened = 'none';
		
	}else if(parent.addMyMediaType == 3){
		
		parent.setContactAvatar(picloc);
		//parent.removeDiv('backfade'); parent.removeDiv('addPicture'); parent.winOpened = 'none';
	}else if(parent.addMyMediaType == 4){
		
		parent.addBackgroundThumb(picloc);
		//parent.removeDiv('backfade'); parent.removeDiv('addPicture'); parent.winOpened = 'none';
	}
	
	
	
	
}

function addBackgroundThumb(picloc){
	
	
	
}






function useMediaForItimOld(picloc){
	
	pic_image_main = picloc;
	//alert('pic = '+picloc);
	parent.pic_image_main = pic_image_main; parent.newitim_main = newitim_main; parent.itimnum_main = itimnum_main; parent.addImageMain();parent.removeDiv('backfade'); parent.removeDiv('addPicture'); parent.winOpened = 'none';
	
	
	
}




function loadProgressMedia(text){
	
	
	if (typeof(text) == "undefined") {
	
		text = 'starting upload...';
	
	}
	var title = 'iTim - Uploading media...';
	writeDiv('myMediaTitle', title);
	writeDiv('myMedia_Holder', '');
	var wd = 300;
	var ht = 400;
	var imgOut = '<div class="progress_text">'+text+'</div>';
	writeDiv('myMedia_Holder', imgOut);
	
	
}

function loadProgressMediaMobile(text){
	
	
	if (typeof(text) == "undefined") {
	
		text = 'Adding Media...';
	
	}
	var title = 'iTim - Uploading media...';
	writeDiv('myMediaTitle', title);
	writeDiv('myMedia_Holder', '');
	var wd = 300;
	var ht = 400;
	var imgOut = '<div class="progress_text">'+text+'</div>';
	writeDiv('myMedia_Holder', imgOut);
	
	
}


function formatSize(bytes){

	var i = -1;                                    
	do {
		bytes = bytes / 1024;
		i++;  
	} while (bytes > 99);
	
	return Math.max(bytes, 0.1).toFixed(1) + ['kB', 'MB', 'GB', 'TB', 'PB', 'EB'][i];          
}



function startUploading(){
	
	
	loadBackfade();loadProgressMedia(); moveDivCenter('myMedia');
	
}


function startUploadingMobile(){
	
	
	loadBackfade();loadProgressMediaMobile(); moveDivCenter('myMedia');
	
}


function reWriteGoogleAd(){
	
	var googleDiv = "googlead2";	
	//var content = document.getElementById('photos').innerHTML;
	var content = '<script type="text/javascript">google_ad_client = "ca-pub-9937771777735654";/* square_ad */google_ad_slot = "3576120674";google_ad_width = 300;google_ad_height = 250;</script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>';
	
	//alert('writing content');
	//writeDiv(googleDiv, '');
	
	//alert('about to reload google');
	
	//reloadGoogleAd();
	//document.getElementById(googleDiv).style.height = "0px";

	
	
}



 function reloadGoogleAd()
   {
      var gElem= document.getElementById('googlead2');
      var script= document.createElement('script');
      script.type= 'text/javascript';
      script.src= 'http://pagead2.googlesyndication.com/pagead/show_ads.js';
      gElem.appendChild(script);
   }

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(bgClose){
	writeDiv('mySettings_holder', '');
	//var i_c_id = 68;
	
	var content = '<iframe id="settingsIframe" src="updatesettings.php?bgclose='+bgClose+'&id='+itim_user_id+'&sessID='+sessId+'" 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
		/* Not needed, no bar_itim_4 divs bcos no open itims sections
		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);
	
	//not used anymore
	//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");
	//alert(" after just removed itiom "+itimnum);
	
	// 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);
		
		
	}
	
	//var temp_i_c_id = itimnumArray[itimnum];
			
	//findAndRemoveIcidLocation(temp_i_c_id);
	
	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);
		//alert("wind to focus "+itimnum);
	
		itimWinToFocus(itimid, fname);
		//alert("after win focus itiom "+itimnum);
	
		removeFlashAlertNewmes(fname);
		//alert("JUST SET mad focus uiyi");
		thisMovie(fname).tabIndex = 0;
		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, message_type){
	
	
	if(typeof(avatar) == "undefined") {
		
		avatar = '';
	}
	
	
	var check = avatar.search(/nopic/i);
	
	//alert(" You have a message from "+sent_by+"\n\n"+newMessage+" and "+avatar+" and check = "+check);
	// 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")
	}
	*/
	
	// not necessary any more since ajax controls the getnewmsg now not the flash
	//showNewMsg(itimnum);
	
	
	newMessage = unescape(newMessage);
	
	
	//don't use blank avatar or nopic
	if((check > -1) || (avatar == '') || (typeof(avatar) == "undefined")) {
	
		//alert(" avatar is not givin "+avatar);
	
		if(message_type == 2){
			avatar = "images3/avatar_bubble.png";
			 
		} else if((sent_by > 0)||(message_type == 1)){
			
			avatar = "images3/avatar_cellular2.png";
			
		}else{
			avatar = "images3/avatar_bubble.png";
			
		}
		
		//alert("after avatar is not givin "+avatar);
		
	}
	
	
	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);
}

// stop animation here

function stopAnimTitle(){
	if(favNewMes == 1){
		favNewMes = 0;
		favicon.change("favicons/favicon_mbw.ico", "iTim World -  Send and Receive Text Messages Online - And Instant Messenger");
	}
	
	
}

/** lost connection
*
*/
function lostConnection(){
	
	
}

function switchNewItimToIM(){
	
	//save the value of message
	var tempMsg = document.newitimform.newmessage.value;	
	//save the value of attach
	var tempAttach = newAttachment;
	var tempAudio = newAudio;
	
	//alert('mes = '+tempMsg+' and attachment = '+tempAttach+' mes type = '+new_mes_type);
	//remove im new msg;
	removeDiv('backfade'); removeDiv('startNewItim'); winOpened = 'none';
	
	//open new mobile
	loadBackfade(); topIndex++; document.getElementById('startNewItimIM').style.zIndex = topIndex; moveDiv('startNewItimIM', '250', '203'); clearNewItimIM(); winOpened = 'startNewItimIM';
	new_form_opened = 1;
	
	//set message
	
	document.newitimformIM.newmessageIM.value = tempMsg;
	
	
	//set attachment
	if(tempAttach != ''){
		
		var picwd_main  = 50;
		var picht_main  = 50;
		addImage2NewItimIM(tempAttach, picwd_main, picht_main);	
		
		
	}
	
	newAudio = tempAudio;
	new_mes_type = 2;
	
	
}


function switchNewItimToMobile(){
	
	//save the value of message
	var tempMsg = document.newitimformIM.newmessageIM.value;	
	//save the value of attach
	var tempAttach = newAttachment;
	var tempAudio = newAudio;
	
	//alert('mes = '+tempMsg+' and attachment = '+tempAttach+' mes type = '+new_mes_type);
	
	//remove im new msg;
	removeDiv('backfade'); removeDiv('startNewItimIM'); winOpened = 'none';
	
	//open new mobile
	loadBackfade(); topIndex++; document.getElementById('startNewItim').style.zIndex = topIndex; moveDiv('startNewItim', '250', '203'); clearNewItim(); winOpened = 'startNewItim';
	new_form_opened = 1;
	//set message
	document.newitimform.newmessage.value = tempMsg;
	
	
	//set attachment
	if(tempAttach != ''){
		
		var picwd_main  = 50;
		var picht_main  = 50;
		addImage2NewItim(tempAttach, picwd_main, picht_main);	
		
		
	}
	
	newAudio = tempAudio;
	
	new_mes_type = 1;
	
	
}

function startNewItimMain(mestype){
	
	//first we need to get the icid

	var cellnum = '';
	var message = '';	

	if(mestype == 2){
		//alert('mestype == '+mestype);
		
		
		var cellnum = document.newitimformIM.nick.value;
		var message = document.newitimformIM.newmessageIM.value;	
		
		showDiv('sendprogress');
		
		showDiv('sendOverlayIM');
		showDiv('sendprogresswinIM');
		//alert('mestype == '+mestype);
		
		
		
	}else{
	
		//alert('mestype == '+mestype);
	
	
		var cellnum = document.newitimform.cellnumber.value;
		var message = document.newitimform.newmessage.value;	
		
		showDiv('sendprogress');
		
		showDiv('sendOverlay');
		showDiv('sendprogresswin');
		
	}

	
	if((cellnum.length != 10)&&(mestype != 2)){
		hideDiv('sendprogress');
		hideDiv('sendOverlay');
		hideDiv('sendprogresswin');
		alert('\n You must enter a valid 10 digit number');
		document.newitimform.cellnumber.focus();
		
	}else if(cellnum == ''){
		hideDiv('sendprogress');
		if(mestype == 2){
	
	
			hideDiv('sendOverlayIM');
			hideDiv('sendprogresswinIM');
			alert('\n You must enter an @itim.me nickname');
			document.newitimformIM.nick.focus();
					
		}else{
				
			hideDiv('sendOverlay');
			hideDiv('sendprogresswin');
			
			alert('\n You must enter a valid 10 digit number');
			document.newitimform.cellnumber.focus();
			
		}
	}else if((message.length == 0) && (newAttachment.length == 0)){
		hideDiv('sendprogress');
		alert('\n You must enter a message or add a photo');
		
		if(mestype == 2){
			hideDiv('sendOverlayIM');
			hideDiv('sendprogresswinIM');
		
			document.newitimformIM.newmessageIM.focus();
		}else{
			hideDiv('sendOverlay');
			hideDiv('sendprogresswin');
		
			document.newitimform.newmessage.focus();
		}
	}else{
	
		var newicid;

		var cellinfo = new Array();
		//alert(' okay newicid'+mestype);
		
		if(mestype == 2){
			
			newicid = getIcidForNick(cellnum);
			//alert('cellnum = '+newicid+' and array = '+friendInfoArray+' and cellnum = '+cellnum);
			//cellinfo = contactIcidInfoArray[cellnum];
		
		}else{
			newicid = icidForCellnumArray[cellnum];

			cellinfo = contactIcidInfoArray[cellnum];
		}
		if((typeof(cellinfo) != "undefined")){
	
			
			if(cellinfo[0] > 0){
				//there is a contact and a name
					
				newicid = cellinfo[0];
				name = cellinfo[1]+' '+cellinfo[2];
				name = trim(name);
				avatarpic = cellinfo[3];
			}else{
				
				//newicid = icidForCellnumArray[cellnum];
				
			}
		
		}
		//alert('cellnum = '+cellnum+' and mestype = '+mestype+' and newicid = '+newicid);

		newcellnum = cellnum;
		
		//var newAttachment = '';		//attachment when createing a new message
		if((cellnum > 0)&&(mestype != 2)){
			
			new_mes_type = 1;	
		}else{
			new_mes_type = 2;
			
		}





		
		if(newicid > 0){
		
			//alert('\ncellnum = '+cellnum+'\nmessage = '+message+'\nhey index = '+newicid+' and userid = '+itim_user_id);
			
			//send a message
			new_icid = newicid;
			sendTim();			
			
		}else{
			//alert('\n you must search for the icid for '+cellnum);

			newcellnum = escape(newcellnum);

			var new_getIcidUrl = getIcidUrl+'?&send=1&cellnum3='+newcellnum+'&message_type='+new_mes_type;
			
			
			changeDivWidth('sendgif', 40);
			changeDivWidth('sendgifwin', 40);
			getIcidAjax(new_getIcidUrl);

		}
		
		
		//check if icid exists in the array we have
		
		
		//if not, get icid using ajax to call geticid
		
		
		//then send the message
		
		
		//insert in the all itim section
		
		//then open the conversation using the icid
		
		
	}
	
	
}


//gets the icid for a nickname

function getIcidForNick(nick){
	nick = nick.toLowerCase();	
	var icid = 0;
	
	var tempicid = icidForNicknameArray[nick];
	//alert(' temp icid = '+tempicid+' and array = '+icidForNicknameArray);
	if(tempicid > 0){
		
		icid = tempicid	;
		
	}else{
	
	
		for(var i = 0; i < friendInfoArray.length; i++){
				var fnick = friendInfoArray[i][1];
				//alert('compaing fnick = '+fnick+' to ur search = '+nick);
				if(fnick == nick){
					icid = friendInfoArray[i][0];
					i = friendInfoArray.length;
					
				}
				
				
		}

	}
	return icid;
}



//gets the icid for a nickname

function getNickForIcid(icid){
	
	var nickarr = new Array;
	for(var i = 0; i < friendInfoArray.length; i++){
			var fnick = friendInfoArray[i][1];
			var tmpicid = friendInfoArray[i][0];
			
			//alert('compaing fnick = '+fnick+' to ur search = '+nick);
			if(tmpicid == icid){
				nickarr = friendInfoArray[i];
				//fr_i_c_id, fr_name, fr_id, fr_avatar."
				i = friendInfoArray.length;
				
			}
			
			
	}

	
	return nickarr;
}







/** 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).tabIndex = 0;
	thisMovie(fname).focus();
	
	
}





function getAndSetCameraPic(){
	

	// get url get_camera_filename.php and set the var camera_pic
	//alert("url = "+get_camera_url);
	
	//only bcos we did nt fix the ams
	/*
	if(location.hostname != 'www.2waystar.com'){
		//var get_camera_url = baseUrl+"get_camera_filename.php?user_id="+parent.itim_user_id;
	
		var get_camera_url = "http://www.2waystar.com/itimworld/get_camera_filename.php?user_id="+parent.itim_user_id;
		alert("url = "+get_camera_url);
	
	}
	*/
	
	
	ajaxGetUrlSetVarsFunc(get_camera_url, "setCameraPic");	
	
	
	
	
	
	
	
	
}



function setCameraPic(){
	
	
	//alert('setting camera pic = '+camera_pic);
	
	if(camera_pic != ""){
	
		//alert('setcamerra pic and type = '+parent.addMyMediaType);
		
		
		
		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);
		
		//moved to prevent leak
		new_element.innerHTML = content;
		
		//alert("inserting pic"+next_pic_num+"\n\n"+content);
		
		// close the camera window
	}
	if(use_drag_drop != 1){
		
		
		removeDiv('backfade');
		winOpened = 'none';
	
	}
	removeDiv('myCamera'); 
	
	
	if(parent.addMyMediaType == 4){
			
		//pass the camera photo
		//close
		parent.addBgThumbToSettings(camera_pic); 
		parent.closeAddPicture();		
			
	}
	
}


function addRecentThumbnail(picloc){

		//alert('addin recent thoumnail = '+picloc);
		var camera_pic = picloc;
	
		//alert('add recent thum pic type = '+addMyMediaType);
		// 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);
		
		new_element.innerHTML = content;
		//alert("2. inserting pic"+next_pic_num+"\n\n"+content);	
	
		
	if(parent.addMyMediaType == 4){
			
		//pass the camera photo
		//close
		parent.addBgThumbToSettings(camera_pic); 
		parent.closeAddPicture();		
			
	}
	
}



function addBgThumbToSettings(picloc){
	//alert('about to pass to iframe pic = '+picloc);
	document.getElementById('settingsIframe').contentWindow.addBgThumb(picloc);
		
	
	
}

function addBgThumb(picloc){
	
	//alert(' adding pic with '+picloc);
	var content = '<div style="float:left; height:75px; width:110px;"><a href="javascript:void(0);" onClick="previewNewBG(\''+picloc+'\');"><img src="'+picloc+'" alt="m" width="100" height="63" border="0" style="border:1px solid #000000;"/></a></div>';
		
		
	
	var photo_container = document.getElementById('bg_chooser_itim');
	// 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);
	new_element.innerHTML = content;
	previewNewBG(picloc);	
}
	



/**
*
*
*/
function setPicMain(pic_image, disp_newpic, disp_wd, disp_ht){
	//alert('usd drag drop = '+use_drag_drop+' and pic = '+pic_image);
	if(use_drag_drop == 1){
		loadBackfade();
		
	
		loadSelectedMedia(pic_image);
		
		
		moveDivCenter('myMedia');
	
					
	
	}else{
		
		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 setPicMainOld(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);
	

	
	
}


//
//gets the dimensions of an image
//returns array of (wd, ht)
function getImgSize(imgSrc)
{
	
	
	var httpArr = imgSrc.split('http://');
	
	if(typeof(httpArr) != "undefined"){
	
	
		if(httpArr.length > 1){
			//do nothing	
			
		}else{
			
			//add base url
			imgSrc = baseUrl+imgSrc;
			//alert('imgsrc = '+imgSrc);	
			
		}
	
	
	
	}
	
	var newImg = new Image();
	newImg.src = imgSrc;

	
	newImg.style.display = "block";
	var	curHeight = newImg.height;
	var curWidth = newImg.width;
	var dim = new Array(curWidth, curHeight);
	return dim;
	
	
}


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+' and newitimganin = '+newitim_main);
	
	if(newitim_main == 1){
		if(new_mes_type == 2){
			addImage2NewItimIM(pic_image_main, picwd_main, picht_main);
			
		}else{
			addImage2NewItim(pic_image_main, picwd_main, picht_main);
		}
	}else{
	
		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 closeAddPicture(){
	
	
	
	var tempType = addMyMediaType;
	addMyMediaType = 0;
	removeDiv('addPicture'); winOpened = 'none'; removeDiv('backfade');

	if(new_form_opened == 1){
		
		//alert(' newitim opened = '+new_form_opened+' and winopen = '+winOpened+' and id = '+id);
		
		if(new_mes_type == 2){
		
			//loadBackfade(); topIndex++; document.getElementById('startNewItimIM').style.zIndex = topIndex; moveDiv('startNewItimIM', '250', '203'); clearNewItimIM(); winOpened = 'startNewItimIM';
			
			
			loadBackfade(); topIndex++; document.getElementById('startNewItimIM').style.zIndex = topIndex; moveDiv('startNewItimIM', '250', '203'); clearNewItimIMExtras(); winOpened = 'startNewItimIM';
			
		}else{
			//loadBackfade(); topIndex++; document.getElementById('startNewItim').style.zIndex = topIndex; moveDiv('startNewItim', '250', '203'); clearNewItim(); winOpened = 'startNewItim';
			
			
			loadBackfade(); topIndex++; document.getElementById('startNewItim').style.zIndex = topIndex; moveDiv('startNewItim', '250', '203'); clearNewItimExtras();  winOpened = 'startNewItim';
			
		}
		
		
	}else if(tempType == 3){

		
		if(prev_con_i_c_id > 0){
			showProfile(prev_con_i_c_id, prev_con_name, prev_con_avatar);
		}else{
			//loadNewProfile();
			//addNewContact();
			loadBackfade();
			loadNewProfile(1);
			moveDivCenter('addShowProfile');
			winOpened = 'addShowProfile';	
			
		}


	}else if(tempType == 4){

		//loadSettings();
		
		loadBackfade();
		//loadSettings(1); 
		var newDiv=document.getElementById('mySettings'	);
		var newStyle=newDiv.style;
		topIndex++;
		newStyle.zIndex = topIndex;
		moveDivCenter('mySettings'); 
		winOpened = 'mySettings';
		//showProfile(prev_con_i_c_id, prev_con_name, prev_con_avatar);

	}

}


function closeErrorAlert(){

	if(winOpened == 'errorAlert'){
		checkLostConnectionLogout();
		removeDiv('errorAlert'); winOpened = 'none'; removeDiv('backfade');

	}



}

function checkLostConnectionLogout(){
	
	if(lostConnectionLogout == 1){
		//alert('hey loging out ');
		//logMeOut('lostconnection');
		refreshMyHome();
		
		
	}
	
}

function showErrorAlert(msg) {
	
	
	loadBackfade();
	var content;
	if(msg == ''){
		
		
		if(disconnect_count < reconnect_max){
			content = "Oops, we could not connect to the iTim Servers. Please check your internet connection. ";
			lostConnectionLogout = 0;
		}else{
			
			content = "Oops, you need to reload this page. We could not connect to the iTim Servers. Please check your internet connection. ";
			lostConnectionLogout = 1;
			
		}
		
		
	}else{
		
		content = msg;	
	}
	writeDiv("errormsg", content);
	  
	moveDivCenter('errorAlert');
	winOpened = 'errorAlert';	
	
}




function addImageNew(){
	
	//alert('okayu adding itim = '+itimnum);
	loadBackfade();
	loadAddNewPicture();  
	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);
	*/
	
}


//showFavorites

function showFavorites(){
	
	//get current_itimnum
	
	
	loadBackfade();
	//loadAddPicture(itimnum);  
	topIndex++;
	document.getElementById('showFavorites').style.zIndex = topIndex;
	moveDivCenter('showFavorites');
	winOpened = 'showFavorites';
	
	
	
	
	/**
	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 showLoginOver(){
	
	//get current_itimnum
	
	
	loadBackfade();
	//loadAddPicture(itimnum);  
	topIndex++;
	document.getElementById('showLoginOver').style.zIndex = topIndex;
	moveDivCenter('showLoginOver');
	winOpened = 'showLoginOver';
	
	
	
	
	/**
	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 addImageCurr(){
	
	//get current_itimnum
	var lastIndex = currentFnameArray.length - 1;
	var fname = currentFnameArray[lastIndex];
	var itimnum = 0;
	if((fname == '')||(typeof(fname) == "undefined")){
	
		//alert('Please open a conversion first, then try again :)');
	
	}else{
	
		var itimnum_arr = fname.split('iTim_');
		temp_itimnum = itimnum_arr[1];
		if(temp_itimnum > 0){
			
			itimnum = temp_itimnum;	
		}
		
	}
	
	
	//alert('okayu adding itim = '+fname+ ' and itimnum = '+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);
	**/
	
	
	
}


function prepareAddAvatar(){
	
	
	
}


//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 addImage2NewItim(pic_image_main, picwd_main, picht_main){
	newAttachment = pic_image_main;
	
	//check if this a video
	var videoarr = newAttachment.split(".flv");
	
	if(videoarr.length > 1){
		
		pic_image_main = 'tim_video_thumbnails/'+videoarr[0]+'.png';
		//alert(' this is video = '+newAttachment+' and thumb = '+pic_image_main);
	}else{
		
		var picarr = pic_image_main.split("/");
	
		if(picarr.length > 1){
			
			//pic_image_main = 'tim_video_thumbnails/'+videoarr[0]+'.png';
			//alert(' this is video = '+newAttachment+' and thumb = '+pic_image_main);
		}else{
			
			pic_image_main = 'tim_images/'+pic_image_main;
			
		}
			
		
		
	}
	
	
	
	
	
	
	var dim = getImgSize(pic_image_main);
	//alert(' dimensions = wid = '+picwd_main+' and heifh = '+picht_main+' and dim = '+dim);
	loadBackfade(); topIndex++; document.getElementById('startNewItim').style.zIndex = topIndex;
	var content = "<a href=\"javascript:void(0)\" onClick=\"viewPicIM('"+pic_image_main+"'); \"><img src=\""+pic_image_main+"\" width=\"42\" height=\"52\" alt=\"attached media\" title=\"attached media\" border=\"0\" style=\"-webkit-box-shadow: -1px 1px 5px  #333333; -moz-box-shadow: -1px 1px 5px  #333333; margin-top:5px;\"></a><div style=\"margin:3px; font-size:10px; font-style:italic; color:#FF3300\"><a href=\"javascript:void(0)\" onClick=\"resetNewAddMms(); \">Remove Media</a></div><div id=\"paperclip\" style=\" position:relation; margin-top:-85px; margin-left:-35px;\"><img src=\"icons_main/paper-clip.png\" width=\"32\" height=\"32\" border=\"0\"></div>";   
     writeDiv("newitim_addmms", content);
	
	
}


function addImage2NewItimIM(pic_image_main, picwd_main, picht_main){
	newAttachment = pic_image_main;
	
	//check if this a video
	var videoarr = newAttachment.split(".flv");
	
	if(videoarr.length > 1){
		
		//pic_image_main = videoarr[0]+'.png';
		pic_image_main = 'tim_video_thumbnails/'+videoarr[0]+'.png';
		
		//alert(' this is video = '+newAttachment+' and thumb = '+pic_image_main);
	}else{
		
		var picarr = pic_image_main.split("/");
	
		if(picarr.length > 1){
			
			//pic_image_main = 'tim_video_thumbnails/'+videoarr[0]+'.png';
			//alert(' this is video = '+newAttachment+' and thumb = '+pic_image_main);
		}else{
			
			pic_image_main = 'tim_images/'+pic_image_main;
			
		}
			
		
		
	}
	
	
	
	
	
	//alert(' dimensions = wid = '+picwd_main+' and heifh = '+picht_main);
	loadBackfade(); topIndex++; document.getElementById('startNewItimIM').style.zIndex = topIndex;
	var content = "<a href=\"javascript:void(0)\" onClick=\"viewPicIM('"+pic_image_main+"'); \"><img src=\""+pic_image_main+"\" width=\"42\" height=\"52\" alt=\"attached media\" title=\"attached media\" border=\"0\" style=\"-webkit-box-shadow: -1px 1px 5px  #333333; -moz-box-shadow: -1px 1px 5px  #333333; margin-top:5px;\"></a><div style=\"margin:3px; font-size:10px; font-style:italic; color:#FF3300\"><a href=\"javascript:void(0)\" onClick=\"resetNewAddMmsIM(); \">Remove Media</a></div><div id=\"paperclip\" style=\" position:relation; margin-top:-85px; margin-left:-35px;\"><img src=\"icons_main/paper-clip.png\" width=\"32\" height=\"32\" border=\"0\"></div>";   
     writeDiv("newitim_addmmsIM", content);
	
	
}

function resetNewAddMmsIM(){
	newAttachment = "";
	newAudio = "";
	var content = "<a href=\"javascript:void(0)\" onClick=\"addImageNew(); \"><img src=\"icons_main/cool_icons/camera_icon.png\" width=\"42\" height=\"35\" alt=\"add photo\" title=\"add photo\" border=\"0\" style=\"-webkit-box-shadow: -1px 1px 5px  #333333; -moz-box-shadow: -1px 1px 5px  #333333; margin-top:5px;\"></a><div style=\"margin:3px; font-size:10px; font-style:italic; color:#999\"> <a href=\"javascript:void(0)\" onClick=\"addImageNew(); \">Add Media</a></div>";   
     writeDiv("newitim_addmmsIM", content);           	
	
	
}
function resetNewAddMms(){
	newAttachment = "";
	newAudio = "";
	var content = "<a href=\"javascript:void(0)\" onClick=\"addImageNew(); \"><img src=\"icons_main/cool_icons/camera_icon.png\" width=\"42\" height=\"35\" alt=\"add photo\" title=\"add photo\" border=\"0\" style=\"-webkit-box-shadow: -1px 1px 5px  #333333; -moz-box-shadow: -1px 1px 5px  #333333; margin-top:5px;\"></a><div style=\"margin:3px; font-size:10px; font-style:italic; color:#999\"> <a href=\"javascript:void(0)\" onClick=\"addImageNew(); \">Add Media</a></div>";   
     writeDiv("newitim_addmms", content);           	
	
	
}


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);
	
	new_form_opened = 0;
	
	
}

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 viewPicIM(imgloc, mp3loc){
	//
	//alert('opeong image = '+imgloc+' and audio = '+mp3loc);	
	if(imgloc == 'undefined'){
		imgloc = '';
		
	}else if(typeof(imgloc) != "undefined"){
		imgloc = trim(imgloc);	
	}else{
		imgloc = '';	
	}
	
	
	if(mp3loc == 'undefined'){
		mp3loc = '';
		
	}else if(typeof(mp3loc) != "undefined"){
		mp3loc = trim(mp3loc);	
	}else{
		mp3loc = '';	
	}
	//imgloc = trim(imgloc);
	//mp3loc = trim(mp3loc);
	//alert('1 opeong image = '+imgloc+' and audio = '+mp3loc);
	
	loadBackfade();
	loadShowMedia(imgloc, mp3loc);  
	moveDivCenter('addShowMedia');
	winOpened = 'addShowMedia';
	
	
	
	
}

function loadShowMedia(imgloc, mp3loc){
	writeDiv('addShowMedia_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>';
	//var content = "<div><img src=\""+imgloc+"\"></div>";	
	
	var content = "";
	var audiocon = "";
	
	var fblike = "<iframe src=\"http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2Fitimtext&amp;layout=button_count&amp;show_faces=false&amp;width=450&amp;action=like&amp;font=tahoma&amp;colorscheme=light&amp;height=21\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; height:21px;\" width=\"100\" allowTransparency=\"true\"></iframe>";
	
	//var tw_text = "Love New Audio/Music MMS received via iTim Text App (http://itim.me/text). Amazing #itimMMS App";
	var thisurl = "";
	//flv is passed by startvideo
	var flvarr = imgloc.split('.flv');
	if(flvarr.length > 1){
		//this is a video file
		
		//http://itimworld.com/viewer.php?m=abcd2009-12-25_085326_2.mp3&q=abcd2009-12-25_085326_0.gif
		
		
		
		thisurl = "http://itimworld.com/viewer.php?v="+imgloc;
		
		var tw_text = "Checkout video MMS received on iTim Text App (http://itim.me/text). #itimMMS RT ";
		//tw_text = escape(tw_text);
		
		tw_text = escape(tw_text);
		thisurl = escape(thisurl);
	
		var vidfile = "";
		
		var twstr = "<iframe title=\"Twitter For Websites: Tweet Button\" style=\"width: 110px; height: 20px;\" src=\"http://platform0.twitter.com/widgets/tweet_button.html?_=1282698752491&amp;count=horizontal&amp;counturl="+thisurl+"&amp;lang=en&amp;related=itimworld%3AAuthor%20of%20the%20post&amp;text="+tw_text+"&amp;url="+thisurl+"&amp;via=itimworld\" allowtransparency=\"true\" tabindex=\"0\" class=\"twitter-share-button twitter-count-horizontal\" frameborder=\"0\" scrolling=\"no\"></iframe>";
		
		
		var tumblr = '<div><a href="http://www.tumblr.com/share?v=3&amp;u='+thisurl+'&amp;t='+tw_text+'" target=\"_blank\" onclick="javascript:_gaq.push([\'_trackPageview\',\'/yoast-ga/outbound-article/http://www.tumblr.com/share?v=3&amp;u='+thisurl+'&amp;t='+tw_text+'\']);" title="" style="display: inline-block; text-indent: -9999px; overflow: hidden; width: 81px; height: 20px; background: url(&quot;http://platform.tumblr.com/v1/share_1.png&quot;) no-repeat scroll left top transparent;"></a></div>'
		
		var content = "<table class=\"profileHolderVideo\"><tr><td valign=\"top\" width=\"500\"><div id=\"vidplayer\" class=\"profilePhoto\" style=\"margin-top:-5px;margin-left:20px; background-color:#333; width:500px; height:400px;\"> &nbsp;</div></td><td valign=\"top\" align=\"left\"><div class=\"profileInfo\"><div>Share</div><div>"+twstr+"</div><div>&nbsp;</div><div>"+tumblr+"</div><div>&nbsp;</div><div>"+fblike+"</div><div>&nbsp;</div><div>Enjoy!!</div></div></td></tr></table>";	
			
		
		var itim_mp4_url_prefix = "";
		
		
		writeDiv('addShowMedia_holder', content);
	
	
	
		if((safari)||(is_chrome)){
			vidfile = "tim_video_mp4/"+flvarr[0]+".mp4";
			vidfilewebm = "tim_video_mp4/"+flvarr[0]+".webm";
	
			//videostr = "<video src=\""+vidfile+"\" width=\"500\" height=\"400\" autoplay controls preload=\"auto\"></video>";
			
			
			//videostr = "<video  width=\"500\" height=\"400\" autoplay controls preload=\"auto\"><source src=\""+vidfile+"\" type=\"video/mp4\"></video>";
			
			videostr = "<video  width=\"500\" height=\"400\" autoplay controls preload=\"auto\"><source src=\""+vidfile+"\" type=\"video/mp4\"><source src=\""+vidfilewebm+"\" type=\"video/webm\"></video>";
			
			
			
			//videostr = "<video  width=\"500\" height=\"400\" autoplay controls><source src=\""+vidfile+"\" type='video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"'></video>";
			
			
			//videostr = "<video  width=\"500\" height=\"400\" autoplay controls><source src=\"http://clips.vorwaerts-gmbh.de/VfE_html5.mp4\" type=\"video/mp4\"></video>";
			
			//<source src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" type="video/mp4">

			
			writeDiv('vidplayer', videostr);
		
			
		}else{
			
			
			vidfile = "../tim_video_flv/"+flvarr[0]+".flv";
			//alert('vid file = '+
			var flashvars = {};
			flashvars.src = vidfile;
	
			//flashvars.src = "http://www.2waystar.com/itimworld/tim_video_flv/supermax.flv";
			
			//flashvars.src = "http://www.2waystar.com/itimworld/tim_video_mp4/26165_06-08-2011_06-51-21_b0da_2ipodfile.mp4";
			
			flashvars.autoPlay = true;
			var params = {};
			params.allowfullscreen = "true";
			params.allowscriptaccess = "always";
			params.wmode = "transparent";
			var attributes = {};
			swfobject.embedSWF("swf/FlashMediaPlayback.swf", "vidplayer", "500", "400", "10.1.0", "expressInstall.swf", flashvars, params, attributes);
			
			
			
			//swfobject.embedSWF("http://fpdownload.adobe.com/strobe/FlashMediaPlayback.swf", "vidplayer", "500", "400", "10.1.0", "expressInstall.swf", flashvars, params, attributes);



		}
		
		
		//writeDiv('vidplayer', videostr);
		
		
		

	
	}else{
		
		
		//get img size and set it
		
		
		//do nothing until it loads
			
		var image = new Image();
		image.onload = function() {
			// always called
			//alert('image loaded  and audio = '+mp3loc);
		
		
			var dim = getImgSize(imgloc);
			var wd = dim[0];
			var ht = dim[1];
			//alert('okay wd = '+wd+' and ht = '+ht+' of avatar = '+avatar);
			var target_wd = 500;
			var target_ht = 400;
			var newdim = resizeDim(imgloc, target_wd, target_ht, wd, ht);
			//alert('okay wd = '+wd+' and ht = '+ht+' and newdim = '+newdim+' of avatar = '+imgloc);
			
			wd = newdim[0];
			ht = newdim[1];
			
			var imgloc2 = imgloc;
			var photoarr = imgloc.split('/');
			if(photoarr.length > 1){
				var lastindex = photoarr.length-1;
				imgloc2 = photoarr[lastindex];	
	
			}
			thisurl = "http://itimworld.com/viewer.php?q="+imgloc2+"&m="+mp3loc;
			var tw_text = "Checkout Photo MMS received on iTim Text App (http://itim.me/text). #itimMMS RT ";
	
			if(mp3loc != ''){
				
				tw_text = "Checkout audio-pic MMS received on iTim Text App (http://itim.me/text). #itimMMS RT ";
		
			}
			
			tw_text = escape(tw_text);
			thisurl = escape(thisurl);
			
			var twstr = "<iframe title=\"Twitter For Websites: Tweet Button\" style=\"width: 110px; height: 20px;\" src=\"http://platform0.twitter.com/widgets/tweet_button.html?_=1282698752491&amp;count=horizontal&amp;counturl="+thisurl+"&amp;lang=en&amp;related=itimworld%3AAuthor%20of%20the%20post&amp;text="+tw_text+"&amp;url="+thisurl+"&amp;via=itimworld\" allowtransparency=\"true\" tabindex=\"0\" class=\"twitter-share-button twitter-count-horizontal\" frameborder=\"0\" scrolling=\"no\"></iframe>";
		
			
			var content = "<table class=\"profileHolder\"><tr><td valign=\"top\" width=\"500\"><div><img id=\"imageview\" src=\""+imgloc+"\" width=\""+wd+"\" height=\""+ht+"\" class=\"profilePhoto\" ><canvas id=\"canvasview\" height='1'></canvas></div><div id=\"mp3streamer\" style=\"margin-top:-5px;margin-left:20px;\"> </div></td><td valign=\"top\" align=\"left\"><div class=\"profileInfo\"><div>Share</div><div>"+twstr+"</div><div>&nbsp;</div><div>"+fblike+"</div><div>&nbsp;</div><div>Enjoy</div><div id=\"rotate_left\"><a href=\"javascript:void(0)\" onClick=\"rotateLeft();\"><img src=\"icons_main/cool_icons/sub_blue_rotate_ccw.png\" alt=\"rotate left\" title=\"rotate left\" width=\"91\" height=\"85\" border=\"0\" style=\" margin-right:4px;\"></a></div><div id=\"rotate_right\"><a href=\"javascript:void(0)\" onClick=\"rotateRight();\"><img src=\"icons_main/cool_icons/sub_blue_rotate_cw.png\" alt=\"rotate right\" title=\"rotate right\" width=\"91\" height=\"85\" border=\"0\" style=\" margin-right:4px;\"></a></div><div id=\"save_edit\" style=\"visibility:hidden;\"><input name=\"Save\" type=\"submit\" id=\"Save\" value=\"Save\" style=\" width:90px; font-size:14px;\" onClick=\"saveRotate();\"><input name=\"Save\" type=\"submit\" id=\"Cancel\" value=\"Cancel\" style=\" width:90px; font-size:14px;\" onClick=\"cancelRotate();\"></div> </div></td></tr></table>";	
				
				//<input name="Save" type="submit" id="Save" value="Save" style=" width:90px; font-size:14px;">
		//<div id=\"rotate_left\"><a href=\"javascript:void(0)\" onClick=\"rotateLeft('');\"><img src=\"icons_main/error_go.png\" alt=\"pictures\" width=\"16\" height=\"16\" border=\"0\" style=\" margin-right:4px;\"></a></div>
			
			var itim_mp4_url_prefix = "";
			
			
			writeDiv('addShowMedia_holder', content);
		
			//alert('mp3loc = '+mp3loc);
			if((mp3loc != '')&&(mp3loc != '(null)')&&(mp3loc != 'null')){
				var itim_mp3_url_prefix = "tim_audio_mp3/";
	
				//alert(' ahey mp3loc = '+mp3loc);
	
				var soundurl = itim_mp3_url_prefix+mp3loc;
				
				//alert(' image sound url = '+soundurl);
				//var audioplayerbase = "<span style=\"margin-left:10px;\"><object type=\"application/x-shockwave-flash\" data=\"http://www.smodcast.com/av/player.swf\" id=\"audioplayer1\" width=\"290\" height=\"24\"><param name=\"movie\" value=\"http://www.smodcast.com/av/player.swf\"><param name=\"FlashVars\" value=\"playerID=1&amp;loop=yes&amp;autostart=yes&amp;soundFile="+soundurl+"\"><param name=\"quality\" value=\"high\"><param name=\"menu\" value=\"false\"><param name=\"wmode\" value=\"transparent\"></object></span>";
				
				
				var audioplayerbase = "<span style=\"margin-left:10px; border:#999 solid 2px;\"><object type=\"application/x-shockwave-flash\" data=\"swf/mp3player.swf\" id=\"audioplayer1\" width=\"290\" height=\"24\"><param name=\"movie\" value=\"swf/mp3player.swf\"><param name=\"FlashVars\" value=\"playerID=1&amp;loop=yes&amp;autostart=yes&amp;soundFile="+soundurl+"\"><param name=\"quality\" value=\"high\"><param name=\"menu\" value=\"false\"><param name=\"wmode\" value=\"transparent\"></object></span>";
				
				
				
				
				
				var fvars = "playerID=1&loop=yes&autostart=yes&soundFile="+soundurl;
				var fname = 'audioplayer1';
				var fid = 'audioplayer1';
				//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','290','height','24','src', mp3swf ,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie', mp3swf, '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','290','height','24','src', mp3swf ,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie', mp3swf, 'name', fname, 'id', fid, 'wmode', 'opaque','allowScriptAccess','sameDomain', 'swLiveConnect','true','flashVars', fvars);
				
				
				
				
				
				var audiostr;
				//var safari = true;
				if((safari)||(is_chrome)){
					
					audiostr = "<audio src=\""+soundurl+"\" height=\"140\" autoplay  autobuffer controls></audio>";
	
				
					
				}else{
					
					//preloadflash('swf/mp3player.swf');
					
					
					//audiostr = audioplayerbase;
					audiostr = swfOut;	
					/*
					var flashpre = new Image();
					flashpre.onload = function() {
						alert(' just loaded flsh = '+flashpre.src);
						writeDiv('mp3streamer', audiostr);
		
					};
					*/
					//alert(' swf = '+baseUrl+mp3swf+'.swf');
					
					//flashpre.src = baseUrl+mp3swf+".swf";
				}
				writeDiv('mp3streamer', audiostr);
		
			
				//content += "<div id=\"mp3streamer\" style=\"margin-top:-20px;margin-left:20px;\">"+audiostr+"</div>";
		
			}
			
		
			//writeDiv('addShowMedia_holder', content);
		
		
		};
		image.src = imgloc;

		
		
		
		
		
	
	}
		
	
	
	
	//alert(' iframe = '+content);
	
}

function resetShowMedia(){

	var content  = "";	
	writeDiv('addShowMedia_holder', content);
	
	
}


function forwardMsg(fwdmsg, fwdattachment, fwdaudio){
	//alert('fowrd msg = '+fwdmsg+' and attach = '+fwdattachment+' and audio = '+fwdaudio);
	
	
	loadBackfade(); topIndex++; document.getElementById('startNewItim').style.zIndex = topIndex; moveDiv('startNewItim', '250', '203'); clearNewItim(); winOpened = 'startNewItim';
	new_form_opened = 1;
	
	
	//set message
	var tempMsg = unescape(fwdmsg);
	document.newitimform.newmessage.value = tempMsg;
	
	var tempAttach = fwdattachment;
	newAttachment = fwdattachment;
	
	newAudio = fwdaudio;
	
	//set attachment
	if(tempAttach != ''){
		
		var picwd_main  = 50;
		var picht_main  = 50;
		addImage2NewItim(tempAttach, picwd_main, picht_main);	
		
		
	}
	
	
	new_mes_type = 1; 
	
	
	
}

//Called after ICID has loaded, last_mes_id is not zero if last was received.
//init_itim_html calls this from flash
function setIcidArray(i_c_id, itimnum, tempcell, avatar, cellName, lastmesidout, islastreply, lasttimeago, lasttimestamp, lastmsg){
	
	
	reWriteGoogleAd();
	if(lasttimestamp > 0){
		
		
	}else if(lastmsg == "undefined"){
		
		//probable a new convo since no timesatmp and no lastmsg
		lastmsg = "...";	
		
	}
	
	if(cellName.length > 0 ){
		var oldcname = cellName;
		var re = /'/;
		cellName = cellName.replace(re, "\$1");
		//alert('old = '+oldcname+' \nreplaced cellname =  '+cellName);
	}
	
	var oldavatar = avatar;
	
	if(avatar == 'tim_images/'){
		
		if(tempcell > 0){
			message_type = 1;
			
		}else{
			message_type = 2;
			
		}
		
		if(message_type == 2){
			avatar = "images3/avatar_bubble.png";
			 
		} else {
			
			avatar = "images3/avatar_cellular2.png";
			
		}
		
		
	}else{
	
		//var avatarsplitarr = avatarpic.split('_sm.jpg');
		var avatarsplitarr = avatar.split('_sm.jp');
		if(avatarsplitarr.length > 1){
			var origpic = avatar;
			avatar = avatarsplitarr[0]+'.jp'+avatarsplitarr[1];	
			//alert('avatarpic = '+avatar+' and old was '+origpic);
		}
		
		
	}
	//alert('setting icid = '+i_c_id+' and avatar = '+avatar);
	//make sure avatar does not have shttp:// in it
	var avatararr = avatar.split("http:");
	
	if(avatararr.length > 2){
		
		avatar = avatararr[3];
		
	}
	
	checkAllitimsAvatar(i_c_id, avatar);
	
	//alert('after = '+i_c_id+' and avatar = '+avatar+' and ole ava = '+oldavatar);
	//alert('icid = '+i_c_id+'avat = '+avatar+' and lastmes = '+lastmesidout+' and isreply = '+islastreply+' and last ago = '+lasttimeago+' and lasttm = '+lasttimestamp);
	
	
	//hideDiv('loading_'+i_c_id);
	//uyienoma here we should load the icid convo in the div
	
	
	if((safari)&&(!is_chrome)){
		hideDiv('loading_'+i_c_id);
	
	}else if(((ie4)||(ie5))&&(!is_chrome)){	
		
		
		hideDiv('loading_'+i_c_id);
		
	}else{
		
	 	changeClass('convo_'+i_c_id, 'itimConversationLoaded fade100');
	}
	
	if((islastreply == 1)&&(lastmesidout > 0)){
		setReplyRead(i_c_id, itim_user_id, lastmesidout);
	}
	if((i_c_id > 0)&&(itimnum > 0)){
		//icidArray[i_c_id] = itimnum;
		// set above in startitim
		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);
	//alert('hey lstms = '+lastmsg);
	lastmsg = unescape(lastmsg);
	
	//new contact
	if(typeof(lastmsg) == "undefined"){
		lastmsg = "";	
		
	}
	
	
	var write_success = writeAllitimText(lastmsg, i_c_id);
	
	//alert('done with write text ');
	
	//make sure this isn't negative
	var currtimestamp = Math.round(new Date().getTime() / 1000 );
		//current time
	var time_ago = "";
	
	
	//new contact
	if(typeof(lasttimestamp) == "undefined"){
		time_ago = "";	
		
	}else if(currtimestamp < lasttimestamp){
		
		time_ago = "few secs ago";
	}else if(lasttimestamp > 0){
	
		time_ago = timeago(lasttimestamp);
		//alert(" new time ago because it is greater than");
	}else{
		
		time_ago = "";	
	}
	
	//alert(" new tie = "+time_ago+" and original = "+lasttimeago+" curr = "+currtimestamp+" and lastts = "+lasttimestamp);

	
	var addClose = time_ago+" <span id=\"closeItim_"+i_c_id+"\" style=\"margin-left: 5px; visibility: visible;\"><a href=\"javascript:void(0)\" onclick=\"closeDivIcid("+i_c_id+");\" style=\"font-family: Verdana,Arial,Helvetica,sans-serif;\">close</a></span>";
	writeDiv('time_'+i_c_id, addClose);	
	//alert('done with timestamp');
	//var lasttimestamp = Math.round(new Date().getTime() / 1000 );
	writeDiv('timestamp_'+i_c_id, lasttimestamp);	
	changeClass("allitim_"+i_c_id, "midRightBarNewOpenFocus");
	
}



function checkAllitimsAvatar(i_c_id, avatar){
	
	//crazy at it may seem, the avatar may change if the friend chnages it, 
	// this will check to make sure
	
	if(typeof(avatar) != "undefined"){
	
		var imgId = "avatar_"+i_c_id;
		var imgobj=document.getElementById(imgId);
		var avatarstr = imgobj.src;
		
		//alert('hjey avatar = '+avatar+' and src = '+avatarstr);
		
		
		var cell_avatar2 = "avatar_cellular2.png";
		var cell_avatar = "avatar_cellular.png";		
		var im_avatar = "avatar_bubble.png";
		
		
		var srcarr = avatarstr.split("/");
			
		var avatar_arr = avatar.split("/");
			
		if(srcarr.length > 1){
			var lastIndex = srcarr.length - 1;
			curr_src = srcarr[lastIndex];
			
			
		}	
		
		
		if(avatar_arr.length > 1){
			var lastIndex = avatar_arr.length - 1;
			curr_avatar = avatar_arr[lastIndex];
			
			
		}	
		
		//alert(' now avatar = '+curr_avatar+' vs '+curr_src);
		if(((curr_avatar == "avatar_cellular2.png")||(curr_avatar == "avatar_cellular.png")||(curr_avatar == "avatar_bubble.png")) && ((curr_src != "avatar_cellular2.png")||(curr_src != "avatar_cellular.png")||(curr_src != "avatar_bubble.png"))){
		
			//don nothing bcos it means that the avatar in the source now is a uploaded image but you are trying to replace with a default image, not googd
			//alert('doing noting');
		
		}else if((curr_avatar != curr_src)&&(curr_avatar != 'nopic.jpg')){
			
			imgobj.src = avatar;			
			
		}
		
	}
}


/*************
* 	this script will shake a div
*

how to use
var nn=new ShakeItClass('boxhandle5',20,70);
nn.start();

to stop use nn.stop();


*******/




function ShakeItClass (divId,Rate,speed, disp) {
	var obj=document.getElementById(divId);

	 var oL=obj.offsetLeft;
	 var oT=obj.offsetTop;
	 this.stop=null;
	 this.oTime=null;
	 var om=this;
	 if(disp > 0){
		 
	 }else{
		 disp = 2;
		 
	 }
	 
	 this.start=function(){
			 if(parseInt(obj.style.left)==oL-disp){
				obj.style.top=oT+disp+"px";
				setTimeout(function(){obj.style.left=oL+disp+"px"},Rate)
			 }
			 else{
				obj.style.top=oT-disp+"px";
				setTimeout(function(){obj.style.left=oL-disp+"px"},Rate)
			}
		this.oTime=setTimeout(function(){om.start()},speed);
	 }
	 this.stop=function(){
	   clearTimeout(this.oTime);
	 
	 }
}


function startShake(divId){

	//alert(' about to start shaking = '+divId);
	shakeIntervalId = setInterval(stopShake, 5000);

	//shakeUnit
	//shakeUnit=new ShakeItClass(divId,20,70, 5);
	
	
	shakeUnit=new ShakeItClass(divId,10,30, 5);
	
	shakeUnit.start();
	
}

function stopShake(){

/* later */
	if(shakeIntervalId){
		clearInterval(shakeIntervalId);
		shakeUnit.stop();
	
	}
	
	
}



function setReplyRead(i_c_id, user_id, mes_id){
	//$i_c_id $user_id $mes_id
	//alert(' need to update read for icid = '+i_c_id+' and lastmes = '+mes_id+' and user = '+user_id);
	
	
	var newReadTimUrl = timreadUrl+"?send=1&i_c_id="+i_c_id+"&user_id="+user_id+"&mes_id="+mes_id+"&id="+itim_user_id+"&sessID="+sessId;
	//alert('myurl = '+newReadTimUrl+'\n');
	var func = "doNothingBro";
	if(typeof(newMessageArray[mes_id]) != "undefined"){
		if(newMessageArray[mes_id][5] != 1){
			
			newMessageArray[mes_id][5] = 1;
			ajaxGetUrlAndFunc(newReadTimUrl, func);	
		
		}
	
	}else{
		//alert(' there is no entry yet for probably on top '+mes_id);	
		ajaxGetUrlAndFunc(newReadTimUrl, func);	
		
	}
	//ajaxGetUrl(newReadTimUrl);
}


function setReplyReadFromFocus(i_c_id){
	if(typeof(newMessageByIcidArray[i_c_id]) != "undefined"){
		
		if(newMessageByIcidArray[i_c_id][0] > 0){
			var mes_id = newMessageByIcidArray[i_c_id][0];
			setReplyRead(i_c_id, itim_user_id, mes_id);
		}
		
	}
		
	
	
}

function doNothingBro(str){
	//alert('do notheing with '+str);
	
};


function startItimBar(i_c_id, itimTop, itimLeft){
	// check if fname is already open
	var remIndex;
	
	var curr_itimnum = icidArray[i_c_id];
	
	if(divIdExists('closeItim_'+i_c_id) != 1){
		
		//alert('div deos not existst closeItim_'+i_c_id+' needs to be created');
		
	}
	
	showDiv('closeItim_'+i_c_id);
	var fname = 'iTim_'+curr_itimnum;
	var box_id = "boxHandle"+curr_itimnum;
	//alert('starring for icid = '+i_c_id+' and fname = '+curr_itimnum+' and curr_itimnum = '+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, itimTop, itimLeft);	
	}
	//alert('loading add pic itim = '+curr_itimnum);
	
	//make new msg = 0
	var tmpcountDiv=document.getElementById("count_new_allitim_"+i_c_id);
	tmpcountDiv.innerHTML = 0;
	checkAndRemoveAlert(i_c_id);
}


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 getFnameForIcidAndCheckEasy(i_c_id){
	
	
	
	
	
	var resFname = fnameForIcid[i_c_id];
	if(typeof(resFname) == "undefined"){
		
		
		
		var resFname = "a";
	}
	
	

	return resFname;
}


function createAllItimElemFromIcid(icid, f_id){
	
	
	var allitimdiv = "allitim_"+icid;
	var divExists = 0;
	
	//alert('about to cheeck for it now = '+allitimdiv);
	if(divIdExists(allitimdiv) != 1){
		//alert(' no sir no div for allitim icid = '+icid+' so add please');	
		//divExists = 1;
	
		var newmsg_esc = "...";
		var attachment = "";
		
		var time_ago = " ";
		
		//get the cellnum and the name/nickname
		if(f_id > 0){
			//check if we have friend info	
			
		}else{
			
			
		}
	
	
		createNewAllItim(cellnum, newmsg_esc, attachment, message_type, icid, name, "0", time_ago, '', '0');
		
		
		
	}else{
		//alert(' element exist for = '+allitimdiv);
		divExists = 1;	
	}
		
	
	
}


function closeAllNewAlerts(){
	//loopes thru the openAlertsArray to get all the itimnums
	//and closes them
	//alert(' array = '+openAlertsArray);
	var temp_openAlertsArray = openAlertsArray;
	for(var i = 0; i < temp_openAlertsArray.length; i++){
		var alertArr = temp_openAlertsArray[i];
		var alertArr2 = temp_openAlertsArray[i-1];
		
		//alert(' stare alert = '+alertArr+' and i = '+i+' and preior = '+alertArr2);
	
		var temp_itimnum = alertArr[0];
		var temp_mes_id = alertArr[1];
	
		if(temp_itimnum > 0){
			closeAlertArr(temp_mes_id,'1' ); 
			closeDiv(temp_itimnum);
			i--;
		
		}else{
			
			//alert(' no itimunu = '+alertArr);	
		}
	
	
	}
	//alert(' Done should be empty = '+openAlertsArray+'-==');
	//then reset the array of opens
	openAlertsArray = new Array;	
	
	hideDiv('closeallalerts');
	
}


function getUnixTimestamp(itim_date){
	
	
	
}

// takes a timestamp and returns twitter type 5 days ago, 2 minutes ago etc
function timeago(timestamp){
	var difference = Math.round(new Date().getTime() / 1000)  - timestamp;
	if(difference < 1) difference= 1;
	//var periods = new Array("sec", "min", "hour", "day", "week", "month", "years", "decade");
	var periods = new Array("sec", "min", "hour", "day", "wk", "mon", "yr", "decade");
	var lengths = new Array("60","60","24","7","4.35","12","10");
	for(var j = 0; difference >= lengths[j]; j++)
	difference /= lengths[j];
	difference = Math.round(difference);
	if(difference != 1) periods[j]+= "s";
	var text = difference+" "+periods[j]+" ago";
	return text;
}

// takes a timestamp and returns twitter type 5 days ago, 2 minutes ago etc
function timeagofull(timestamp){
	var difference = Math.round(new Date().getTime() / 1000)  - timestamp;
	var periods = new Array("second", "minute", "hour", "day", "week", "month", "year", "decade");
	var lengths = new Array("60","60","24","7","4.35","12","10");
	for(var j = 0; difference >= lengths[j]; j++)
	difference /= lengths[j];
	difference = Math.round(difference);
	if(difference != 1) periods[j]+= "s";
	var text = difference+" "+periods[j]+" ago";
	return text;
}


//this is for firefox
function popupFirefox(title, text, imageUrl) {
	
	
	//alert('okey tring prop and image = '+imageUrl+' title = '+title+' and tmsg = '+text);
	
	
	
  try {
    Components.classes['@mozilla.org/alerts-service;1'].
              getService(Components.interfaces.nsIAlertsService).
              showAlertNotification(null, title, text, false, '', null);
			  
			  
			  
		/*	  
	var alertsService = Components.classes["@mozilla.org/alerts-service;1"].
                      getService(Components.interfaces.nsIAlertsService);
alertsService.showAlertNotification("chrome://mozapps/skin/downloads/downloadIcon.png", 
                                    "Alert title", "Alert text goes here.", 
                                    false, "", null, "");			  
			*/  
			  
  } catch(e) {
    // prevents runtime error on platforms that don't implement nsIAlertsService
  	
	//alert('popup not working');
  
  }
}



function checkNotifications(){
	// check for notifications support
	// you can omit the 'window' keyword
	var result  = 0;
	if (window.webkitNotifications) {
	  alert("Notifications are supported!");

		result  = 1;
	}
	else {
	  alert("Notifications are not supported for this Browser/OS version yet.");
	}	
	
	return result;
	
}

//This needs to be called from an onClick event
function checkPermissionsForAlert(){
	
	if (window.webkitNotifications.checkPermission() == 0) { // 0 is PERMISSION_ALLOWED
		// function defined in step 2
		//createNotificationInstance({ notificationType: 'html' });
		
		//createNotificationInstance({ notificationType: 'simple' });
		
		//alert('showing new msg'); 
     /*
	  window.webkitNotifications.createNotification(
          'http://www.itimworld.com/images/icon_itim.png', 'Uyi',
          'new message').show(); // note the show()
    
		*/
		
	} else {
		//alert('requstion perimission');
		//window.webkitNotifications.requestPermission();
	}	
	
	
}





//works with chrom
function createNewItimNotification(avatar, name, message, message_type) {
	var title = '';
	if(message_type == 2){
		title = "@"+name+" says:";
	}else{
		
		title = name+" says:";
		
	}
	
	if(message.length > 30){
		var re = /(.{28}).+/;
		message = message.replace(re, "$1...");
		//alert('replaced cellname =  '+cellName);
	}
	//if(is_chrome)
	try {
		
		if(window.webkitNotifications !== undefined){
		
			if (window.webkitNotifications.checkPermission() == 0) { // 0 is PERMISSION_ALLOWED
				avatar = baseUrl+avatar;
				//alert(' we can get a mesg = '+avatar+' title = '+title+' and message = '+message);
				
				
				/*
				var popup = window.webkitNotifications.createNotification(thumb, title, body);
	 
			//Show the popup
			popup.show();
	 
			//set timeout to hide it
			setTimeout(function(){
			popup.cancel();
			}, '10000');
					*/
				
				
				var popup = window.webkitNotifications.createNotification(
			  avatar, title,
			  message); // note the show()
			  
			  //Show the popup
			popup.show();
	 
			//set timeout to hide it
			setTimeout(function(){
			popup.cancel();
			}, '10000');
					
			  
		
				/*
				window.webkitNotifications.createNotification(
			  'http://www.itimworld.com/images/icon_itim.png', 'Uyi',
			  'new message').show(); // note the show()
				*/
		
				//return window.webkitNotifications.createNotification(avatar, title, message);
				
				
			}

		}

	} catch (e) { //alert('error son - ')
	
	}

}





//works with chrom
function createNotificationInstance(options) {
  if (options.notificationType == 'simple') {
    return window.webkitNotifications.createNotification(
        'icon.png', 'Notification Title', 'Notification content...');
  } else if (options.notificationType == 'html') {
    return window.webkitNotifications.createHTMLNotification('http://someurl.com');
  }
}



//this removes an icid object rom itimlocationarr
//called when adding a nw one in, and when closing 
function findAndRemoveIcidLocation(i_c_id){
	//alert('remivnig icid = '+i_c_id);
	if(i_c_id > 0){
		var maxct = itimLocationArr.length; 
		for(var i = 0; i < maxct; i++){	
			var icidLoc = itimLocationArr[i];	
		
			if(typeof(icidLoc) != "undefined"){
				if(i_c_id == icidLoc[0]){
					
					//splice it out array
					itimLocationArr.splice(i, 1);
					i = maxct;
					return i;
				
					
				}
			}
			
		
		}
		//update the cooke
		setWindowLocCookie();

	}
	
}



//this makes sure the topmost icid is at the dnd
// so it show up  
function findAndBringToFrontIcidLocation(i_c_id){
	//alert('remivnig icid = '+i_c_id);
	if(i_c_id > 0){
		var locItem;
		var maxct = itimLocationArr.length; 
		var foundLoc = 0;
		for(var i = 0; i < maxct; i++){	
			var icidLoc = itimLocationArr[i];	
			if(typeof(icidLoc) != "undefined"){
		
				if(i_c_id == icidLoc[0]){
					
					//splice it out array
					locItem = itimLocationArr.splice(i, 1);
					i = maxct;
					foundLoc = 1
					return i;
				
					
				}
				
			}
		
		}
		if(foundLoc == 1){
		
			itimLocationArr.push(locItem);
		
		
		}
		//update the cooke
		setWindowLocCookie();

	}
	
}




function onWinBlur() {
	//document.body.className = 'blurred';

	//alert(' you are infocus');	
};
function onWinFocus(){
	//document.body.className = 'focused';


	//alert(' you are minimized ');
};


function checkItimFocus(){
	
	
	
	
	if (/*@cc_on!@*/false) { // check for Internet Explorer
		document.onfocusin = onWinFocus;
		document.onfocusout = onBlur;
	} else {
		window.onfocus = onWinFocus;
		window.onblur = onWinBlur;
	}
	


}



//from is the name
function startItimAlert(temp_i_c_id, message, from, temp_mes_id, temp_msgdate, newmsg_count, message_type, cellnum, avatar, timestamp, newMessageStr){
	var itimalert = "alertItim_"+temp_i_c_id;
	topIndex++;
	message = unescape(message);
	message = searchAndReplace(message, "\\'", "'");
	
	//alert(' createing new alert = '+newMessageStr);	
	//checkItimFocus();	
	//alert('check focus about ot descide');
	
	
	createNewItimNotification(avatar, from, message, message_type);	
	
	//alert(' ater noticf descide');
	
	
	
	
	
	//** 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 - ')
	
	}
	
	
	//alert(' about ot descide');
	
	
	//alert('staring new alert');
	var newFname = "a";
	if(temp_i_c_id > 0){
		//newFname = getFnameForIcidAndCheck(temp_i_c_id);
		
		
		newFname = getFnameForIcidAndCheckEasy(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);	
	
	
	
	var write_success = writeAllitimText(message, temp_i_c_id);
	
	
	//alert('wrote info and success = '+write_success+' new alert');
	
	if(write_success != 1){
		// this is a new icid altogether, then we must create the allitim part and put it on top
		//alert("icid does not exist icid = "+temp_i_c_id+"\nFrom: "+from+" and count = "+newmsg_count);	
		var attachment = "";
		//var time_ago = "2 mins ago";
		var time_ago = timeago(timestamp);
		
		
		createNewAllItim(cellnum, message, attachment, message_type, temp_i_c_id, from, newmsg_count, time_ago, avatar, timestamp);
		//(temp_i_c_id, message, from, temp_mes_id, temp_msgdate, newmsg_count)
	}else{
		
		//add this to the top 	
		
		var closeTimeAgo = timeago(timestamp);
		//alert(' starting here');
		var new_close_vis = 'hidden'; 
		var addClose = closeTimeAgo+" <span id=\"closeItim_"+temp_i_c_id+"\" style=\"margin-left: 5px; visibility: "+new_close_vis+";\"><a href=\"javascript:void(0)\" onclick=\"closeDivIcid("+temp_i_c_id+");\" style=\"font-family: Verdana,Arial,Helvetica,sans-serif;\">close</a></span>";
		
		writeDiv('time_'+temp_i_c_id, addClose);
		//get nmber of unread and updateit
		//count_new_allitim_19721
		//showDiv('new_alltim_'+temp_i_c_id);
		var countDiv=document.getElementById("count_new_allitim_"+temp_i_c_id);
		var countMsg = countDiv.innerHTML;
		//alert('prev count = '+countMsg+' and newmsg = '+newmsg_count);
		var newMsgCt = 1;
		if(countMsg > 0){
			newMsgCt = parseFloat(countMsg) + parseFloat(newMsgCt);
			//newMsgCt = parseFloat(countMsg) + 1;
			
		}
		
		if(newmsg_count >0){
			
		}else{
			newmsg_count = 1;	
		}
		
		writeDiv('count_new_allitim_'+temp_i_c_id, newmsg_count);
			
		//check if win is focus, if no, show div, if open send reply read
		showDiv('new_alltim_'+temp_i_c_id);
		
	}
	
	//Move to the top
	var allitimdiv = "allitim_"+temp_i_c_id;
	//this is an alert, no need to change class
	moveItimToTop(allitimdiv, 'all_itims');
	document.getElementById('all_itims').scrollTop = 0;
	
	
	//alert('cheking is open');
	var isOpen= isIcidOpen(temp_i_c_id);
	
	//alert('hey icid='+temp_i_c_id+'	 is Open = '+isOpen+' and fname = '+newFname+' and topOpen = '+topOpenedIcid);
	
	
	if((newFname.length < 3)&&(topOpenedIcid != temp_i_c_id)){	// if no itim window is open for the icid
		//alert('start alert newfname = '+newFname);
		showDiv('newMsgAllMain');
		showDiv('new_alltim_'+temp_i_c_id);
		
		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 olddate = temp_msgdate;
		var temp_msgdate = timeago(timestamp);
		
		//alert('-- iago stuff  = '+temp_msgdate+' and odldate = '+olddate+' for timestamep = '+timestamp);
		//showDiv('new_alltim_'+temp_i_c_id);
		
		
		var mouseDown = "onMouseDown=\"closeWinOpened(); startItimBar('"+temp_i_c_id+"');hideDiv('newMsgAllMain'); clearNewMsgDot('"+temp_i_c_id+"');  //closeDiv("+itimnum+");\"";
		//var mouseDown = "onMouseDown=\"startItimBar('"+temp_i_c_id+"');hideDiv('newMsgAllMain');\"";
		//startItimBar(19648); hideDiv('new_alltim_19648');   hideDiv('newMsgAllMain');
		
		//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\" "+mouseDown+" >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
		
		//check and remove an alert form this person
		//if it is open
		checkAndRemoveAlert(temp_i_c_id);
		
		//add to open alerts array
		var alertArr = new Array(itimnum, temp_mes_id, temp_i_c_id);
		openAlertsArray.push(alertArr);
		
		//show the close button
		showDiv('closeallalerts');
		var name = from;
		var sent_by = cellnum;
		if(message_type != 1){
			sent_by = name;
		}else{
			
			if(name != ''){
				sent_by = name;	
				
			}else{
				
				sent_by = cellnum;	
			}
		}
		
		//alert('sent by = '+sent_by);
		//animFavNewMessage( sent_by, message, avatar, itimnum, message_type);
		
		
		//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);
		
		
		//play alert sound
		//alert_main_new_msg is the swf
		var alertSwfDiv = "alert_main_new_msg";
		playAlert(alertSwfDiv);
		
		document.getElementById("showAlert_"+temp_i_c_id).focus();
		message = searchAndReplace (message, "\\'", "'");
		
		//alert(' itimnum = '+itimnum+' and msg = '+message);
		
		animFavNewMessage( sent_by, message, avatar, itimnum, message_type);
	
	
		popupFirefox("New Message | "+sent_by, message, avatar);
	
		if(message_type != 2){
			updateIcidList(cellnum, message_type, temp_i_c_id);


		}else{
			
			updateIcidList(from, message_type, temp_i_c_id);
			
			
		}
	
	
		showDiv('new_alltim_'+temp_i_c_id);
		
		
	}else{
		
		//alert('windwo open about ot alert');
		var name = from;
		var sent_by = cellnum;
		if(message_type != 1){
			sent_by = name;
		}else{
			
			if(name != ''){
				sent_by = name;	
				
			}else{
				
				sent_by = cellnum;	
			}
		}
		
		
		animFavNewMessage( sent_by, message, avatar, itimnum, message_type);
		
		hideDiv('new_alltim_'+temp_i_c_id);
		
		//changeClass("allitim_"+temp_i_c_id, "midRightBarNewOpenUnread");
		
		//alert(' tell me if top icid = '+topOpenedIcid+'  is the same as the alert icid = '+temp_i_c_id);
		
		
		addNewMessage(newMessageStr, newFname);
		
		topOpenedIcid = getTopIcid();
		//alert('top = '+topOpenedIcid+' and must compare to '+temp_i_c_id);
		
		if(topOpenedIcid == temp_i_c_id){
			
		
			setReplyRead(temp_i_c_id, itim_user_id, temp_mes_id);
			//ske i
			document.getElementById('allitim_'+temp_i_c_id).className = "midRightBarNewOpen";
	
		
		}else{
		
			var emparr = newFname.split('_');
			var shakeId = "boxHandle"+emparr[1];
			startShake(shakeId);
			changeClass("allitim_"+temp_i_c_id, "midRightBarNewOpenUnread");
			
			
		}
		
	}
	
}


function updateAlliTimsTimeago(){
	
	
	var children = document.getElementById('all_itims').childNodes;	
	//alert('hjey shit is the child = '+children[0].id);
	for(var i = 0; i < children.length; i++){
		//get the name
		// Check if there is an element
		// get the icid
			//var allitimdiv = "allitim_"+newicid;
			//var divExists = 0;
			var stringdiv = children[i].id;
			//alert('nb4 id = '+stringdiv);
			if(typeof(stringdiv) != "undefined"){
			
			
				//alert('id = '+stringdiv);
				var cnamearr = children[i].id.split("allitim_");
				var icid = cnamearr[1];
				
				//get the timestamp (received time)
				
				if(divIdExists("timestamp_"+icid) == 1){
					var tsDiv=document.getElementById("timestamp_"+icid);
					var timestamp = tsDiv.innerHTML;
					
					//update the time_icid with time ago of timestamp
					
					if(timestamp > 0){
					
						var time_ago = timeago(timestamp);
						
					}else{
						
						//alert(' No timestmap for icid = '+icid);	
						var time_ago = '';
					}					
				
					//get visibility of closeItim
					var closeitim_vis = document.getElementById('closeItim_'+icid).style.visibility;
					//alert(' hey icid = '+icid+' and vis of close = '+closeitim_vis+' and newtime = '+time_ago);
			
					
					if(closeitim_vis == 'visible'){
						
			
					}else{
					
						closeitim_vis = 'hidden';	
						
					}
					
					var addClose = time_ago+" <span id=\"closeItim_"+icid+"\" style=\"margin-left: 5px; visibility: "+closeitim_vis+";\"><a href=\"javascript:void(0)\" onclick=\"closeDivIcid("+icid+");\" style=\"font-family: Verdana,Arial,Helvetica,sans-serif;\">close</a></span>";
					writeDiv('time_'+icid, addClose);	
			
				}
				
			}
			
			
			
			
			
	}
	
	
	
}

function startTimeAgoUpdater(){
	//setInterval ( "startItimAlert('47', 'Hello uyi', 'Uyi Ogbeide')", 10000 );
	//setInterval ( "checkNewMsgAndFriend()", 10000 );
	
	var updateTimeagoIntervalId = setInterval ( "updateAlliTimsTimeago()", 60000 );
	
	
}



function updateIcidList(cellnum, mestype, i_c_id){
	
	if(mestype != 2){
		if(cellnum > 0){
			icidForCellnumArray[cellnum] = i_c_id ;
		}
	}else{
		var nick = cellnum.toLowerCase();
		nick = trim(nick);
		if(nick.length > 0){
			icidForNicknameArray[nick] = i_c_id;
		}
	}
	
	
}

function clearNewMsgDot(icid){
	//alert('uyienoma clearnewmsg dot -new_alltim_'+icid);
	var divId  = 'new_alltim_'+icid;
	//hideDiv('new_alltim_408033');
	hideDiv(divId);	
	var tmpcountDiv=document.getElementById("count_new_allitim_"+icid);
	tmpcountDiv.innerHTML = 0;
	
	
}


//starts IM
function startItimIM(i_c_id){
		//alert('okay i am starting friend id '+i_c_id);
		
		var allitimdiv = "allitim_"+i_c_id;
		
		//alert('about to cheeck for it now = '+allitimdiv);
		if(divIdExists(allitimdiv) != 1){
			//get the nick for this icid			
			var namearr = getNickForIcid(i_c_id);
			//fr_i_c_id, fr_name, fr_id, fr_avatar
			
			//alert(' a cool so name arr = '+namearr);
			
			var avatarpic = namearr[3];
			var name = namearr[1];
			var newmsg_esc = "...";
			var attachment = "";
			
			var time_ago = "          ";
			
			//var time_ago = "2 mins ago";
			
			//get the cellnum and the name/nickname
			
		
			var message_type = '2';
			var cellnum = 0;
			
			createNewAllItim(cellnum, newmsg_esc, attachment, message_type, i_c_id, name, "0", time_ago, avatarpic);
			
			
			
			
		}
		startItimBar(i_c_id); 
		//hideDiv('new_alltim_50');   
		hideDiv('newMsgAllMain');
	
}


function inArray(needle, haystack) {
    var length = haystack.length;
    for(var i = 0; i < length; i++) {
        if(haystack[i] == needle) return true;
    }
    return false;
}

function in_array(needle, haystack) {
    var length = haystack.length;
    for(var i = 0; i < length; i++) {
        if(haystack[i] == needle) return i;
    }
    return -1;
}


function startItim(i_c_id, itimTop, itimLeft){
	//alert("crazy, u got "+i_c_id);
	//var newtop = 100;
	//var newleft = 200;
	
	//reWriteGoogleAd();
	//icidArray[i_c_id] = itimnum;
	
	
	
	topOpenedIcid = i_c_id;
	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' ";
	
	
	//send the baseUrl as base_url_main for flash to use
	var fvars = "i_c_id="+i_c_id+"&itimnum="+itimnum+"&itim_user_id="+itim_user_id+"&winfocus=1&blinkingbarStatus=onfocus&sessId="+sessId+"&itim_nickname="+itim_nickname+"&base_url_main="+baseUrl;
	var fname = 'iTim_'+itimnum;
	var fid = 'iTim_'+itimnum;
	
	
	
	icidArray[i_c_id] = 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);
	
	
	//safari can't handle what we do with itim_8
	//safari = true;
	if((safari)&&(!is_chrome)){
		
		itimswf = itimswf_safari;	
	}else if(((ie4)||(ie5))&&(!is_chrome)){
		
		itimswf = itimswf_safari;
		//alert('using interna exp');	
	}
	
	//alert('hey itimswf = '+itimswf);
	
	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>";
	
	
	/** uncomment for live version, took out flash above for test **/
	
	//if(safari){
	// u can call afunction top.frames['frame_name'].myFunc();	
	
	var test_icid_content = "<div style=\"border-width:0; overflow-x:auto; overflow-y:scroll; width:385px; height:229px;\"><div><table width=\"100%\"><tr><td width=\"50%\" align=\"center\" valign=\"middle\"><div id=\"callButton\" class=\"topButton\" onclick=\"callCurrCell();\">Call</div></td><td align=\"center\" valign=\"top\" id=\"addcontactMain\"><div id=\"contactButton\" class=\"topButton\" onclick=\"editContact();\">Add To Contacts </div></td></tr></table></div><div id=\"adbanner\"><div style=\"border: 0px solid #ee2288; left:-8px; height: 50px; position: relative;\"><!-- admob <script type=\"text/javascript\">var admob_vars = { pubid: 'a14b9eb90a0269b', bgcolor: '000000', text: 'FFFFFF', test: false };</script><script type=\"text/javascript\" src=\"http://mm.admob.com/static/iphone/iadmob.js\"></script> --><script type=\"text/javascript\"><!--window.googleAfmcRequest = {client: 'ca-mb-pub-1636383240212339',ad_type: 'text_image',output: 'html', channel: '7592805155',format: '320x50_mb',  oe: 'utf8', color_border: '336699',color_bg: 'FFFFFF',color_link: '0000FF',color_text: '000000',color_url:'008000',};//--></script><script type=\"text/javascript\" src=\"http://pagead2.googlesyndication.com/pagead/show_afmc_ads.js\"></script></div></div><div id=\"itim_content\"><!-- start mesId_19235078 --><div style=\"margin-bottom:5px;\"><div style=\"text-align:center; font-size:10px; margin-bottom:3px; color:#666666\"> Apr 19, 2011 6:46 PM </div><div><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td>&nbsp;</td><td align=\"right\"><div class=\"myMessage\"><div id=\"mesId_19235078\" onclick=\"copyText(document.getElementById(this.id).innerHTML);\" style=\"margin:3px; width:auto; \"> Hi babe. Call my phone. Tmobile turned it off so I can't call out</div></div></td><td width=\"10px\" valign=\"top\"><div class=\"myMesTail\"></div></td></tr></table></div></div><!-- end mesId_19235078 --></div>";
	
	var convoScrollDiv = "<div id=\"convoScroll_"+i_c_id+"\" class=\"mynewscroll\" style=\"border-width:0; overflow-x:hidden; overflow-y:scroll; width:385px; height:229px; background-color:#fff;\"></div>";
	
	
	//style="border-width:0; overflow-x:hidden; overflow-y:scroll; width:385px; height:229px; border:#066 solid 2px;
		
	var browser_style = "";
	if((safari)&&(!is_chrome)){
		
		browser_style = "style=\"top:-393px;\"";
		
		
		
		var icid_content = "<iframe name=\"\" src=\"con_scripts/itim_init_iphone_widget.php?user_id="+itim_user_id+"&i_c_id="+i_c_id+"&is_iphone=1\" style=\" border-width:0; overflow-x:auto; overflow-y:scroll;\" width=\"385px\" height=\"229px\" frameborder=\"0\"></iframe>";
		//icid_content = test_icid_content;
		icid_content = convoScrollDiv;
		
		//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; top:16px;'>"+swfOut+"</div><div id=\"handle"+itimnum+"\" class=\"handle\"  style=\"width:350px; z-index:20; position:relative; top:-425px; -khtml-opacity: 0.6; opacity: 0.6; -webkit-border-top-right-radius: 7px; -webkit-border-top-left-radius: 7px; margin-left:20px; text-align:center; font-weight:normal; color:#999; font-size:10px; padding-top:3px; \">: : : : : :&nbsp;&nbsp;&nbsp;&nbsp;click to drag&nbsp;&nbsp;&nbsp;&nbsp;: : : : : :</div> <div id=\"convo_"+i_c_id+"\" class=\"itimConversation fade50\" "+browser_style+">"+icid_content+"</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; top:16px;'>"+swfOut+"</div><div id=\"handle"+itimnum+"\" class=\"handle\"  style=\"width:350px; z-index:20; position:relative; top:-425px; -khtml-opacity: 0.6; opacity: 0.6; -webkit-border-top-right-radius: 7px; -webkit-border-top-left-radius: 7px; margin-left:20px; text-align:center; font-weight:normal; color:#999; font-size:10px; padding-top:3px; \">: : : : : :&nbsp;&nbsp;&nbsp;&nbsp;click to drag&nbsp;&nbsp;&nbsp;&nbsp;: : : : : :</div><div id=\"loading_"+i_c_id+"\" class=\"itimOverLoad\">Loading Conversation<br>Please wait...&nbsp;</div></div>";
		
	}else if(((ie4)||(ie5))&&(!is_chrome)){
		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; top:16px;'>"+swfOut+"</div><div id=\"handle"+itimnum+"\" class=\"handle\"  style=\"width:390px; z-index:20; position:relative; top:-425px;  \">&nbsp;</div><div id=\"loading_"+i_c_id+"\" class=\"itimOverLoad\">Loading Conversation<br>Please wait...&nbsp;</div></div>";
		
		
	}else{
	
		var speechMicDiv = '';
		
		if(is_chrome){
			//alert('hey fname = '+fname);
			speechMicDiv = '<div id="speech_'+i_c_id+'" class="speechMic"><input name="supermax" type="text" id="speechmic_'+i_c_id+'" speech x-webkit-speech required  onspeechchange="addSpeechToText(this.value, \''+i_c_id+'\', \''+fname+'\')" onwebkitspeechchange="addSpeechToText(this.value, \''+i_c_id+'\', \''+fname+'\')" style="width:30px; font-size:24px; border-radius:5px; border-width:0px; height:36px; margin-left:10px; cursor:pointer;"/></div>';	
			
		}
		
		var icid_content = "<iframe name=\"\" src=\"con_scripts/itim_init_iphone_widget.php?user_id="+itim_user_id+"&i_c_id="+i_c_id+"&is_iphone=1\" style=\" border-width:0; overflow-x:auto; overflow-y:scroll;\" width=\"385px\" height=\"229px\" frameborder=\"0\"></iframe>";
		//icid_content = test_icid_content;
		icid_content = convoScrollDiv;
		
		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 id=\"convo_"+i_c_id+"\" class=\"itimConversation fade50\">"+icid_content+"</div> "+speechMicDiv+"</div>";
	
	}
	
	
	
	
	
	if(currentFnameArray.length > 0){
		var lastIndex = currentFnameArray.length - 1;
		//alert("Removing focus -- array = "+currentFnameArray);
		removeFlashFocus(currentFnameArray[lastIndex])
	}
	
	
	
	//alert("JUST SET mad focus uiyi - \n\n"+content);
	
	
	
	
	writeDivInDiv("iTimHolder"+itimnum, "midSection", content)
	//lastItimWin = currentItimWin
	//currentItimWin = "boxHandle"+itimnum
	
	
	if((typeof(itimLeft) != "undefined")&&(typeof(itimTop) != "undefined")){
		
		if((itimLeft > 0)&&(itimTop > 0)){
			
			moveDiv('boxHandle'+itimnum, itimTop, itimLeft)
		
			
		}else{
		
		
			moveDiv('boxHandle'+itimnum, newtop, newleft)
		
		
		}
		
		
	}else{
	
	
		moveDiv('boxHandle'+itimnum, newtop, newleft)
	
	
	}
	
	
	
	//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))
	
	//alert("jey reg coord = "+newtop+", "+newleft+" and itim = = "+itimTop+", "+itimLeft);
	
	
		
		
	//constrain
	//var boxRegionConstraint = document.getElementById("boxRegionConstraint") 
	//group = drag.createSimpleGroup(boxRegionConstraint) 
	var origin = coordinates.create(20, 20)
	var bottom = coordinates.create(1000, 1000) 
	//alert('origin = '+origin+' and bottom = '+bottom);


	group.addTransform(function(coordinate, dragEvent) { 
	var originalTopLeftOffset = dragEvent.topLeftOffset.minus(dragEvent.topLeftPosition) 
	return coordinate.constrainTo(origin, bottom)
	//return coordinate.constrainTo(origin, originalTopLeftOffset) 
	}) 
	
	
	//addItimToolbar(itimnum)
	//alert("JUST SET mad focus uiyi - \n\n"+content);
	//setIcidArray(i_c_id, itimnum);
	thisMovie(fname).tabIndex = 0;
	thisMovie(fname).focus();
			
	fnameForIcid[i_c_id] = fname;		
			
	if(isAllMuted == 1){		
	
		muteAll(fname);
	
	}
	changeClass("allitim_"+i_c_id, "midRightBarNewOpenFocus");
	//alert('loading add pic itim = '+itimnum);
	//loadAddPicture(itimnum);
	
	
}

function bringSwfToFrontDelay(icid, itimnum, swfinfront){
	
	swfIntervalId = setInterval ( "bringSwfToFront('"+icid+"', '"+itimnum+"', '"+swfinfront+"')", 1000 );	
	
}

function bringSwfToFront(icid, itimnum, swfinfront){
	//alert('icid = '+icid+' and itinum = '+itimnum+' and infromt = '+swfinfront);
	var swfdivId = "iTim_div_"+itimnum;
	var convodivId = "convo_"+icid;
	if(document.getElementById) {
		//var elem = document.getElementById(Elem);
		var swfElem = document.getElementById(swfdivId);
		var convoElem = document.getElementById(convodivId);
		//alert(' must be elem = '+swfElem+' and covoe = '+convodivId);
	} else if (document.all){
		//var elem = document.all[Elem];
		
		var swfElem = document.all[swfdivId];
		var convoElem = document.all[convodivId];
		//alert(' must be ie ');
	}
	
	
	//var swfElem = document.getElementById(swfdivId);
	
	//var convoElem = document.getElementById(convodivId);
	//alert('zindex of swf = '+swfElem.style.zIndex+' and index of convo = '+convoElem.style.zIndex); 
	if(swfinfront == 1){
		
	
		convoElem.style.zIndex = 10;
		swfElem.style.zIndex = 19;	
		
	}else{
		
		swfElem.style.zIndex = 10;
		convoElem.style.zIndex = 19;
		
	}
	
	if(swfIntervalId){
		clearInterval(swfIntervalId);
	}
	//alert(' after zindex of swf = '+swfElem.style.zIndex+' and index of convo = '+convoElem.style.zIndex); 
}

function addSpeechToText(str, icid, fname){
	//alert('string = '+str+' and fname = '+fname+' and icid = '+icid);
	thisMovie(fname).tabIndex = 0;
	thisMovie(fname).focus();
	addMessageToSend(str, fname);
	
	var divId = "speechmic_"+icid;
	
	
	document.getElementById(divId).value = "";
	
}


function getDateFormat(timestamp){
	
	var today = new Date();
	var today_mon = today.getMonth();		//return 0 for jan
	var today_day = today.getDate();
	var today_year = today.getFullYear();
	
	var sameday = 0;
	
	
	
	var newDate = new Date();
	newDate.setTime( timestamp*1000 );	//timestamp is in seconds, set time uses millissecs
	
	//dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT");
	//Saturday, June 9th, 2007, 5:46:21 PM
	
	
	/* dteFormat is a flash function , not js
	var myDate = dateFormat(newDate, "mmm d, yyyy");
	
	var myTime = dateFormat(newDate, "HH:MM TT");
	*/
	
	var mon = newDate.getMonth();		//return 0 for jan
	var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	var m_names_3 = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
	
	var day = newDate.getDate();
	var year = newDate.getFullYear();
	
	var year2 = year.toString().slice(2);
	var myDate = m_names_3[mon]+" "+day+", "+year;
	
	var realmon = mon + 1;
	var myDate2 = realmon+"/"+day+"/"+year2;
	
	
	
	var curr_hour = newDate.getHours();		// returns 0 to 23

	if (curr_hour < 12){
	   a_p = "AM";
	   
	}else{
	   a_p = "PM";
	}
	if (curr_hour == 0) {
	
	   curr_hour = 12;
	
	}
	if (curr_hour > 12) {
	
	   curr_hour = curr_hour - 12;
	
	
	}
	
	
	var curr_min = newDate.getMinutes();

	curr_min = curr_min + "";

	if (curr_min.length == 1){
   		curr_min = "0" + curr_min;
   	}
	var myTime = curr_hour + ":" + curr_min + " " + a_p;
	
	
		
	if((today_mon == mon)&&(today_day == day)&&(today_year == year)){
		sameday = 1;
	
	}
		
	var outDate = new Array(myDate, myTime, myDate2, sameday);
	
	return outDate;
	
	
	
}


//calls addReceivedMessage in the flash funwidget
function addNewMessage(str, movieName){
	
	
	//alert('hey sonny add new msg to = '+movieName);
	
	//str = newmes_0=19721-_-_-phone-_-_-1-_-_-totalmsg-_-_-Jul 1, 2011-_-_-09:37 AM-_-_-20487614-_-_-jbond-_-_-are you asllip-_-_-attachment-_-_-avatars/nopic.jpg-_-_-audio-_-_-1309538221"
	var strarr = str.split('-_-_-');
	var temp_mes_id = strarr[6];
	var message = strarr[8];
	message = searchAndReplace (message, ":ampreg:", "&");
	
	
	//alert('message = '+message+' ==\nunecs = '+unescape(message)+' and \nesc = '+escape(message));
				
	
	var myDateArr = getDateFormat(strarr[12]);
	var myDate = myDateArr[0];
	var myTime = myDateArr[1];
	
	var temp_msgdate = myDate+" "+myTime;
	var from = strarr[7];
	var attachment = strarr[9];
	var add_attachment = 0;
	if(typeof(attachment) != "undefined"){
		
		if(attachment != ""){
			
			add_attachment = 1;	
			
			
			
			//attachment and auddio are single , no folders
		
			var picarr = attachment.split("/");
		
			if(picarr.length > 1){
				var lastIndex = picarr.length - 1;
				attachment = picarr[lastIndex];
				
				//pic_image_main = 'tim_video_thumbnails/'+videoarr[0]+'.png';
				//alert(' this is video = '+newAttachment+' and thumb = '+pic_image_main);
			}	
			
			
		}
		
	}
	
	
	//alert('2.  here flash = '+movieName);
	
	
	var attach_audio = strarr[11];

	if(typeof(attach_audio) != "undefined"){
		
		if(attach_audio != ""){
			
			
			
			//attachment and auddio are single , no folders
		
			var audioarr = attach_audio.split("/");
		
			if(audioarr.length > 1){
				var lastIndex = picarr.length - 1;
				attach_audio = audioarr[lastIndex];
				
				//pic_image_main = 'tim_video_thumbnails/'+videoarr[0]+'.png';
				//alert(' this is video = '+newAttachment+' and thumb = '+pic_image_main);
			}	
			
			
		}
		
	}
	
	
	
	




	//		$flashout .= "&message_$k=$mes_id-_-_-$message-_-_-$is_reply-_-_-$date-_-_-$sent_to-_-_-$sent_by-_-_-$attachment-_-_-$add_attachment-_-_-$attach_audio";
	// 			20487689-_-_-hello+son-_-_-1-_-_-Jul 01, 2011 9:43 AM-_-_-itim-support-_-_-jbond-_-_--_-_-0-_-_-
	
	//message = escape(message);
	var oldmsg = message;
	message = searchAndReplace (message, "%5C%27", "%27");
	
	message = searchAndReplace (message, "%5c%27", "%27");
	message = unescape(message);
	message = searchAndReplace (message, "\n", "\r");
	message = searchAndReplace (message, "\'", "'");
	var newMsgStr = temp_mes_id+"-_-_-"+message+"-_-_-1-_-_-"+temp_msgdate+"-_-_-"+itim_nickname+"-_-_-"+from+"-_-_-"+attachment+"-_-_-"+add_attachment+"-_-_-"+attach_audio;
	
	
	//alert(' here flash = '+movieName);
	
	
	//alert(' adding to '+movieName+' new msg = '+newMsgStr+' \n oldmsg = '+oldmsg);
	
	flashID = thisMovie(movieName);
	if((from == 'itim-support')||(itim_nickname == 'itim-support')){
		var re = /'/;
		var esc_re = escape("'");
		//newMsgStr = newMsgStr.replace(re, "appuyiapp");
		//alert("flashid = "+flashID+" and movieName = "+movieName+"\nstring = "+newMsgStr);
	}
	flashID.SetVariable( "newMessageStr", newMsgStr);
	flashID.addReceivedMessage();
	
}

function addMessageToSend(str, movieName){
	flashID = thisMovie(movieName);
	//alert("flashid = "+flashID);
	flashID.SetVariable( "jsNewMessage", str);
	flashID.addMessageToSend();
	
}


function checkForNewMessageNow2(movieName){
	alert(' it is 2 checking to mName '+movieName);
	flashID = thisMovie(movieName);
	//alert("flashid = "+flashID);
	flashID.getNewMessageNow();


	
}

//This tells a flash window to check for new msgs now, 
//it should be called after functions parseNewMes if it finds that the 
// flash icid window is already open.

function checkForNewMessageNow(movieName){
	alert(' it is 1 checking to mName '+movieName);
	flashID = thisMovie(movieName);
	//alert("flashid = "+flashID);
	flashID.getNewMessageNow();


	
}

//replaced by above so a dive can show the conversation
function startItimOrig(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>";
	
	
	/** uncomment for live version, took out flash above for test **/
	
	//if(safari){
		
		
	if((safari)&&(!is_chrome)){
		
		
		
		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; top:16px;'>"+swfOut+"</div><div id=\"handle"+itimnum+"\" class=\"handle\"  style=\"width:350px; z-index:20; position:relative; top:-425px; -khtml-opacity: 0.6; opacity: 0.6; -webkit-border-top-right-radius: 7px; -webkit-border-top-left-radius: 7px; margin-left:20px; text-align:center; font-weight:normal; color:#999; font-size:10px; padding-top:3px; \">: : : : : :&nbsp;&nbsp;&nbsp;&nbsp;click to drag&nbsp;&nbsp;&nbsp;&nbsp;: : : : : :</div> <div id=\"loading_"+i_c_id+"\" class=\"itimOverLoad\">Loading Conversation<br>Please wait...&nbsp;</div> </div>";
		
		
		
	}else{
	
		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 id=\"loading_"+i_c_id+"\" class=\"itimOverLoad\">Loading Conversation<br>Please wait...&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).tabIndex = 0;
	thisMovie(fname).focus();
			
	if(isAllMuted == 1){		
	
		muteAll(fname);
	
	}
	
	//alert('loading add pic itim = '+itimnum);
	//loadAddPicture(itimnum);
	
	
}


function stopRecon(){
	reconOn = 0;
	clearInterval(reconIntervalId);
	

	
}

function startRecon(){
	stopChecker();
	reconOn = 1;
	showDiv('recon_top');
	reconIntervalId = setInterval ( "reconnectCounter(30)", 1000 );

}

/**** controls reconnection when connection is los
*
*	only in sec
*
*/
function reconnectCounter(maxsec){
	
	var elemId = document.getElementById('recon_ct');
	var currCt = elemId.innerHTML;
	
	if(maxsec > currCt){
	
		currCt = currCt - 1;	
		
	}else{
		
		currCt = maxsec-1;
		
	}
	
	if(currCt < 1){
		//activate recon
		reconnectServers();
	}else{
		var newDivId = 	'recon_main';
		var content = "reconnecting in <span id=\"recon_ct\">"+currCt+"</span>&nbsp;secs&nbsp;&nbsp;<a href=\"javascript:void(0)\" onClick=\"reconnectServers();\">Try now</a>";
		writeDiv(newDivId, content);
		
		
	}
	
	
	
	
}

function resetRecon(){
	
	
		var newDivId = 	'recon_main';
		var content = "Reconnection Failed :( <span id=\"recon_ct\" style=\"visibility:hidden;\">30</span>";
		writeDiv(newDivId, content);
			
	
}


function reconnectServers(){
	var newDivId = 	'recon_main';
	var content = "Reconnecting now... <span id=\"recon_ct\" style=\"visibility:hidden;\">30</span>";
	writeDiv(newDivId, content);
	stopRecon();
	
	startChecker();
	lostConnection = 1;
	checkNewMsgAndFriend();
}


function reconCountdown(){
	
	var divId = 'recon_ct';	
	
}



/*
*
* 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 origflv = flvpath;
	var flvpath = "tim_video_flv/"+flvpath;
	
	//alert("crazy, u got "+i_c_id+" and flvpath = "+origflv+" and sender = "+sender);
	
	viewPicIM(origflv, '');
	//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).tabIndex = 0;
	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) {
	
	
	try {
		
	
	
		
		  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);
		  }

	} catch (e) { //alert('error son - ')
	
	}
	
}


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);

	
}




//alert_main_new_msg is the swf
function playAlert(movieName){
	if(isAllMuted != 1){
		flashID = thisMovie(movieName);
		//alert("flashid = "+flashID+"  for movename = "+movieName);
		flashID.playNewAlert();

	}
	
	
}


function changeWidthAnimated(divId, newwd, duration){
	
	
	
	var elem = document.getElementById(divId);
	elem.style.transitionProperty = "width";
	
	if(duration > 0){
		elem.style.transitionDuration = duration+"ms";
	}
	elem.style.width = newwd+"px";
	
	
	
}

//duration is ms
function changeHeightAnimated(divId, newht, duration){
	
	
	
	var elem = document.getElementById(divId);
	elem.style.transitionProperty = "height";
	if(duration > 0){
		elem.style.transitionDuration = duration+"ms";
	}
	
	elem.style.height = newht+"px";
	
	
	
}

function presetLogin(){
	
	document.getElementById('username').value = document.getElementById('nickname').value;
	
	document.getElementById('pword').value = document.getElementById('pwd').value;
	
}

function goToRegistration(is_pwd){
	//move holder
	signupdone = 0;
	hideDiv("login_tab");
	var regId = "register_holder";
	document.getElementById(regId).style.left = "-403px";
	//change ht of bg animated
	changeHeightAnimated('login_bg', '400');
	
	changeWidthAnimated('login_bg', '550');
	
	//setFocusOnLoad();
	//show registration_tab
	
	
	if(is_pwd == 1){
	
	
	setTimeout('showDiv(\'registration_tab\');setFocusPwdOnLoad();', 500);	
	
	
	
	setTimeout('setFocusPwdOnLoad();', 1500);	
		
		
	}else{
		
	
	setTimeout('showDiv(\'registration_tab\');setFocusOnLoad();', 500);	
	
	
	
	setTimeout('setFocusOnLoad();', 1500);	
		
	}
	
	
	
	
	
	
	
}


function goToProgress(){
	//move holder
	hideDiv("registration_tab");
	showDiv("progress_tab");
	
	var regId = "register_holder";
	document.getElementById(regId).style.left = "-903px";
	//change ht of bg animated
	//changeHeightAnimated('login_bg', '400');
	
	//changeWidthAnimated('login_bg', '550');
	
	//setFocusOnLoad();
	//show registration_tab
	//setTimeout('showDiv(\'registration_tab\');setFocusOnLoad();', 500);	
	//setTimeout('setFocusOnLoad();', 1500);	
	
	
	
	
	
	
}


function goToSuccess(){
	//move holder
	hideDiv("progress_tab");
	showDiv("success_tab");

	var regId = "register_holder";
	document.getElementById(regId).style.left = "-1365px";
	
	var email = document.getElementById('email').value;
	var content = '<strong>Congratulations...</strong><div style=" margin-top:25px;color:#fff; font-size:14px; line-height:24px;">You are now a Member of the iTimWorld. An activation link has been sent to '+email+'. Please check your email and click on the link to activate your account.<br>Thank You. <br></div>';
	writeDiv('success_con', content); 
	
	
	
	//change ht of bg animated
	//changeHeightAnimated('login_bg', '400');
	
	//changeWidthAnimated('login_bg', '550');
	
	//setFocusOnLoad();
	//show registration_tab
	//setTimeout('showDiv(\'registration_tab\');setFocusOnLoad();', 500);	
	//setTimeout('setFocusOnLoad();', 1500);	
	
	
	
	
	
	
}


function backToLogin(){
	//move holder
	hideDiv("registration_tab");
	var regId = "register_holder";
	document.getElementById(regId).style.left = "0px";
	//change ht of bg animated
	changeHeightAnimated('login_bg', '250');
	changeWidthAnimated('login_bg', '350');
	
	//show registration_tab
	setTimeout('showDiv(\'login_tab\')', 200);	
	setTimeout('setFocusFormField(\'username\');', 1500);	
	
}



function fadeConvo(icid, alpha){
	var divId = 'convo_'+icid;
	
	
	
	
	if(alpha == 100){
		
		changeClass(divId, 'itimConversationLoaded fade100');
		fadingConvo = 0;
	}else if(fadingConvo != 1){
		fadingConvo = 1;
		//alert('fading icid = '+icid+' and dvi = '+divId);
		changeClass(divId, "itimConversationLoaded fade50");
		
	}
	
	
}


//called after function addreceivedmessage calls the flash moviename
function writeToConvo(icid, content){
	//alert('I am in and icid = '+icid);
	//alert('and icid = '+icid+' con = '+content);
	//alert('about to write before');
	
	var divId = 'convoScroll_'+icid;
	var newDiv=document.getElementById('convoScroll_'+icid);
	
	//var newStyle=newDiv.style;
	//newStyle.top = "-2000px";
	//newStyle.visibility = "hidden";
	//var newcDiv=document.getElementById(cid);
	var currcon = newDiv.innerHTML;
	var newcontent = content+currcon;
	//alert('about to write');
	writeDiv(divId, newcontent);	
	newDiv.scrollTop = 0;
	
}

function clearConvo(icid){
	var divId = 'convoScroll_'+icid;
	var newcontent = "";
	writeDiv(divId, newcontent);	
	
}

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);
		
		//change tab clas 
		var fnamearr = movieName.split("_");
		var tempitimnum = fnamearr[1];
		
		
		
		//change the toolbar class
		//alert('setting class');
		var divId = "bar_"+movieName;
		
		
	
		var focusicid = itimnumArray[tempitimnum];
		
		
		if(focusicid > 0){
		
			//alert('removing focus icid = '+focusicid+' for itimnum = '+tempitimnum);
			document.getElementById("allitim_"+focusicid).className = "midRightBarNewOpen";
		}
		
		
	}
}


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).tabIndex = 0;
		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);
		
	
		var focusicid = itimnumArray[tempitimnum];
		
		
		if(focusicid > 0){
		
			//alert('hey focus icid = '+focusicid+' for itimnum = '+tempitimnum);
			document.getElementById("allitim_"+focusicid).className = "midRightBarNewOpenFocus";
		
		
			//zero the rad msgs
			var countDiv=document.getElementById("count_new_allitim_"+focusicid);
			countDiv.innerHTML = 0;
			//alert("Existing hiding in win to focus = new_alltim_"+focusicid);
			hideDiv('new_alltim_'+focusicid);
			
			
			
		
			topOpenedIcid = focusicid;
			setReplyReadFromFocus(topOpenedIcid);
	
			findAndBringToFrontIcidLocation(focusicid);
	
		}
		
		if(shakeIntervalId){
			stopShake();
			
		}
		
		
	}else{
		var fnamearr = movieName.split("_");
		var tempitimnum = fnamearr[1];
		
		var focusicid = itimnumArray[tempitimnum];
		//alert("New hiding in win to focus = new_alltim_"+focusicid);
		
		//hideDiv('new_alltim_'+focusicid);
		
		
		if(focusicid > 0){
			hideDiv('new_alltim_'+focusicid);
		
			//topOpenedIcid = focusicid;
			document.getElementById("allitim_"+focusicid).className = "midRightBarNewOpenFocus";
				
		}
		
		
		if(shakeIntervalId){
			stopShake();
			
		}
		
		
		
	}
	
	
	
	topOpenedIcid = getTopIcid();
	//alert('hey top open = '+topOpenedIcid);	
	
	// 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");
	}
	*/
	stopAnimTitle();
	
	//alert("JUST SET mad focus uiyi itimwin focua");
	thisMovie(movieName).tabIndex = 0;
	thisMovie(movieName).focus();
	//alert(" you clicked id = "+id+"\n moviename = "+movieName+' and loading = '+tempitimnum);
	//loadAddPicture(tempitimnum);
}


/**
*
* this mutes all the itims in the 
*../icons_main/sound_mute.png
*/
function muteAlliTims(){
	
	var content = '<a href="javascript:void(0)" onClick="unmuteAlliTims();" title="UnMute All iTims"><img src="../icons_main/sound_mute.png" alt="Mute All iTims" width="16" height="16" border="0"  style="margin-right:5px"></a>	';
	writeDiv('muteallicon', content);
	
	
	if(currentFnameArray.length > 0){
		//../icons_main/sound_mute.png
		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);
		}
	
	}
		
		
		
	isAllMuted = 1;	
	
	
	
		
		
		
	
	
	
}


/**
*
* this unmutes all the itims in the 
*
*/
function unmuteAlliTims(){
	
	var content = '<a href="javascript:void(0)" onClick="muteAlliTims();" title="Mute All iTims"><img src="../icons_main/sound.png" alt="Mute All iTims" width="16" height="16" border="0"  style="margin-right:5px"></a>	';
	writeDiv('muteallicon', content);
	
	if(currentFnameArray.length > 0){
		
		
		
		for(var i = 0; i < currentFnameArray.length; i++){
	
			var movieName = currentFnameArray[i];
			//alert("fname array = "+currentFnameArray+"\n\nfname = "+movieName);
			unmuteAll(movieName);
		}
		
		
	}
	
	
	isAllMuted = 0;
	
}




/*
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);
		}
	
	}
		
	
	
	
		
		
		
	
	
	
}


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
	
	if(typeof(flash_id) != "undefined"){
		
		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;
					
				}
			}
			
		}
		
	
	}
	
	//alert('flash id = '+flash_id);
	
	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];
		}
		//crazy humbry
		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 changeItimBG(divId, imageloc, position, repeat){
	
//itimBackground	

	alert('itim bg new image = '+imageloc+' and pos = '+position+' and repeat = '+repeat);
	if((typeof(position) == "undefined")&&(typeof(repeat) == "undefined")){
	
		var bgImage = document.getElementById('itimBackground');
		bgImage.src = imageloc;
	
	}else if((position != '')&&(repeat != '')){
		
		
		var bgImage = document.getElementById('itimBackground');
		bgImage.src = imageloc;
		
	}else{
		
		changeDivBackground (divId, imageloc, position, repeat);
		
	}
	
}


function changeDivBackground (divId, imageloc, position, repeat){
	
	
	
	
	var changedBg = 0;
	
	if(divId == 'tester'){
		
		
		if((typeof(position) == "undefined")&&(typeof(repeat) == "undefined")){
		
			var bgImage = document.getElementById('itimBackground');
			bgImage.src = imageloc;
			changedBg = 1;
		}else if((position != '')&&(repeat != '')){
			
			
			var bgImage = document.getElementById('itimBackground');
			bgImage.src = imageloc;
			changedBg = 1;
		}
		
		
	}
	
	//alert('itim bg new image = '+imageloc+' and pos = '+position+' and repeat = '+repeat+' and changeBG = '+changedBg);
	
	if(changedBg != 1){
		var C_el = document.getElementById(divId);
		imageurl = "url("+imageloc+")";
		C_el.style.backgroundImage  = imageurl;
		
		
		
		//background-position:center; background-repeat:no-repeat;
		if(typeof(position) != "undefined"){
							
			if(position != ''){
				
				C_el.style.backgroundPosition = position;
				
			}
							
							
		}
		
		
		if(typeof(repeat) != "undefined"){
							
			if(repeat != ''){
				
				C_el.style.backgroundRepeat = repeat;
				
			}
							
							
		}	
		
		
	}
	
	//alert('just change image loc to '+imageloc);
	
}
//this take values of imagelocurl url("images5/sky.gif"
function changeCssBackground (divId, imageurl){
	var C_el = document.getElementById(divId);
	
	C_el.style.backgroundImage  = imageurl;
	//alert('just change image loc to '+imageloc);
	
}	
	
function ajaxChangeBg(divId, imageloc, user_id){
	
	changeDivBackground (divId, imageloc);
	
	saveIsmsBg( imageloc, user_id);
	
}

function ajaxChangeBackground(divId, imageloc, position, repeat){
	
	changeDivBackground (divId, imageloc, position, repeat);
	
}

function undoChangeBackground(){
	
	var temp_curr_bg = getPrevCurrBg();
	var temp_curr_bg_pos = getPrevCurrBgPos();
	var temp_curr_bg_repeat = getPrevCurrBgRepeat();
	//alert('curr bg = '+temp_curr_bg);
	setCurrBg(temp_curr_bg, temp_curr_bg_pos, temp_curr_bg_repeat);
	changeDivBackground ('tester', temp_curr_bg, temp_curr_bg_pos, temp_curr_bg_repeat);
	
}



function setCurrBg(new_bg, new_pos, new_repeat){
	curr_bg = prev_curr_bg;	//bcos curr_bg may bve changed by a previous previw, we put the old one back
	prev_curr_bg = curr_bg;
	curr_bg = new_bg;
	
	curr_bg_pos = prev_bg_pos;
	prev_bg_pos = curr_bg_pos;
	curr_bg_pos = new_pos;
	
	curr_bg_repeat = prev_bg_repeat;
	prev_bg_repeat = curr_bg_repeat;
	curr_bg_repeat = new_repeat;
	
	
}

function getPrevCurrBg(){
	
	var temp_curr_bg = prev_curr_bg;
	//alert(' curr bg = '+curr_bg);
	return temp_curr_bg;
	
}


function getPrevCurrBgPos(){
	
	var temp_curr_bg_pos = prev_bg_pos;
	//alert(' curr bg = '+curr_bg);
	return temp_curr_bg_pos;
	
}



function getPrevCurrBgRepeat(){
	
	var temp_curr_bg_repeat = prev_bg_repeat;
	//alert(' curr bg = '+curr_bg);
	return temp_curr_bg_repeat;
	
}

function getCurrBg(){
	/*
	var bg_el = document.getElementById('tester');
	var mid_el = document.getElementById('midRightMenu');
	var bg_ht = getElementHeight('tester');
	var mid_ht = getElementHeight('midRightMenu');
	alert('hey backgour ht = '+bg_el.style.height+' and bg_ht = '+bg_ht+' \nmid ht = '+mid_el.style.height+' and mid_ht = '+mid_ht+' and itimuserid = '+itim_user_id);
	var temp_curr_bg = bg_el.style.backgroundImage;
	*/
	var temp_curr_bg = curr_bg;
	//alert(' curr bg = '+curr_bg);
	return temp_curr_bg;
	
}


function saveIsmsBg( imageloc, user_id){
	
	
	//alert("saving image = "+imageloc+" for userid = "+user_id);
	
	
}
	
	




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);
}




//numbers only

function numericOnly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

function clearNewItim(){
	pic_image_main = '';
	hideDiv('sendOverlay');
	hideDiv('sendprogresswin');
	hideDiv('sendprogress');
	var tofield = 'cellnumber';
	var mesfield = 'newmessage';
	var newAttachment = '';		//attachment when createing a new message
	var newcellnum = '';
	var newnickname = '';
	var new_mes_type = 1;
	var new_group_id = 0;
	var new_group_type = 1;
	var new_admin_group = 0;
	var new_itim_version = '';
	
	
	new_form_opened = 0;
	newitim_main = 0;
	resetNewAddMms();
	
	document.newitimform.cellnumber.value = "";
	document.newitimform.newmessage.value = "";	
	document.newitimform.cellnumber.focus();
	
	
	
	
}


function clearNewItimIM(){
	pic_image_main = '';
	hideDiv('sendOverlayIM');
	hideDiv('sendprogresswinIM');
	hideDiv('sendprogress');
	var tofield = 'cellnumber';
	var mesfield = 'newmessage';
	var newAttachment = '';		//attachment when createing a new message
	var newcellnum = '';
	var newnickname = '';
	var new_mes_type = 2;
	new_form_opened = 0;
	newitim_main = 0;
	
	
	
	var new_group_id = 0;
	var new_group_type = 1;
	var new_admin_group = 0;
	var new_itim_version = '';
	
	
	
	resetNewAddMmsIM();
	
	document.newitimformIM.nick.value = "";
	document.newitimformIM.newmessageIM.value = "";	
	//alert('clearing and value = '+document.newitimformIM.newmessageIM.value);
	document.newitimformIM.nick.focus();
	
	
	
	
}




function clearNewItimExtras(){
	hideDiv('sendOverlay');
	hideDiv('sendprogresswin');
	hideDiv('sendprogress');
	var tofield = 'cellnumber';
	var mesfield = 'newmessage';
	var new_mes_type = 1;
	new_form_opened = 0;
	newitim_main = 0;
	resetNewAddMms();
	
	document.newitimform.cellnumber.focus();
	
	
	
	
}


function clearNewItimIMExtras(){
	hideDiv('sendOverlayIM');
	hideDiv('sendprogresswinIM');
	hideDiv('sendprogress');
	var tofield = 'cellnumber';
	var mesfield = 'newmessage';
	var new_mes_type = 2;
	new_form_opened = 0;
	newitim_main = 0;
	resetNewAddMmsIM();
	
	//alert('clearing and value = '+document.newitimformIM.newmessageIM.value);
	document.newitimformIM.nick.focus();
	
	
	
	
}



function limitFieldChar(myfield, numletter){
	var myfieldlen = myfield.value.length;
	//alert('hey leng = '+myfieldlen+' vs max = '+numletter);
	if(myfieldlen > numletter){
		return false;	
		
	}else{
		return true;	
		
	}
	
	
}


function onlyNumbers(evt)
{
	alert('hey sonny');
	var e = event || evt; // for trans-browser compatibility
	var charCode = e.which || e.keyCode;

	if (charCode > 31 && (charCode < 48 || charCode > 57)){
		alert('not a number');
		return false;
	}else{
		alert(' number pressed');
		return true;
	}
}
	
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++;
	var oldTop = topIndex;
	//alert('moving div to cent = '+id+ ' and top index = '+topIndex);
	topIndex++;
	document.getElementById(id).style.zIndex = topIndex;
	
	//alert('moving div to cent = '+id+ ' and oldtp = '+oldTop+' and top index = '+topIndex);
	
	if((winOpened == "startNewItim")||(winOpened == "startNewItimIM")){
		
		//we don't wnat startnewitim to move to the middle
		//we want to stay where it is 	
		
	}else{
	
		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);
  }
}





//This captures key pressed events

function enterkeyPressHandler(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==13){
	 //alert("Enter pressed and kC = "+kC);
	 //document.loginForm.submit();
	 //document.forms['loginForm'].submit();
	 document.getElementById('loginForm').submit();
  }else{
	  //alert(" You pressed "+kC);
  }
}





function detectEnterButton(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;


// take enter button key is pressed
if (key==13) 
   return true;


else
   return false;
}




function writeDiv(divId, content){
	//alert(" wtiting 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){
				
				//alert("done = "+x.status);
				if(lostConnection == 1){
					disconnect_count++;
					resetRecon();
					lostConnection = 0;
					if(reconOn != 1){
						
						//alert("Server Connection Lost. Please Check your internet connection. Thanks ;)  "+x.status);
						var msg = '';
						showErrorAlert(msg);
						
						
					}
					startRecon();
				}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;
				
				//alert("hey done = "+x.responseText);
				lostConnection = 0;
				disconnect_count = 0;
				stopRecon();
				hideDiv('recon_top');
				closeErrorAlert();
				var tempoutputstr = x.responseText;
				var outputstrArr = tempoutputstr.split('&EOF');		//we need eof because responsetext adds spaces to the end
				var outputstr = escape(outputstrArr[0]);
				
				//it is important to urlencode
				
				
				
				//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+' and func = '+func);
				
				eval(func+"('"+outputstr+"');");
				
				//setTimeout('removeDiv(\'loadingX\')', 1000);
				//removeDiv('loadingX');
				//alert("eval dont con = "+func+"('"+outputstr+"');");
				
				//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));
	
}

// replaces strings
function searchAndReplace (string, searchfor, replacement)
{
    temparray = string.split(searchfor);
    newstring = temparray.join(replacement);
    return (newstring);
}


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 divExists = 0;
			
	//alert('about to cheeck for it now = '+allitimdiv);
	if(divIdExists(divId) == 1){
		var C_el = document.getElementById(divId);
		C_el.style.visibility = "hidden";
		
	}

	//var C_el = document.getElementById(divId);
	//C_el.style.visibility = "hidden";
	
	
}

function checkVisible(divId){
	
	var vis = 0;
	
	
	if(divIdExists(divId) == 1){
		
		if(document.getElementById(divId).style.visibility == "visible"){
			
			vis = 1;	
			
		}
		
	}
	//alert('vis = '+divId +' and vis = '+vis) ;
	
	
	return vis;	
	
}

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);
	}
	
}


var funcsloaded = 1;
