// Menu G3 Convertor
// Last Modified: 08-Jun-2003
// Web Site: yxScripts.com
// Email: m_yangxin@hotmail.com

// Copyright 2003  Xin Yang   All Rights Reserved.

function nvl(tag, value) {
  return value!=""?("; "+tag+":"+value):"";
}

function addStylePad(sp_name,s_width,s_height,s_color,b_size,b_style,b_color,p_dx,p_dy,p_mode,p_dir) {
  if (typeof(p_mode)=="undefined") p_mode="";
  if (typeof(p_dir)=="undefined") p_dir="";

  return 'addStylePad("'+sp_name+'", "padding:'+s_height+' '+s_width+nvl("background-color",s_color)+'; border-size:'+b_size+(b_size==0?'':(nvl("border-style",b_style)+nvl("border-color",b_color)))+'; offset-left:'+p_dx+'; offset-top:'+p_dy+nvl("menu-form", p_mode)+nvl("direction", p_dir)+'");'
}

function addStyleItem(si_name,i_width,p_width,p_height,b_size,b_style_N,b_style_H,b_color_N,b_color_H,i_color_N,i_color_H,i_method,si_dis,i_height,b_style_C,b_color_C,i_color_C) {
  if (typeof(b_style_C)=="undefined") b_style_C="";
  if (typeof(b_color_C)=="undefined") b_color_C="";
  if (typeof(i_color_C)=="undefined") i_color_C="";

  return 'addStyleItem("'+si_name+'", "width:'+i_width+(typeof(i_height)=="undefined"?'':('; height:'+i_height))+'; padding:'+p_height+' '+p_width+'; border-size:'+b_size+(b_size==0?'':('; border-style:'+b_style_N+' '+b_style_H+' '+b_style_C+'; border-color:'+b_color_N+' '+b_color_H+' '+b_color_C))+'; background-color:'+i_color_N+' '+i_color_H+' '+i_color_C+nvl("sub-menu", i_method)+'");'
}

function addStyleItem31(si_name,i_width,i_height,p_width,p_height,b_size,b_style_N,b_style_H,b_color_N,b_color_H,i_color_N,i_color_H,i_method,si_dis,b_style_C,b_color_C,i_color_C) {
  if (typeof(b_style_C)=="undefined") b_style_C="";
  if (typeof(b_color_C)=="undefined") b_color_C="";
  if (typeof(i_color_C)=="undefined") i_color_C="";

  return 'addStyleItem("'+si_name+'", "width:'+i_width+(typeof(i_height)=="undefined"?'':('; height:'+i_height))+'; padding:'+p_height+' '+p_width+'; border-size:'+b_size+(b_size==0?'':('; border-style:'+b_style_N+' '+b_style_H+' '+b_style_C+'; border-color:'+b_color_N+' '+b_color_H+' '+b_color_C))+'; background-color:'+i_color_N+' '+i_color_H+' '+i_color_C+nvl("sub-menu", i_method)+'");'
}

function addStyleFont(sf_name,f_family,f_size,f_weight,f_style,f_color_N,f_color_H,f_align,f_color_C) {
  if (typeof(f_color_C)=="undefined") f_color_C="";

  return 'addStyleFont("'+sf_name+'", "font-family:'+f_family+'; font-size:'+f_size+nvl("font-weight", f_weight)+nvl("font-style", f_style)+'; color:'+f_color_N+' '+f_color_H+' '+f_color_C+nvl("text-align", f_align)+'");';
}

function addStyleTag(st_name,t_option,t_path,t_N,t_H,t_width,t_height,t_align) {
  return 'addStyleTag("'+st_name+'", "'+(t_option=='off'?'; visibility:hidden':('; path:'+t_path+'; tag-normal:'+t_N+'; tag-highlight:'+t_H+'; width:'+t_width+'; height:'+t_height+nvl("align", t_align)))+'");'
}

function addStyleSeparator(ss_name,s_style,s_color,s_size) {
  return 'addStyleSeparator("'+ss_name+'", "style:'+s_style+'; color:'+s_color+'; size:'+s_size+'");'
}

function addInstance(i_name,i_menu,i_type,i_pos,i_ref,i_idx,i_xalign,i_yalign,i_x,i_y,i_form,i_dir,i_vis,i_target,i_style,i_mode,b_mode) {
  return 'addInstance("'+i_name+'", "'+i_menu+'", "position:'+i_pos+' '+i_ref+' '+i_idx+nvl("align", i_xalign)+nvl("valign", i_yalign)+'; offset-left:'+i_x+'; offset-top:'+i_y+nvl("menu-form", i_form)+nvl("direction", i_dir)+(i_vis=="hide"?'; visibility:hidden':'; visibility:visible')+nvl("target", i_target)+nvl("style", i_style)+(i_mode=="sticky"?'sticky:yes':'')+(b_mode=="release"?'highlight:no':'')+'");'
}

function convert(content) {
  var lines=content.split(/\n/);
  var g4Content="";

  for (var i=0; i<lines.length; i++) {
    if (lines[i].search(/^\s*(addStylePad|addStyleItem|addStyleFont|addStyleTag|addStyleSeparator|addInstance)/)!=-1) {
      g4Content+=eval(lines[i])+"\n";
    }
    else {
      g4Content+=lines[i]+"\n";
    }
  }

  return g4Content;
}
