////JQUERY JSON LIBRARY:
/*
* This document is licensed as free software under the terms of the
* MIT License: http://www.opensource.org/licenses/mit-license.php
*
* Adapted by Rahul Singla.
*
* Brantley Harris wrote this plugin. It is based somewhat on the JSON.org
* website's http://www.json.org/json2.js, which proclaims:
* "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.", a sentiment that
* I uphold.
*
* It is also influenced heavily by MochiKit's serializeJSON, which is
* copyrighted 2005 by Bob Ippolito.
*/
/**
* jQuery.JSON.encode( json-serializble ) Converts the given argument into a
* JSON respresentation.
*
* If an object has a "toJSON" function, that will be used to get the
* representation. Non-integer/string keys are skipped in the object, as are
* keys that point to a function.
*
* json-serializble: The *thing* to be converted.
*/
jQuery.JSON = {
encode: function(o) {
if (typeof (JSON) == 'object' && JSON.stringify)
return JSON.stringify(o);
var type = typeof (o);
if (o === null)
return "null";
if (type == "undefined")
return undefined;
if (type == "number" || type == "boolean")
return o + "";
if (type == "string")
return this.quoteString(o);
if (type == 'object') {
if (typeof o.toJSON == "function")
return this.encode(o.toJSON());
if (o.constructor === Date) {
var month = o.getUTCMonth() + 1;
if (month < 10)
month = '0' + month;
var day = o.getUTCDate();
if (day < 10)
day = '0' + day;
var year = o.getUTCFullYear();
var hours = o.getUTCHours();
if (hours < 10)
hours = '0' + hours;
var minutes = o.getUTCMinutes();
if (minutes < 10)
minutes = '0' + minutes;
var seconds = o.getUTCSeconds();
if (seconds < 10)
seconds = '0' + seconds;
var milli = o.getUTCMilliseconds();
if (milli < 100)
milli = '0' + milli;
if (milli < 10)
milli = '0' + milli;
return '"' + year + '-' + month + '-' + day + 'T' + hours + ':'
+ minutes + ':' + seconds + '.' + milli + 'Z"';
}
if (o.constructor === Array) {
var ret = [];
for (var i = 0; i < o.length; i++)
ret.push(this.encode(o[i]) || "null");
return "[" + ret.join(",") + "]";
}
var pairs = [];
for (var k in o) {
var name;
var type = typeof k;
if (type == "number")
name = '"' + k + '"';
else if (type == "string")
name = this.quoteString(k);
else
continue; // skip non-string or number keys
if (typeof o[k] == "function")
continue; // skip pairs where the value is a function.
var val = this.encode(o[k]);
pairs.push(name + ":" + val);
}
return "{" + pairs.join(", ") + "}";
}
},
/**
* jQuery.JSON.decode(src) Evaluates a given piece of json source.
*/
decode: function(src) {
if (typeof (JSON) == 'object' && JSON.parse)
return JSON.parse(src);
return eval("(" + src + ")");
},
/**
* jQuery.JSON.decodeSecure(src) Evals JSON in a way that is *more* secure.
*/
decodeSecure: function(src) {
if (typeof (JSON) == 'object' && JSON.parse)
return JSON.parse(src);
var filtered = src;
filtered = filtered.replace(/\\["\\\/bfnrtu]/g, '@');
filtered = filtered
.replace(
/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
']');
filtered = filtered.replace(/(?:^|:|,)(?:\s*\[)+/g, '');
if (/^[\],:{}\s]*$/.test(filtered))
return eval("(" + src + ")");
else
throw new SyntaxError("Error parsing JSON, source is not valid.");
},
/**
* jQuery.JSON.quoteString(string) Returns a string-repr of a string, escaping
* quotes intelligently. Mostly a support function for JSON.encode.
*
* Examples: >>> jQuery.JSON.quoteString("apple") "apple"
*
* >>> jQuery.JSON.quoteString('"Where are we going?", she asked.') "\"Where
* are we going?\", she asked."
*/
quoteString: function(string) {
if (string.match(this._escapeable)) {
return '"' + string.replace(this._escapeable, function(a) {
var c = this._meta[a];
if (typeof c === 'string')
return c;
c = a.charCodeAt();
return '\\u00' + Math.floor(c / 16).toString(16)
+ (c % 16).toString(16);
}) + '"';
}
return '"' + string + '"';
},
_escapeable: /["\\\x00-\x1f\x7f-\x9f]/g,
_meta: {
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"': '\\"',
'\\': '\\\\'
}
}
/*
* FUNCTIONS By 15 Green leaves
*
*/
var meta_marker='_value';
var apm_show_attributes=false;
var filters={};
function setCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function deleteCookie(name) {
setCookie(name,"",-1);
}
var fgl_setAutoSetSaveTitle=function(obj){
form=jQuery('#post');
var ob=obj
jQuery('#post').attr('obj',obj);
jQuery('#post').live('submit',function(){
//alert(jQuery(this).attr('obj'));
///SEt POST TITLE FROM OTHER FIELDS FOLLOWING SCHEMA
postTitleObj=jQuery('input[name="post_title"]');
var str=ob.schema;
jQuery.each(ob.fields,function(index, field) {
//alert(index + ': ' + field.field+ ': ' + field.field_type);
fi=jQuery('input[name="'+field.field+meta_marker+'"]');
if(field.field_type!=='select'){
str=str.split('{'+field.field+'}').join(jQuery(fi).val());
} else {
o=jQuery('#'+field.field);
v=jQuery(o).find('option:selected').text();
str=str.split('{'+field.field+'}').join(v);
}
})
D=new Date();
str=str.split('[currentdate]').join(D.getFullYear()+"-"+D.getMonth()+"-"+D.getDate());
jQuery(postTitleObj).val(str);
//CHECK REQUIRED
var test=true;
fi=jQuery('input[class="apm_is_required"]');
jQuery.each(fi,function(index, field) {
if(jQuery(field).val()==""){
test=false;
jQuery(field).parent().parent().addClass('apm_invalid');
}
});
//CHECK EMAIL
fi=jQuery('input[class="apm_is_email"]');
jQuery.each(fi,function(index, field) {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address = jQuery(field).val();
if(reg.test(address) == false && address!=='') {
jQuery(field).parent().parent().addClass('apm_invalid');
test=false;
}
});
//CHECK NUMBERS
fi=jQuery('input[class="apm_is_numbers"]');
jQuery.each(fi,function(index, field) {
var num = jQuery(field).val();
if ( isNaN(num)) {
jQuery(field).parent().parent().addClass('apm_invalid');
test=false;
}
});
//CHECK PHONE
fi=jQuery('input[class="apm_is_phone"]');
jQuery.each(fi,function(index, field) {
var phone = jQuery(field).val();
var stripped = phone.replace(/[\(\)\.\-\+\ ]/g, '');
if (isNaN(stripped)) {
jQuery(field).parent().parent().addClass('apm_invalid');
test=false;
} else if (stripped.length <8 && stripped.length >0 ) {
jQuery(field).parent().parent().addClass('apm_invalid');
test=false;
}
});
if(test==false){
alert("Some fields are invalid.")
return false;
}
});
}
var fgl_setAutoSetTitle=function(obj){
var inputs=jQuery(':input');
//alert(posttitle);
var myobj=obj;
var postTitleObj=null;
postTitleObj=jQuery('input[name="post_title"]');
var str=obj.schema;
jQuery.each(obj.fields,function(index, field) {
//alert(index + ': ' + field.field+ ': ' + field.field_type);
fi=jQuery('input[name="'+field.field+meta_marker+'"]');
if(field.field_type!=='select'){
str=str.split('{'+field.field+'}').join(jQuery(fi).val());
} else {
o=jQuery('#'+field.field);
v=jQuery(o).find('option:selected').text();
str=str.split('{'+field.field+'}').join(v);
}
})
D=new Date();
str=str.split('[currentdate]').join(D.getFullYear()+"-"+D.getMonth()+"-"+D.getDate());
jQuery(postTitleObj).val(str);
return;
}
var fgl_deleteComment=function(id,fieldname){
var commentTpl=jQuery("#apm_comment_"+id);
var commentNb=jQuery("#"+fieldname+"_comment_nb");
nb=Number(jQuery(commentNb).html())-1;
jQuery(commentNb).html(nb);
commentTpl.animate({
opacity:0
},500, function() {
commentTpl.hide();
})
jQuery.ajax({
url: ajaxurl ,
type: "POST",
data: "comment_id="+id+"&action=apm_delete_comments",
//context: document.body,
success: function(data){
}
});
}
var apm_convert=function(o,action,post_id,appname,post_type){
document.location.href="admin.php?page="+appname+"-main-menu&post_id="+post_id+"&action_name="+action+"&post-type="+post_type+"&action-type=convert";
}
var apm_actionbtn=function(o,action,post_id,appname,post_type){
var fields=jQuery(o).attr('fields');
oFields=eval(fields);
jQuery.each(oFields, function(key,field){
fieldToUpdate=jQuery('input[name="'+field[0]+meta_marker+'"]');
if(jQuery(fieldToUpdate).val()==undefined){
if(document.post[field[0]+meta_marker]!==undefined){//= is select
o=document.post[field[0]+meta_marker].options[0];
//document.post[field[0]+meta_marker].selectedIndex =5;
for (var i = 0; i < document.post[field[0]+meta_marker].length; i++)
{
if (Number(document.post[field[0]+meta_marker].options[i].value) == Number(field[1]))
{
//alert(document.post[field[0]+meta_marker].options[i].value +'-'+ field[1]);
document.post[field[0]+meta_marker].selectedIndex =i;
//document.post[field[0]+meta_marker].selected = true;
}
}
}
if(tinyMCE.get(field[0]+meta_marker+'_comment')!==undefined){
txt=tinyMCE.get(field[0]+meta_marker+'_comment').getContent();//jQuery(commentBlock).attr("value");
//tinyMCE.get('content id').getContent()
tinyMCE.get(field[0]+meta_marker+'_comment').setContent(field[1]);
}
//jQuery(fieldToUpdate).val("3");
} else {
val=field[1];
if(val=='NOW()'){
var myDate=new Date();
m=myDate.getMonth();
m++;
if(m<10){
m='0'+m;
}
d=myDate.getDate();
if(d<10){
d='0'+d;
}
val=m+"/"+d+"/"+myDate.getFullYear();
}
if(val=='TIME()'){
var myDate=new Date();
h=myDate.getHours();
m=myDate.getMinutes();
if(m<10){
m='0'+m;
}
if(h<10){
d='0'+h;
}
val=h+":"+m;
}
jQuery(fieldToUpdate).val(val);
}
});
jQuery("#post").submit();
//document.location.href="admin.php?page="+appname+"-main-menu&post_id="+post_id+"&action_name="+action+"&post-type="+post_type+"&action-type=convert";
}
var apm_add_notif=function(o){
var userList=jQuery(o).prev();
var notifField=jQuery(o).next();
//alert(userList.val());
if(notifField.val().indexOf(',')>-1){
var notifUsersList=notifField.val().split(',');
} else if(notifField.val()!==""){
var notifUsersList=[notifField.val()];
}
var userToAdd=userList.val();
var newNotifUsersList=[];
var already_exist=false;
if(notifField.val()!==""){
jQuery.each(notifUsersList, function(key,userid){
if(Number(userid)!==Number(userToAdd) && Number(userid)!==0){
newNotifUsersList.push(userid);
} else {
already_exist=true;
}
});
}
newNotifUsersList.push(userToAdd);
//alert(jQuery(o).next().next().html());
if(already_exist==false){
newUserStr=""+jQuery(o).prev().find("option:selected").text()+" 
Status: Loading records');
//filters=param_filters==undefined? false:param_filters;
if(param_filter_key!==undefined){
filters[param_filter_key]=param_filter_value;
}
filters_str=jQuery.JSON.encode(filters);
jQuery.ajax({
url: ajaxurl ,
type: "POST",
data: "modulekey="+modulekey+"&action=apm_manage_grid_data&todo=get_data&filters="+filters_str,
success: function(data){
dataStr=String(data);
dataStr=dataStr.substring(0,dataStr.length-1);
dataCut=dataStr.split("//cutter//");
table.append(dataCut[0])
//alert(eval(dataCut[1]);
rtrnObj=jQuery.parseJSON( dataCut[1]);
if(rtrnObj.filters_results!==""){
status_zone.html('Status: Records loaded ('+rtrnObj.count+' / '+rtrnObj.total_count+'), filtered by: '+rtrnObj.filters_results+'');
}else {
status_zone.html('Status: Records loaded ('+rtrnObj.count+' / '+rtrnObj.total_count+')');
}
}
});
}
}
jQuery.each(data_grids, function(key, data_grid){
apm_load_data_grid(data_grid);
});
///SET A-Z filtering
jQuery(".apm_grid_az_header > li > a").live('click', function(){
letter=jQuery(this).attr('letter');
var grid=jQuery(this).parents('.apm_grid_block_cls');
refresh_grid(grid,"letter",letter);
});
var cb_clicked_store=[];
jQuery(".apm_grid_row_cb").live('click', function(){
post_id= jQuery(this).attr('post_id');
var do_check=false;
if(jQuery(this).attr('checked')=='checked'){
do_check=true;
pos=jQuery.inArray(post_id,cb_clicked_store);
if(pos==-1){
cb_clicked_store.push(post_id);
}
} else {
do_check=false;
pos=jQuery.inArray(post_id,cb_clicked_store);
if(pos>-1){
cb_clicked_store.splice(pos,1);
}
}
//alert(pos+"-"+post_id+"-"+do_check+"-"+cb_clicked_store);
});
jQuery(".apm_grid_head_cb").live('click', function(){
var do_check=false;
if(jQuery(this).attr('checked')=='checked'){
do_check=true;
}
div=jQuery(this).parents('.apm_grid_block_cls');//.parent().parent().parent().parent().parent();//.parent().next();
table=div.find('table > tbody > tr');
cb_clicked_store=[];
jQuery.each(table,function(index, tr) {each
tds=jQuery(tr).find('td');
td=tds[0].firstChild;
post_id=jQuery(td).attr('post_id');
if(do_check){
jQuery(td).attr('checked','checked');
cb_clicked_store.push(post_id);
} else {
jQuery(td).removeAttr('checked');
}
});
});
var refresh_grid=function(grid,param_filter_key,param_filter_value){
var data_grid=grid.find('tbody');
jQuery(data_grid).html("");
apm_load_data_grid(data_grid,param_filter_key,param_filter_value);
}
jQuery(".apm_refresh_btn").on('click', function(){
var grid=jQuery(this).parents('.apm_grid_block_cls');//.parent().parent().parent();
refresh_grid(grid);
});
///SHOW LAYER ACTION ON DATA GRIDS
var countHideLayer=0;
var apm_selected_post_id=0;
var apm_selected_post_status=false;
var apm_selected_post_object=false;
var apm_activateActionLayer=function(){
countHideLayer=0;
jQuery(".apm_act_action").live('mouseover', function(){
actionLayer=jQuery('#apm_grid_actions_layer');
thisObj=jQuery(this);
actionLayer.css("left",thisObj.position().left+20+"px").css("top",thisObj.position().top+"px");
apm_selected_post_id=jQuery(this).attr('post_id');
apm_selected_post_status=jQuery(this).attr('post_status');
actionLayer.show();
if(apm_selected_post_status=='publish'){
actionLayer.find('.apm_act_pub').hide();
actionLayer.find('.apm_act_unpub').show();
actionLayer.find('.apm_act_trash').show();
} else if(apm_selected_post_status=='pending' || apm_selected_post_status=='draft'){
actionLayer.find('.apm_act_pub').show();
actionLayer.find('.apm_act_unpub').hide();
actionLayer.find('.apm_act_trash').show();
}else if(apm_selected_post_status=='trash'){
actionLayer.find('.apm_act_pub').show();
actionLayer.find('.apm_act_unpub').show();
actionLayer.find('.apm_act_trash').hide();
}
countHideLayer=0;
apm_selected_post_object=this;
});
jQuery(".apm_act_action").live('mouseout', function(){
apm_startCountHideLayer('#apm_grid_actions_layer');
});
jQuery("#apm_grid_actions_layer > span").live('mouseout', function(){
apm_startCountHideLayer('#apm_grid_actions_layer');
})
jQuery("#apm_grid_actions_layer > span").live('mouseover', function(){
countHideLayer=0;
})
jQuery(".apm_act_edit").live('click', function(){
window.open('post.php?post='+apm_selected_post_id+'&action=edit','_blank');
});
jQuery(".apm_act_trash").live('click', function(){
if(jQuery(this).hasClass('apm_pad_icon')){
apm_multi_update_status_ajax(this,'trash_multirecs','Trashing','Trashed');
} else if(jQuery(this).hasClass('apm_filter_icon')){
apm_filter_status_ajax(this,'filter_trash');
}else {
jQuery(apm_selected_post_object).parent().parent().hide();
var grid=jQuery(apm_selected_post_object).parents('.apm_grid_block_cls');//.parent().parent().parent().parent().parent().parent();
var status_zone=grid.find('.apm_grid_status_zone');
var grid_tbody=grid.find('tbody');
var modulekey=grid_tbody.attr('modulekey');
status_zone.html('
Status: trashing Record Id '+apm_selected_post_id+' ');
jQuery.ajax({
url: ajaxurl ,
type: "POST",
data: "modulekey="+modulekey+"&action=apm_manage_grid_data&todo=trash_rec&post_id="+apm_selected_post_id,
success: function(data){
status_zone.html('Status: Record trashed');
}//apm_get_grid_data
});
}
});
jQuery(".apm_act_del").live('click', function(){
if(cb_clicked_store.length==0 && jQuery(this).hasClass('apm_pad_icon')){
alert("Please select at least one record");
return;
}
if(jQuery(this).hasClass('apm_pad_icon')){
var answer = confirm('Are you sure that you want to delete the Record(s) # '+cb_clicked_store.join(', ')+' ?');
if (answer){
apm_multi_update_status_ajax(this,'del_multirecs','Deleting','Deleted');
}
} else {
var answer = confirm('Are you sure that you want to delete the Record ID '+apm_selected_post_id+' ?');
if (answer){
jQuery(apm_selected_post_object).parent().parent().hide();
var grid=jQuery(apm_selected_post_object).parents('.apm_grid_block_cls');//.parent().parent().parent().parent().parent().parent();
var status_zone=grid.find('.apm_grid_status_zone');
var grid_tbody=grid.find('tbody');
var modulekey=grid_tbody.attr('modulekey');
status_zone.html('
Status: deleting Record Id '+apm_selected_post_id+' ');
jQuery.ajax({
url: ajaxurl ,
type: "POST",
data: "modulekey="+modulekey+"&action=apm_manage_grid_data&todo=del_rec&post_id="+apm_selected_post_id,
success: function(data){
status_zone.html('Status: Record Deleted');
}//apm_get_grid_data
});
}
}
});
var apm_filter_status_ajax=function(obj,status_action){
gridwrap=jQuery(obj).parents(".apm_datagrid_wrapper");
var grid=gridwrap.find('.apm_grid_block_cls');
var status_zone=grid.find('.apm_grid_status_zone');
refresh_grid(grid,"post_status",status_action);
}
var apm_multi_update_status_ajax=function(obj,status_action,status_text1,status_text2){
if(cb_clicked_store.length==0){
alert("Please select at least one record");
return;
}
p=jQuery(obj).parent();
var status_action=status_action;
modulekey=jQuery(p).attr('modulekey');
gridwrap=jQuery(obj).parents(".apm_datagrid_wrapper");
var grid=gridwrap.find('.apm_grid_block_cls');
var status_zone=grid.find('.apm_grid_status_zone');
html='
';
html+='Status: '+status_text1+' the '+cb_clicked_store.length+' record(s) '+cb_clicked_store.join(', ')+' ';
status_zone.html(html);
jQuery.ajax({
url: ajaxurl ,
type: "POST",
data: "modulekey="+modulekey+"&action=apm_manage_grid_data&todo="+status_action+"&post_ids="+cb_clicked_store.join(','),
success: function(data){
status_zone.html('Status: '+cb_clicked_store.length+' Record(s) '+status_text2+'');
switch(status_action){
default:
jQuery.each(cb_clicked_store, function(key,id){
tr=jQuery('.'+modulekey+"_"+id);
td_status=tr.find('.td_status');
switch(status_action){
case 'unpub_multirecs':
jQuery(td_status[0]).removeClass('apm_act_pub');
jQuery(td_status[0]).addClass('apm_act_unpub');
jQuery(td_status[0]).addClass('apm_act_trash');
break;
case 'pub_multirecs':
jQuery(td_status[0]).removeClass('apm_act_unpub');
jQuery(td_status[0]).addClass('apm_act_pub');
jQuery(td_status[0]).addClass('apm_act_trash');
break;
case 'trash_multirecs':
jQuery(td_status[0]).addClass('apm_act_unpub');
jQuery(td_status[0]).addClass('apm_act_pub');
jQuery(td_status[0]).removeClass('apm_act_trash');
break;
}
});
if(status_action=="trash_multirecs"){
refresh_grid(grid);
cb_clicked_store=[];
}
break;
/*case 'trash_multirecs':
break;*/
case 'del_multirecs':
refresh_grid(grid);
cb_clicked_store=[];
break;
}
//refresh_grid(grid);
}
});
}
var apm_update_status_ajax=function(status_action,status_text1,status_text2){
var grid=jQuery(apm_selected_post_object).parents('.apm_grid_block_cls');
apm_act_action=jQuery(apm_selected_post_object).parent().parent().find('.apm_act_action');
jQuery(apm_act_action).attr('post_status','draft')
td_status=jQuery(apm_selected_post_object).parent().parent().find('.td_status');
if(status_action=='unpub_rec'){
jQuery(td_status).removeClass('apm_act_pub');
jQuery(td_status).addClass('apm_act_unpub');
jQuery(td_status).addClass('apm_act_trash');
} else if(status_action=='pub_rec'){
jQuery(td_status).removeClass('apm_act_unpub');
jQuery(td_status).addClass('apm_act_pub');
jQuery(td_status).addClass('apm_act_trash');
} else if(status_action=='trash_multirecs'){
jQuery(td_status).addClass('apm_act_unpub');
jQuery(td_status).addClass('apm_act_pub');
jQuery(td_status).removeClass('apm_act_trash');
}
var status_zone=grid.find('.apm_grid_status_zone');
var grid_tbody=grid.find('tbody');
var modulekey=grid_tbody.attr('modulekey');
html='
';
html+='Status: '+status_text1+' Record Id '+apm_selected_post_id+' ';
status_zone.html(html);
jQuery.ajax({
url: ajaxurl ,
type: "POST",
data: "modulekey="+modulekey+"&action=apm_manage_grid_data&todo="+status_action+"&post_id="+apm_selected_post_id,
success: function(data){
status_zone.html('Status: Record '+status_text2+'');
}
});
}
jQuery(".apm_act_all").live('click', function(){
if(jQuery(this).hasClass('apm_filter_icon')){
apm_filter_status_ajax(this,'filter_all');
}
});
jQuery(".apm_act_unpub").live('click', function(){
if(jQuery(this).hasClass('apm_pad_icon')){
apm_multi_update_status_ajax(this,'unpub_multirecs','Unpublishing','Unpublished');
} else if(jQuery(this).hasClass('apm_filter_icon')){
apm_filter_status_ajax(this,'filter_unpub');
} else {
apm_update_status_ajax('unpub_rec','Unpublishing','Unpublished');
}
});
jQuery(".apm_act_pub").live('click', function(){
if(jQuery(this).hasClass('apm_pad_icon')){
apm_multi_update_status_ajax(this,'pub_multirecs','Publishing','Published');
} else if(jQuery(this).hasClass('apm_filter_icon')){
apm_filter_status_ajax(this,'filter_pub');
} else {
apm_update_status_ajax('pub_rec','Publishing','Published');
}
});
jQuery(".apm_act_view").live('click', function(){
//alert('view '+apm_selected_post_id);
});
}
apm_activateActionLayer();
var apm_startCountHideLayer=function(obj_id){
var date = new Date();
countHideLayer=date.getTime();
setTimeout(apm_CheckHideLayer,500,obj_id);
}
var apm_CheckHideLayer=function(obj_id){
//alert(countHideLayer);
if(countHideLayer!==0){
actionLayer=jQuery(obj_id);
actionLayer.hide();
apm_selected_post_id=0;
apm_selected_post_object=false;
}
countHideLayer=0;
}
/////HANDLE Show the help layer on rollover on a ? icon
jQuery(".apm_help_btn").live('mouseover', function(){
//alert(jQuery(this).next());
// alert(jQuery(this).next().text());
helpTxt=jQuery(this).next().text();
helpObject=jQuery(this).next();
helpObject.css("left",jQuery(this).position().left+30+"px").css("top",jQuery(this).position().top+"px");
helpObject.show();
});
jQuery(".apm_help_btn").live('mouseout', function(){
helpObject=jQuery(this).next();
helpObject.hide();
});
//END
jQuery('.fileRemove').live('click',function(){
jQuery(this).parent().hide();
jQuery(this).next().val(jQuery(this).attr('fileid'));
fieldname=jQuery(this).attr('fieldname');
filednb=jQuery(this).attr('fieldnb');
filetype=jQuery(this).attr('filetype');
if(filetype=="main"){
jQuery("#"+fieldname).show();
}
});
//
jQuery('.fileAddDescription_btn').live('click',function(){
jQuery(this).next().next().show();
jQuery(this).next().next().css('display','block');
});
jQuery('.fileHelpLayer_btn').live('click',function(){
});
//
jQuery('.apm_add_upload').live('click',function(){
if(this.nbupload==undefined){
this.nbupload=0;
}
this.nbupload+=1;
fieldname=jQuery(this).attr('fieldname');
uploadfield=jQuery("#"+fieldname);
uploadfieldcount=jQuery("#"+fieldname+"_add_file");
jQuery(uploadfieldcount).val(this.nbupload);
//
uploadfieldnew=jQuery(this).parent().parent().append('');
uploadfieldnew.css('display','block');
});
/* a = jQuery('.autocomplete_field').autocomplete( {
serviceUrl:ajaxurl+"?callback=?&action=amp-ajax-autocomplete&fieldname="+jQuery(this).attr(),
minChars:2
});*/
jQuery.each(jQuery('.autocomplete_field'), function(i, obj){
var fieldname=jQuery(obj).attr('fieldname');
var post_type=jQuery(obj).attr('post_type');
a= jQuery(obj).autocomplete( {
serviceUrl:ajaxurl+"?callback=?&action=amp-ajax-autocomplete&fieldname="+fieldname+"&post_type="+post_type,
minChars:2
});
jQuery(obj).blur(function(){
if(jQuery(this).val()==''){
jQuery(this).next().val('');
}
});
});
jQuery('.apm_is_required').live('blur',function(i, obj){
if(jQuery(this).val()==''){
//alert('This field is required, please input a value');
jQuery(this).parent().parent().addClass('apm_invalid');
jQuery(this).focus()
} else {
jQuery(this).parent().parent().removeClass('apm_invalid');
}
});
jQuery('.apm_is_email').live('blur',function(i, obj){
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address = jQuery(this).val();
if(reg.test(address) == false && address!=='') {
jQuery(this).parent().parent().addClass('apm_invalid');
jQuery(this).focus()
} else {
jQuery(this).parent().parent().removeClass('apm_invalid');
}
});
jQuery('.apm_is_numbers').live('blur',function(i, obj){
var num = jQuery(this).val();
if ( isNaN(num)) {
jQuery(this).parent().parent().addClass('apm_invalid');
jQuery(this).focus()
} else {
jQuery(this).parent().parent().removeClass('apm_invalid');
}
});
jQuery('.apm_is_phone').live('blur',function(i, obj){
error='';
var phone = jQuery(this).val();
var stripped = phone.replace(/[\(\)\.\-\+\ ]/g, '');
if (isNaN(stripped)) {
error = "The phone number contains illegal characters.\n";
jQuery(this).parent().parent().addClass('apm_invalid');
} else if (stripped.length <8 && stripped.length >0 ) {
error = "The phone number is the wrong length. Make sure you included an area code.\n";
jQuery(this).parent().parent().addClass('apm_invalid');
} else {
jQuery(this).parent().parent().removeClass('apm_invalid');
}
});
//apm_is_required
jQuery('.apm_imgfile > img').live('click',function(){
str_height=' height="500" ';
if(jQuery(this).attr('has_resize')=='true'){
str_height='';
}
jQuery('body').prepend('
Field required.
Senging....