
function msgBox(object, msg){
	var myWidth = 400;
	if(!document.getElementById('messageBox')){
		var myElementString = '<div id="messageBox" '
			+'style="background-color:#FFFFFF;'
			+'background-image:url(images/cross.png);'
			+'background-repeat:no-repeat;'
			+'border:1px solid #000000;'
			+'display:none;'
			+'font-size:12px;'
			+'height:100px;'
			+'overflow:auto;'
			+'padding:12px 12px 12px 20px;'
			+'position:absolute;'
			+'width:'+myWidth+'px;'
			+'"'
			+' onclick="(this.style.display = \'none\')"></div>';

		var MonDiv=document.createElement('DIV');
		MonDiv.innerHTML = myElementString;


		document.body.appendChild(MonDiv);

	}

	var winWH = getWindowSizeWH();
	var myScroll = getScrollXY();
	var myTop = findPosY(object)-30;
	var myLeft = findPosX(object);

	if(myLeft>(winWH[0]-myWidth)) myLeft = (winWH[0]-myWidth-60);

	document.getElementById("messageBox").innerHTML = '';
	document.getElementById('messageBox').style.left = myLeft;
	document.getElementById('messageBox').style.top = myTop;
	document.getElementById("messageBox").innerHTML = ''+msg;
	document.getElementById('messageBox').style.display = "block";
}

function getWindowSizeWH(){
	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, myHeight ];

}

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

function setCheckBoxTab(checkBoxS, value){
	//For each check box set $value
	for (var i = 0; i < checkBoxS.length; i++){
		checkBoxS[i].checked = value;
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
		while(1){
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}

function FormData(name, value){
	this.name = name;
	this.value = value;
}

function formSetValueWithName(myForm, data){


	for(var i=0; i<myForm.elements.length; i++){

		currElement = myForm.elements[i];

		if(data[currElement.name]!=null){
			switch(currElement.type){
			case "text":
			case "hidden":
			case "password":
			case "textarea":
			case "select-one":
				currElement.value = data[currElement.name].value;
				break;
			case "radio":
			case "checkbox":
				if(currElement.value === data[currElement.name].value){
					currElement.checked = true;
				}
				break;
			default:
				currElement.value = data[currElement.name].value;
			break;
			}


		}

	}


}

function submitFormForceAction(myForm, action){
	myForm.action = action;
	myForm.submit();
}


//<input type="hidden" id="idwriteroot" name="writeroot" value="" />
//must be placed in form
function formAddHiddenNotInArray(myForm, dataa){
	var insertHere = document.getElementById('idwriteroot');
	var i = 0;
	for(var myFormData in dataa){

		if(myForm.elements[myFormData]==null){

			var newFields = document.getElementById('idwriteroot').cloneNode(true);

			newFields.name = myFormData+'';
			newFields.value = dataa[myFormData]+'';
			newFields.id = 'idwriteroot'+i;
			//insertHere.parentNode.insertBefore(newFields,insertHere);

			newOp = createNamedElement("input", myFormData+'');
			newOp.type = 'hidden';
			newOp.value=dataa[myFormData]+'';
			insertHere.parentNode.insertBefore(newOp,insertHere);
			i++;
		}
	}

}

function createNamedElement(type, name) {
	var element = null;
	// Try the IE way; this fails on standards-compliant browsers
	try {
		element = document.createElement('<'+type+' name="'+name+'">');
	} catch (e) {
	}
	if (!element || element.nodeName != type.toUpperCase()) {
		// Non-IE browser; use canonical method to create named element
		element = document.createElement(type);
		element.name = name;
	}
	return element;
}


function getCkeckedValue(input){

	for (var ii = 0; ii < input.length; ii++){
		if (input[ii].checked)
			return input[ii].value;
	}

	return input.value;

}

function getSelectWithArray(name, defaultvalue, myarray, style){
	var out = '';

	if(!style) style = '';
	out += '<select style="font-size: 11px;'+style+'" name="'+name+'">';

	for(key in myarray){

		var selected = '';

		if(defaultvalue==key){
			selected = ' selected="selected"';
		}

		out += '<option  value="'+key+'" '+selected+'>'+myarray[key]+'</option>';

	}
	out += '</select>';
	return out;
}

function convertDateMySqlToDateObject(date_mysql){
    return new Date(date_mysql.substr(0, 4), date_mysql.substr(5, 2)-1, date_mysql.substr(8, 2));
}

function convertDateMySqlToNormalDate(date_mysql){
    return ''+date_mysql.substr(8, 2)+'/'+date_mysql.substr(5, 2)+'/'+date_mysql.substr(0, 4)+'';
}

function getAgeInYears(birsDayDate){
	var currnow = new Date();
	return currnow.getFullYear()-birsDayDate.getFullYear();
}

function getDate(input){
	var agesplit=input.value.split("/");
	return new Date(agesplit[2],agesplit[1],agesplit[0]);
}




function isEmpty(str){
	if(str==''){
		return true;
	}
	return false;
}

function isInt(str){

	if(str.match(/^[0-9]{1,10}$/)){
		return true;
	}
	return false;
}

function isDecimal(str){
	var regex = new RegExp('^[0-9]{1,10000}\\.[0-9]{1,10000}$');
	var match = regex.exec(str);

	if(match){
		return true;
	}

	regex = new RegExp('^[0-9]{1,10000}$');
	match = regex.exec(str);
	if(match){
		return true;
	}

	return false;
}


function isDate(str){
	var regex = new RegExp("^([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})$");
	var match = regex.exec(str);
	if(match){
		if (match.length == 4) {
			var myDate =  new Date(match[3], match[2]-1, match[1]);
			if(myDate.getDate()==match[1] && myDate.getMonth()==(match[2]-1) && myDate.getFullYear()==match[3]){
	        	return true;
	        }
		}
	}
	return false;
}



function isMail(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
		return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false;
	}

	if (str.indexOf(at,(lat+1))!=-1){
		return false;
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	}

	if (str.indexOf(dot,(lat+2))==-1){
		return false;
	}

	if (str.indexOf(" ")!=-1){
		return false;
	}
	return true;
}


function validInt(input){
	return valid(input, isInt(input.value));
}
function validDecimal(input){
	return valid(input, isDecimal(input.value));
}

function validDate(input){
	return valid(input, isDate(input.value));
}

function validMail(input){
	return valid(input, isMail(input.value));
}

function valid(input, isValid){
	if(isValid){
		input.className = input.className.replace(/ui-state-error/g, '');
	}else{
		input.className = input.className+' ui-state-error';
	}

	return isValid;
}

function invalidEmpty(input){
	if(isEmpty(input.value)){
		input.className = input.className+' ui-state-error';
		return false;
	}
	return true;
}

function validNotEmpty(input){
	return valid(input, !isEmpty(input.value));
}

function print_r(obj) {
  win_print_r = window.open('about:blank', 'win_print_r',"menubar=no, status=no, scrollbars=yes, menubar=no, width=400, height=600");
  win_print_r.document.write('<html><body>');
  r_print_r(obj, win_print_r);
  win_print_r.document.write('</body></html>');
}

function r_print_r(theObj, win_print_r) {
	  if(theObj.constructor == Array ||
	   theObj.constructor == Object){
	   if (win_print_r == null)
	    win_print_r = window.open('about:blank', 'win_print_r');
	   }
	   for(var p in theObj){
	    if(theObj[p].constructor == Array||
	     theObj[p].constructor == Object){
	     win_print_r.document.write("<li>["+p+"] =>"+typeof(theObj)+"</li>");
	     win_print_r.document.write("<ul>")
	     r_print_r(theObj[p], win_print_r);
	     win_print_r.document.write("</ul>")
	    } else {
	     win_print_r.document.write("<li>["+p+"] =>"+theObj[p]+"</li>");
	    }
	   }
	  win_print_r.document.write("</ul>")
}

function HTMLentities(texte) {

	texte = texte.replace(/"/g,'&quot;'); // 34 22
			texte = texte.replace(/&/g,'&amp;'); // 38 26
	texte = texte.replace(/\'/g,'&#39;'); // 39 27
	texte = texte.replace(/</g,'&lt;'); // 60 3C
	texte = texte.replace(/>/g,'&gt;'); // 62 3E
	texte = texte.replace(/\^/g,'&circ;'); // 94 5E
	texte = texte.replace(/â??/g,'&lsquo;'); // 145 91
	texte = texte.replace(/â??/g,'&rsquo;'); // 146 92
	texte = texte.replace(/â??/g,'&ldquo;'); // 147 93
	texte = texte.replace(/â??/g,'&rdquo;'); // 148 94
	texte = texte.replace(/â?¢/g,'&bull;'); // 149 95
	texte = texte.replace(/â??/g,'&ndash;'); // 150 96
	texte = texte.replace(/â??/g,'&mdash;'); // 151 97
	texte = texte.replace(/Ë?/g,'&tilde;'); // 152 98
	texte = texte.replace(/â?¢/g,'&trade;'); // 153 99
	texte = texte.replace(/Å¡/g,'&scaron;'); // 154 9A
	texte = texte.replace(/â?º/g,'&rsaquo;'); // 155 9B
	texte = texte.replace(/Å?/g,'&oelig;'); // 156 9C
	texte = texte.replace(/Â?/g,'&#357;'); // 157 9D
	texte = texte.replace(/Å¾/g,'&#382;'); // 158 9E
	texte = texte.replace(/Å¸/g,'&Yuml;'); // 159 9F
//	texte = texte.replace(/ /g,'&nbsp;'); // 160 A0
	texte = texte.replace(/Â¡/g,'&iexcl;'); // 161 A1
	texte = texte.replace(/Â¢/g,'&cent;'); // 162 A2
	texte = texte.replace(/Â£/g,'&pound;'); // 163 A3
//	texte = texte.replace(/ /g,'&curren;'); // 164 A4
	texte = texte.replace(/Â¥/g,'&yen;'); // 165 A5
	texte = texte.replace(/Â¦/g,'&brvbar;'); // 166 A6
	texte = texte.replace(/Â§/g,'&sect;'); // 167 A7
	texte = texte.replace(/Â¨/g,'&uml;'); // 168 A8
	texte = texte.replace(/Â©/g,'&copy;'); // 169 A9
	texte = texte.replace(/Âª/g,'&ordf;'); // 170 AA
	texte = texte.replace(/Â«/g,'&laquo;'); // 171 AB
	texte = texte.replace(/Â¬/g,'&not;'); // 172 AC
	texte = texte.replace(/Â­/g,'&shy;'); // 173 AD
	texte = texte.replace(/Â®/g,'&reg;'); // 174 AE
	texte = texte.replace(/Â¯/g,'&macr;'); // 175 AF
	texte = texte.replace(/Â°/g,'&deg;'); // 176 B0
	texte = texte.replace(/Â±/g,'&plusmn;'); // 177 B1
	texte = texte.replace(/Â²/g,'&sup2;'); // 178 B2
	texte = texte.replace(/Â³/g,'&sup3;'); // 179 B3
	texte = texte.replace(/Â´/g,'&acute;'); // 180 B4
	texte = texte.replace(/Âµ/g,'&micro;'); // 181 B5
	texte = texte.replace(/Â¶/g,'&para'); // 182 B6
	texte = texte.replace(/Â·/g,'&middot;'); // 183 B7
	texte = texte.replace(/Â¸/g,'&cedil;'); // 184 B8
	texte = texte.replace(/Â¹/g,'&sup1;'); // 185 B9
	texte = texte.replace(/Âº/g,'&ordm;'); // 186 BA
	texte = texte.replace(/Â»/g,'&raquo;'); // 187 BB
	texte = texte.replace(/Â¼/g,'&frac14;'); // 188 BC
	texte = texte.replace(/Â½/g,'&frac12;'); // 189 BD
	texte = texte.replace(/Â¾/g,'&frac34;'); // 190 BE
	texte = texte.replace(/Â¿/g,'&iquest;'); // 191 BF
	texte = texte.replace(/Ã?/g,'&Agrave;'); // 192 C0
	texte = texte.replace(/Ã?/g,'&Aacute;'); // 193 C1
	texte = texte.replace(/Ã?/g,'&Acirc;'); // 194 C2
	texte = texte.replace(/Ã?/g,'&Atilde;'); // 195 C3
	texte = texte.replace(/Ã?/g,'&Auml;'); // 196 C4
	texte = texte.replace(/Ã?/g,'&Aring;'); // 197 C5
	texte = texte.replace(/Ã?/g,'&AElig;'); // 198 C6
	texte = texte.replace(/Ã?/g,'&Ccedil;'); // 199 C7
	texte = texte.replace(/Ã?/g,'&Egrave;'); // 200 C8
	texte = texte.replace(/Ã?/g,'&Eacute;'); // 201 C9
	texte = texte.replace(/Ã?/g,'&Ecirc;'); // 202 CA
	texte = texte.replace(/Ã?/g,'&Euml;'); // 203 CB
	texte = texte.replace(/Ã?/g,'&Igrave;'); // 204 CC
	texte = texte.replace(/Ã?/g,'&Iacute;'); // 205 CD
	texte = texte.replace(/Ã?/g,'&Icirc;'); // 206 CE
	texte = texte.replace(/Ã?/g,'&Iuml;'); // 207 CF
	texte = texte.replace(/Ã?/g,'&ETH;'); // 208 D0
	texte = texte.replace(/Ã?/g,'&Ntilde;'); // 209 D1
	texte = texte.replace(/Ã?/g,'&Ograve;'); // 210 D2
	texte = texte.replace(/Ã?/g,'&Oacute;'); // 211 D3
	texte = texte.replace(/Ã?/g,'&Ocirc;'); // 212 D4
	texte = texte.replace(/Ã?/g,'&Otilde;'); // 213 D5
	texte = texte.replace(/Ã?/g,'&Ouml;'); // 214 D6
	texte = texte.replace(/Ã?/g,'&times;'); // 215 D7
	texte = texte.replace(/Ã?/g,'&Oslash;'); // 216 D8
	texte = texte.replace(/Ã?/g,'&Ugrave;'); // 217 D9
	texte = texte.replace(/Ã?/g,'&Uacute;'); // 218 DA
	texte = texte.replace(/Ã?/g,'&Ucirc;'); // 219 DB
	texte = texte.replace(/Ã?/g,'&Uuml;'); // 220 DC
	texte = texte.replace(/Ã?/g,'&Yacute;'); // 221 DD
	texte = texte.replace(/Ã?/g,'&THORN;'); // 222 DE
	texte = texte.replace(/Ã?/g,'&szlig;'); // 223 DF
	texte = texte.replace(/Ã /g,'&aacute;'); // 224 E0
	texte = texte.replace(/Ã¡/g,'&aacute;'); // 225 E1
	texte = texte.replace(/Ã¢/g,'&acirc;'); // 226 E2
	texte = texte.replace(/Ã£/g,'&atilde;'); // 227 E3
	texte = texte.replace(/Ã¤/g,'&auml;'); // 228 E4
	texte = texte.replace(/Ã¥/g,'&aring;'); // 229 E5
	texte = texte.replace(/Ã¦/g,'&aelig;'); // 230 E6
	texte = texte.replace(/Ã§/g,'&ccedil;'); // 231 E7
	texte = texte.replace(/Ã¨/g,'&egrave;'); // 232 E8
	texte = texte.replace(/Ã©/g,'&eacute;'); // 233 E9
	texte = texte.replace(/Ãª/g,'&ecirc;'); // 234 EA
	texte = texte.replace(/Ã«/g,'&euml;'); // 235 EB
	texte = texte.replace(/Ã¬/g,'&igrave;'); // 236 EC
	texte = texte.replace(/Ã­/g,'&iacute;'); // 237 ED
	texte = texte.replace(/Ã®/g,'&icirc;'); // 238 EE
	texte = texte.replace(/Ã¯/g,'&iuml;'); // 239 EF
	texte = texte.replace(/Ã°/g,'&eth;'); // 240 F0
	texte = texte.replace(/Ã±/g,'&ntilde;'); // 241 F1
	texte = texte.replace(/Ã²/g,'&ograve;'); // 242 F2
	texte = texte.replace(/Ã³/g,'&oacute;'); // 243 F3
	texte = texte.replace(/Ã´/g,'&ocirc;'); // 244 F4
	texte = texte.replace(/Ãµ/g,'&otilde;'); // 245 F5
	texte = texte.replace(/Ã¶/g,'&ouml;'); // 246 F6
	texte = texte.replace(/Ã·/g,'&divide;'); // 247 F7
	texte = texte.replace(/Ã¸/g,'&oslash;'); // 248 F8
	texte = texte.replace(/Ã¹/g,'&ugrave;'); // 249 F9
	texte = texte.replace(/Ãº/g,'&uacute;'); // 250 FA
	texte = texte.replace(/Ã»/g,'&ucirc;'); // 251 FB
	texte = texte.replace(/Ã¼/g,'&uuml;'); // 252 FC
	texte = texte.replace(/Ã½/g,'&yacute;'); // 253 FD
	texte = texte.replace(/Ã¾/g,'&thorn;'); // 254 FE
	texte = texte.replace(/Ã¿/g,'&yuml;'); // 255 FF
	return texte;
}


