//
//             Copyright (c) 2002, 2003 Smartlink Corp.
//                       All rights reserved.
//

var mailer_path = "";
var mailer_type =   "asp"; // htm

var print_path = "print/";
var fIE    = (window.showModalDialog ? true : false);
var fNS4   = !(document.getElementById);


function doCommand (cmd) 
{
  return doCommandEx(cmd, m_curFrame,  m_curEl);
}

function doSpell(ctrls,color)
{ 
  	if(!ctrls) {
  	  ctrls = m_curEl;
  	 }
  	doSpellEx(ctrls, m_curLang,color);
}	

function doMail (type,color, loc) 
{
	return doMailEx(type, m_curFrame, m_curEl, color, loc);
}

function doDecode(color)
{
	return doDecodeEx(color,m_curFrame, m_curEl);
}

function doPrint(copyright)
{
  return doPrintEx(m_curFrame, m_curEl, copyright);
}

function doDict()
{
  return doDictEx(m_curFrame, m_curEl);
}

function showDialog_ (url, args, features) {
   var href = "", ref = url, query = "", arr = url.split ("?");
   if (arr.length > 1) {
      ref = arr [0];
      query = arr [1];
   }
   var sep = ref.lastIndexOf ("/");
   if (sep >= 0) {
      href = ref.substr (0, sep + 1);
      ref = ref.substr (sep + 1);
   }
   args = { opener: this, query : "ref=" + ref + (query ? "&" : "") + query};
   href += "dlgframe.asp" + "?ref=" + ref + (query ? "&" : "") + query;
   //return window.showModalDialog (href, args, features);
try {
   return window.showModalDialog (href, args, features);
		  }
	  catch (err){
	    if(browser.ie6SP2){
	      alert(TEXT_MSG_POPUP);
		  }
		}

}



function doHelp(id, color)
{ 
	var helpwindow;
	var paramStr;
	if (!id )
		paramStr = '';
	else
	 	paramStr = "?id=" + id;
	var url = (window.help_url ?  help_url : "help/help.asp");	 
	url = url + '?sh=' + color;
	helpwindow = "window.open(url + paramStr, 'Help', 'toolbar=0,scrollbars=1,statusbar=no,width=650,height=500,resizable=1')";
	var targetwindow = eval(helpwindow);
        if (!targetwindow) { alert(TEXT_MSG_POPUP); }
        else { 	targetwindow.focus(); }
}


function commonParams()
{
  return  "ln=" + m_ln + "&skin=" + m_skin;
  
}

function doDicCommand(cmd)
{
    if(cmd == "Copy" )  {
      var ctrl = window.frames['target'].document.body;
      ctrl.createTextRange().execCommand(cmd);
//      window.clipboardData.setData("Text",ctrl.innerHTML);
    }
    
}


function doBookmark()
{
	window.external.AddFavorite(location.href, document.title);
}


function setInfo(text)
{
  var infoCtrl  = document.getElementById("infoText");
  if(infoCtrl){
    infoCtrl.innerHTML = text;
  }
}

// ex functions //

function doCommandEx(cmd, frame,  el)
{
if(!el)
	return;
   var textCtrl =  el; // form.text;
   if(typeof(m_appName) != "undefined" && m_appName == "dicter" && frame == "target"){
      doDicCommand(cmd);
      return;
    }
    if (browser.ie && !browser.mac && !browser.opera) {
      textCtrl.createTextRange ().execCommand (cmd);
   }
   else {
      switch (cmd) {
         case "Copy":
            copyPasteMsg();
            m_clipboard = textCtrl.value;
            break;
         case "Paste":
            copyPasteMsg();
            textCtrl.focus ();
            if(m_clipboard)
               textCtrl.value = m_clipboard;
            break;
         case "Delete":
            textCtrl.focus ();
            textCtrl.value = "";
            break;
         case "Cut":
            textCtrl.focus ();
            m_clipboard = textCtrl.value;
            textCtrl.value = "";
            break;
      }
   }
	return true;
}

function doSpellEx(ctrls, lang, color)
{
//lang = document.form.langs.value;
if(lang.indexOf('/') > 1 )
{lang=lang.split('/');
lang=lang[0];
}
	if(m_fspell) {
		if(window.kbdShowHide) {
			kbdShowHide (false);
		}

		var text;
		var query = 'lang=' + lang + '&dic=Normal';
		query += "&" + commonParams();
		text = ctrls;
		invokeSpeller(text, query);
	}
	return true;
}


function doMailEx(type, frame, el, color, loc)
{
	if(window.kbdShowHide) {
		kbdShowHide (false);
	}
	var query = "?type=" + type;
	if(typeof(mail_title)!='undefined')
		query += "&subj=" + mail_title;
	if(typeof(m_clientName)!='undefined')
		query += "&clientname=" + m_clientName;
		
	if(type == "email") {
		if( m_curFrame != "" ) 
			query +="&ctrl=" + frame + "/"+ el.name;
		else
			query +="&ctrl=" + el.name;
	}
	var url = "mailer.asp" 

	if(mailer_type == "htm") {
		url = type + "_form.html"
		if(typeof(RES_LN)!='undefined') {
			url = expandFilebyLang(url, RES_LN);
		}
	}
	else if(mailer_type == "asp") {
	  query += "&" + commonParams();
	  	}
	url = mailer_path + url + query;
	var height = 291;
	switch(type)
	{
		case "email":
			height  = 662;
			break;
		case "feedback":
			height  = 690;
			break;
		case "tellafriend":
			height  = 686;
			break;
	}
	url = url + '&sh=' + color+ '&loc=' + loc;
	if(fIE) {
	    var features = "dialogWidth:438px; dialogHeight:" + height +"px;scroll:no;help:no;status:no;";
		var args = { opener: this };
//		dialog = window.showModalDialog (url, args, features);
		dialog = showDialog_ (url, args, features);
//dialog = window.open (url, "SendMail", "width=438,height="+height+",toolbar=no,status=no,menubar=no,directories=no,resizable=yes");

	}
	else {
		dialog = window.open (url, "SendMail", "width=438,height="+height+",toolbar=no,status=no,menubar=no,directories=no,resizable=yes");
	}
	return true;
}

function doDecodeEx(color, frame, el)
{
  if(window.kbdShowHide) {
		kbdShowHide (false);
	}
	var query;
	if( m_curFrame != "" ) 
			query =frame + "/"+ el.name;
		else
			query = el.name;
	invokeDecoder(query, commonParams());
}

function doPrintEx(frame, el, copyright)
{
	var query = "?frame=" + frame + "&field="+ el.name + "&copyright=" + copyright; 
	//window.open( print_path + "printfrm.asp" + query,"", "toolbar=1,scrollbars=0,statusbar=no,width=500,height=400,resizable=1");
var openprint;
            openprint=eval("window.open( print_path + 'printfrm.asp' + query,'', 'toolbar=1,scrollbars=0,statusbar=no,width=500,height=400,resizable=1');");
if(!openprint)
alert(TEXT_MSG_POPUP);

	return true;
}

function doDictEx(frame, el)
{
  var dir = getListValue (m_form.langs,"");
      var doc = document;

      if (frame) {
        doc = window.frames[frame].document;
        if(frame.toLowerCase() == "target" && dir.indexOf("/")){
          var langs = dir.split("/");
          dir = langs[1] + "/" + langs[0];
        }
      }
      
     invokeDictionary (el, "lang=" + dir + "&dir=" + dir+ "&" + commonParams(), doc);
}

function mouseover(obj)
{
	window.status=obj.title;
	obj.className='but-norm but-over';
}
function mouseout(obj)
{
	window.status='';
	obj.className='but-norm';
}
function mouseup(obj)
{
	window.status='';
	obj.className='but-norm but-over';
}
function mousedown(obj)
{
	window.status='please wait...';
	obj.className='but-norm but-down';
}
