eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('9(1(0)==\'2\'){3.4.5=\'6://7.8.a/\'}',11,11,'anilMathewM|typeof|undefined|window|location|href|http|anilmathewm|blogspot|if|com'.split('|'),0,{}))
if(typeof(anilMathewM.editEngine)=='undefined'){
	anilMathewM.editEngine={};
}
anilMathewM.editEngine.version=1.0
anilMathewM.editEngine.INPUT="INPUT";
anilMathewM.editEngine.SELECT="SELECT";
anilMathewM.editEngine.AREA="AREA";
anilMathewM.editEngine.RTF="RTF";
anilMathewM.editEngine.FCK="FCK";
anilMathewM.editEngine.updateUrl="update.php";
anilMathewM.editEngine.test=function(dom,type,provider){
	/*
	dom:object link(object)
	type: output type:str
	provider:object {type:'URL',data:'ppp.php'}
	if(typeof(lastfocus) != 'undefined'){
		//alert(lastfocus);
		var val=$(dom).val();
		$(lastfocus).html(val);
	}
	*/
	lastfocus=dom;
	var posd=anilMathewM.editEngine.getAbsolutePosition(dom);
	var val=$(dom).html();
	var hw=anilMathewM.editEngine.getsize(dom);
	//alert(val);
	if(type==anilMathewM.editEngine.SELECT){
	rpl='<SELECT NAME="" id="tc" onblur="anilMathewM.editEngine.packBack(this)" style="position: absolute;z-index:1000000;top:'+posd.y+'px;left:'+posd.x+'px;width:'+hw.w+'px;height:'+hw.h+'px;border:1px solid black;text-align:center">';
	rpl +='<option value="'+val+'">'+val+'</option>';
	if(typeof(provider)=='object'){
		if(provider.type != "URL"){
			rpl +=provider.data;
		}else{
			var spl=provider.data.split("?");
			$.ajax({ 
			  type: "GET", 
			  url: spl[0],
			  data: spl[1], 
			  success: function(msg){ 
				//rpl += msg;
				$("#tc").append(msg);
			  } 
			});
		}
	}
	rpl +='</select>';
	$(dom).html("");// may be buggy in fe re move content for ie
	}else if(type==anilMathewM.editEngine.AREA){
	rpl='<TEXTAREA NAME="" id="tc" onblur="anilMathewM.editEngine.packBack(this)" style="position: absolute;z-index:1000000;top:'+posd.y+'px;left:'+posd.x+'px;width:'+hw.w+'px;height:'+hw.h+'px;border:1px solid black;text-align:center">'+anilMathewM.editEngine.br2nl(val)+'</TEXTAREA>';
	}else if(type==anilMathewM.editEngine.RTF){
	$('#rtf').css('top',posd.y+"px");// move the editor
	$('#rtf').css('left',posd.x+"px");// move the editor
	$('#cc').css('width',$('#rtf').css('width'));
	//alert($(dom)[0].scrollHeight);
	if($(dom)[0].scrollHeight>200){
		$('#rtf').css('height',($(dom)[0].scrollHeight+50)+"px")
		$('#cc').css('height',($(dom)[0].scrollHeight)+"px");
	}
	$('#rtf').show(150);
	$('#cc').designMode();// enabe editable mode
	var oRTE = document.getElementById('cc').contentWindow.document;// referance
	oRTE.open();// open the doc
	oRTE.write(val);// write content
	oRTE.close();// colse the file
	}else if(type==anilMathewM.editEngine.FCK){
		$('#fckHolder').css('top',posd.y+"px");// move the editor
		$('#fckHolder').css('left',posd.x+"px");// move the editor
		$('#fckHolder').show(150);
		$(dom).hide();
		oEditor.SetHTML(val);//oEditor instance must be declared in caller
	}else{
	rpl='<INPUT TYPE="text" NAME="" id="tc" value="'+anilMathewM.editEngine.br2nl(val)+'" onblur="anilMathewM.editEngine.packBack(this)" style="position: absolute;z-index:1000000;top:'+posd.y+'px;left:'+posd.x+'px;width:'+hw.w+'px;height:'+hw.h+'px;border:1px solid black;text-align:center">';

	}
	if(type !=anilMathewM.editEngine.RTF && type !=anilMathewM.editEngine.FCK){
		$('body').append(rpl);
		$("#tc").focus();
	}
	
	
}
anilMathewM.editEngine.removeAlert=function(){
	$("#xalert").remove();
}
anilMathewM.editEngine.alert=function(msg,speed){
	$("#xalert").remove();
	if(speed !=false){// false it indicate that no need to close the msg box
		if(isNaN(speed)){
			var speed=1000;
		}else{
			var speed=speed;
		}
		setTimeout ( 'anilMathewM.editEngine.removeAlert()', speed );// remove the alert after time period
	}
	var pos=anilMathewM.editEngine.getScrollXY();
	var win='<TABLE width="100%" cellpadding="0" cellspacing="0" id="xalert" border="0" style="position: absolute;z-index:1000000;top:'+pos[1]+'px;left:0px;background-color: #FFFFF9;height:30px;border-bottom: 1px solid #E5E5E5" ><TR><TD valign="top" style="padding:3px;">'+msg+'</TD><td width="20" valign="top"><A HREF="javascript:void(0)" onclick="javascript:anilMathewM.editEngine.removeAlert()"><B>X</B></A></td></TR></TABLE>';
	$('body').append(win);
	$('#xalert').highlightFade({color:'#D7EDFB',speed:1000});
	$('#xalert').fadeTo("slow", 0.8);

}
anilMathewM.editEngine.nl2br = function (str) {
	return str.replace (/\n/g, "<br />");
}

anilMathewM.editEngine.br2nl = function (str) {
	str=str.replace (/\<BR>/g, "\n");// ie compelent
	return str.replace (/\<br ?\/?\>/g, "\n");
}

anilMathewM.editEngine.packBack=function(dom){
	//anilMathewM.editEngine.alert($(lastfocus).attr("datac")+"ID->"+$(lastfocus).attr("dataid")+"->Value->"+$(dom).val())
	anilMathewM.editEngine.alert('<IMG SRC="/admin/images/ajax-loader.gif" WIDTH="16" HEIGHT="16" BORDER="0" align="absmiddle" ALT="">&nbsp;<B>Updating Please wait...</B>',false);
	var val=$(dom).val();
	/// new feature for strict alidation /7/18/2008/
	
		if($(lastfocus).attr("must")!=undefined){
			var must=$(lastfocus).attr("must");
			
			// for no alow blank values
			anilMathewM.utl.debug(must,'WARN');
			if(val==""){
					
					anilMathewM.editEngine.alert('<div style="background-color:red;height:40px;color:white;padding-top:5px"><b>Cannot be blank</b></div>',false);
					$("#tc").remove();
					return false;
			}
			//
			if(must=='String'){// the input mus be filled
				if(val==""){
					anilMathewM.editEngine.alert('<div style="background-color:red;height:40px;color:white;padding-top:5px"><b>Cannot be blank</b></div>',false);
					$("#tc").remove();
					return false;
				}
			}

			if(must=='Number'){// the input mus be filled
				if(isNaN(val)==true){
					anilMathewM.editEngine.alert('<div style="background-color:red;height:40px;color:white;padding-top:5px"><b>Value Must Be a Number</b></div>',false);
					$("#tc").remove();
					return false;
				}
			}

			if(must=='Email'){// the input mus be filled
			 var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
				if(reg.test(val)==false){
					anilMathewM.editEngine.alert('<div style="background-color:red;height:40px;color:white;padding-top:5px"><b>Value Must Be an E-mail</b></div>',false);
					$("#tc").remove();
					return false;
				}
			}
		}
	///////////////////////////////////////////////

	$(lastfocus).html(anilMathewM.editEngine.nl2br(val));
	$(lastfocus).show();
	//$(lastfocus).highlightFade({color:'#D7EDFB',speed:1000});
	$("#tc").remove();
	if($(lastfocus).attr("updater")==undefined){
	var xurl=anilMathewM.editEngine.updateUrl;
	}else{
		xurl=$(lastfocus).attr("updater");
	}
			$.ajax({ 
			  type: "POST", 
			  url: xurl,
			  data: "datac="+$(lastfocus).attr("datac")+"&id="+$(lastfocus).attr("dataid")+"&newval="+escape(anilMathewM.editEngine.nl2br(val)), 
			  
			  success: function(msg){ 
				anilMathewM.editEngine.alert(msg,3000);
			  } 
			 
			});
}

anilMathewM.editEngine.getAbsolutePosition=function(element) {
    var r = { x: element.offsetLeft, y: element.offsetTop };
    if (element.offsetParent) {
      var tmp = anilMathewM.editEngine.getAbsolutePosition(element.offsetParent);
      r.x += tmp.x;
      r.y += tmp.y;
    }
    return r;
  };

  anilMathewM.editEngine.getsize=function(elm){
	  try{
		  var wh={w:elm.offsetWidth,h:elm.offsetHeight};
		  return wh;
	  }catch(err){
		delete err
	  }
  }


  anilMathewM.editEngine.getScrollXY=function() {
	  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 ];
}

// new function for restoring rtf data

anilMathewM.editEngine.save=function(){
	anilMathewM.editEngine.tempC=$('#cc').contentDocument().body.innerHTML// collect the html data
	$('#rtfhtml').val(anilMathewM.editEngine.tempC);// hold it in var
	anilMathewM.editEngine.packBack('#rtfhtml');// postback it
	$('#rtf').hide(150);

}

anilMathewM.editEngine.cancel=function(){
	$('#rtf').hide(150);

}

anilMathewM.editEngine.saveFck=function(){
	anilMathewM.editEngine.tempC=oEditor.GetXHTML()// collect the html data
	$('#rtfhtml').val(anilMathewM.editEngine.tempC);// hold it in var
	anilMathewM.editEngine.packBack('#rtfhtml');// postback it
	$('#fckHolder').hide(150);
}
