ADD_NEW_CONTACT_FLAG 	= "null";
ADD_NEW_CONTACT_CID  	= -1;
ADD_IN_PROGRESS = false;

flag_p1 = false;
flag_p2 = false;
FLAG_EDIT_MEETING	= false;
isEditUpdate		= false;

var flag_is_drag 	= false;
drag_id 		= "";

lc_history = "Историја на контакт";
if (document.getElementById("lang").value=="ENG")	{
	lc_history = "Prospect history";
}


function convert_titles(STR_OR)	{
		STR_OR = STR_OR.replace(/&title1;/g,"Контактот е маркиран како потенцијал за производи! Кликни за да го маркираш како контакт за бизнис");
		STR_OR = STR_OR.replace(/&title2;/g, "Контактот е маркиран како потенцијал за бизнис! Кликни за да го маркираш како неодреден");
		STR_OR = STR_OR.replace(/&title3;/g, "Кликни за да го маркираш како контакт за производи");
		STR_OR = STR_OR.replace(/&title4;/g, "Контактот е вклучен во вашиот список на чекање! Кликни за да го извадиш од списокот на чекање");
		STR_OR = STR_OR.replace(/&title5;/g, "Кликни за да го вклучиш во овој конаткт во списокот на чекање");
		STR_OR = STR_OR.replace(/&title6;/g, "Контактот е вклучен во вашиот тековен список! Кликни за да го исклучиш од тековниот список");
		STR_OR = STR_OR.replace(/&title7;/g, "Кликни за да го вклучиш овој контакт во тековниот список");
		STR_OR = STR_OR.replace(/&title8;/g, "Контактот ви е означен како контактиран! Кликни за да го маркираш како неконтактиран");
		STR_OR = STR_OR.replace(/&title9;/g, "Кликни за да го маркираш овој конакт како контактиран");
		STR_OR = STR_OR.replace(/&title10;/g, "Контактот е маркиран како контакт заинтересиран за соработка! Кликни за да го маркираш како моментално незаинтересиран за соработка (нареден клик го маркира контактот како дистрибутер)");
		STR_OR = STR_OR.replace(/&title11;/g, "Контактот е маркиран како незаинтересиран за соработка! Кликни за да го маркираш како дистрибутер (нареден клик го маркира контактот како неактивен дистрибутер)");
		STR_OR = STR_OR.replace(/&title12;/g, "Контактот е маркиран како дистрибутер! Кликни за да го маркираш како неактивен дистрибутер (нареден клик го маркира контактот како активен дистрибутер)");
		STR_OR = STR_OR.replace(/&title13;/g, "Кликни за да го маркираш како заинтересиран за соработка (нареден клик го маркира контактот како незаинтересиран за соработка)");
		STR_OR = STR_OR.replace(/&title14;/g, "Контактот ви е означен како активен дистрибутер! Кликни за да го маркираш како неактивен дистрибутер");
		STR_OR = STR_OR.replace(/&title15;/g, "Кликни за да го маркираш како активен дистрибутер");

return STR_OR;
}

function convert_str(STR_OR)	{


		STR_OR = STR_OR.replace(/&u0101;/g,"А");
		STR_OR = STR_OR.replace(/&u0102;/g,"Б");
		STR_OR = STR_OR.replace(/&u0103;/g,"В");
		STR_OR = STR_OR.replace(/&u0104;/g,"Г");
		STR_OR = STR_OR.replace(/&u0105;/g,"Д");
		STR_OR = STR_OR.replace(/&u0106;/g,"Ѓ");
		STR_OR = STR_OR.replace(/&u0107;/g,"Е");
		STR_OR = STR_OR.replace(/&u0108;/g,"Ж");
		STR_OR = STR_OR.replace(/&u0109;/g,"З");
		STR_OR = STR_OR.replace(/&u0110;/g,"Ѕ");
		STR_OR = STR_OR.replace(/&u0111;/g,"И");
		STR_OR = STR_OR.replace(/&u0112;/g,"Ј");
		STR_OR = STR_OR.replace(/&u0113;/g,"К");
		STR_OR = STR_OR.replace(/&u0114;/g,"Л");
		STR_OR = STR_OR.replace(/&u0115;/g,"Љ");
		STR_OR = STR_OR.replace(/&u0116;/g,"М");
		STR_OR = STR_OR.replace(/&u0117;/g,"Н");
		STR_OR = STR_OR.replace(/&u0118;/g,"Њ");
		STR_OR = STR_OR.replace(/&u0119;/g,"О");
		STR_OR = STR_OR.replace(/&u0120;/g,"П");
		STR_OR = STR_OR.replace(/&u0121;/g,"Р");
		STR_OR = STR_OR.replace(/&u0122;/g,"С");
		STR_OR = STR_OR.replace(/&u0123;/g,"Т");
		STR_OR = STR_OR.replace(/&u0124;/g,"Ќ");
		STR_OR = STR_OR.replace(/&u0125;/g,"У");
		STR_OR = STR_OR.replace(/&u0126;/g,"Ф");
		STR_OR = STR_OR.replace(/&u0127;/g,"Х");
		STR_OR = STR_OR.replace(/&u0128;/g,"Ц");
		STR_OR = STR_OR.replace(/&u0129;/g,"Ч");
		STR_OR = STR_OR.replace(/&u0130;/g,"Џ");
		STR_OR = STR_OR.replace(/&u0131;/g,"Ш");


		STR_OR = STR_OR.replace(/&u0001;/g,"а");
		STR_OR = STR_OR.replace(/&u0002;/g,"б");
		STR_OR = STR_OR.replace(/&u0003;/g,"в");
		STR_OR = STR_OR.replace(/&u0004;/g,"г");
		STR_OR = STR_OR.replace(/&u0005;/g,"д");
		STR_OR = STR_OR.replace(/&u0006;/g,"ѓ");
		STR_OR = STR_OR.replace(/&u0007;/g,"е");
		STR_OR = STR_OR.replace(/&u0008;/g,"ж");
		STR_OR = STR_OR.replace(/&u0009;/g,"з");
		STR_OR = STR_OR.replace(/&u0010;/g,"ѕ");
		STR_OR = STR_OR.replace(/&u0011;/g,"и");
		STR_OR = STR_OR.replace(/&u0012;/g,"ј");
		STR_OR = STR_OR.replace(/&u0013;/g,"к");
		STR_OR = STR_OR.replace(/&u0014;/g,"л");
		STR_OR = STR_OR.replace(/&u0015;/g,"љ");
		STR_OR = STR_OR.replace(/&u0016;/g,"м");
		STR_OR = STR_OR.replace(/&u0017;/g,"н");
		STR_OR = STR_OR.replace(/&u0018;/g,"њ");
		STR_OR = STR_OR.replace(/&u0019;/g,"о");
		STR_OR = STR_OR.replace(/&u0020;/g,"п");
		STR_OR = STR_OR.replace(/&u0021;/g,"р");
		STR_OR = STR_OR.replace(/&u0022;/g,"с");
		STR_OR = STR_OR.replace(/&u0023;/g,"т");
		STR_OR = STR_OR.replace(/&u0024;/g,"ќ");
		STR_OR = STR_OR.replace(/&u0025;/g,"у");
		STR_OR = STR_OR.replace(/&u0026;/g,"ф");
		STR_OR = STR_OR.replace(/&u0027;/g,"х");
		STR_OR = STR_OR.replace(/&u0028;/g,"ц");
		STR_OR = STR_OR.replace(/&u0029;/g,"ч");
		STR_OR = STR_OR.replace(/&u0030;/g,"џ");
		STR_OR = STR_OR.replace(/&u0031;/g,"ш");

/***************************RUSKI ZNACI************************************/

		STR_OR = STR_OR.replace(/&u0032;/g, "э");
		STR_OR = STR_OR.replace(/&u0132;/g, "Э");
		STR_OR = STR_OR.replace(/&u0033;/g, "я");
		STR_OR = STR_OR.replace(/&u0133;/g, "Я");
		STR_OR = STR_OR.replace(/&u0034;/g, "щ");
		STR_OR = STR_OR.replace(/&u0134;/g, "Щ");
		STR_OR = STR_OR.replace(/&u0035;/g, "ю");
		STR_OR = STR_OR.replace(/&u0135;/g, "Ю");
		STR_OR = STR_OR.replace(/&u0036;/g, "ы");
		STR_OR = STR_OR.replace(/&u0136;/g, "Ы");
		STR_OR = STR_OR.replace(/&u0037;/g, "ъ");
		STR_OR = STR_OR.replace(/&u0137;/g, "Ъ");
		STR_OR = STR_OR.replace(/&u0038;/g, "ь");
		STR_OR = STR_OR.replace(/&u0138;/g, "Ь");
		STR_OR = STR_OR.replace(/&u0039;/g, "й");
		STR_OR = STR_OR.replace(/&u0139;/g, "Й");
		STR_OR = STR_OR.replace(/&u0040;/g, "ё");
		STR_OR = STR_OR.replace(/&u0140;/g, "Ё");

/***************************RUSKI ZNACI************************************/


/************************SPECIJALNI ZNACI**********************************/

		STR_OR = STR_OR.replace(/&u1000;/g,"„");
		STR_OR = STR_OR.replace(/&u1001;/g,"“");
		STR_OR = STR_OR.replace(/&u1002;/g,"–");
		STR_OR = STR_OR.replace(/&u1003;/g,"…");
		STR_OR = STR_OR.replace(/&u1004;/g,"”");
		STR_OR = STR_OR.replace(/&u1005;/g,"•");
		STR_OR = STR_OR.replace(/&u1006;/g,"’");
		STR_OR = STR_OR.replace(/&u1007;/g,"«");
		STR_OR = STR_OR.replace(/&u1008;/g,"»");

/************************SPECIJALNI ZNACI**********************************/

return STR_OR;

}

function lc_convert_str(STR_OR)	{


		STR_OR = STR_OR.replace(/&u0101;/g,"А");
		STR_OR = STR_OR.replace(/&u0102;/g,"Б");
		STR_OR = STR_OR.replace(/&u0103;/g,"В");
		STR_OR = STR_OR.replace(/&u0104;/g,"Г");
		STR_OR = STR_OR.replace(/&u0105;/g,"Д");
		STR_OR = STR_OR.replace(/&u0106;/g,"Ѓ");
		STR_OR = STR_OR.replace(/&u0107;/g,"Е");
		STR_OR = STR_OR.replace(/&u0108;/g,"Ж");
		STR_OR = STR_OR.replace(/&u0109;/g,"З");
		STR_OR = STR_OR.replace(/&u0110;/g,"Ѕ");
		STR_OR = STR_OR.replace(/&u0111;/g,"И");
		STR_OR = STR_OR.replace(/&u0112;/g,"Ј");
		STR_OR = STR_OR.replace(/&u0113;/g,"К");
		STR_OR = STR_OR.replace(/&u0114;/g,"Л");
		STR_OR = STR_OR.replace(/&u0115;/g,"Љ");
		STR_OR = STR_OR.replace(/&u0116;/g,"М");
		STR_OR = STR_OR.replace(/&u0117;/g,"Н");
		STR_OR = STR_OR.replace(/&u0118;/g,"Њ");
		STR_OR = STR_OR.replace(/&u0119;/g,"О");
		STR_OR = STR_OR.replace(/&u0120;/g,"П");
		STR_OR = STR_OR.replace(/&u0121;/g,"Р");
		STR_OR = STR_OR.replace(/&u0122;/g,"С");
		STR_OR = STR_OR.replace(/&u0123;/g,"Т");
		STR_OR = STR_OR.replace(/&u0124;/g,"Ќ");
		STR_OR = STR_OR.replace(/&u0125;/g,"У");
		STR_OR = STR_OR.replace(/&u0126;/g,"Ф");
		STR_OR = STR_OR.replace(/&u0127;/g,"Х");
		STR_OR = STR_OR.replace(/&u0128;/g,"Ц");
		STR_OR = STR_OR.replace(/&u0129;/g,"Ч");
		STR_OR = STR_OR.replace(/&u0130;/g,"Џ");
		STR_OR = STR_OR.replace(/&u0131;/g,"Ш");


		STR_OR = STR_OR.replace(/&u0001;/g,"а");
		STR_OR = STR_OR.replace(/&u0002;/g,"б");
		STR_OR = STR_OR.replace(/&u0003;/g,"в");
		STR_OR = STR_OR.replace(/&u0004;/g,"г");
		STR_OR = STR_OR.replace(/&u0005;/g,"д");
		STR_OR = STR_OR.replace(/&u0006;/g,"ѓ");
		STR_OR = STR_OR.replace(/&u0007;/g,"е");
		STR_OR = STR_OR.replace(/&u0008;/g,"ж");
		STR_OR = STR_OR.replace(/&u0009;/g,"з");
		STR_OR = STR_OR.replace(/&u0010;/g,"ѕ");
		STR_OR = STR_OR.replace(/&u0011;/g,"и");
		STR_OR = STR_OR.replace(/&u0012;/g,"ј");
		STR_OR = STR_OR.replace(/&u0013;/g,"к");
		STR_OR = STR_OR.replace(/&u0014;/g,"л");
		STR_OR = STR_OR.replace(/&u0015;/g,"љ");
		STR_OR = STR_OR.replace(/&u0016;/g,"м");
		STR_OR = STR_OR.replace(/&u0017;/g,"н");
		STR_OR = STR_OR.replace(/&u0018;/g,"њ");
		STR_OR = STR_OR.replace(/&u0019;/g,"о");
		STR_OR = STR_OR.replace(/&u0020;/g,"п");
		STR_OR = STR_OR.replace(/&u0021;/g,"р");
		STR_OR = STR_OR.replace(/&u0022;/g,"с");
		STR_OR = STR_OR.replace(/&u0023;/g,"т");
		STR_OR = STR_OR.replace(/&u0024;/g,"ќ");
		STR_OR = STR_OR.replace(/&u0025;/g,"у");
		STR_OR = STR_OR.replace(/&u0026;/g,"ф");
		STR_OR = STR_OR.replace(/&u0027;/g,"х");
		STR_OR = STR_OR.replace(/&u0028;/g,"ц");
		STR_OR = STR_OR.replace(/&u0029;/g,"ч");
		STR_OR = STR_OR.replace(/&u0030;/g,"џ");
		STR_OR = STR_OR.replace(/&u0031;/g,"ш");

/***************************RUSKI ZNACI************************************/

		STR_OR = STR_OR.replace(/&u0032;/g, "э");
		STR_OR = STR_OR.replace(/&u0132;/g, "Э");
		STR_OR = STR_OR.replace(/&u0033;/g, "я");
		STR_OR = STR_OR.replace(/&u0133;/g, "Я");
		STR_OR = STR_OR.replace(/&u0034;/g, "щ");
		STR_OR = STR_OR.replace(/&u0134;/g, "Щ");
		STR_OR = STR_OR.replace(/&u0035;/g, "ю");
		STR_OR = STR_OR.replace(/&u0135;/g, "Ю");
		STR_OR = STR_OR.replace(/&u0036;/g, "ы");
		STR_OR = STR_OR.replace(/&u0136;/g, "Ы");
		STR_OR = STR_OR.replace(/&u0037;/g, "ъ");
		STR_OR = STR_OR.replace(/&u0137;/g, "Ъ");
		STR_OR = STR_OR.replace(/&u0038;/g, "ь");
		STR_OR = STR_OR.replace(/&u0138;/g, "Ь");
		STR_OR = STR_OR.replace(/&u0039;/g, "й");
		STR_OR = STR_OR.replace(/&u0139;/g, "Й");
		STR_OR = STR_OR.replace(/&u0040;/g, "ё");
		STR_OR = STR_OR.replace(/&u0140;/g, "Ё");

/***************************RUSKI ZNACI************************************/


/************************SPECIJALNI ZNACI**********************************/

		STR_OR = STR_OR.replace(/&u1000;/g,"„");
		STR_OR = STR_OR.replace(/&u1001;/g,"“");
		STR_OR = STR_OR.replace(/&u1002;/g,"–");
		STR_OR = STR_OR.replace(/&u1003;/g,"…");
		STR_OR = STR_OR.replace(/&u1004;/g,"”");
		STR_OR = STR_OR.replace(/&u1005;/g,"•");
		STR_OR = STR_OR.replace(/&u1006;/g,"’");
		STR_OR = STR_OR.replace(/&u1007;/g,"«");
		STR_OR = STR_OR.replace(/&u1008;/g,"»");

/************************SPECIJALNI ZNACI**********************************/

return STR_OR;

}

function convert_str2(STR_OR, what)	{

		STR_OR = STR_OR.replace("А" , "&u0101;");
		STR_OR = STR_OR.replace("Б" , "&u0102;");
		STR_OR = STR_OR.replace("В" , "&u0103;");
		STR_OR = STR_OR.replace("Г" , "&u0104;");
		STR_OR = STR_OR.replace("Д" , "&u0105;");
		STR_OR = STR_OR.replace("Ѓ" , "&u0106;");
		STR_OR = STR_OR.replace("Е" , "&u0107;");
		STR_OR = STR_OR.replace("Ж" , "&u0108;");
		STR_OR = STR_OR.replace("З" , "&u0109;");
		STR_OR = STR_OR.replace("Ѕ" , "&u0110;");
		STR_OR = STR_OR.replace("И" , "&u0111;");
		STR_OR = STR_OR.replace("Ј" , "&u0112;");
		STR_OR = STR_OR.replace("К" , "&u0113;");
		STR_OR = STR_OR.replace("Л" , "&u0114;");
		STR_OR = STR_OR.replace("Љ" , "&u0115;");
		STR_OR = STR_OR.replace("М" , "&u0116;");
		STR_OR = STR_OR.replace("Н" , "&u0117;");
		STR_OR = STR_OR.replace("Њ" , "&u0118;");
		STR_OR = STR_OR.replace("О" , "&u0119;");
		STR_OR = STR_OR.replace("П" , "&u0120;");
		STR_OR = STR_OR.replace("Р" , "&u0121;");
		STR_OR = STR_OR.replace("С" , "&u0122;");
		STR_OR = STR_OR.replace("Т" , "&u0123;");
		STR_OR = STR_OR.replace("Ќ" , "&u0124;");
		STR_OR = STR_OR.replace("У" , "&u0125;");
		STR_OR = STR_OR.replace("Ф" , "&u0126;");
		STR_OR = STR_OR.replace("Х" , "&u0127;");
		STR_OR = STR_OR.replace("Ц" , "&u0128;");
		STR_OR = STR_OR.replace("Ч" , "&u0129;");
		STR_OR = STR_OR.replace("Џ" , "&u0130;");
		STR_OR = STR_OR.replace("Ш" , "&u0131;");


		STR_OR = STR_OR.replace("а" , "&u0001;");
		STR_OR = STR_OR.replace("б" , "&u0002;");
		STR_OR = STR_OR.replace("в" , "&u0003;");
		STR_OR = STR_OR.replace("г" , "&u0004;");
		STR_OR = STR_OR.replace("д" , "&u0005;");
		STR_OR = STR_OR.replace("ѓ" , "&u0006;");
		STR_OR = STR_OR.replace("е" , "&u0007;");
		STR_OR = STR_OR.replace("ж" , "&u0008;");
		STR_OR = STR_OR.replace("з" , "&u0009;");
		STR_OR = STR_OR.replace("ѕ" , "&u0010;");
		STR_OR = STR_OR.replace("и" , "&u0011;");
		STR_OR = STR_OR.replace("ј" , "&u0012;");
		STR_OR = STR_OR.replace("к" , "&u0013;");
		STR_OR = STR_OR.replace("л" , "&u0014;");
		STR_OR = STR_OR.replace("љ" , "&u0015;");
		STR_OR = STR_OR.replace("м" , "&u0016;");
		STR_OR = STR_OR.replace("н" , "&u0017;");
		STR_OR = STR_OR.replace("њ" , "&u0018;");
		STR_OR = STR_OR.replace("о" , "&u0019;");
		STR_OR = STR_OR.replace("п" , "&u0020;");
		STR_OR = STR_OR.replace("р" , "&u0021;");
		STR_OR = STR_OR.replace("с" , "&u0022;");
		STR_OR = STR_OR.replace("т" , "&u0023;");
		STR_OR = STR_OR.replace("ќ" , "&u0024;");
		STR_OR = STR_OR.replace("у" , "&u0025;");
		STR_OR = STR_OR.replace("ф" , "&u0026;");
		STR_OR = STR_OR.replace("х" , "&u0027;");
		STR_OR = STR_OR.replace("ц" , "&u0028;");
		STR_OR = STR_OR.replace("ч" , "&u0029;");
		STR_OR = STR_OR.replace("џ" , "&u0030;");
		STR_OR = STR_OR.replace("ш" , "&u0031;");

		STR_OR = STR_OR.replace("„" , "&u1000;");
		STR_OR = STR_OR.replace("“" , "&u1001;");
		STR_OR = STR_OR.replace("–" , "&u1002;");
		STR_OR = STR_OR.replace("…" , "&u1003;");
		STR_OR = STR_OR.replace("”" , "&u1004;");
		STR_OR = STR_OR.replace("•" , "&u1005;");
		STR_OR = STR_OR.replace("’" , "&u1006;");

return STR_OR;

}

function convertChar(STR_OR)	{
	var new_Str = "";
	for (i=0; i<STR_OR.length;i++)	{
		new_Str += convert_str3(STR_OR.charAt(i));
	}
	
return new_Str;
}
function convert_str3(STR_OR, what)	{

		STR_OR = STR_OR.replace("А" , "%C0");
		STR_OR = STR_OR.replace("Б" , "%C1");
		STR_OR = STR_OR.replace("В" , "%C2");
		STR_OR = STR_OR.replace("Г" , "%C3");
		STR_OR = STR_OR.replace("Д" , "%C4");
		STR_OR = STR_OR.replace("Ѓ" , "%81");
		STR_OR = STR_OR.replace("Е" , "%C5");
		STR_OR = STR_OR.replace("Ж" , "%C6");
		STR_OR = STR_OR.replace("З" , "%C7");
		STR_OR = STR_OR.replace("Ѕ" , "%BD");
		STR_OR = STR_OR.replace("И" , "%C8");
		STR_OR = STR_OR.replace("Ј" , "%A3");
		STR_OR = STR_OR.replace("К" , "%CA");
		STR_OR = STR_OR.replace("Л" , "%CB");
		STR_OR = STR_OR.replace("Љ" , "%8A");
		STR_OR = STR_OR.replace("М" , "%CC");
		STR_OR = STR_OR.replace("Н" , "%CD");
		STR_OR = STR_OR.replace("Њ" , "%8C");
		STR_OR = STR_OR.replace("О" , "%CE");
		STR_OR = STR_OR.replace("П" , "%CF");
		STR_OR = STR_OR.replace("Р" , "%D0");
		STR_OR = STR_OR.replace("С" , "%D1");
		STR_OR = STR_OR.replace("Т" , "%D2");
		STR_OR = STR_OR.replace("Ќ" , "%8D");
		STR_OR = STR_OR.replace("У" , "%D3");
		STR_OR = STR_OR.replace("Ф" , "%D4");
		STR_OR = STR_OR.replace("Х" , "%D5");
		STR_OR = STR_OR.replace("Ц" , "%D6");
		STR_OR = STR_OR.replace("Ч" , "%D7");
		STR_OR = STR_OR.replace("Џ" , "%8F");
		STR_OR = STR_OR.replace("Ш" , "%D8");


		STR_OR = STR_OR.replace("а" , "%E0");
		STR_OR = STR_OR.replace("б" , "%E1");
		STR_OR = STR_OR.replace("в" , "%E2");
		STR_OR = STR_OR.replace("г" , "%E3");
		STR_OR = STR_OR.replace("д" , "%E4");
		STR_OR = STR_OR.replace("ѓ" , "%83");
		STR_OR = STR_OR.replace("е" , "%E5");
		STR_OR = STR_OR.replace("ж" , "%E6");
		STR_OR = STR_OR.replace("з" , "%E7");
		STR_OR = STR_OR.replace("ѕ" , "%BE");
		STR_OR = STR_OR.replace("и" , "%E8");
		STR_OR = STR_OR.replace("ј" , "%BC");
		STR_OR = STR_OR.replace("к" , "%EA");
		STR_OR = STR_OR.replace("л" , "%EB");
		STR_OR = STR_OR.replace("љ" , "%9A");
		STR_OR = STR_OR.replace("м" , "%EC");
		STR_OR = STR_OR.replace("н" , "%ED");
		STR_OR = STR_OR.replace("њ" , "%9C");
		STR_OR = STR_OR.replace("о" , "%EE");
		STR_OR = STR_OR.replace("п" , "%EF");
		STR_OR = STR_OR.replace("р" , "%F0");
		STR_OR = STR_OR.replace("с" , "%F1");
		STR_OR = STR_OR.replace("т" , "%F2");
		STR_OR = STR_OR.replace("ќ" , "%9D");
		STR_OR = STR_OR.replace("у" , "%F3");
		STR_OR = STR_OR.replace("ф" , "%F4");
		STR_OR = STR_OR.replace("х" , "%F5");
		STR_OR = STR_OR.replace("ц" , "%F6");
		STR_OR = STR_OR.replace("ч" , "%F7");
		STR_OR = STR_OR.replace("џ" , "%9F");
		STR_OR = STR_OR.replace("ш" , "%F8");

		STR_OR = STR_OR.replace(" " , "%20");

		STR_OR = STR_OR.replace("„" , "&u1000;");
		STR_OR = STR_OR.replace("“" , "&u1001;");
		STR_OR = STR_OR.replace("–" , "&u1002;");
		STR_OR = STR_OR.replace("…" , "&u1003;");
		STR_OR = STR_OR.replace("”" , "&u1004;");
		STR_OR = STR_OR.replace("•" , "&u1005;");
		STR_OR = STR_OR.replace("’" , "&u1006;");

return STR_OR;

}


function LoadCont(WHO,WHICH)
{



var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {

	var STR = xmlHttp.responseText;

	


	if (WHICH==34 || WHICH==36 || WHICH==37 || WHICH=="sort_contacts" || WHICH=="sort_contacts_temp")	{
//alert("Loaded");
		STR_OR = convert_str(STR);
		if (STR_OR=="expire") window.location = "/login.asp?S=exp";

		STR_OR = convert_titles(STR_OR);
		TDISP = document.getElementById("TD_DISP");
		TDISP.innerHTML=STR_OR;
//		if (WHICH=="sort_contacts")		TDISP.innerText=TDISP.innerText + STR_OR;
		if (document.getElementById("DIV_CONT"))	{
			DC = document.getElementById("DIV_CONT");
			DC.style.backgroundColor = "";
	}
	}

	if (WHICH=="sort_by_name" || WHICH=="sort_by_name_temp")	{
		STR_OR = convert_str(STR);
		if (STR_OR=="expire") window.location = "/login.asp?S=exp";
		TDISP = document.getElementById("r_contacts");
		TDISP.innerHTML=STR_OR;
//		if (document.getElementById("DIV_CONT"))	{
//			DC = document.getElementById("DIV_CONT");
//			DC.style.backgroundColor = "";
//	}
	}


	if (WHICH=="view_card")	{
		STR_OR = convert_str(STR);
		//STR_OR = STR;
		var SRES = STR_OR.split("~");
		sb = document.getElementById("show_busy");
		sb.style.display = "none";
		if(STR_OR=="NO_EXIST")	{
			document.getElementByID("show_message").style.display = "inline";
		}
		else			{
//alert(convert_str(SRES[0]));
		document.getElementById("fname_c").value = lc_convert_str(SRES[0]);
//		document.getElementById("fname_c").value = lc_convert_str(SRES[0]);
		document.getElementById("tl1").value = SRES[1];
		document.getElementById("tl2").value = SRES[2];
		document.getElementById("em_c").value = lc_convert_str(SRES[3]);
		document.getElementById("cm_c").value = lc_convert_str(SRES[4]);
		document.getElementById("ad_c").value = lc_convert_str(SRES[5]);
		document.getElementById("pl_c").value = lc_convert_str(SRES[6]);
		source_of_contact		      = SRES[7];
		if(source_of_contact>=1 && source_of_contact<=6)
			document.getElementById("cl"+source_of_contact).checked = true;
		document.getElementById("how_c").value = lc_convert_str(SRES[8]);
		document.getElementById("why_c").value = lc_convert_str(SRES[9]);
		document.getElementById("start_c").value = lc_convert_str(SRES[11]);
		

		vc = document.getElementById("view_card");
		vc.style.display = "inline";
		LoadCont(ACTIVE_CONTACT,'retreive_history');
		LoadCont(ACTIVE_CONTACT,'retreive_steps');
		}
		
	}
	if (WHICH=="change_contact_values")	{
		STR_OR = convert_str(STR);
		var SRES = STR_OR.split("~");
		document.getElementById("show_busy").style.display = "none";
		if(STR_OR=="NO_EXIST")	{
			document.getElementById("show_message").style.display = "inline";
		}
		
	}


	if(WHICH=="search_contact")	{
		STR_OR = convert_str(STR);
		sc = document.getElementById("search_contact");
		sc.style.backgroundColor = "#c3d69b";
		sc.style.borderWidth= "1px";


		if(STR_OR!="^")			ListObj.IsList = true;
		else				cancelList();


		var RET_VALS = STR_OR.split("^");
		var RS = RET_VALS[0].split("~");
		var RI = RET_VALS[1].split("~");
		ListObj.IDList = RI;
		ListObj.nodeCount = RS.length-1;
		var i=0;
		var ihtml= "";
		ihtml = "<table width=160px>";
		while(i<RS.length-1)	{
			ihtml += "<tr><td id=\"td"+i+"\">"+ RS[i] + "</td></tr>";
			i++;
		}
		ihtml += "</table>";
		sc.innerHTML = ihtml;

	}


	if(WHICH=="set_attribute")		{
		arrWho = WHO.split(",");
		attrib	= arrWho[0];
		status	= arrWho[1];
		row_id	= arrWho[3];
//		attrib 	= attrib+row_id;

		aWho = document.getElementById(attrib+row_id);

		if ("interes"==attrib) {
			if(status=="1")	
				aWho.innerHTML = "<img style=\"cursor: pointer;\" src=\"/images/attributes/interes_products.jpg\"  title=\"Кликни за да го маркираш како контакт за бизнис\" onclick=\"LoadCont( 'interes,2,"+ arrWho[2] +","+ arrWho[3] +"', 'set_attribute');\">";
			else if (status=="2") 
				aWho.innerHTML = "<img style=\"cursor: pointer;\" src=\"/images/attributes/interes_business.jpg\"  title=\"Кликни за да го маркираш како неодреден\" onclick=\"LoadCont( 'interes,0,"+ arrWho[2] +","+ arrWho[3] +"', 'set_attribute');\">";
			else
				aWho.innerHTML = "<img style=\"cursor: pointer;\" src=\"/images/attributes/interes_inactive.jpg\"  title=\"Кликни за да го маркираш како контакт за производи\" onclick=\"LoadCont( 'interes,1,"+ arrWho[2] +","+ arrWho[3] +"', 'set_attribute');\">";
		}

		if ("waiting"==attrib) {
			if(status=="1")	
				aWho.innerHTML = "<img style=\"cursor: pointer;\" src=\"/images/attributes/waiting.jpg\"  title=\"Кликни за да го извадиш од списокот на чекање\" onclick=\"LoadCont( 'waiting,0,"+ arrWho[2] +","+ arrWho[3] +"', 'set_attribute');\">";
			else
				aWho.innerHTML = "<img style=\"cursor: pointer;\" src=\"/images/attributes/waiting_inactive.jpg\"  title=\"Кликни за да го вклучиш во списокот на чекање\" onclick=\"LoadCont( 'waiting,1,"+ arrWho[2] +","+ arrWho[3] +"', 'set_attribute');\">";

		}
		if ("current"==attrib) {
			if(status=="1")	
				aWho.innerHTML = "<img style=\"cursor: pointer;\" src=\"/images/attributes/current.jpg\"  title=\"Кликни за да го исклучиш од тековниот список\" onclick=\"LoadCont( 'current,0,"+ arrWho[2] +","+ arrWho[3] +"', 'set_attribute');\">";
			else
				aWho.innerHTML = "<img style=\"cursor: pointer;\" src=\"/images/attributes/current_inactive.jpg\"  title=\"Кликни за да го вклучиш во тековниот список\" onclick=\"LoadCont( 'current,1,"+ arrWho[2] +","+ arrWho[3] +"', 'set_attribute');\">";

		}
		if ("contacted"==attrib) {
			if(status=="1")	
				aWho.innerHTML = "<img style=\"cursor: pointer;\" src=\"/images/attributes/telephone.jpg\"  title=\"Кликни за да го маркираш како неконтактиран\" onclick=\"LoadCont( 'contacted,0,"+ arrWho[2] +","+ arrWho[3] +"', 'set_attribute');\">";
			else
				aWho.innerHTML = "<img style=\"cursor: pointer;\" src=\"/images/attributes/telephone_inactive.jpg\"  title=\"Кликни за да го маркираш како контактиран\" onclick=\"LoadCont( 'contacted,1,"+ arrWho[2] +","+ arrWho[3] +"', 'set_attribute');\">";

		}
		if ("active"==attrib) {
			if(status=="1")	
				aWho.innerHTML = "<img style=\"cursor: pointer;\" src=\"/images/attributes/active.jpg\"  title=\"Контактот ви е означен како активен дистрибутер! Кликни за да го маркираш како неактивен дистрибутер\" onclick=\"LoadCont( 'active,0,"+ arrWho[2] +","+ arrWho[3] +"', 'set_attribute');\">";
			else
				aWho.innerHTML = "<img style=\"cursor: pointer;\" src=\"/images/attributes/active_inactive.jpg\"  title=\"Кликни за да го маркираш како активен дистрибутер\" onclick=\"LoadCont( 'active,1,"+ arrWho[2] +","+ arrWho[3] +"', 'set_attribute');\">";

		}
		if ("status"==attrib) {
			if(status=="1")	
				aWho.innerHTML = "<img style=\"cursor: pointer;\" src=\"/images/attributes/interested.jpg\"  title=\"Контактот е маркиран како контакт заинтересиран за соработка! Кликни за да го маркираш како моментално незаинтересиран за соработка (нареден клик го маркира контактот како дистрибутер)\" onclick=\"LoadCont( 'status,2,"+ arrWho[2] +","+ arrWho[3] +"', 'set_attribute');\">";
			else if (status=="2") 
				aWho.innerHTML = "<img style=\"cursor: pointer;\" src=\"/images/attributes/uninterested.jpg\"  title=\"Контактот е маркиран како незаинтересиран за соработка! Кликни за да го маркираш како дистрибутер (нареден клик го маркира контактот како неактивен дистрибутер)\" onclick=\"LoadCont( 'status,3,"+ arrWho[2] +","+ arrWho[3] +"', 'set_attribute');\">";
			else if (status=="3") 
				aWho.innerHTML = "<img style=\"cursor: pointer;\" src=\"/images/attributes/distributor.jpg\"  title=\"Контактот е маркиран како дистрибутер! Кликни за да го маркираш како неактивен дистрибутер (нареден клик го маркира контактот како активен дистрибутер)\" onclick=\"LoadCont( 'status,0,"+ arrWho[2] +","+ arrWho[3] +"', 'set_attribute');\">";
			else
				aWho.innerHTML = "<img style=\"cursor: pointer;\" src=\"/images/attributes/distributor_inactive.jpg\"  title=\"Кликни за да го маркираш како заинтересиран за соработка (нареден клик го маркира контактот како незаинтересиран за соработка)\" onclick=\"LoadCont( 'status,1,"+ arrWho[2] +","+ arrWho[3] +"', 'set_attribute');\">";
		}

	}



	if (WHICH=="retreive_history")			{
		STR_OR = lc_convert_str(STR);
		cd = document.getElementById("chistory_div");
		chistory_div.innerHTML = STR_OR;
	}

	if (WHICH=="add_chistory")	{
		STR_OR = convert_str(STR);
		if(STR_OR!="OK")		alert(STR_OR);
	}
	if (WHICH=="ch_result")	{
		STR_OR = convert_str(STR);
		if(STR_OR!="OK")		alert(STR_OR);
		document.getElementById("ch_buttons").innerHTML = CHB_CONT;
	}
	if (WHICH=="retreive_steps")			{
		STR_OR = lc_convert_str(STR);
		document.getElementById("steps_div").innerHTML = STR_OR;
//		wURL = "/signin/contact_list/retreive_steps.asp?WHO="+ ACTIVE_CONTACT
	}
	if (WHICH=="set_next_step")			{
		STR_OR = lc_convert_str(STR);
		document.getElementById("steps_div").innerHTML = STR_OR;
//		wURL = "/signin/contact_list/retreive_steps.asp?WHO="+ ACTIVE_CONTACT
	}

      }
    }
	var sWHO = WHO.toString();



	sWHO = sWHO.substr(1,sWHO.length);


	if (WHICH==34)			{
		wURL = "/sign_in/contact_list/list_of_contacts.asp";
	}

	if (WHICH==36)	{
		n = document.getElementById("fulln");
		t = document.getElementById("tel");
		m = document.getElementById("email");
		c = document.getElementById("comment");
		if (WHO=="add")		{
			wURL = "/signin/contact_list/add_new_contact.asp?N="+n.value+"&T="+t.value+"&M="+m.value+"&C="+c.value;
			OnTCANCEL();
		}
		else if(WHO=="load")	{
			wURL = "/signin/contact_list/list_of_contacts.asp";
		}
		else
			wURL = "/signin/contact_list/update_contact.asp?N="+n.value+"&T="+t.value+"&M="+m.value+"&C="+c.value+"&CID="+WHO;
	}

	if (WHICH==37)	{
		n = document.getElementById("fulln");
		t = document.getElementById("tel");
		m = document.getElementById("email");
		c = document.getElementById("comment");
		if (WHO=="add")		{
			wURL = "/signin/contact_list/add_new_contact.asp?N="+n.value+"&T="+t.value+"&M="+m.value+"&C="+c.value;
			OnTCANCEL();
		}
		else if(WHO=="load")	{
			wURL = "/signin/contact_list/list_of_contacts_new.asp";
		}
		else
			wURL = "/signin/contact_list/update_contact.asp?N="+n.value+"&T="+t.value+"&M="+m.value+"&C="+c.value+"&CID="+WHO;
	}

	if (WHICH=="view_card")	{
		com= document.getElementById("show_busy");
		document.getElementById("d1").style.display = "block";
		com.style.display= "inline";
		ACTIVE_CONTACT = WHO;
		wURL = "/signin/contact_list/retreive_card.asp?WHO="+WHO;
	}
	if (WHICH=="change_contact_values")	{
		com= document.getElementById("show_busy");
		vc = document.getElementById("view_card");
		com.style.display= "inline";
		vc.style.display = "none";
		who =  ACTIVE_CONTACT+"~";
		who += convert_str3(document.getElementById("fname_c").value) + "~";
		who += convert_str3(document.getElementById("tl1").value)  + "~";
		who += convert_str3(document.getElementById("tl2").value)  + "~";
		who += convert_str3(document.getElementById("em_c").value)  + "~";
		who += convert_str3(document.getElementById("cm_c").value)  + "~";
		who += convert_str3(document.getElementById("ad_c").value)  + "~";
		who += convert_str3(document.getElementById("pl_c").value)  + "~";

		isw=true;
		if(document.getElementById("cl1").checked)	{	who += "1" + "~"; isw = false;	}
		if(document.getElementById("cl2").checked)	{	who += "2" + "~"; isw = false;	}
		if(document.getElementById("cl3").checked)	{	who += "3" + "~"; isw = false;	}
		if(document.getElementById("cl4").checked)	{	who += "4" + "~"; isw = false;	}
		if(document.getElementById("cl5").checked)	{	who += "5" + "~"; isw = false;	}
		if(document.getElementById("cl6").checked)	{	who += "6" + "~"; isw = false;	}
		if(isw)	who+="~";

		who += convert_str3(document.getElementById("how_c").value)  + "~";
		who += convert_str3(document.getElementById("why_c").value)  + "~";
		who += convert_str3(document.getElementById("start_c").value);


		document.getElementById("n"+ACTIVE_CONTACT_NUM).innerHTML = "<font color=orange size=2 face=arial>"+ document.getElementById("fname_c").value +"</font>";
		document.getElementById("t"+ACTIVE_CONTACT_NUM).innerHTML = "<font color=orange size=2 face=arial>"+ document.getElementById("tl1").value +"</font>";
		document.getElementById("m"+ACTIVE_CONTACT_NUM).innerHTML = "<font color=orange size=2 face=arial>"+ document.getElementById("em_c").value +"</font>";
//		document.getElementById("c"+ACTIVE_CONTACT_NUM).innerHTML = "<font color=orange size=2 face=arial>"+ document.getElementById("cm_c").value +"</font>";

		wURL = "/signin/contact_list/write_card.asp?WHO="+who;
	}


	if(WHICH=="search_contact")	{
		st = document.getElementById("search_term");
		wURL = "/signin/contact_list/search_contact.asp?st="+st.value;
	}



	if(WHICH=="set_attribute")		{
		wURL = "/signin/contact_list/set_attribute.asp?who="+WHO+"&rnd="+randomString();
	}
	if(WHICH=="sort_contacts")		{
		wURL = "/signin/contact_list/list_of_contacts.asp?"+WHO+"=1"+"&rnd="+randomString();
	}
	if(WHICH=="sort_contacts_temp")		{
		wURL = "/signin/contact_list/list_of_contacts_new.asp?"+WHO+"=1"+"&rnd="+randomString();
	}

	if(WHICH=="sort_by_name"){
		wURL = "/signin/contact_list/retreive_contacts.asp?name="+ document.getElementById("search_term").value;
	}
	if(WHICH=="sort_by_name_temp"){
		wURL = "/signin/contact_list/retreive_contacts_temp.asp?name="+ document.getElementById("search_term").value;
	}


	if (WHICH=="retreive_history")			{
		wURL = "/signin/contact_list/retreive_history.asp?WHO="+ ACTIVE_CONTACT
	}
	if (WHICH=="add_chistory")	{
		cc = document.getElementById("chistory_content");
		cd = document.getElementById("chistory_div");
		var d = new Date();
		m = d.getMonth();
		m = "0"+m;
		m = m.substr(m.length-2,2);
		day = d.getDate();
		day = "0"+day;
		day = day.substr(day.length-2,2);
		h = d.getHours();
		h = "0"+h;
		h = h.substr(d.length-2,2);
		min = d.getMinutes();
		min = "0"+min;
		min = min.substr(min.length-2,2);
		s = d.getSeconds();
		s = "0"+s;
		s = s.substr(s.length-2,2);

		cd.innerHTML = cd.innerHTML +"<table cellpadding=4><tr><td style=\"width: 100px; color: #eb7f00; font-family: arial; font-size: 12px;\" valign=top><b>"+ day +"."+ m +"."+ d.getFullYear() +"</b> <font color=black ><i>"+ h +":"+ min +":</i></td><td style=\"color: black; font-size: 11; font-family: tahoma;\">"+ cc.value +"</td></tr></table>";
		wURL = "/signin/contact_list/add_history.asp?WHO="+ ACTIVE_CONTACT +"&type="+ WHO +"&value="+ cc.value +"&d="+ d.getFullYear() +"-"+ m +"-"+ day +" "+ h +":"+ min +":"+ s +".000";
		document.getElementById("chistory_content").value = "";
	}
	if (WHICH == "ch_result")	{
		cc = document.getElementById("chistory_content");
		cd = document.getElementById("result"+WHO);
		var d = new Date();
		m = d.getMonth();
		m = "0"+m;
		m = m.substr(m.length-2,2);
		day = d.getDate();
		day = "0"+day;
		day = day.substr(day.length-2,2);
		h = d.getHours();
		h = "0"+h;
		h = h.substr(d.length-2,2);
		min = d.getMinutes();
		min = "0"+min;
		min = min.substr(min.length-2,2);
		s = d.getSeconds();
		s = "0"+s;
		s = s.substr(s.length-2,2);

		cd.innerHTML = "<table style=\"margin-left: 40px; margin-top: 2px; margin-bottom: 5px;\"><tr><td vailgn=top style=\"color: orange; font-size: 13px;\">R</td><td style=\"border-left: 1px solid #bcbcbc; font-size: 12px; font-family: Times New Roman; color: black;\"><i>"+ cc.value +"</i></td></tr></table>";
		wURL = "/signin/contact_list/add_result.asp?WHO="+ WHO +"&value="+ cc.value +"&d="+ d.getFullYear() +"-"+ m +"-"+ day +" "+ h +":"+ min +":"+ s +".000";

		document.getElementById("chistory_content").value = "";

	}

	if (WHICH=="retreive_steps")			{
		wURL = "/signin/contact_list/retreive_steps.asp?WHO="+ ACTIVE_CONTACT;
	}
	if (WHICH=="set_next_step")			{
		wURL = "/signin/contact_list/retreive_steps.asp?WHO="+ ACTIVE_CONTACT + "&set_next_step=yes";
	}




  xmlHttp.open("GET", wURL,true);
  xmlHttp.send(null);

  }

var tid=0;

function sort_by_name()	{
	if(tid!=0)	clearTimeout ( tid );

	tid = setTimeout ( "LoadCont('','sort_by_name')", 400 );
}

function sort_by_name_temp()	{
	if(tid!=0)	clearTimeout ( tid );

	tid = setTimeout ( "LoadCont('','sort_by_name_temp')", 400 );
}

function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}



function ADD_CONTACT_VALUES()		{
	document.getElementById("fulln").value 	= document.getElementById("fname").value;
	document.getElementById("tel").value 	= document.getElementById("tl").value;
	document.getElementById("email").value 	= document.getElementById("em").value;
	document.getElementById("comment").value= document.getElementById("cm").value;

	LoadCont("add",36);
}

function OnTEUPDATE()			{
	document.getElementById("fulln").value 	= document.getElementById("nname").value;
	document.getElementById("tel").value 	= document.getElementById("ntel").value;
	document.getElementById("email").value 	= document.getElementById("nmail").value;
//	document.getElementById("comment").value= document.getElementById("ncomm").value;
	ADD_NEW_CONTACT_FLAG = "null";

	LoadCont(ADD_NEW_CONTACT_CID ,36);
}

function OnTBOVER(who)	{
//alert(who);
	r = "r"+who;
	n = "n"+who;
	t = "t"+who;
	m = "m"+who;
//	c = "c"+who;
	a = "a"+who;
	rw = document.getElementById(r);
	nw = document.getElementById(n);
	tw = document.getElementById(t);
	mw = document.getElementById(m);
	aw = document.getElementById(a);
	rw.style.backgroundColor = "#ebf1dd";
	nw.style.backgroundColor = "#ebf1dd";
	tw.style.backgroundColor = "#ebf1dd";
	mw.style.backgroundColor = "#ebf1dd";
//	aw.style.backgroundColor = "#ebf1dd";

}
function OnTBOUT(who)	{
	r = "r"+who;
	n = "n"+who;
	t = "t"+who;
	m = "m"+who;
//	c = "c"+who;
	a = "a"+who;
	rw = document.getElementById(r);
	nw = document.getElementById(n);
	tw = document.getElementById(t);
	mw = document.getElementById(m);
//	cw = document.getElementById(c);
	aw = document.getElementById(a);
	rw.style.backgroundColor = "white";
	nw.style.backgroundColor = "white";
	tw.style.backgroundColor = "white";
	mw.style.backgroundColor = "white";
//	aw.style.backgroundColor = "white";
}

function OnTCLICK(who)	{

	if(who!='new')	{
		if (ADD_NEW_CONTACT_FLAG=="null") 	{
			document.getElementById("new_contact").style.display = "inline";
		}
		else					{
			if (ADD_NEW_CONTACT_FLAG!=who)		OnTEUPDATE();
		}
	}
	else		{

		if (ADD_NEW_CONTACT_FLAG=="null")		{
			document.getElementById("new_contact").style.display = "inline";
			document.getElementById("fname").value 	= "";
			document.getElementById("tl").value 	= "";
			document.getElementById("em").value 	= "";
			document.getElementById("cm").value= "";
		}
		else	
			OnTEUPDATE();

	}
}

function OnNewContact(who)	{
		ADD_NEW_CONTACT_FLAG=="null"
		document.getElementById("new_contact").style.display = "inline";
		document.getElementById("fname").value=who;
		document.getElementById("tl").value="";
		document.getElementById("em").value="";
		document.getElementById("cm").value="";
		document.getElementById("fname").focus();
}

function OnTECLICK(who, cid)	{
//	if (ADD_NEW_CONTACT_FLAG!=who && ADD_NEW_CONTACT_CID!= cid) 	{
	if (ADD_NEW_CONTACT_FLAG=="null") 	{
		ADD_NEW_CONTACT_FLAG = who;
		ADD_NEW_CONTACT_CID = cid;
		r = "r"+who;
		n = "n"+who;
		t = "t"+who;
		m = "m"+who;
		c = "c"+who;
		rw = document.getElementById(r);
		nw = document.getElementById(n);
		tw = document.getElementById(t);
		mw = document.getElementById(m);
		cw = document.getElementById(c);
		temp = nw.innerHTML;
		nw.innerHTML="<input type=text id=nname value=\""+temp+"\">";
		temp = tw.innerHTML;
		if (temp=="&nbsp;")
			tw.innerHTML = "<input type=text id=ntel value=\"\">";
		else
			tw.innerHTML="<input type=text id=ntel value=\""+temp+"\">";
		temp = mw.innerHTML;
		if (temp=="&nbsp;")
			mw.innerHTML="<input type=text id=nmail value=\"\">";
		else
			mw.innerHTML="<input type=text id=nmail value=\""+temp+"\">";
		temp = cw.innerHTML;
		if (temp=="&nbsp;")
			cw.innerHTML="<input type=text id=ncomm value=\"\">";
		else
			cw.innerHTML="<input type=text id=ncomm value=\""+temp+"\">";
	}
	else					{
//		alert("should update, flag: "+ADD_NEW_CONTACT_FLAG+", who: "+who+", fcid: "+ADD_NEW_CONTACT_CID+", cid: "+cid);
		if (ADD_NEW_CONTACT_FLAG!=who)	{
				OnTEUPDATE();
				ADD_NEW_CONTACT_FLAG="null";
		}
	}
}
function OnTCANCEL()	{
	document.getElementById("new_contact").style.display = "none";
	ADD_NEW_CONTACT_FLAG="null";
}
function OnVCANCEL()	{
	document.getElementById("view_card").style.display = "none";
	document.getElementById("d1").style.display = "none";
}



/********************search contacts functions*******************/

	function classList()		{
		this.IsList = false;
		this.currentNode = -1;
		this.nodeCount	 = 0;
		this.setNode	 = setNode;
		this.IDList	 = new Array();
		this.cancelList	 = cancelList;
	}
	function setNode(who)		{
		oldNode = document.getElementById('td'+this.currentNode);
		newNode = document.getElementById('td'+who);
		this.currentNode = who;
		if(oldNode)	oldNode.bgColor = "#c3d69b";
		if(newNode)	newNode.bgColor = "#85b12a";

	}
	function cancelList()		{
		sc = document.getElementById("search_contact");
		sc.style.backgroundColor = "#c3d69b";
		sc.style.borderWidth= "0px";
		sc.innerHTML = "";
		this.IsList = false;
		this.currentNode = -1;
		this.nodeCount	 = 0;

	}
	var ListObj = new classList();
	

	function getKey(event)		{
		if(ListObj.IsList)		{
		if (document.all){
			if (event.keyCode == 13)	{	//enterKey
				event.cancelBubble = true;
				event.returnValue = false;
				if(ListObj.currentNode != -1)
					LoadCont(ListObj.IDList[ListObj.currentNode], 'view_card');	//ako ima izbrano od ponudenite kontakti od listata
				else
					OnNewContact(document.getElementById('search_term').value);
			}
			else if (event.keyCode == 40)	{	//downKey
				event.cancelBubble = true;
				event.returnValue = false;
				if(ListObj.currentNode+1 == ListObj.nodeCount)	{
					ListObj.setNode(0);
				}
				else						{
					ListObj.setNode(ListObj.currentNode+1);
				}
			}
			else if (event.keyCode == 38)	{	//upKey
				event.cancelBubble = true;
				event.returnValue = false;
				if(ListObj.currentNode == 0)	{
					ListObj.setNode(ListObj.nodeCount-1);
				}
				else						{
					ListObj.setNode(ListObj.currentNode-1);
				}
			}
			else
				LoadCont('', 'search_contact');

		}
		else if (document.getElementById){
			if (event.which == 13){
				event.returnValue=false;
				event.cancel = true;
				if(ListObj.currentNode != -1)
					LoadCont(ListObj.IDList[ListObj.currentNode], 'view_card');	//ako ima izbrano od ponudenite kontakti od listata
				else
					//alert(document.getElementById('search_term').value);
					OnNewContact(document.getElementById('search_term').value);
			}
			else if (event.which == 40)	{	//downKey
				event.cancelBubble = true;
				event.returnValue = false;
				if(ListObj.currentNode+1 == ListObj.nodeCount)	{
					ListObj.setNode(0);
				}
				else						{
					ListObj.setNode(ListObj.currentNode+1);
				}
			}
			else if (event.which == 38)	{	//upKey
				event.cancelBubble = true;
				event.returnValue = false;
				if(ListObj.currentNode == 0 || ListObj.currentNode ==-1)	{
					ListObj.setNode(ListObj.nodeCount-1);
				}
				else						{
					ListObj.setNode(ListObj.currentNode-1);
				}
			}
			else if (event.which == 27)	{	//ESCkey
				event.cancelBubble = true;
				event.returnValue = false;
				ListObj.cancelList();
			}
			else
				LoadCont('', 'search_contact');
 		}
		else if (document.layers){
			alert(event.which);
			if (event.which == 13){
				event.returnValue=false;
				event.cancel = true;
				OnSubmit();
			}
 		}
		}
		else
			LoadCont('', 'search_contact');

	}
/********************search contacts functions*******************/



/********************get document real height*******************/

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}
/********************get document real height*******************/


/*************************TODO_ABOUTBOX*************************/
		function ShowDivt(who)	{
			d = document.getElementById("div1");
			p = document.getElementById("div"+who);
//			d.style.display="inline";
			d.style.height=getDocHeight();
			d.style.display="inline";
			p.style.display="inline";
		}
		function HideDivt()	{
			d = document.getElementById("div1");
			p = document.getElementById("div2");
			v = document.getElementById("div3");
			i = document.getElementById("div4");
			b = document.getElementById("bplaner");
			d.style.display="none";
			p.style.display="none";
			v.style.display="none";
			i.style.display="none";
			b.style.display="none";
		}

		function ADD_TODO()						{
			if(ADD_IN_PROGRESS == false)	{
				tdl = document.getElementById("todo_list");
				old_cont = tdl.innerHTML;
				new_cont = old_cont + "<table id=add_todo_table width=350px><tr><td width=21 align=center><input type=checkbox disabled></td><td width=21><img src=\"http://www.training.cecwag.com/images/edit.gif\" title=\"Исправка на задачата ...\" style=\"cursor: pointer;\"></td><td width=21>";
				new_cont += "<img src=\"http://www.training.cecwag.com/images/del.gif\" title=\"Избриши ја задачата засекогаш ...\" style=\"cursor: pointer;\"></td><td width=21><img src=\"http://www.training.cecwag.com/images/lupa.gif\" title=\"Целосен преглед на задачата ...\" style=\"cursor: pointer;\"></td><td>";
				new_cont += "<img src=\"http://www.training.cecwag.com/images/ok2.gif\" onclick=\"AddNewToDo();\" style=\"position: absolute; margin-left: 226px; margin-top: 2px;\"><input type=text style=\"font-family: arial; font-size: 12; color: #5f667d; width: 245; border: 1px solid #5f667d; background: white;\">";
				new_cont += "<input type=text id=add_todo style=\"font-family: arial; font-size: 12; color: #5f667d; width: 224; border: 0px solid #5f667d; background: white; position: absolute; margin-left: -244px; margin-top: 1px;\" onkeypress=\"checkEnterKey(event)\" ></td></tr></table>";
				tdl.innerHTML = new_cont;
				ADD_IN_PROGRESS = true;
			}
			else				{
				AddNewToDo();
			}

		}
		function AddNewToDo()			{
			ADD_IN_PROGRESS = false;
			LoadCont("" , "addnewtodo");
		}

		function checkEnterKey(event)		{
			if (document.all){
				if (event.keyCode == 13)	{
					event.cancelBubble = true;
					event.returnValue = false;
					AddNewToDo();
				}
			}
			else if (document.getElementById){
				if (event.which == 13){
					event.returnValue=false;
					event.cancel = true;
					AddNewToDo();
				}
 			}
			else if (document.layers){
				if (event.which == 13){
					event.returnValue=false;
					event.cancel = true;
					AddNewToDo();
				}
	 		}

		}

		function ArchiveToDO(who)	{
			LoadCont(who, "archivetodo");
		}
		function DeleteToDo(who)	{
			LoadCont(who, "deletetodo");
		}
		function ViewToDo(who)		{
			st = document.getElementById("show_todo");
			st.style.display = "inline";
			LoadCont(who, "viewtodo");
		}
		function HideDiv2()		{
			st = document.getElementById("show_todo");
			tc = document.getElementById("todo_cont");
			st.style.display = "none";
			tc.innerHTML = "<tr><td align=center valign=middle><p align=center> <img src=/images/loader_rect.gif> </p></td></tr>"
		}

/*************************TODO_ABOUTBOX*************************/


/*************************SONYA_SHOWORIMAGE*************************/

		oldDIMContent="";

		function ShowOrigImage(who, what)	{
			d = document.getElementById("div1");
			p = document.getElementById("div"+who);
			p.innerHTML = "<table width=100% height=100% ><tr><td valign=middle align=center><table><tr><td style=\"border: 0px solid red; background-color: white; padding: 30px;\"><img src=\""+what+"\" style=\"border: 1px solid gray;\"></td></tr></table></td></tr></table>";
			d.style.height=getDocHeight();
			d.style.display="block";
			p.style.display="inline";
		}


/*************************SONYA_SHOWORIMAGE*************************/

		function show_business_planer()		{
			d = document.getElementById("div1");
			p = document.getElementById("bplaner");
			d.style.height=getDocHeight();
			d.style.display="inline";
			p.style.display="inline";
			LoadCont('ignore', 'bplaner');
		}

/***************************CALENDAR.INC FUNCTIONS*****************************/
function mover(WHO)	{
		tid = document.getElementById(WHO);
//		tid.style.border ="1px solid gray;"
		tid.style.borderColor ="gray";
		tid.style.cursor ="pointer";
}
function mout(WHO)	{
		tid = document.getElementById(WHO);
	//	tid.style.border ="1px solid none;"
		tid.style.borderColor ="#fdfdfd";
}
function mclick(WHO)	{
//		cm = document.getElementById("cmonth");
//		cy = document.getElementById("cyear");
		LoadCont(WHO,"set_day");
}
function ShowSelDate()	{
		cd = document.getElementById("cday");
		cm = document.getElementById("cmonth");
		cy = document.getElementById("cyear");
		LoadCont(cm.value+"/"+ cd.value +"/"+cy.value, 'next_week');
}
/***************************CALENDAR.INC FUNCTIONS*****************************/

/*****************activities calendar functions******************/
	function SetMeeting(cell_id, c_hour)	{
		if(!FLAG_EDIT_MEETING)	{		//znaci dodavame nov sostanok => prikazi 
//alert('set meeting');
			nm = document.getElementById("new_meeting");
			nm.style.display = 'inline';
			date_string = document.getElementById("jscript_date_array").value;
			date_arrays = date_string.split(";");
			start_day	= cell_id.substr(0,1);
			start_minutes 	= cell_id.substr(1,1);
			if(start_minutes=="1")
				start_minutes 	= "00";
			else
				start_minutes 	= "30";
			start_date = date_arrays[start_day-1];
			document.getElementById("query_info").value = "sdate="+start_date+"&shour="+c_hour+"&sminutes="+start_minutes;

		}
		else				{
			FLAG_EDIT_MEETING=false;
		}
	}


	function EditMeeting(event, event_id, cell_id, cell_num, cell_hour, vhour, vmin)	{
//alert("event_ID: "+event_id+", cell_id: "+cell_id+", cell_num: "+cell_num+", cell_hour: "+cell_hour+", vhour: "+ vhour+ ", vmin: "+vmin);
//alert('edit');
		document.getElementById("eID").value = event_id;
		FLAG_EDIT_MEETING=true;
		var posx = 0;
		var posy = 0;
		if (!e) var e = event;
		if (e.pageX || e.pageY) 	{
			posx = e.pageX;
			posy = e.pageY;
		}
		else if (e.clientX || e.clientY) 	{
			posx = e.clientX + document.body.scrollLeft
				+ document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop
				+ document.documentElement.scrollTop;
		}

		ec = document.getElementById("edit_meeting");
		cont = document.getElementById("cont"+cell_id+cell_num+cell_hour);
		if(document.all){
			innerCont = cont.innerText;
		} else{
			innerCont = cont.textContent;
		}
		document.getElementById("query_info").value = innerCont;
		ed = document.getElementById("edit_comment");
		ed.innerHTML = "<font color=navy size=2 face=tahoma>"+innerCont+"</font>";

		if (posx-720<0 )	ec.style.left  = 5;
		else			ec.style.left = posx-720;
		if (posy-300<0 )	ec.style.top  = -20;
		else			ec.style.top  = posy-300;
		document.getElementById("vhour").selectedIndex=vhour;
		switch(vmin)	{
			case("15") :	document.getElementById("vmin").selectedIndex=1; break;
			case("30") :	document.getElementById("vmin").selectedIndex=2; break;
			case("45") :	document.getElementById("vmin").selectedIndex=3; break;
			default	 :	document.getElementById("vmin").selectedIndex=0; break;
		}
		ec.style.display = 'inline';

	}


	function EditComment()		{
		if (!isEditUpdate)	{
			ed = document.getElementById("edit_comment");
			if(document.all){
				cont = ed.innerText;
			} else{
				cont = ed.textContent;
			}
			ed.innerHTML = "<input id=\"new_comment\" type=text style=\"width: 350px; height:20px; border: 1px solid #c8d6fb; font-size: 10; font-family: Arial, Tahoma; color: #ce2121\" value=\""+ cont +"\">";
			document.getElementById('btn_edit').value="Запиши";
//			document.getElementById('btn_edit').OnClick = alert('test');
			document.getElementById('new_comment').focus();
			isEditUpdate=true;
		}
		else			{
			isEditUpdate=false;
//alert("event_ID: "+document.getElementById("eID").value);
			LoadCont(document.getElementById("eID").value, "edit_meeting");
		}
		

	}
	function DeleteMeeting()	{
		//alert(document.getElementById("eID").value);
		LoadCont(document.getElementById("eID").value, 'delete_meeting');
	}

	function OnNMCANCEL(who)	{
		document.getElementById(who).style.display = "none";
	}


	function classDrag()		{
		this.eID	= "";
		this.eHours	= "";
		this.eMinutes	= "";
		this.sHours	= "";
		this.sMinutes	= "";
		this.rowID	= "";
		this.cellID	= "";
		this.X 		= "";
		this.Y		= "";
		this.newDateTime= "";
	}
	var DragObj = new classDrag();

	function OnDrag(event, who, r_id, c_id, chour, ehours, eminutes)	{
		drag_id		= who;
		flag_is_drag 	= true;
		FLAG_EDIT_MEETING=true;
		DragObj.eID 	= who;
		DragObj.eHours	= ehours;
		DragObj.eMinutes= eminutes;
		DragObj.sHours	= chour;
		if(c_id=="1")
			DragObj.sMinutes="00";
		else
			DragObj.sMinutes="30";
		DragObj.rowID	= r_id;
		DragObj.cellID	= c_id;

		/****************** DISABLE TEXT SELECTION *******************/
		if (document.all)	{
			document.getElementById("cont").onselectstart = function () { return false; }
		}
		else			{
			document.getElementById("cont").onmousedown = function () { return false; }
		}
		/****************** DISABLE TEXT SELECTION *******************/
	

	}


	function OnDrag2(event, who, r_id, c_id, chour, ehours, eminutes)	{
		drag_id		= who;
		flag_is_drag 	= true;
		FLAG_EDIT_MEETING=true;
		DragObj.eID 	= who;
		DragObj.eHours	= ehours;
		DragObj.eMinutes= eminutes;
		DragObj.sHours	= chour;
		if(c_id=="1")
			DragObj.sMinutes="00";
		else
			DragObj.sMinutes="30";
		DragObj.rowID	= r_id;
		DragObj.cellID	= c_id;

		/****************** DISABLE TEXT SELECTION *******************/
		if (document.all)	{
			document.getElementById("cont").onselectstart = function () { return false; }
		}
		else			{
			document.getElementById("cont").onmousedown = function () { return false; }
		}
		/****************** DISABLE TEXT SELECTION *******************/

		odiv = document.getElementById("event"+who);
		sdiv = document.getElementById("scroll_div");
		opos = CalcPos(odiv);

		if (who.substr(0,1)=="7")
			DragObj.X = opos[0]-odiv.offsetWidth-10;
		else if(who.substr(0,1)=="6")
			DragObj.X = opos[0]-odiv.offsetWidth-10;
		else
			DragObj.X = opos[0];
		DragObj.Y = opos[1];

		
		var posx = 0;
		var posy = 0;
		evente = event;
		if (!e) var e = event;
		if (e.pageX || e.pageY) 	{
			posx = e.pageX;
			posy = e.pageY;
		}
		else if (e.clientX || e.clientY) 	{
			posx = e.clientX + document.body.scrollLeft
				+ document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop
				+ document.documentElement.scrollTop;
		}

		spos = CalcPos(sdiv);
		stop = spos[1];
		sbottom = spos[1] + sdiv.offsetHeight;
		document.onmousemove = pageScroll;

		
		

	}



	/****************funkcija za sledenje na glusecot**********/
	var IE = document.all?true:false
	// If NS -- that is, !IE -- then set up for mouse capture
	if (!IE) document.captureEvents(Event.MOUSEMOVE)

	if(document.getElementById("DoMouseMove"))
	document.onmousemove = pageScroll2;
	var tempX = 0;
	var tempY = 0;

	function pageScroll(e) {

		if (IE) { // grab the x-y pos.s if browser is IE
			tempX = event.clientX + document.body.scrollLeft;
			tempY = event.clientY + document.body.scrollTop;
		} else {  // grab the x-y pos.s if browser is NS
			tempX = e.pageX;
			tempY = e.pageY;
		}  
		// catch possible negative values in NS4
		if (tempX < 0){tempX = 0;}
		if (tempY < 0){tempY = 0;}  



		sdiv = document.getElementById("scroll_div");
		spos = CalcPos(sdiv);
		stop = spos[1];
		odiv = document.getElementById("event"+DragObj.eID);
		opos = CalcPos(document.getElementById("t"+DragObj.eID));
		odiv.style.top = (tempY- 2*spos[1])+"px";
//		odiv.style.left = (tempX- 2*spos[0])+"px";
//		odiv.style.left = "50"+"px";
		odiv.style.top  = (tempY - DragObj.Y+20) +"px";
		odiv.style.left = (tempX - DragObj.X+20) +"px";
/*		document.getElementById("mX").value = tempX;
		document.getElementById("my").value = tempY;
		document.getElementById("pX").value = odiv.style.left;
		document.getElementById("py").value = odiv.style.top;
*/

		sbottom = spos[1] + sdiv.offsetHeight;
		if(tempY>=(sbottom-10) && tempY<=sbottom)	{
	    		sdiv.scrollTop+=50; // horizontal and vertical scroll increments
		}
		if(tempY>=spos[1] && tempY<= (spos[1]+10)){
	    		sdiv.scrollTop-=50; // horizontal and vertical scroll increments
		}

		return true;
	}


	function NoMouseMove(e)		{
		return true;
	}
	/****************funkcija za sledenje na glusecot**********/


	function CalcPos(obj)			{
			var curleft = curtop = 0;
			if (obj.offsetParent) {
				do {
					curleft += obj.offsetLeft;
					curtop += obj.offsetTop;
				} while (obj = obj.offsetParent);
				return [curleft,curtop];

			}
	}


	function OnDrop(event, who, chour)	{

		if(FLAG_EDIT_MEETING && flag_is_drag)	{
		flag_is_drag = false;
		odiv = document.getElementById("event"+DragObj.eID);
		odiv = document.getElementById("scroll_div");
		odiv.style.left= DragObj.X;
		odiv.style.top = DragObj.Y;
		
		document.onmousemove = NoMouseMove;
		if(DragObj.sHours==chour && DragObj.rowID == who.substr(0,1))	{
			divpos 	= document.getElementById("event"+DragObj.eID);
			divpos.style.top = 0;
			divpos.style.left = 0;
			EditMeeting(event, DragObj.eID, DragObj.rowID, DragObj.cellID, DragObj.sHours, DragObj.eHours, DragObj.eMinutes);
		}
		else			{
			date_string = document.getElementById("jscript_date_array").value;
			date_arrays = date_string.split(";");
			start_day	= who.substr(0,1);
			start_date = date_arrays[start_day-1];

			if(who%10==1)	{
				DragObj.newDateTime = start_date+" "+chour+":00.000";
			}
			else 		{
				DragObj.newDateTime = start_date+" "+chour+":30.000";
			}
			LoadCont(0, "drag_n_drop");
		}
		}

	}

/*****************activities calendar functions******************/


function OnContactsMenu(who)	{
	cm = document.getElementById("contacts_menu");

	if(who==1)	{
		cm.innerHTML = 	"<table><tr><td align=center width=140><font color=white face=arial size=2><b>Преглед на контакт</font></td><td><img src=\"/images/table/orange_separator.gif\"></td><td align=center width=140 style=\"cursor: pointer;\" onclick=\"return OnContactsMenu(2);\"><font color=#f4d7b6 face=arial size=2>"+ lc_history +"</font></td><td><img src=\"/images/table/orange_separator.gif\"></td><td align=center width=80 style=\"cursor: pointer;\" onclick=\"return OnContactsMenu(3);\"><font color=#f4d7b6 face=arial size=2>7 Чекори</font></td></tr></table>";
		document.getElementById("darrow").style.marginLeft = "60";
		document.getElementById("c_general").style.visibility = "visible";
		document.getElementById("c_history").style.visibility = "hidden";
		document.getElementById("c_steps").style.visibility = "hidden";

	}
	if(who==2)	{
		cm.innerHTML = 	"<table><tr><td align=center width=140 style=\"cursor: pointer;\" onclick=\"return OnContactsMenu(1);\"><font color=#f4d7b6 face=arial size=2>Преглед на контакт</font></td><td><img src=\"/images/table/orange_separator.gif\"></td><td align=center width=140 style=\"cursor: pointer;\" onclick=\"return OnContactsMenu(2);\"><font color=white face=arial size=2><b>Историја на контакт</font></td><td><img src=\"/images/table/orange_separator.gif\"></td><td align=center width=80 style=\"cursor: pointer;\" onclick=\"return OnContactsMenu(3);\"><font color=#f4d7b6 face=arial size=2>7 Чекори</font></td></tr></table>";
		document.getElementById("darrow").style.marginLeft = "220";
		document.getElementById("c_general").style.visibility = "hidden";
		document.getElementById("c_history").style.visibility = "visible";
		document.getElementById("c_steps").style.visibility = "hidden";

	}
	if(who==3)	{
		cm.innerHTML = 	"<table><tr><td align=center width=140 style=\"cursor: pointer;\" onclick=\"return OnContactsMenu(1);\"><font color=#f4d7b6 face=arial size=2>Преглед на контакт</font></td><td><img src=\"/images/table/orange_separator.gif\"></td><td align=center width=140 style=\"cursor: pointer;\" onclick=\"return OnContactsMenu(2);\"><font color=#f4d7b6 face=arial size=2>Историја на контакт</font></td><td><img src=\"/images/table/orange_separator.gif\"></td><td align=center width=80 style=\"cursor: pointer;\" onclick=\"return OnContactsMenu(3);\"><font color=white face=arial size=2><b>7 Чекори</font></td></tr></table>";
		document.getElementById("darrow").style.marginLeft = "340";
		document.getElementById("c_general").style.visibility = "hidden";
		document.getElementById("c_history").style.visibility = "hidden";
		document.getElementById("c_steps").style.visibility = "visible";
		LoadCont('', 'retreive_steps');

	}
}

var CHB_CONT="";

function CHResult(who)	{
	chb = document.getElementById("ch_buttons");
	CHB_CONT = document.getElementById("ch_buttons").innerHTML;
	document.getElementById("chistory_content").value="";
	document.getElementById("ch_buttons").innerHTML = "<img src=\"/images/icon_results.png\"  onclick=\"LoadCont('"+who+"', 'ch_result');\" style=\"margin-left: 4px; margin-bottom: 10px; cursor: pointer;\">"
}
