//PR functions

function onlyDigits(value){
	if(value.match('^[0-9]+$')){
		return true;
	} else {
		return false;
	}
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
		
function handlePopupOkClick() {
	try {
		pageHandlePopupOkClick();
	} catch(e) {
	
	}
}

function mfBeforeReloadPopup(){
	showPopup2('mfWait','true');
	return false;
}	

function mfShowInfoPopup(txt){
	tpGet('mrRequestPopupText').innerHTML = txt;
	showPopup2('mfRequest');
	tpGet('mfRequest').getElementsByTagName('div')[0].setAttribute('class','withButton');
	tpGet('mfRequest').getElementsByTagName('div')[0].setAttribute('className','withButton');	
	return false;
}	

function mfAskBeforeReload(txt){
	tpGet('mrWarnPopupText').innerHTML = txt;
	showPopup2('mfWarnPopup2');
	return false;
}	

function mfAfterReloadPopup(x){
	showPopup2('mfRequest');
	if (x!=null) setTimeout('mfHideAfterReloadPopup()', x); else
	{
		tpGet('mfRequest').getElementsByTagName('div')[0].setAttribute('class','withButton');
		tpGet('mfRequest').getElementsByTagName('div')[0].setAttribute('className','withButton');
	}
	return false;
}

function mfHideAfterReloadPopup(){
	hidePopup2('mfRequest');
	return false;
}

	var showDarkGlassPaneInit2 = false;
	function showDarkGlassPane2(noClose)
	{
		var div = tpGet('tpGlassPaneDarkDiv2');
		var ua = navigator.userAgent.toLowerCase();
		div.parentNode.removeChild(div);
		document.body.insertBefore(div, document.body.childNodes[0]);
		div = tpGet('tpGlassPaneDarkDiv2');	
		if(!showDarkGlassPaneInit2 && (ua.indexOf('msie') != -1))
		{
			div.style.position = 'absolute';
			div.style.zIndex = 1000005;
			div.style.setExpression("width", "document.body.clientWidth");
			div.style.setExpression("height", "document.body.clientHeight");
			div.style.setExpression("top", "(document.body.scrollTop) + 'px'");
			div.style.setExpression("left", "(document.body.scrollLeft) + 'px'");
			document.body.onscroll = function() {
				tpGet('tpGlassPaneDarkDiv2').style.top = (document.body.scrollTop) + 'px';
				tpGet('tpGlassPaneDarkDiv2').style.left = (document.body.scrollLeft) + 'px';
			}
		} else if (ua.indexOf('msie') == -1) {
			div.style.position = 'fixed';
			div.style.zIndex = 1000005;
		}
		
		//if(BroswerInfo.isIE6)
		
		if(BrowserDetect.browser=="Explorer" && BrowserDetect.version=="6"){
			disableSelects();
		}
			
		if (noClose) {
			div.setAttribute('onclick','null');
		}
		div.style.display = 'block';
		showDarkGlassPaneInit2 = true;
	}

	function hideDarkGlassPane2()
	{
		tpGet('tpGlassPaneDarkDiv2').style.display = 'none';
		//if(BroswerInfo.isIE6)
		
		if(BrowserDetect.browser=="Explorer" && BrowserDetect.version=="6"){
			enableSelects();
		}
			
	}

var tpLastPopupId = null;
var tpLastPopupId2 = null;
function showPopup2(id,noClose)
{
	tpLastPopupId = id;
	tpLastPopupId2 = 'tpPopupCloseButton';
	showDarkGlassPane2(noClose);
	var obj = tpGet(id);
	obj.parentNode.removeChild(obj);
	document.body.insertBefore(obj, document.body.childNodes[0]);
	obj = tpGet(id);
	var close = tpGet('tpPopupCloseButton');
	close.parentNode.removeChild(close);
	document.body.insertBefore(close, obj);
	close = tpGet('tpPopupCloseButton');
	var ua = navigator.userAgent.toLowerCase();
	var l=0;
	var t=0;
	if(ua.indexOf('msie') == -1)
	{
		close.style.position = 'fixed';
		obj.style.position = 'fixed';
		obj.style.zIndex = 1000006;/*998;*/
		obj.style.display = 'block';
		var w = obj.offsetWidth;
		var h = obj.offsetHeight;
		l = parseInt((document.body.clientWidth-w)/2);
		t = parseInt((document.body.clientHeight-h)/2);
	}
	else
	{
		close.style.position = 'absolute';
		obj.style.position = 'absolute';
		obj.style.zIndex = 1000006/*998;*/
		obj.style.display = 'block';
		var w = obj.offsetWidth;
		var h = obj.offsetHeight;		
		l = parseInt((document.body.clientWidth-w)/2);
		t = document.body.scrollTop + parseInt((document.body.clientHeight-h)/2);
	}
	if (l<13) l=15; if (t<13) t=15; 
	obj.style.left = l+'px';
	obj.style.top = t+'px';
	close.style.left = l-13;
	close.style.top = t-13;
	if (!noClose) {
		close.style.display='block';
		setTimeout('tpGet(\'tpPopupCloseButton\').getElementsByTagName(\'a\')[0].focus()',100);
	}
}

function hidePopup2(id)
{
	hideDarkGlassPane2();
	if(id) tpGet(id).style.display='none';
	if(tpLastPopupId!=null) tpGet(tpLastPopupId).style.display='none';
	if(tpLastPopupId2!=null) tpGet(tpLastPopupId2).style.display='none';
	tpLastPopupId = null; tpLastPopupId2 = null;
	tpGet('tpPopupCloseButton').style.display='none';
}

//phone numbers...//////////////////////////////////////////////////////

function ftInitPhoneNumberInput(idPrefix,fun, idxStart, formatTXT)
{	
// console.log('ftInitPhoneNumberInput');
	var idStart = 1;
	if(idxStart){
		idStart = idxStart;
	}
	for(var i=idStart;i<=3;i++)
	{
		var inp = tpGet(idPrefix+i);
		inp.setAttribute('maxLength',(i==3)?4:3);
		var f = new Function('event',((i<=3)?('ftPhoneNumberInputKeyUp(event,\''+idPrefix+'\','+i+',\''+formatTXT+'\');'):'') );
		
		//var f = function(idPrefix,i) {
		//	return function(event) {
		//		if (i<=3) {
		//			return ftPhoneNumberInputKeyUp(event,idPrefix,i,formatTXT); 
		//		} 
		//	}
		//}(idPrefix,i);
		
		//var f2 = new Function('event','var temp = chkKey(event); if (temp==13 && fun) return fun(); else return ftPhoneNumberInputKeyPress(event,\''+idPrefix+'\','+i+'); ');

		var f2 = function(fun,idPrefix,i) {
			return function(event) {
				mfdigits = tpGet(idPrefix+i).value;
				mfdigits2 = tpGet(idPrefix+i).value;
				var temp = chkKey(event); 
				if (temp==13 && fun) {
					fun(); 
					return false;
				} else {
					return ftPhoneNumberInputKeyPress(event,idPrefix,i);
				}
			}
		}(fun,idPrefix,i);


		var f3 = new Function('event','ftHintHideSearchDivSetTimer();mf=\'\';');
		var f4 = new Function('event','ftHintHideSearchDivClearTimer();');
		
		//var f5 = new Function('event','ftPhoneNumberInputKeyDown(event,\''+idPrefix+'\','+i+',\''+formatTXT+'\');');
		var f5 = function(fun,idPrefix,i) {
			return function(event) {
				if (mfdigits2=='' && i<4) {
					//if (mf=='') 
					mf=i;
					mfdigits2 = tpGet(idPrefix+mf).value;
				}
				var temp = chkKey(event); 
				if (temp==13 && fun) {
					return fun(); 
				} else {
					return ftPhoneNumberInputKeyDown(event,idPrefix,i,formatTXT);
				}
			}
		}(fun,idPrefix,i);
		
		if(inp.attachEvent)
		{
			inp.attachEvent('onkeyup',f5);
			inp.attachEvent('onkeydown',f);
			inp.attachEvent('onkeypress',f2);
		}
		else
		{
			inp.addEventListener('keyup',f5,false);
			inp.addEventListener('keydown',f,false);
			inp.onkeypress = f2;
		}
	}
}

function ftInitAccountNumberInput(idPrefix,fun,formatTXT)
{
	var format = formatTXT.split(':');
	for(var i=1;i<=format.length;i++)
	{
		var inp = tpGet(idPrefix+i);
		inp.setAttribute('maxLength',format[i-1]);
		var f = new Function('event',((i<=format.length)?('ftPhoneNumberInputKeyUp(event,\''+idPrefix+'\','+i+',\''+formatTXT+'\');'):'') );
		//var f2 = new Function(['event',fun],'// console.log(arguments);var temp = chkKey(event); if (temp==13 && fun) return fun(); else return ftPhoneNumberInputKeyPress(event,\''+idPrefix+'\','+i+');');

		var f2 = function(fun,idPrefix,i) {
			return function(event) {
				mfdigits = tpGet(idPrefix+i).value;
				mfdigits2 = tpGet(idPrefix+i).value;
				var temp = chkKey(event); 
				if (temp==13 && fun) {
					fun(); 
					return false;
				} else {
					return ftPhoneNumberInputKeyPress(event,idPrefix,i);
				}
			}
		}(fun,idPrefix,i);


		var f3 = new Function('event','ftHintHideSearchDivSetTimer();mf=\'\';');
		var f4 = new Function('event','ftHintHideSearchDivClearTimer();');
		
		//var f5 = new Function('event','ftPhoneNumberInputKeyDown(event,\''+idPrefix+'\','+i+',\''+formatTXT+'\');');
		var f5 = function(fun,idPrefix,i) {
			return function(event) {
				if (mfdigits2=='' && i<(format.length+1)) {
					//if (mf=='') 
					mf=i;
					mfdigits2 = tpGet(idPrefix+mf).value;
				}
				var temp = chkKey(event);
				if (temp==13 && fun) {
					return fun(); 
				} else {
					return ftPhoneNumberInputKeyDown(event,idPrefix,i,formatTXT);
				}
			}
		}(fun,idPrefix,i);
		
		if(inp.attachEvent)
		{
			inp.attachEvent('onkeyup',f5);
			inp.attachEvent('onkeydown',f);
			inp.attachEvent('onkeypress',f2);
		}
		else
		{
			inp.addEventListener('keyup',f5,false);
			inp.addEventListener('keydown',f,false);
			inp.onkeypress = f2;
		}
	}
}

function mfSet(x) {
	mf = x;
}
function ftPhoneNumberInputKeyUp(e,idPrefix,i,formatTXT)
{
	var format = formatTXT.split(':');
	var keynum;
	if(window.event) //ie
	{
		keynum = e.keyCode;
	}
	else if(e.which) //netscape/ff/opera
	{
		keynum = e.which;
	}

	if (((keynum>=48 && keynum<=57) || (keynum>=96 && keynum<=105)) && i==mf) 
	{ 
		//tpGet(idPrefix+i).value='';//String.fromCharCode(e.keyCode); 
		//tpGet(idPrefix+i).focus(); //mf=i; 
	}
	if (((keynum>=48 && keynum<=57) || (keynum>=96 && keynum<=105)) && i<format.length)
	{
		if(tpGet(idPrefix+i).value.length==(mfMax(idPrefix,i)-1) || tpGet(idPrefix+i).value.length==(mfMax(idPrefix,i))) //jesli wpiszesz ostatni dozwolony
		{
			if (tpGet(idPrefix+(i+1)).value.length>(mfMax(idPrefix,(i+1))-1)) //highlight next field
			{	    
			    setTimeout('if (tpGet(\''+(idPrefix+(i+1))+'\').value.length>(mfMax(\''+idPrefix+'\','+(i+1)+')-1)) { if (mfdigits==tpGet(\''+(idPrefix+(i))+'\').value || (tpGet(\''+(idPrefix+(i))+'\').value.length==(mfMax(\''+idPrefix+'\','+(i)+')-1))) tpGet(\''+(idPrefix+(i+1))+'\').select();}', 10)
			} //else tpGet(idPrefix+(i+1)).focus();
		} 
	}
}
var mf='';
var mfdigits='';
var mfdigits2='';
function ftPhoneNumberInputKeyDown(e,idPrefix,i,formatTXT)
{
	var format = formatTXT.split(':');
	var keynum;
	var equal = true;
// console.log('format.length',format.length);	
	for(u=0;u<format.length;u++) {
		equal = equal && tpGet(idPrefix+(u+1)).value.length==mfMax(idPrefix,(u+1));
	}
// console.log('equal',equal);		
	if (equal) 
	{
		if (tpGet(idPrefix.substring(0,idPrefix.length-format.length)+'AddDivClick')!=null)
	 		tpGet(idPrefix.substring(0,idPrefix.length-format.length)+'AddDivClick').style.display='inline'; 
	} else { 
	  	if (tpGet(idPrefix.substring(0,idPrefix.length-format.length)+'AddDivClick')!=null)
	 		tpGet(idPrefix.substring(0,idPrefix.length-format.length)+'AddDivClick').style.display='none'; 
	}
	if(window.event) //ie
	{
		keynum = e.keyCode;
	}
	else if(e.which) //netscape/ff/opera
	{
		keynum = e.which;
	}
	if(keynum == 8  && i>1) { //backspace
	
		var tmp = tpGet(idPrefix+(i-1)); 
		//var mfdigits2 = tpGet(idPrefix+(i)).value;
//alert(mf+' '+i+' '+mfdigits2);		
		if(tpGet(idPrefix+i).value == "" && mfdigits2 == "" && i>1){
			if (tmp.disabled==null || tmp.disabled==false) {
				tmp.focus();
				if (mf>1) mf--;
				if (tmp.value.length > 1){
					tmp.value = tmp.value.substring(0, tmp.value.length-1);
				}
				else{
					tmp.value = "";
				}
			}				
		} 
		if (mf>0 && mf<(format.length+1)) mfdigits2 = tpGet(idPrefix+i).value;
	//alert(mf+' '+i+' '+mfdigits2);
	}
	if ((keynum>=48 && keynum<=57) || (keynum>=96 && keynum<=105))
	{
		if (tpGet(idPrefix+i)!=null) { if(tpGet(idPrefix+i).value.length==mfMax(idPrefix,i)) {
		 if (tpGet(idPrefix+(i+1))!=null) { 
		 	if (i<format.length && tpGet(idPrefix+(i+1)).value.length<mfMax(idPrefix,i+1))
				{	
// console.log('wczesniejszy i za krotki jeszcze');				
		 			tpGet(idPrefix+(i+1)).focus();
		 			tpGet(idPrefix+(i+1)).value=tpGet(idPrefix+(i+1)).value;
		 			if (mf<format.length) { mf++;
// console.log('zwiekszam mf');		 			
}		 			
		 			if (mf>0 && mf<(format.length+1)) { mfdigits2 = tpGet(idPrefix+mf).value;
// console.log('ustawiam mfdigits2');		 			
}		 			
		 		}
		 	} 
		 }} 
	}
	
}

function mfMax(idPrefix,i) {
	if (tpGet(idPrefix+i)!=null) return tpGet(idPrefix+i).getAttribute('maxLength'); else return null;
}

function ftPhoneNumberInputKeyPress(e,idPrefix,i)
{
// console.log('keyPress');
	var keynum;
	if(window.event) //ie
	{
		keynum = e.keyCode;
	}
	else if(e.which) //netscape/ff/opera
	{
		keynum = e.which;
	}
	
	if(!keynum || (keynum>=48 && keynum<=57) || keynum==13 || keynum==8 || keynum==0 || (keynum==118 && e.ctrlKey) || (keynum==99 && e.ctrlKey))
	{
		return true;
	}
	return false;
}
function chkKey(e)
{
	var keynum;
	if(window.event) //ie
	{
		keynum = e.keyCode;
	}
	else if(e.which) //netscape/ff/opera
	{
		keynum = e.which;
	}
	return keynum;
}

function ftClearPhoneNumberInput(idPrefix)
{
	for(var i=1;i<=3;i++)
	{
		tpGet(idPrefix+i).value = '';
	}
}
function ftValidatePhoneNumberInput(idPrefix, isCf)
{
	var nr = '';
	for(var i=1;i<=3;i++)
	{
		nr += tpGet(idPrefix+i).value;
	}
	if(nr=='')
	{
		return 'EMPTY';
	}
	var bug = 'INCORRECT';
	
	if(!isCf || nr.length==10){
		//alert('full');
		if(nr.match('^[0-9]+$'))
		{
			bug = 'TOOSHORT';
		}
		for(var i=1;i<=3;i++)
		{
			var inp = tpGet(idPrefix+i);
			if(!inp.value.match('^[0-9]{'+((i==3)?4:3)+'}$'))
			{
				inp.focus();
				return bug;
			}
		}
		var npa = nr.substring(0,3);
		var correct = false;
		for(var i=0; i<NPA_codes.length; ++i){
			if(NPA_codes[i] == npa){
				correct = true;
				break;
			}
		}
		if(!correct){
			return 'NPA_INVALID';
		}

	}
	else{
		var isShort = ((nr.length == 7) && (tpGet('pn1')).value.length==0 );
		//alert('isShort: '+isShort);
		
		if(nr.match('^[0-9]+$'))
		{
			bug = 'TOOSHORT';
		}
		
		var i = (isShort)?2:1;
		for(;i<=3;i++)
		{
			var inp = tpGet(idPrefix+i);
			if(!inp.value.match('^[0-9]{'+((i==3)?4:3)+'}$'))
			{
				inp.focus();
				return bug;
			}
		}
		if(!isShort){
			var npa = nr.substring(0,3);
			var correct = false;
			for(var i=0; i<NPA_codes.length; ++i){
				if(NPA_codes[i] == npa){
					correct = true;
					break;
				}
			}
			if(!correct){
				return 'NPA_INVALID';
			}
		}
	}
	
	return 'OK';
}



function showValidationInfo(text,fun,beforeShow,afterHide)
{

	if(OV.isVmnOpen){
		fixVmnZIndexBeforeShow();
	}
	if(beforeShow && (typeof beforeShow === "function")){
		beforeShow();
	}

	var div = tpGet('tpValidationDiv');
	
	if(afterHide && (typeof afterHide === "function")){
		if(OV.isVmnOpen){
			OVValidationPopupCallback = function(){
				fixVmnZIndexAfterHide();
				afterHide();
			}
		}
		else{
			OVValidationPopupCallback = afterHide;
		}
	}
	else{
		if(OV.isVmnOpen){
			OVValidationPopupCallback = fixVmnZIndexAfterHide;
		}
	}
	div.innerHTML = text+'<br /><br /><div><input type="button" value="" class="okbtn" onclick="hidePopup(\'tpValidationDiv\');'+(fun?fun:'')+'"/></div>';
	showPopup('tpValidationDiv');
}
function showValidationAsk(text,fun)
{
	var div = tpGet('tpValidationDiv2');
	div.innerHTML = text+'<br /><br /><div><input type="button" value="" class="okbtn" onclick="hidePopup(\'tpValidationDiv2\');'+(fun?fun:'')+'"/></div>';
	showPopup('tpValidationDiv2');
}

var ftPl = new Object();
function ftPlInit(prefix,max)
{
	ftClearPhoneNumberInput(prefix+'add');
	ftPl[prefix] = new Object();
	ftPl[prefix].max = max;
	ftPl[prefix].nrs = new Array();
}
function mfPlInitPhone(prefix,fun)
{
	var format = '3:3:4';
	ftInitAccountNumberInput(prefix,fun,format);
}
function mfPlInitAccount(prefix,fun)
{
	var format = '5:6:2';
	ftInitAccountNumberInput(prefix,fun,format);
}
function mfPlInitAccountWest(prefix,fun,format)
{
	ftInitAccountNumberInput(prefix,fun,format);
}

function current_date() {
	var months = new Array(12);
	months[0]  = "January";
	months[1]  = "February";
	months[2]  = "March";
    months[3]  = "April";
    months[4]  = "May";
    months[5]  = "June";
    months[6]  = "July";
    months[7]  = "August";
    months[8]  = "September";
    months[9]  = "October";
    months[10] = "November";
    months[11] = "December"; 
	   
    var day = new Array(7);
    day[0]  = "Sunday";
    day[1]  = "Monday";
    day[2]  = "Tuesday";
    day[3]  = "Wednesday";
    day[4]  = "Thursday";
    day[5]  = "Friday";
    day[6]  = "Saturday";
	
	var today = new Date();
	today = day[today.getDay()] + ", " + months[today.getMonth()] + " " + today.getDate() + ", " + today.getFullYear();
	
    document.write(today);
}

function mfShowWarning(fId,fText,fSec,fTimes){
	if (mCan) {
		clearAlerts();
	
		mCan = false;
		mTimes = fTimes;
		mId = fId;
		mText = fText;
		mSec = fSec;		

		var obj = document.getElementById('warningMessage');
		if (obj!=null) obj.parentNode.removeChild(obj);
		obj = document.createElement('div');
		obj.setAttribute('id', 'warningMessage');
		obj.id = 'warningMessage';
		var div = document.getElementById(mId);
		mPos = div.parentNode.style.position;
		obj.onclick = function() { this.style.display='none'; document.getElementById(mId).parentNode.style.position=mPos; };
		obj.style.left = (div.offsetLeft - 30);
			
		obj.innerHTML = mText;
		
		obj.style.opacity = 0;
		if( obj.style.MozOpacity != undefined)
	        obj.style.MozOpacity = 0;
	     obj.style.filter='alpha(opacity=0)';
	     mOp = 0;
	    document.getElementById(mId).parentNode.style.position='relative';
	    document.getElementById(mId).parentNode.appendChild(obj);
	    
	    var ua = navigator.userAgent.toLowerCase();
		if (ua.indexOf('msie') != -1) {
			obj.style.top = obj.style.top - (obj.offsetHeight-26/16+3)+'px';
	    } 
	    
	    var h = obj.offsetHeight;
	    
	    var temp = obj.offsetWidth;
	    obj.style.width = temp;
	   
		var hTemp = h;
		while((hTemp == h) ) {
			obj.style.width = temp-2;
			temp--;
			hTemp = obj.offsetHeight;
		}
		obj.style.width = temp+2;
		mfShowWarningInner();
	}
}

var mA=0;
var mB=1;
var mC=1;
var mOp=0;
var mTimes=0;
var mSec=0;
var mId='';
var mText='';
var mTimeout='';
var mPos='';
var mCan=true;
//var mInterval = null;

function mfShowWarningInner() {
	var el = document.getElementById('warningMessage');
	var ff = (el.style.MozOpacity != undefined);
	var ie = (el.style.filter != undefined);
	if (mC==0) mOp=mOp-5; else mOp=mOp+5; 
	
	var num = new Number(mOp/100);

	if(ff) { 	
		el.style.opacity = num.toFixed(2);
		el.style.MozOpacity = num.toFixed(2);
	} if (ie) {
		el.style.display = 'block';
		el.style.bottom = '35px';
		el.style.filter = "alpha(opacity="+ (mOp) +")";
	} else {
		el.style.opacity = num.toFixed(2);
	}
//console.log('el.style.filter',el.style.filter);
	if (mOp==0 || mOp>=100) {
		mTimes--;
		if ((mTimes<=0) && (mOp==0)) {
			clearTimeout(mTimeout);
			document.getElementById(mId).parentNode.style.position=mPos;
			document.getElementById('warningMessage').style.display='none';
			mCan=true;
			mTimes=0;mC=1;
		} else {
			if (mC==0) mC=1; else mC=0; 
			mTimeout=setTimeout("mfShowWarningInner()", 2000); 
		}
	} else {
		mTimeout=setTimeout("mfShowWarningInner()", mSec); 
	}
	return false;
}

function hideWarningMessage(){
	if (!mCan) {
		try{
			clearTimeout(mTimeout);
			document.getElementById(mId).parentNode.style.position=mPos;
			document.getElementById('warningMessage').style.display='none';
			mCan=true;
			mTimes=0;mC=1;
		} catch(error){}
	}
}

function keyPressWrong(e,id,reg,txt,accept) {

	clearAlerts();

	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return false;
	if(keycode==8 || keycode==0 || keycode==13){
		return false;
	} else {
		if (accept==false) {
			if (reg.test(String.fromCharCode(keycode)))
			   mfShowWarning(id,txt,30,1); 
		} else {
			if (!reg.test(String.fromCharCode(keycode)))
			   mfShowWarning(id,txt,30,1); 
		}
		return false;
	}
}	

function keyPressWrongOrMax(e,id,max,reg,txt,accept) {

	clearAlerts();

	var temp = tpGet(id);
	var currSelectionSize = 0;
	try{
		currSelectionSize = GetSelectedText().length;
	} catch(error){}
	if ( (currSelectionSize==0) && (temp.value.length==max) ) {
		keyPressWrong(e,id,/.*/,'Password can be maximum '+max+' characters.',false);
	} else {
		keyPressWrong(e,id,reg,txt,accept);
	}	
}

function clearAlerts(){
	//clear any errors messages in alert div
	if(document.getElementById("alertDiv")){
		document.getElementById("alertDiv").innerHTML = "";
	}
	if(document.getElementById("optimumIDAlertDiv")){
		document.getElementById("optimumIDAlertDiv").innerHTML = "";
	}
}

function keyPressWrongOrMaxID(e,id,max,reg,txt,accept) {

	clearAlerts();

	var temp = tpGet(id);
	if (temp.value.length==max) {
		keyPressWrong(e,id,/.*/,'Optimum ID can be maximum '+max+' characters.',false);
	} else {
		keyPressWrong(e,id,reg,txt,accept);
	}	
}

function GetSelectedText() {
    var selText = "";
    if (window.getSelection) {      // Firefox, Opera, Google Chrome and Safari
        if (document.activeElement && 
                (document.activeElement.tagName.toLowerCase () == "textarea" || 
                 document.activeElement.tagName.toLowerCase () == "input")) 
        {
            var text = document.activeElement.value;
            selText = text.substring (document.activeElement.selectionStart, 
                                      document.activeElement.selectionEnd);
        }
        else {
            var selRange = window.getSelection ();
            selText = selRange.toString ();
        }
    }
    else {
        if (document.selection.createRange) {       // Internet Explorer
            var range = document.selection.createRange ();
            selText = range.text;
        }
    }
    return selText;
}




