var on_focus	= 0;
var is_saved	= 0;
var save_queue	= 0;

function show_box( elid ) {
	
	if ( document.getElementById( elid ) ) {
		
		document.getElementById( elid ).style.display	= 'block';
	}
}

function hide_box( elid ) {
	
	if ( document.getElementById( elid ) ) {
		
		document.getElementById( elid ).style.display	= 'none';
	}
}

function img_prev_swap( elid, cls ) {
	
	if ( document.getElementById( elid ) ) {
		
		document.getElementById( elid ).className	= cls;
	}
}

function str_replace( search, replace, subject ) {
	
	return subject.split( search ).join( replace );
}

function do_highlight( elid, ext ) {
	
	editAreaLoader.init({
		id : elid		// textarea id
		,syntax: ext			// syntax to be uses for highgliting
		,start_highlight: true		// to display with highlight mode on start-up
	});
}

function check_unic(  ) {
	
//	var id = 5;
//	$.getJSON( "sku_list.php", {id:id}, dates );
}

function dates( datos ) {
	
	//$("#list").html("Name:"+datos[1].name+"<br>"+"Last Name:"+datos[1].lastname+"<br>"+"Address:"+datos[1].address);
}


///////////////////////////////////// admin menu script ///////////////////////////////////////////
function cfg_menu(  ) {
	
	this.menu_active	= new Array(  );
	this.over			= 0;
	this.mid			= 0;
}

cgm = new cfg_menu(  );

function menu_admin_over( mid ) {
	
	did	= 'drop_' + mid;
	
	if( document.getElementById( did ) ) {
		
		cgm.menu_active[ did ] = 1;
		
		document.getElementById( did ).style.display    = 'block';
	}
}

function menu_admin_out( mid ) {
	
	did	= 'drop_' + mid;
	
	if( document.getElementById( did ) ) {
		
		cgm.menu_active[ did ] = 0;
		
		setTimeout( "menu_drop_hide( '" + mid + "' );", 250 );
	}
}

function menu_drop_hide( mid ) {
	
	did	= 'drop_' + mid;
	
	if( 0 == cgm.menu_active[ did ] ) {
		
		if( document.getElementById( did ) ) {
			
			document.getElementById( did ).style.display    = 'none';
		}
	}
}



function tab_on( active_tab, el_pref ) {
	
	$( "." +el_pref + "_all" ).removeClass( el_pref + '_press' );
	$( "." +el_pref + "_all" ).removeClass( el_pref + '_over' );
	$( "." +el_pref + "_all" ).addClass( el_pref + '_out' );
	
	$( "#" + el_pref + "_" + active_tab ).removeClass( el_pref + '_out' );
	$( "#" + el_pref + "_" + active_tab ).addClass( el_pref + '_press' );
	
	$( ".box_int" ).hide(  );
	$( "#tab_" + active_tab ).show(  );
	
	document.location.href = "#tab=" + active_tab;
}

function set_tab( el_pref ) {
	
	var str		= document.URL;
	
	var s_pos	= str.indexOf( "#" );
	
	if ( s_pos > 0 ) {
		
		str			= str.substr( s_pos - 1 + 2 );
		
		var arr_1	= str.split( "=" );
		
		if ( arr_1[1] ) {
			
			active_tab	= arr_1[1];
		}
		else {
			
			active_tab	= 'gen';
		}
	}
	else {
		
		active_tab		= 'gen';
	}
	
	$( "." +el_pref + "_all" ).removeClass( el_pref + '_press' );
	$( "." +el_pref + "_all" ).addClass( el_pref + '_out' );
	
	$( "#" + el_pref + "_" + active_tab ).removeClass( el_pref + '_out' );
	$( "#" + el_pref + "_" + active_tab ).addClass( el_pref + '_press' );
	
	$( ".box_int" ).hide(  );
	$( "#tab_" + active_tab ).show(  );
}

function tab_over( this_el, id, cl_pref ) {
/*	
	elid		= 'tab_' + id;
	cl_over		= cl_pref + '_over';
	cl_press	= cl_pref + '_press';
	
	cl_old	= this_el.className;
	
	if ( cl_press != cl_old ) {
		
		this_el.className	= 'tab_all ' + cl_over;
	}
*/
}

function tab_out( this_el, id, cl_pref ) {
/*	
	elid		= 'tab_' + id;
	cl_out		= cl_pref + '_out';
	cl_press	= cl_pref + '_press';
	
	cl_old	= this_el.className;
	
	
	if ( cl_press != cl_old ) {
		
		this_el.className	= cl_out;
	}
*/
}

function tab_show( elid ) {
	
	$( "#" + elid ).show(  );
//	$( "#" + elid ).animate( {opacity : "show"}, 500 );
}

function body_row_over( this_el ) {
	
	this_el.className	= 'row_over';
}

function body_row_out( this_el, cl ) {
	
	this_el.className	= cl;
}

function del_target( t_link, t_name, t_elid ) {
	
	popup_start( 530, 250, 'center', 'center', 'delete_confirmation', t_name, t_link, t_elid );
}

function open_popup( t_name ) {
	
	popup_start( 530, 250, 'center', 'center', 'standard', t_name );
}

function list_target( t_link ) {
	
	document.location.href = t_link;
}

function edit_target( t_link ) {
	
	document.location.href = t_link;
}

function pdf_target( t_link ) {
	
	document.location.href = t_link;
}

function swap_target( t_link ) {
	
	document.location.href = t_link;
}

function ajx_del_target( t_link, t_name, elid ) {
	
	if ( !elid ) {
		
		elid				= "tab_gen";
	}
	
	popup_start( 450, 180, 'center', 'center', 'delete_confirmation', t_name, t_link, elid );
}

function ajx_target( t_link, bid ) {
	
	t_link+= '&ajax=1';
	
	$( "#" + bid ).load( t_link );
}

function ajx_list_target( t_link, bid, delay ) {
	
	t_link+= '&ajax=1';
	
	if ( delay ) {
		
		setTimeout( "ajx_list_target( '" + t_link + "', '" + bid + "' )", delay );
	}
	else {
		
		$( "#" + bid ).load( t_link );
	}
}

function ajx_edit_target( t_link, str ) {
	
	f_arr	= new Array(  );
	s_arr	= new Array(  );
	mgr		= new Array(  );
	
	f_arr 	= str.split( '/' );
	
	for( unit in f_arr ) {
		
		s_arr			= f_arr[unit].split( '=' );
		mgr[s_arr[0]]	= s_arr[1];
	}
	
	if ( mgr['bid'] )	{	bid		=	mgr['bid'];		}	else	{	bid		= '';	}
	if ( mgr['elid'] )	{	elid	=	mgr['elid'];	}	else	{	elid	= '';	}
	if ( mgr['fid'] )	{	fid		=	mgr['fid'];		}	else	{	fid		= '';	}
	
	t_link+= '&ajax=1';
	
	if ( fid && elid && document.getElementById( elid ) ) {
		
		document.getElementById( elid ).innerHTML		= '';
		
		$( "#" + elid ).load( t_link, false );
	}
	
	show_box( bid );
}

function ajx_swap_target( t_link, elid ) {
	
	t_link+= '&ajax=1';
	
	if ( elid && document.getElementById( elid ) ) {
		
		$( "#" + elid ).load( t_link, false );
	}
}
/*
function ajx_del_target( t_link, elid ) {
	
	t_link+= '&ajax=1';
	
	if ( elid && document.getElementById( elid ) ) {
		
		$( "#" + elid ).load( t_link, false );
	}
}

function ajaxify_form( fid, bid, str_add, elid ) {
	
	$( "#" + fid ).ajaxForm( function(  ) {
		
		
	} );
}
*/

/////////////////////////////// validation scripts ///////////////////////////////////

function form_submit( fid, save_status ) {
	
	if ( form_validate( fid ) ) {
		
		if ( undefined != save_status && document.getElementById( 'save_and_edit_item' ) ) {
			
			document.getElementById( 'save_and_edit_item' ).value	= 1;
		}
		
		if ( document.getElementById( 'save_as_draft' ) ) {
			
			document.getElementById( 'save_as_draft' ).value	= 0;
		}
		
		if ( !is_saved ) { 
			
			document.getElementById( fid ).submit(  );
			
			is_saved	= 1;
		}
	}
}

function goto_link( fid, link_goto ) {
	
	if ( document.getElementById( fid ) ) {
		
		if ( form_check_change( fid ) ) {
			
			document.location.href	= link_goto;
		}
		else {
			
			str	= 'Some fields are changed.<br />Are you sure, you want to cancel these changes ?<br /><br />';
			str+= '<input type="button" class="red_but_click" value="Leave Page" style="margin-left:25px;" onclick="document.location.href= \'' + link_goto + '\'" />';
			str+= '<input type="button" class="blue_but_click" value="Stay on Page" onclick="hide_box( \'box_warning\' );" />';
			
			size		= get_scr_size(  );
			
			pos_left	= ( size['scr_width'] - 300 )/2 + 'px';
			pos_top		= ( size['scr_height'] - 140 )/2 + 'px';
			
			$( "#box_warning" ).css( 'left', pos_left );
			$( "#box_warning" ).css( 'top', pos_top );
			
			$( "#body_warning" ).html( str );
			
			$( "#box_warning" ).show(  );
		}
	}
	else {
		
		document.location.href	= link_goto;
	}
}

function draft_submit( fid ) {
	
	if ( document.getElementById( 'save_as_draft' ) && 0 == document.getElementById( 'save_as_draft' ).value ) {
		
		document.getElementById( 'save_as_draft' ).value	= 1;
	}
	
	document.getElementById( fid ).submit(  );
}

function form_check_change( fid ) {
	
	var status	= 1;
	
	for ( var i=0; i < document.forms[ fid ].elements.length; i++ ) {
		
		if( document.forms[ fid ].elements[i].className ) {
			
			if ( -1 != document.forms[ fid ].elements[i].className.indexOf( 'field_is_change' ) ) {
				
				status = 0;
			}
		}
	}
	
	return status;
}

function form_validate( fid ) {
	
	var status	= 1;
	var str		= '';
	var res		= 1;
	var message = "";
	
	for ( var i=0; i < document.forms[ fid ].elements.length; i++ ) {
		
		if( document.forms[ fid ].elements[i].className && document.forms[ fid ].elements[i].name && !document.forms[ fid ].elements[i].disabled ) {
			
			res = field_check( document.forms[ fid ].elements[i] );
			
			if ( !res && document.forms[ fid ].elements[i].title ) {
				
				message+=  '<p class="validation_messsage_item"><span style="color:red; font-weight:bold;">' + document.forms[ fid ].elements[i].title + '</span> is required</p>';;
			}
		}
		if ( 0 == res ) {
			
			status = 0;
		}
	}
	
	if ( document.getElementById( 'validation_message' ) ) {
		
		if ( !status && message ) {
			
			document.getElementById( 'validation_message' ).style.display = 'block';
			document.getElementById( 'validation_message' ).innerHTML		= message;
		}
	}
	
	return status;
}

function field_check( elObj ) {
	
	message_alt	= "";
	
	if ( elObj.title ) {
		
		message_alt	= str_replace( " ", "&nbsp;", elObj.title ) + "&nbsp;is&nbsp;Required";
	}
	
	if ( -1 != elObj.className.indexOf( 'req_simple' ) ) {
		
		if( !elObj.value ) {
			
			mark_as_wrong( elObj, message_alt );
			result	= 0;
		}
		else {
			
			mark_as_good( elObj );
			result	= 1;
		}
	}
	else if ( -1 != elObj.className.indexOf( 'req_mail' ) ) {
		
		if( !elObj.value || ( elObj.value && !validate_email( elObj.value ) ) ) {
			
			mark_as_wrong( elObj, message_alt );
			result	= 0;
		}
		else {
			
			mark_as_good( elObj );
			result	= 1;
		}
	}
	else if ( -1 != elObj.className.indexOf( 'req_phone_6_7' ) ) {
		
		if( !elObj.value || ( elObj.value && !validate_phone( elObj.value, 6, 7 ) ) ) {
			
			mark_as_wrong( elObj, message_alt );
			result	= 0;
		}
		else {
			
			mark_as_good( elObj );
			result	= 1;
		}
	}
	else if ( -1 != elObj.className.indexOf( 'req_phone_8_9' ) ) {
		
		if( !elObj.value || ( elObj.value && !validate_phone( elObj.value, 8, 9 ) ) ) {
			
			mark_as_wrong( elObj, message_alt );
			result	= 0;
		}
		else {
			
			mark_as_good( elObj );
			result	= 1;
		}
	}
	else if ( -1 != elObj.className.indexOf( 'req_phone_usa_10' ) ) {
		
		if( !elObj.value || ( elObj.value && !validate_phone( elObj.value, 10, 10 ) ) ) {
			
			mark_as_wrong( elObj, message_alt );
			result	= 0;
		}
		else {
			
			mark_as_good( elObj );
			result	= 1;
		}
	}
	else if ( -1 != elObj.className.indexOf( 'req_phone_inter_11_16' ) ) {
		
		if( !elObj.value || ( elObj.value && !validate_phone( elObj.value, 11, 16 ) ) ) {
			
			mark_as_wrong( elObj, message_alt );
			result	= 0;
		}
		else {
			
			mark_as_good( elObj );
			result	= 1;
		}
	}
	else if ( -1 != elObj.className.indexOf( 'req_card' ) ) {
		
		if( !elObj.value || ( elObj.value && !validate_card( elObj.value ) ) ) {
			
			mark_as_wrong( elObj, message_alt );
			result	= 0;
		}
		else {
			
			mark_as_good( elObj );
			result	= 1;
		}
	}
	else if ( -1 != elObj.className.indexOf( 'req_cvv' ) ) {
		
		if( !elObj.value || ( elObj.value && !validate_cvv( elObj.value ) ) ) {
			
			mark_as_wrong( elObj, message_alt );
			result	= 0;
		}
		else {
			
			mark_as_good( elObj );
			result	= 1;
		}
	}
	else if ( -1 != elObj.className.indexOf( 'req_pwd' ) ) {
		
		if( !elObj.value || ( elObj.value && !validate_pwd( elObj.value ) ) ) {
			
			mark_as_wrong( elObj, message_alt );
			result	= 0;
		}
		else {
			
			mark_as_good( elObj );
			result	= 1;
		}
	}
	else if ( -1 != elObj.className.indexOf( 'simple_mail' ) ) {
		
		if( !elObj.value || ( elObj.value && !validate_email( elObj.value ) ) ) {
			
			mark_as_wrong( elObj, message_alt );
			result	= 0;
		}
		else {
			
			mark_as_good( elObj );
			result	= 1;
		}
	}
	else if ( -1 != elObj.className.indexOf( 'simple_phone_6_7' ) ) {
		
		if( !elObj.value || ( elObj.value && validate_phone( elObj.value, 6, 7 ) ) ) {
			
			mark_as_good( elObj );
			result	= 1;
		}
		else {
			
			mark_as_wrong( elObj, message_alt );
			result	= 0;
		}
	}
	else if ( -1 != elObj.className.indexOf( 'simple_phone_8_9' ) ) {
		
		if( !elObj.value || ( elObj.value && validate_phone( elObj.value, 8, 9 ) ) ) {
			
			mark_as_good( elObj );
			result	= 1;
		}
		else {
			
			mark_as_wrong( elObj, message_alt );
			result	= 0;
		}
	}
	else if ( -1 != elObj.className.indexOf( 'simple_phone_usa_10' ) ) {
		
		if( !elObj.value || ( elObj.value && validate_phone( elObj.value, 10, 10 ) ) ) {
			
			mark_as_good( elObj );
			result	= 1;
		}
		else {
			
			mark_as_wrong( elObj, message_alt );
			result	= 0;
		}
	}
	else if ( -1 != elObj.className.indexOf( 'simple_phone_inter_11_16' ) ) {
		
		if( !elObj.value || ( elObj.value && validate_phone( elObj.value, 11, 16 ) ) ) {
			
			mark_as_good( elObj );
			result	= 1;
		}
		else {
			
			mark_as_wrong( elObj, message_alt );
			result	= 0;
		}
	}
	else if ( -1 != elObj.className.indexOf( 'simple_card' ) ) {
		
		if( !elObj.value || ( elObj.value && validate_card( elObj.value ) ) ) {
			
			mark_as_good( elObj );
			result	= 1;
		}
		else {
			
			mark_as_wrong( elObj, message_alt );
			result	= 0;
		}
	}
	else if ( -1 != elObj.className.indexOf( 'simple_cvv' ) ) {
		
		if( !elObj.value || ( elObj.value && validate_cvv( elObj.value ) ) ) {
			
			mark_as_good( elObj );
			result	= 1;
		}
		else {
			
			mark_as_wrong( elObj, message_alt );
			result	= 0;
		}
	}
	else if ( -1 != elObj.className.indexOf( 'simple_pwd' ) ) {
		
		if( !elObj.value || ( elObj.value && validate_pwd( elObj.value ) ) ) {
			
			mark_as_good( elObj );
			result	= 1;
		}
		else {
			
			mark_as_wrong( elObj, message_alt );
			result	= 0;
		}
	}
	else {
		
		result	= 1;
	}
	
	return result;
}

function mark_as_wrong( elObj, message ) {
	
	if ( elObj.parentNode.nextSibling.firstChild ) {
		
		elObj.parentNode.nextSibling.firstChild.style.display	= 'block';
		
		elObj.parentNode.nextSibling.firstChild.firstChild.innerHTML	= message + '&nbsp;*';
	}
}

function mark_as_good( elObj ) {
	
	if ( elObj.parentNode.nextSibling ) {
		
		elObj.parentNode.nextSibling.style.display	= 'none';
	}
}

function validate_email( email ) {
	
	var at_sym	= email.indexOf( '@' );
	var period	= email.lastIndexOf( '.' );
	
	if ( ( ( at_sym != 0 ) && ( at_sym != -1 ) ) && ( at_sym < period ) && ( at_sym != period - 1 ) )	{	return true;	}
	
	return false;
}

function validate_phone( phone, val_min, val_max ) {
	
	num_str		= str_replace( "/", "", phone	);
	num_str		= str_replace( "(", "", num_str	);
	num_str		= str_replace( ")", "", num_str	);
	num_str		= str_replace( " ", "", num_str	);
	num_str		= str_replace( "-", "", num_str	);
	no_zero_str	= str_replace( "0", "", num_str	);
	
	if ( no_zero_str == parseInt( no_zero_str ) && ( num_str.length >= val_min ) && ( num_str.length <= val_max ) )	{	return true;	}
	
	return false;
}

function validate_card( card_num ) {
	
	num_str		= card_num;
	no_zero_str	= str_replace( "0", "", num_str	);
	
	if ( no_zero_str == parseInt( no_zero_str ) && ( num_str.length > 12 ) && ( num_str.length < 17 ) )	{	return true;	}
	
	return false;
}

function validate_cvv( cvv_num ) {
	
	num_str		= cvv_num;
	no_zero_str	= str_replace( "0", "", num_str	);
	
	if ( no_zero_str == parseInt( no_zero_str ) && ( num_str.length > 2 ) && ( num_str.length < 5 ) )	{	return true;	}
	
	return false;
}

function validate_pwd( pwd_num ) {
	
	pwd_val		= document.getElementById( 'pwd' ).value;
	re_pwd_val	= document.getElementById( 're_pwd' ).value;
	
	if ( pwd_val == re_pwd_val ) {
		
		return true;
	}
	
	return false;
}

///////////////////////////////////// functions for popup window //////////////////////////////////////////


function popup_start( popup_width, popup_height, popup_top, popup_left, popup_warning, popup_param_1, popup_param_2, popup_param_3 ) {
	
	popup_ini( popup_width, popup_height, popup_top, popup_left, popup_warning, popup_param_1, popup_param_2, popup_param_3 );
	popup_show(  );
}

function popup_ini( popup_width, popup_height, popup_top, popup_left, popup_warning, popup_param_1, popup_param_2, popup_param_3 ) {
	
	getScrSize(  );
	getScrScroll(  );
	
	if ( 'center' == popup_top ) {
		
		popup_top	= ( CG.scrHeight - popup_height )/2; 
	}
	if ( 'center' == popup_left ) {
		
		popup_left	= ( CG.scrWidth - popup_width )/2; 
	}
	
	if ( document.getElementById( 'popup' ) ) {
		
//		document.getElementById( 'popup' ).style.width			= popup_width + 'px';
//		document.getElementById( 'popup' ).style.height			= popup_height + 'px';
		document.getElementById( 'popup' ).style.top			= popup_top - 1 + CG.scrScroll + 'px';
		document.getElementById( 'popup' ).style.left			= popup_left + 'px';
	}
	
	if ( document.getElementById( 'popup_body' ) ) {
		
//		document.getElementById( 'popup_body' ).style.height	= ( popup_height - 50 ) + 'px';
	}
	
	if ( popup_warning ) {
		
		if ( !popup_param_1 ) {
			
			popup_param_1	= '';
		}
		if ( !popup_param_2 ) {
			
			popup_param_2	= '';
		}
		if ( !popup_param_3 ) {
			
			popup_param_3	= '';
		}
		
		size		= get_scr_size(  );
		
		document.getElementById( "body_curtain_cfg" ).style.height		= parseInt( size['scr_height'] ) + parseInt( CG.scrScroll ) + 'px';
		
		body_cont	= popup_standart( popup_width, popup_height, popup_top, popup_left, popup_warning, popup_param_1, popup_param_2, popup_param_3 );
		
		if ( document.getElementById( 'popup_body' ) ) {
			
			document.getElementById( 'popup_body' ).innerHTML	= body_cont;
		}
	}
}

function popup_show(  ) {
	
	if ( document.getElementById( 'popup' ) ) {
		
		document.getElementById( 'popup' ).style.display		= 'block';
	}
}

function popup_hide(  ) {
	
	if ( document.getElementById( 'popup' ) ) {
		
		document.getElementById( 'popup' ).style.display		= 'none';
	}
}

function popup_close(  ) {
	
	if ( document.getElementById( 'popup' ) ) {
		
		document.getElementById( 'popup' ).style.display		= 'none';
	}
	
	if ( document.getElementById( 'popup_body' ) ) {
		
		document.getElementById( 'popup_body' ).innerHTML		= '';
	}
	
	document.getElementById( "body_curtain_cfg" ).style.height		= '0px';
}

function popup_standart( popupWidth, popupHeight, popupTop, popupLeft, popupType, popupParam1, popupParam2, popupParam3 ) {
	
	if ( 'field_not_filled'		== popupType ) {
		
		str	=	'';
		
		str+=	'<div style="padding:20px;">';
		str+=		'<div class="popup_text">You have not filled all mandatory fields</div>';
		str+=		'<input type="button" class="page_but" style="float:right;" value="ok" onclick="popup_close(  );">';
		str+=	'</div>';
	}
	
	if ( 'delete_confirmation'	== popupType ) {
		
		str	=	'';
		
		str+=	'<div style="padding:1px;">';
		str+=	'<div class="popup_header_cfg">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DELETE CONFIRMATION<img src="image/close.png" class="popup_close_icon_cfg" onclick="popup_close(  );"></div>';
		str+=	'<div class="popup_text"><img src="image/del.png" style="border:0px; float:left; margin-right:10px;">Are you sure, you want to delete ' + popupParam1 + ' ?</div>';
		str+=	'<center>';
		str+=		'<input type="button" class="tim_btn btn_out tim_e_s" value="cancel" onclick="popup_close(  );" style="margin-right:10px;">';
		if ( popupParam3 ) {
			str+=	'<input type="button" class="tim_btn btn_out tim_e_s" value="delete" onclick=\' ajx_act_item( "' + popupParam2 + '", 1, "' + popupParam3 + '" ); popup_close(  );\'>';
		}
		else {
			str+=	'<input type="button" class="tim_btn btn_out tim_e_s" value="delete" onclick=\' del_item( "' + popupParam2 + '" ); popup_close(  );\'>';
		}
		str+=	'<br />';
		str+=	'</center>';
		str+=	'</div>';
	}
	
	if ( 'standard'	== popupType ) {
		
		str	=	'';
		
		str+=	'<div style="padding:1px;">';
		str+=	'<div class="popup_header_cfg">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + popupParam1 + '<img src="image/close.png" class="popup_close_icon_cfg" onclick="popup_close(  );"></div>';
		str+=	'<div class="popup_text" id="popup_center"><center><img src="image/loading.gif"></center></div>';
		str+=	'</div>';
	}
	
	return str;
}

function del_item( delString ) {
	
	document.location.href = delString;
}

function del_type( popupWidth, popupHeight, popupTop, popupLeft, popupType, popupParam1, popupParam2, popupParam3 ) {
	
	popup_close(  );
	popup_start( popupWidth, popupHeight, popupTop, popupLeft, popupType, popupParam1, popupParam2, popupParam3 );
}

function del_cat_type( popupWidth, popupHeight, popupTop, popupLeft, popupType, popupParam1, popupParam2, popupParam3 ) {
	
	popup_close(  );
	popup_start( popupWidth, popupHeight, popupTop, popupLeft, popupType, popupParam1, popupParam2, popupParam3 );
}


//////////////////////////////////////////////
function configGlobal(  ) {
	
	this.scrWidth		= '1024';
	this.scrHeight		= '768';
	this.scrScroll		= '0';
}

CG	= new configGlobal(  );

function getScrSize(  ) {
	
	if ( self.innerHeight ) {	// all except Explorer
	
		CG.scrWidth		= self.innerWidth;
		CG.scrHeight	= self.innerHeight;
	}
	else if ( document.documentElement && document.documentElement.clientHeight ) { // Explorer 6 Strict Mode
	
		CG.scrWidth		= document.documentElement.clientWidth;
		CG.scrHeight	= document.documentElement.clientHeight;
	}
	else if ( document.body ) { // other Explorers
	
		CG.scrWidth		= document.body.clientWidth;
		CG.scrHeight	= document.body.clientHeight;
	}
}

function getScrScroll(  ) {
	
	if ( self.pageYOffset ) {
	 
		yScroll = self.pageYOffset;
	}
	else if ( document.documentElement && document.documentElement.scrollTop ) {
		
		yScroll = document.documentElement.scrollTop;
	}
	else if ( document.body ) {
		
		yScroll = document.body.scrollTop; 
	}
	
	CG.scrScroll	= yScroll;
}

/////////////////////////////////////// sort elements //////////////////////////////

function up_el( el_obj ) {
	
	elid	= el_obj.attr( 'id' );
	$( '#'+elid ).insertBefore( $( "#"+elid ).prev(  ) );
}

function down_el( el_obj ) {
	
	elid	= el_obj.attr( 'id' );
	$( '#'+elid ).insertAfter( $( "#"+elid ).next(  ) );
}

function del_el( el_obj ) {
	
	elid	= el_obj.attr( 'id' );
	$( "#"+elid ).remove(  );
}

function sort_el( fid, name ) {
	
	var counter = 0;
	
	for ( var i=0; i < document.forms[ fid ].elements.length; i++ ) {
		
		if( document.forms[ fid ].elements[i].value ) {
			
			if ( 'name_to_change' == document.forms[ fid ].elements[i].name ) {
				
				counter+= 10;
				document.forms[ fid ].elements[i].name	= name + '['+counter+']';
				document.forms[ fid ].elements[i].value	= parseInt( document.forms[ fid ].elements[i].id );
			}
		}
	}
}

function add_el( box_id, form_id, section_pref, clone_id, name_pref, rename ) {
	
	if ( !clone_id ) {	clone_id = 'clone';	}
	
	rand_pref		= Math.round( Math.random(  )*100000 );
	full_rand_pref	= section_pref + '_' + rand_pref;
	
	$( "#" + clone_id ).clone(  ).prependTo( '#' + box_id ).attr( 'id', full_rand_pref ).css( 'display', 'block' );
	
	item_change_name( form_id, rand_pref, name_pref );
	
	if ( 'spec' == section_pref ) {
		
		new_val		= document.getElementById( 'select_link_id' ).value;
		
		document.getElementById( "spec_id_" + rand_pref ).value	= new_val;
	}
}

function del_el( el_obj ) {
	
	elid	= el_obj.attr( 'id' );
	
	$( "#"+elid ).remove(  );
}

function move_el( el_obj, new_parent_id ) {
	
	$( "#" + new_parent_id ).append( el_obj );
}

function filter_select( link, id ) {
	
	document.location.href	= link + id;
}

function ini_editor( editor, name, width, height ) {
	
	if ( 'fckeditor' == editor ) {
		 
		var oFCKeditor = new FCKeditor( name );
		oFCKeditor.BasePath = "/library/fckeditor/";
		
		oFCKeditor.ToolbarSet 	= 'Basic';
		oFCKeditor.Height 		= height + 'px';
		oFCKeditor.Width 		= width + 'px';
		
		oFCKeditor.ReplaceTextarea(  ) ;
	}
	if ( 'tinymce' == editor ) {
		
		tinyMCE.init (
			{
				language : "en",
				theme : "simple",
				elements : name,
				mode : "exact"
			}
		)
	}
}

function edit_item_click( el_obj, status ) {
	
	$( "#" + el_obj.id + " .edit_item_body" ).toggle(  );
	$( "#" + el_obj.id + " .edit_item_brief" ).toggle(  );
	$( "#" + el_obj.id + " .edit_item_brief_curtain" ).remove(  );
}

function item_change_name( fid, rand_pref, name_pref ) {
	
	if ( !name_pref ) { name_pref	= 'add'; }
	
	for ( var i=0; i < document.forms[ fid ].elements.length; i++ ) {
		
		if( document.forms[ fid ].elements[i].className && -1 != document.forms[ fid ].elements[i].className.indexOf( 'change_name' ) ) {
			
			document.forms[ fid ].elements[i].name	= name_pref + '[' + rand_pref + '][' + document.forms[ fid ].elements[i].name + ']';
			document.forms[ fid ].elements[i].parentNode.id	= rand_pref;
			document.forms[ fid ].elements[i].className	= str_replace( 'change_name', '', document.forms[ fid ].elements[i].className );
		}
		if( document.forms[ fid ].elements[i].className && -1 != document.forms[ fid ].elements[i].className.indexOf( 'change_id' ) ) {
			
			document.forms[ fid ].elements[i].id	= 'spec_id_' + rand_pref;
			document.forms[ fid ].elements[i].className	= str_replace( 'change_id', '', document.forms[ fid ].elements[i].className );
		}
	}
}

function reminder_type_click( type ) {
	
	if ( 'single' == type ) {
		$( ".reminder_single" ).show(  );
		$( ".reminder_multi" ).hide(  );
		
		$( ".reminder_multi_val" ).val( "" );
	}
	else {
		$( ".reminder_single" ).hide(  );
		$( ".reminder_multi" ).show(  );
		
		$( ".reminder_single_val" ).val( "" );
	}
}

function update_item_brief( section, type, val, rand ) {
	
	$( "#" + section + "_" + rand + " .edit_item_brief_" + type ).html( val );
}

function update_brief( type, val, rand ) {
	
	$( "#edit_item_brief_" + type + '_' + rand ).html( val );
}


function update_calc_new( section, rand ) {
	
	fid						= 'sku_frm';
	
	ammount_total			= 0;
	ammount_discount		= 0;
	
	for ( var i=0; i < document.forms[ fid ].elements.length; i++ ) {
		
		if( document.forms[ fid ].elements[i].className && -1 != document.forms[ fid ].elements[i].className.indexOf( 'kit_item_index' ) ) {
			
			rand	= document.forms[ fid ].elements[i].value;
			
			sku_id					= $( "#ks_" + rand ).val(  );
			quantity				= $( "#kq_" + rand ).val(  );
			price					= $( "#sku_item_" + sku_id ).val(  );
			discount_percentage		= $( "#kdp_" + rand ).val(  );
			discount_dollar_amount	= $( "#kda_" + rand ).val(  );		
			
			if ( undefined === quantity )	{	quantity	= 0;	}
			if ( undefined === price )		{	price		= 0;	}
			
			ammount_total+= price*quantity;
			ammount_discount+= parseInt( price*quantity*discount_percentage/100 ) + parseInt( discount_dollar_amount*quantity );
		}
	}
	
	$( "#ammount_with_discount_x" ).html( ammount_total - ammount_discount );
	$( "#ammount_without_discount_x" ).html( ammount_total );
	$( "#ammount_discount_x" ).html( ammount_discount );
}

function update_calc( section, rand ) {
	
	fid						= 'sku_frm';
	
	quantity				= $( "#" + section + "_" + rand + " .calc_quantity" ).val(  );
	sku_id					= 0;
	discount_percentage		= $( "#" + section + "_" + rand + " .calc_discount_percentage" ).val(  );
	discount_dollar_amount	= $( "#" + section + "_" + rand + " .calc_discount_dollar_amount" ).val(  );	
	
	for ( var i=0; i < document.forms[ fid ].elements.length; i++ ) {
		
		if( document.forms[ fid ].elements[i].className && -1 != document.forms[ fid ].elements[i].className.indexOf( 'radio_sku_id' ) ) {
			
			name_1			= document.forms[ fid ].elements[i].name;
			
			name_2			= str_replace( "kit[", "", name_1 );
			name_2			= str_replace( "][sku]", "", name_2 );
			
			if ( name_2 == rand ) {
				
				if ( true == document.forms[ fid ].elements[i].checked ) {
					
					sku_id	= document.forms[ fid ].elements[i].value;
				}
			}
		}
	}
	
	price					= $( "#price_" + sku_id ).val(  );
	
	ammount_total			= price*quantity;
	ammount_discount		= parseInt( price*quantity*discount_percentage/100 ) + parseInt( discount_dollar_amount*quantity );
	
	$( "#" + section + "_" + rand + " .calc_ammount_total" ).val( ammount_total );
	$( "#" + section + "_" + rand + " .calc_ammount_discount" ).val( ammount_discount );
	
	set_new_calc_value(  );
}

function set_new_calc_value(  ) {
	
	fid					= 'sku_frm';
	
	ammount_total		= 0;
	ammount_discount	= 0;
	
	for ( var i=0; i < document.forms[ fid ].elements.length; i++ ) {
		
		if( document.forms[ fid ].elements[i].className && -1 != document.forms[ fid ].elements[i].className.indexOf( 'calc_ammount_total' ) ) {
			
			ammount_total += parseInt( document.forms[ fid ].elements[i].value );
		}
		if( document.forms[ fid ].elements[i].className && -1 != document.forms[ fid ].elements[i].className.indexOf( 'calc_ammount_discount' ) ) {
			
			ammount_discount += parseInt( document.forms[ fid ].elements[i].value );
		}
	}
	
	$( "#ammount_with_discount" ).html( ammount_total - ammount_discount );
	$( "#ammount_without_discount" ).html( ammount_total );
	$( "#ammount_discount" ).html( ammount_discount );
}

function add_el_linker_item( el_obj ) {
	
	tbl_id			= Math.round( Math.random(  )*100000 );
	el_obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id		= tbl_id;
	
	
	tmp_id			= Math.round( Math.random(  )*100000 );
	el_obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id		= tmp_id;
	
	rand_pref		= Math.round( Math.random(  )*100000 );
	
	old_name	= $( "#" + tmp_id + " .el_external_linker_name" ).html(  );
	
	new_name	= get_new_name( old_name );
	
	$( "#" + tmp_id ).clone(  ).insertAfter( '#' + tmp_id ).attr( 'id', rand_pref );
	
	$( "#" + rand_pref + " .el_external_linker_name" ).html( new_name );
	$( "#" + rand_pref + " .name_former" ).val( new_name );
	
	$( "#" + rand_pref + " .el_external_linker_value" ).val( "" );
	$( "#" + rand_pref + " .name_former" ).attr( "name", "linker_add[" + rand_pref + "][title]" );
	$( "#" + rand_pref + " .el_external_linker_value" ).attr( "name", "linker_add[" + rand_pref + "][value]" );
	$( "#" + rand_pref + " .el_external_linker_active" ).attr( "name", "linker_add[" + rand_pref + "][active]" );
	$( "#" + rand_pref + " .el_external_linker_add" ).hide(  );
	$( "#" + rand_pref + " .el_external_linker_del" ).show(  );
	
	$( "#" + rand_pref + " .el_external_linker_title" ).attr( "value", new_name );
}

function del_el_linker_item( el_obj ) {
	
	el_obj.parentNode.parentNode.id = '9999999999';
	
	$( "#9999999999" ).remove(  );
}

function edit_el_linker_item( el_obj ) {
	
	el_obj.nextSibling.style.display = 'block';
}

function get_new_name( old_name ) {
	
	name_arr	= old_name.split( " ( " );
	name_base	= name_arr[0];
	
	fid					= 'sku_frm';
	
	max_val				= 1;
	
	for ( var i=0; i < document.forms[ fid ].elements.length; i++ ) {
		
		if( document.forms[ fid ].elements[i].className && -1 != document.forms[ fid ].elements[i].className.indexOf( 'name_former' ) ) {
			
			tmp_old		= document.forms[ fid ].elements[i].value;
			
			tmp_arr		= tmp_old.split( " ( " );
			tmp_base	= tmp_arr[0];
			
			if ( name_base == tmp_base ) {
				
				if ( tmp_arr[1] && parseInt( tmp_arr[1] ) >= max_val ) {
					
					max_val		= parseInt( tmp_arr[1] ) + 1;
				}
			}
		}
	}
	
	return name_base + " ( " + max_val + " ) ";
}

function hide_box_field( rand, class_name ) {
	
	$( "#" + rand + " ." + class_name ).hide(  );
}

function show_ajx_field( rand, pref, class_name, skuid ) {
	
	rand		= str_replace( pref + "_", "", rand );
	
	sheet_id	= document.getElementById( "spec_id_" + rand ).value;
	
	t_link		= "specialspecfieldmgr_ajxedit?ajax=1&merch=" + jQuery( "#merch" ).val(  ) + "&id=" + sheet_id + "&rand=" + rand + '&skuid=' + skuid;
	
	$( "#" + rand + " ." + class_name ).show(  );
	
	if ( "" == $( "#" + rand + " ." + class_name + "_body" ).html(  ) ) {
		
		$( "#" + rand + " ." + class_name + "_body" ).load( t_link );
	}
}

function form_api_url( url_base ) {
	
	api_name 		= document.getElementById( 'play_ground_api' ).value;
	
	key_name 		= document.getElementById( 'play_ground_key' ).value;
	
	url				= url_base + '?f=' + api_name + '&api_key=' + key_name;
	
	document.getElementById( 'play_ground_url' ).value = url;
}

function populate_list(  ) {
	
	$( ".el_external_linker_value" ).val( $( "#external_linker_mfg" ).val(  ) );
}

function set_cb_stat( status, class_name ) {
	
	if ( !class_name ) {
		
		class_name	= 'el_external_linker_active';
	}
	
	$( "." + class_name ).attr( "checked", status );
}

function toggle_unactive_fields( fid, el_obj ) {
	
	if ( true == el_obj.checked ) {
		
		$( ".row_el" ).show(  );
	}
	else {
		
		hide_unactive_fields( fid );
	}
}

function hide_unactive_fields( fid ) {
	
	for ( var i=0; i < document.forms[ fid ].elements.length; i++ ) {
		
		if( document.forms[ fid ].elements[i].className && 'check_el' ==  document.forms[ fid ].elements[i].className ) {
			
			if ( false == document.forms[ fid ].elements[i].checked ) {
				
				document.forms[ fid ].elements[i].parentNode.parentNode.style.display = 'none';
			}
		}
	}
}

function get_scr_size(  ) {
	
	var size = new Array(  );
	
	size['scr_width']		= '1024';
	size['scr_height']		= '768';
	
	if ( self.innerHeight ) {	// all except Explorer
		
		size['scr_width']	= self.innerWidth;
		size['scr_height']	= self.innerHeight;
	}
	else if ( document.documentElement && document.documentElement.clientHeight ) { // Explorer 6 Strict Mode
		
		size['scr_width']	= document.documentElement.clientWidth;
		size['scr_height']	= document.documentElement.clientHeight;
	}
	else if ( document.body ) { // other Explorers
		
		size['scr_width']	= document.body.clientWidth;
		size['scr_height']	= document.body.clientHeight;
	}
	
	return size;
}

////////////////////////////////////// calendar functions //////////////////////////////////

function toggle_item( status, alias ) {
	
	if ( true == status ) {
		
		$( '.event_' + alias ).show(  );
	}
	else {
		
		$( '.event_' + alias ).hide(  );
	}
}

function show_calendar( direction ) {
	
	size	= get_scr_size(  );
	
	document.getElementById( "body_curtain" ).style.height		= size['scr_height'] + 'px';
	document.getElementById( "box_service_body" ).innerHTML		= '<center><img src="/image/loading.gif" style="margin-top:30px;"></center>';
	
	$( '#body_curtain' ).animate( {opacity: "show"}, 400 );
	
	$( '#box_service' ).animate( {opacity: "show"}, 500 );
	
	url_str	= "/calendar_panelajx.php?ajax=1&merch=" + jQuery( "#merch" ).val(  );
	
	if ( direction ) {
		
		url_str+= "&direction=" + direction;
	}
	
	$( "#box_service_body" ).load( url_str );
}

function show_calendar_detail( year, month, day ) {
	
	document.getElementById( 'box_calendar_detail_body' ).innerHTML		= '<center><img src="/image/loading.gif" style="margin-top:30px;"></center>';
	
	$( '#calendar_body_curtain' ).show(  );
	$( '#calendar_body_box' ).show(  );
	
	url_str	= "/calendar_showajx.php?ajax=1&merch=" + jQuery( "#merch" ).val(  ) + "&year=" + year + "&month=" + month + "&day=" + day;
	
	$( "#box_calendar_detail_body" ).load( url_str );
}

function hide_calendar_detail(  ) {
	
	$( '#calendar_body_curtain' ).hide(  );
	$( '#calendar_body_box' ).hide(  );
}

function remove_from_tray( tray_id ) {
	
	url_str	= "tray_removetray.php?ajax=1&merch=" + jQuery( "#merch" ).val(  ) + "&tray=" + tray_id;
	
	$( '#tray_box' ).load( url_str );
}

function hide_service(  ) {
	
	$( '#body_curtain' ).animate( {opacity: "hide"}, 400 );
	
	$( '#box_service' ).animate( {opacity: "hide"}, 500 );
}

function close_box( el_obj ) {
	
	el_obj.style.display = 'none';
}

function open_box( el_obj ) {
	
	el_obj.style.display = 'block';
}

function show_calendar_list( year, month, day ) {
	
	url_str														= "/calendar_listajx.php?ajax=1&merch=" + jQuery( "#merch" ).val(  ) + "&year=" + year + "&month=" + month + "&day=" + day;
	document.getElementById( 'calendar_list_box' ).innerHTML	= '<center><img src="/image/loading.gif" style="margin-top:30px;"></center>';
	
	$( '#calendar_list_box' ).load( url_str );
}

function del_calendar_event( calid, year, month, day ) {
	
	url_str														= "/calendar_delajx.php?ajax=1&merch=" + jQuery( "#merch" ).val(  ) + "&calid=" + calid + "&year=" + year + "&month=" + month + "&day=" + day;
	document.getElementById( 'calendar_list_box' ).innerHTML	= '<center><img src="/image/loading.gif" style="margin-top:30px;"></center>';
	
	$( '#calendar_list_box' ).load( url_str );
}

function show_calendar_edit( calid, year, month, day ) {
	
	url_str														= "/calendar_editajx.php?ajax=1&merch=" + jQuery( "#merch" ).val(  ) + "&calid=" + calid + "&year=" + year + "&month=" + month + "&day=" + day;
	document.getElementById( 'calendar_list_box' ).innerHTML	= '<center><img src="/image/loading.gif" style="margin-top:30px;"></center>';
	
	$( '#calendar_list_box' ).load( url_str );
}

function save_calendar_edit( year, month, day ) {
	
	$( "#calendar_frm" ).ajaxForm( function(  ) {
		
		url_str														= "/calendar_listajx.php?ajax=1&merch=" + jQuery( "#merch" ).val(  ) + "&year=" + year + "&month=" + month + "&day=" + day;
		document.getElementById( 'calendar_list_box' ).innerHTML	= '<center><img src="/image/loading.gif" style="margin-top:30px;"></center>';
		
		$( '#calendar_list_box' ).load( url_str );
	} );
}

function box_quick_edit_over( el_obj ) {
	
	if ( !check_box_clicked( el_obj ) ) {
		
		el_obj.className		= "quick_edit_over";
	}
}

function box_quick_edit_out( el_obj ) {
	
	if ( !check_box_clicked( el_obj ) ) {
		
		el_obj.className		= "quick_edit_out";
	}
}

function box_quick_edit_click( el_obj, tbl, name, index, id_val ) {
	
	if ( !check_box_clicked( el_obj ) ) {
		
		el_obj.innerHTML		= '<textarea class="quick_edit_area" style="width:' + el_obj.clientWidth + 'px;" onblur=\'box_quick_edit_blur( this, "' + tbl + '", "' + name + '", "' + index + '", "' + id_val + '" );\'>'+el_obj.innerHTML+'</textarea>';
		el_obj.className		= "";
		el_obj.firstChild.select(  );
		el_obj.firstChild.focus(  );
	}
}

function box_quick_edit_blur( el_obj, tbl, name, index, id_val ) {
	
	val								= el_obj.value;
	
	if ( '' == val )	{	val		= "&nbsp;";		}
	
	el_obj.parentNode.className		= "quick_edit_out";
	el_obj.parentNode.innerHTML		= val;
	
	val								= str_replace( " ", "__", val );
	val								= str_replace( "&nbsp;", "__", val );
	
	url_str		= "/service_ajxsave.php?ajax=1&merch=" + jQuery( "#merch" ).val(  ) + "&tbl=" + tbl + "&name=" + name + "&index=" + index + "&id=" + id_val + "&val=" + val;
	
	$( "#empty" ).load( url_str );
}

function box_quick_status_edit_click( elid, status_cur, order_id ) {
	
	t_link		= "payment_getstatus.php?ajax=1&merch=" + jQuery( "#merch" ).val(  ) + "&status_cur=" + status_cur + '&order_id=' + order_id;
	
	$( "#" + elid ).load( t_link );
}

function check_box_clicked( el_obj ) {
	
	if( "quick_edit_area" == el_obj.firstChild.className ) {
		
		return 1;
	}
	else {
		
		return 0;
	}
}

function ajx_edit_lst( tbl, name, index, id_val, width ) {
	
	elid		= 'ajx_' + name + '_' + id_val;
	el_val		= document.getElementById( elid ).innerHTML;
	
//	url_str		= '/service_ajxbox.php?ajax=1&tbl=' + tbl + '&name=' + name + '&width=' + width + '&index=' + index + '&id=' + id_val;
	
//	$( "#" + elid ).load( url_str );
}
/*
function ajx_edit_lst( tbl, name, index, id_val, width ) {
	
	elid		= 'ajx_' + name + '_' + id_val;
	
	url_str		= '/service_ajxbox.php?ajax=1&tbl=' + tbl + '&name=' + name + '&width=' + width + '&index=' + index + '&id=' + id_val;
	
	$( "#" + elid ).load( url_str );
}
*/
function ajx_save_lst( tbl, name, val, index, id_val ) {
	
	val		= str_replace( " ", "__", val );
	
	elid	= 'ajx_' + name + '_' + id_val;
	
	url_str		= "/service_ajxsave.php?ajax=1&merch=" + jQuery( "#merch" ).val(  ) + "&tbl=" + tbl + "&name=" + name + "&index=" + index + "&id=" + id_val + "&val=" + val;
	
	$( "#" + elid ).load( url_str );
}

function page_but_over( el_obj, cls_pref ) {
	
	if ( undefined == cls_pref )	{	cls_pref	= 'page';	}
	
	cls_name	= el_obj.className;
	
	if ( cls_pref + '_but_click' != cls_name ) {	el_obj.className	= cls_pref + '_but_over';	}
}

function page_but_out( el_obj, cls_pref ) {
	
	if ( undefined == cls_pref )	{	cls_pref	= 'page';	}
	
	cls_name	= el_obj.className;
	
	if ( cls_pref + '_but_click' != cls_name )	{	el_obj.className	= cls_pref + '_but_out';
	}
}

function page_but_click( el_obj, cls_pref ) {
	
	if ( undefined == cls_pref )	{	cls_pref	= 'page';	}
	
	$( "." + cls_pref + "_but_click" ).addClass( cls_pref + '_but_out' );
	$( "." + cls_pref + "page_but_click" ).removeClass( cls_pref + '_but_click' );
	
	el_obj.className	= cls_pref + '_but_click';
}


function tim_btn_over( el_obj ) {
	
	el_obj.className	= str_replace( "btn_out", "btn_over", el_obj.className );
}

function tim_btn_out( el_obj ) {
	
	el_obj.className	= str_replace( "btn_over", "btn_out", el_obj.className );
}

function tim_btn_click( el_obj ) {
	
//	cls_pref	= 'page';
	
//	$( "." + cls_pref + "_but_click" ).addClass( cls_pref + '_but_out' );
//	$( "." + cls_pref + "page_but_click" ).removeClass( cls_pref + '_but_click' );
	
//	el_obj.className	= cls_pref + '_but_click';
}

function update_merchant_option( merchant ) {
	
	if ( '' == merchant ) {	merchant = 0;	}
	
	$( ".merch_all" ).hide(  );
	$( ".merch_all" ).attr( "disabled", "disabled" );
	
	$( ".merch_" + merchant ).show(  );
	$( ".merch_" + merchant ).removeAttr( "disabled" );
}

function drop_hide( el_pref ) {
	
	if ( 0 == on_focus ) {
		
		if ( 'all' == el_pref ) {
			
			$( ".widget-frame." ).hide(  );
		}
		else {
			
			$( "#dr_" + el_pref ).hide(  );
		}
	}
}

function drop_hide_t( el_pref ) {
	
	on_focus	= 0;
	
	setTimeout( 'drop_hide( "' + el_pref + '" )', 500 );
}

function drop_show_t(  ) {
	
	on_focus	= 1;
}

function drop_show( el_pref ) {
	
	$( "#dr_" + el_pref ).show(  );
	
	document.getElementById( "dr_" + el_pref ).style.zIndex	= '100';
}

function drop_item_click( el_id, el_val, el_pref ) {
	
	on_focus	= 0;
	
	$( "#hd_" + el_pref ).val( el_id );
	$( "#ds_" + el_pref ).html( el_val );
	$( "#dr_" + el_pref ).hide(  );
	
	document.getElementById( "dr_" + el_pref ).style.zIndex	= '30';
}

function drop_over( el_obj, el_pref ) {
	
	$( ".li_" + el_pref ).removeClass( 'selected' );
	
	el_obj.className = "widget-dropdown-list-item selected li_" + el_pref;
}

function box_minimize( rnd ) {
	
	box_id	= 'tpl_item_box_' + rnd;
	min_id	= 'tpl_min_but_' + rnd;
	max_id	= 'tpl_max_but_' + rnd;
	
	$( "#" + box_id ).animate( {height : "hide"}, 300 );
	$( "#" + min_id ).hide(  );
	$( "#" + max_id ).show(  );
}

function box_maximize( rnd ) {
	
	box_id	= 'tpl_item_box_' + rnd;
	min_id	= 'tpl_min_but_' + rnd;
	max_id	= 'tpl_max_but_' + rnd;
	
	$( "#" + box_id ).animate( {height : "show"}, 300 );
	$( "#" + min_id ).show(  );
	$( "#" + max_id ).hide(  );
}

function box_close( rnd ) {
	
	box_id	= 'item_' + rnd;
	
	$( "#" + box_id ).remove(  );
}

function add_item_sample( level, block, module ) {
	
	t_link		= "tplwizard_addsample.php?ajax=1&level=" + level + '&block=' + block + '&module=' + module;
	
	$.getJSON( t_link, {shift:0}, function( json ) { sample_place( json['tpl'], level ); } );
}

function add_item_ext( level_t, module_t, plg_t, addon_t, name_pref_t ) {
	
	merch_t		= jQuery( "#merch" ).val(  );
	
	t_link		= module_t + "_addext.php?ajax=1&merch=" + jQuery( "#merch" ).val(  ) + "&level=" + level_t + '&plg=' + plg_t + '&addon=' + addon_t + '&name_pref=' + name_pref_t;
	
	$.getJSON( t_link, {shift:0}, function( json ) { sample_place( json['tpl'], level_t, name_pref_t, addon_t ); } );
}

function sample_place( tpl, level, name_pref_t, addon_t ) {
	
	$( "#box_but_" + level ).append( tpl );
	
	if ( document.getElementById( "load_counter" + name_pref_t ) ) {
		
		indicator_num		= document.getElementById( "load_counter" + name_pref_t ).value - 1;
		
		document.getElementById( "load_counter" + name_pref_t ).value		= indicator_num;
		document.getElementById( "load_number" + name_pref_t ).innerHTML	= indicator_num;
		
		if ( 'calt' == addon_t ) {
			
			upd_review(  );
		}
		
		if ( indicator_num == 0 ) {
			
			document.getElementById( "load_number" + name_pref_t ).style.display	= 'none';
			document.getElementById( "load_indicator" + name_pref_t ).style.display	= 'none';
		}
	}
}

function edit_item_ext( level, rnd, item_id ) {
	
	t_link		= "checkoutalt_editext.php?ajax=1&merch=" + jQuery( "#merch" ).val(  ) + "&level=" + level + '&rnd=' + rnd + '&item_id=' + item_id;
	
	$( "#item_" + rnd ).load( t_link );
}

function select_prod_ext( level, item_id ) {
	
	t_link		= "checkoutalt_select.php?ajax=1&item_id=" + item_id;
	
	$.getJSON( t_link, {shift:0}, function( json ) { sample_place( json['tpl'], level ); } );
}

function check_csa_exists( el_val, el_type ) {
	
	t_link		= "checkoutalt_checkcsa.php?ajax=1&merch=" + jQuery( "#merch" ).val(  ) + "&el_val=" + el_val + '&el_type=' + el_type;
	
	$( "#box_csa_select" ).load( t_link );
}

function drag_widget_ini( elid, bid ) {
	
	Drag.init( document.getElementById( elid ), document.getElementById( bid )  );
}

function select_vari_val( el_val, rnd ) {
	
	t_link		= "sku_getajx.php?ajax=1&merch=" + jQuery( "#merch" ).val(  ) + "&el_val=" + el_val + '&rnd_val=' + rnd;
	
	document.getElementById( 'vari_val_' + rnd ).innerHTML		= '<center><img src="/image/loading.gif"></center>';
	
	$( "#vari_val_" + rnd ).load( t_link );
}

function mark_as_change( el_obj ) {
	
	el_obj.className	= str_replace( ' field_is_change', '', el_obj.className ) + ' field_is_change';
}

function toggle_row( id, is_exp ) {
	
	if ( is_exp ) {
		
		$( "#exp_" + id ).hide(  );
		$( "#dexp_" + id ).show(  );
		$( "#r_" + id ).show(  );
	}
	else {
		
		$( "#exp_" + id ).show(  );
		$( "#dexp_" + id ).hide(  );
		$( "#r_" + id ).hide(  );
	}
}

function show_state( el_obj, rnd, cur_name ) {
	
	cid				= 'cs_' + rnd + '_' + el_obj.value;
	
	$( ".state_lst_" + rnd ).attr( "name", "" );
	$( ".state_lst_" + rnd ).hide(  );
	
	$( "#" + cid ).show(  );
	$( "#" + cid ).attr( "name", cur_name );
}

function search_on_keyword( el_val, url, elid ) {
	
	if ( el_val ) {
		
		t_link		= url + el_val;
		
		$( "#" + elid ).load( t_link );
	}
}

function update_status( el_obj, elid, order_id, status_old, source_id ) {
	
	t_link		= "payment_updatestatus.php?ajax=1&status_new=" + el_obj.value +"&status_old=" + status_old + '&order_id=' + order_id + '&source_id=' + source_id;
	
	if ( el_obj.value && 0 != el_obj.value ) {
		
		$( "#" + elid ).load( t_link );
	}
}

function select_address( href, type ) {
	
	var container	= jQuery( jQuery( href ).parent(  ) ).parent(  );
	var items		= container.find( 'input[type="hidden"]' );
	
        if ( type == 'billing' ) {
        	
            var ref = {
            'first_name':['s_x_first_name'], 'middle_initial':'s_x_middle', 'last_name':['s_x_last_name'],
            'company':['s_x_company'], 'address':['s_x_address'], 'city': ['s_x_city'], 'state':['s_x_state'],
            'zip':['s_x_zip_code'], 'country':['s_x_country'], 'phone_1': ['s_x_phone_num'], 'phone_2': 's_x_cell_num',
            'email':'s_f_mail'
            };
        }
        if ( type == 'shipping' ) {
        	
            var ref = {
            'first_name':['s_s_first_name'], 'middle_initial':'s_x_middle', 'last_name':['s_s_last_name'],
            'company':['s_s_company'], 'address':['s_s_address'], 'city': ['s_s_city'], 'state':['s_s_state'],
            'zip':['s_s_zip_code'], 'country':['s_s_country'], 'phone_1': ['s_s_phone_num'], 'phone_2': 's_x_cell_num',
            'email':'s_f_mail'
            };
        }
    
	items.each( function (  ) {
		
		var name = jQuery( this ).attr( 'name' );
		
		if ( ref[name] instanceof Array ) {
			
			for ( var ind in ref[name] ){
				
				var newname	= ref[name][ind];
				
				jQuery( 'div' )
					.find( 'input, select' )
					.filter( function(  ) { return jQuery( this ).attr( 'name' ).match( newname ); } )
					.val( jQuery( this ).val(  ) );
			}
		} else {
			
			var newname = ref[name];
			
			if ( "s_f_mail" !=  newname || "" != jQuery( this ).val(  ) ) {
				
				jQuery( 'div' )
					.find( 'input, select' )
					.filter( function(  ) { return jQuery( this ).attr( 'name' ).match( newname ); } )
					.val( jQuery( this ).val(  ) );
			}
		}
	});
	//jQuery( "#dialog-user_address" ).dialog( "close" );
}

function show_prepop_page( el_name, elid ) {
	
	jQuery( '#clone_prepop' ).show(  );
	
	jQuery( '#clone_key' ).attr( "name", el_name );
	jQuery( '#clone_key' ).val( elid );
}

function ajx_act_item( el_url, is_loader, elid ) {
	
	if ( elid ) {
		
		jQuery( "#" + elid + "_t" ).show(  );
		
		jQuery( "#" + elid ).append( '<div style="position:relative;"><div class="curtain_loading_swap"></div><div class="box_loading_swap">Loading ...</div></div>' );
		
		jQuery( "#" + elid ).load( el_url );
	}
	else {
		
		jQuery( "#empty" ).load( el_url );
	}
}







function edit_event( type, id ) {	
	
	if( type == 'se' ) {
		
		show_simple_event_add_dialog( id, 0 );
	}
	else {
		
		show_scheduler_event_add_dialog( id, 0 );
	}
}

function simple_event_response( data ) {
	
	if( data.error ) {
		
		jQuery( '.seaf-messages-container' ).html( data.message );
	}
	else {
		
		jQuery( "#simple-event-add-container" ).dialog( 'close' );
//		jQuery( '#calendar_box' ).load( '/calendarnew_refresh.php?ajax=1' );
		
		document.location.href = 'calendarnew_list.php';
		
//		jQuery( '#calendar' ).fullCalendar( 'refetchEvents' );
		//jQuery('.seaf-messages-container').html('Event saved!');		
		//jQuery('.seaf-messages-container').attr('saved', 1);	
	}
}

function show_simple_event_add_dialog( id, el_date ) {
	
	jQuery( "#simple-event-add-container" ).dialog( {		
		height: 530,
		width: 490,
		modal: true,
		close: function(  ) {
			if( jQuery( '.seaf-messages-container' ).attr( 'saved' ) == 1 ) {
				
				jQuery( '#calendar' ).fullCalendar( 'refetchEvents' );
			}
		}
	});
	jQuery( '.simple-event-container' ).load( "calendarnew_editse.php?ajax=1&merch=" + jQuery( "#merch" ).val(  ) + ( id?("&eid="+id):'' )+( el_date?("&eldate="+el_date):"" ), function(  ) {
		jQuery( "#event_date_start" ).datepicker( {dateFormat: 'yy-mm-dd'} );
		jQuery( "#event_date_end" ).datepicker( {dateFormat: 'yy-mm-dd'} );
		jQuery( '#calendar_se_frm' ).ajaxForm( {
			dataType:  'json',
			success:   simple_event_response
		});
	});
}

function scheduler_event_response( responseText, statusText, xhr, jQueryform ) {
	
	jQuery( "#scheduler-event-add-container" ).dialog( 'close' );
	jQuery( '#calendar' ).fullCalendar( 'refetchEvents' );
}

function show_scheduler_event_add_dialog( id, el_date ) {
	
	jQuery( "#simple-event-add-container" ).dialog( {		
		height: 530,
		width: 490,
		modal: true,
		close: function(  ) {
			if( jQuery( '.seaf-messages-container' ).attr( 'saved' ) == 1 ) {
				
				jQuery( '#calendar' ).fullCalendar( 'refetchEvents' );
			}
		}
	});
	jQuery( '.simple-event-container' ).load( "calendarnew_editst.php?ajax=1&merch=" + jQuery( "#merch" ).val(  ) + ( id?("&eid="+id):'' )+( el_date?("&eldate="+el_date):"" ), function(  ) {
		jQuery( "#event_date_start" ).datepicker( {dateFormat: 'yy-mm-dd'} );
		jQuery( "#event_date_end" ).datepicker( {dateFormat: 'yy-mm-dd'} );
		jQuery( '#calendar_se_frm' ).ajaxForm( {
			dataType:  'json',
			success:   simple_event_response
		});
	});
/*
	jQuery( "#scheduler-event-add-container" ).dialog({
		height: 550,
		width: 710,
		modal: true,
		close: function() {
			if(jQuery('.sheaf-messages-container').attr('saved') == 1)
				jQuery('#calendar').fullCalendar('refetchEvents');
		}
	});
	
	jQuery('.scheduler-event-container').load( 'scheduler_'+(id?'edit':'add')+'.php?ajax=1&type=task'+(id?('&timschedid='+id):''), function() {
		jQuery('.scheduler-event-container .ajax_but_edit_top').remove();
		jQuery('.scheduler-event-container .ajax_but_edit_bot').remove();
		jQuery('.scheduler-event-container').append('<div class="button-container"></div>');
		jQuerybutton = jQuery('<input type="submit" value="save" class="page_but"/>');
		jQuerybutton.click(function() {
			jQuery('#purchase_frm').ajaxSubmit({
				success:   scheduler_event_response
			});
		});
		jQuery('.scheduler-event-container .button-container').append(jQuerybutton);
		//jQuery('#purchase_frm').ajaxForm({
			//success:   scheduler_event_response
		//});
		
	});
*/
}

function form_ajx_submit( frm, el_color, el_message ) {
	
	save_queue		= 0;
	
	jQuery( "#tab_status_box" ).show(  );
	jQuery( "#tab_status_box" ).html( '<p style="color:#' + el_color + ';">' + el_message + '</p>' );
	
	jQuery( '#' + frm ).ajaxSubmit( {
		
		success:   ajx_save_ok
	} );
	
	jQuery.each( $( ".tim_btn_sv" ), function(  ) {
		this.className	= str_replace( "tim_e_", "tim_d_", this.className );
	} );
	jQuery.each( $( ".tim_btn_dd" ), function(  ) {
		this.className	= str_replace( "tim_e_", "tim_d_", this.className );
	} );
}

function ajx_save_ok(  ) {
	
	color_saved	= jQuery( "#color_saved" ).val(  );
	if ( !color_saved ) {	color_saved	= '0066CC';	}
	message_saved	= jQuery( "#message_saved" ).val(  );
	if ( !message_saved ) {	message_saved	= 'Saved';	}
	
	jQuery( "#tab_status_box" ).html( '<p style="color:#' + color_saved + ';">' + message_saved + '</p>' );
	setTimeout( "jQuery( '#tab_status_box' ).hide(  );", 1000 );
	jQuery( ".is_upd" ).removeClass( 'is_upd' );
	
//	if ( el_link = jQuery( "#tab_url" ).val(  ) ) {
//		setTimeout( "tab_ajx_click( '" + el_link + "' )", 100 );
//	}
}

function discard(  ) {
	
	jQuery.each( $( ".tim_btn_sv" ), function(  ) {
		this.className	= str_replace( "tim_e_", "tim_d_", this.className );
	} );
	jQuery.each( $( ".tim_btn_dd" ), function(  ) {
		this.className	= str_replace( "tim_e_", "tim_d_", this.className );
	} );
	jQuery( ".is_upd" ).removeClass( 'is_upd' );
	
	if ( el_link = jQuery( "#tab_url" ).val(  ) ) {
		tab_ajx_click( el_link );
	}
}

function show_event_add_dialog( el_date ) {
	
	el_date		= el_date.getFullYear(  ) + "_" + el_date.getMonth(  ) + "_" + el_date.getDate(  );
	
	jQuery( "#dialog-event-add" ).dialog( {
		resizable: false,
		height:30,
		modal: true,
		buttons: {
			"Simple event": function() {
				jQuery( this ).dialog( "close" );
				show_simple_event_add_dialog( 0, el_date );
			},
			"Scheduler event": function(  ) {
				jQuery( this ).dialog( "close" );
				show_scheduler_event_add_dialog( 0, el_date );
			}
		}
	});
}

function mark_f( elobj ) {
	
	if ( 0 == save_queue ) {
		
		if ( 1 == jQuery( "#autosave_allow" ).val(  ) ) {
			
			save_queue	= 1;
			
			var inter			= 1000*jQuery( "#autosave_interval" ).val(  );
			if ( !inter ) {	inter	= 60000;	}
			var color_saving	= jQuery( "#color_saving" ).val(  );
			if ( !color_saving ) {	color_saving	= '0066CC';	}
			var message_saving	= jQuery( "#message_saving" ).val(  );
			if ( !message_saving ) {	message_saving	= 'Loading';	}
			
			setTimeout( "form_ajx_submit( 'main_frm', '" + color_saving + "', '" + message_saving + "' );", inter );
		}
	}
	
	el_cls			= elobj.className;
	
	if ( el_cls.indexOf( 'is_upd' ) < 0 ) {
		
		elobj.className = elobj.className + " is_upd";
	}
	
	jQuery.each( $( ".tim_btn_sv" ), function(  ) {
		this.className	= str_replace( "tim_d_", "tim_e_", this.className );
	} );
}



function selector_filter_press(  ) {
	
	document.onkeypress = selector_filter_act;
}

function selector_filter_act( e ) {

	var evt = (e) ? e : window.event;

	var code = (document.all) ? evt.keyCode:evt.which;

	if ( 13 == code ) {

		selector_filter(  );
	}
}

function selector_filter( el_rand ) {
	
	var ajx_url		= "/selectoruni_list.php?ajax=1&merch=" + jQuery( "#merch" ).val(  ) + "&el_rand=" + el_rand;
	
	jQuery.each( $( ".sel_" + el_rand ), function(  ) {
		ajx_url		+= "&" + this.id + "=" + this.value;
	} );
	
	jQuery( '#selector_box' + el_rand ).html( '<center><img src="/image/loading.gif" style="border:0px; margin-top:15px;"></center>' );
	
	jQuery( '#selector_box' + el_rand ).load( ajx_url );
}

function update_item_box( elid ) {
	
	 jQuery( "#elid_" + elid ).val( 0 );
	 jQuery( "#box_but_selector_" + elid ).html( '<span style="color:red;">not selected</span>' );
}

function add_item( branch, el_rand, el_tbl ) {
	
	var el_alias	= '';
	var el_name		= '';
	
	el_name			= jQuery( '#item_add_' + el_rand ).val(  );
	el_name			= str_replace( ' ', '__', el_name );
	
	if ( jQuery( '#item_alias_' + el_rand ).val(  ) ) {
		
		el_alias	= jQuery( '#item_alias_' + el_rand ).val(  );
		el_alias	= str_replace( ' ', '__', el_alias );
	}
	
	$( '#empty' ).load( "/selectoruni_addel.php?ajax=1&merch=" + jQuery( "#merch" ).val(  ) + "&branch=" + branch + "&el_tbl=" + el_tbl + "&el_rand=" + el_rand + "&el_name=" + el_name + "&el_alias=" + el_alias );
	
	hide_box( 'box_add_' + el_rand );
}

function check_uniq_field( elid, tbl, field, id, index ) {
	
	el_val		= str_replace( " ", "__", jQuery( '#'+ elid ).val(  ) );
	
	t_link		= "service_checkuniq.php?ajax=1&el_val=" + el_val + '&tbl=' + tbl + '&field=' + field + '&id=' + id + '&index=' + index;
	
	$.getJSON( t_link, {shift:0}, function( json ) { uniq_responce( json['status'], elid ); } );
}

function uniq_responce( status, elid ) {
	
	jQuery( '#' + elid ).removeClass( 'uniq_red' );
	jQuery( '#' + elid ).removeClass( 'uniq_blue' );
	jQuery( '#' + elid ).removeClass( 'uniq_green' );
	
	if ( 1 == status['is_uniq'] ) {
		
		jQuery( '#' + elid ).addClass( 'uniq_green' );
	}
	else {
		
		jQuery( '#' + elid ).addClass( 'uniq_red' );
		jQuery( '#' + elid + '_responce' ).html( status['resp'] );
		
		setTimeout( " jQuery( '#" + elid + "_responce' ).html( '' ); ", 2000 );
	}
}
