// ------------------------------------------------------------------

/**
 *
 */
function w_wo(url)
{
	window.open(url, 'w_wo', 'location=no, statusbars=no, menubar=no, scrollbars=no, left=20, top=20, width=400, height=400');
}

/**
 *
 */
function w_wop(url, obj, name)
{
	wname = name || 'w_wop';
	
	text = 'location=no, statusbars=no, menubar=no';
	text += obj["s"] ? ",scrollbars=yes" : ",scrollbars=no";
	text += obj["w"] ? ",width=" + obj["w"] : ",width=400";
	text += obj["h"] ? ",height=" + obj["h"] : ",height=400";
	text += obj["t"] ? ",top=" + obj["t"] : ",top=20";
	text += obj["l"] ? ",left=" + obj["l"] : ",left=20";
	
	window.open(url, wname, text);
}

// ------------------------------------------------------------------

function replaceSelectedText(obj, replText)
{
 obj.focus();
 
 if (document.selection) 
 {
   var s = document.selection.createRange(); 
   if (s.text)
   {
     s.text = replText;
   	 //eval("s.text="+cbFunc+"(s.text);");
	 s.select();
	 return true;
   }
 }
 else if (typeof(obj.selectionStart)=="number")
 {
 	
 	
   //if (obj.selectionStart!=obj.selectionEnd)
   //{
     var start = obj.selectionStart;
     var end = obj.selectionEnd;

     var rs = replText;
     //eval("var rs = "+cbFunc+"(obj.value.substr(start,end-start));");
     obj.value = obj.value.substr(0,start)+rs+obj.value.substr(end);
     obj.setSelectionRange(end,end);
   //}
   return true;
 }

 return false;
}

// ------------------------------------------------------------------

function $gid(id)
{
	return document.getElementById(id);
}

// ------------------------------------------------------------------

/**
 *	
 */
function ajax_get_http()
{    
	var xmlHttp = false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try 
	{
	  xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
	} 
	catch (e) 
	{
	  try 
	  {
	    xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
	  } 
	  catch (e2) 
	  {
	    xmlHttp = false;
  	  }
	}
	@end @*/
	
	if (!xmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
		xmlHttp = new XMLHttpRequest();
	}
	
	return xmlHttp;
}


// ----------------------------------------------------------------
// ------------------------------------------------------------------
//	sync
// ------------------------------------------------------------------
// ------------------------------------------------------------------

/**
 *	
 */
function ajax_getSContent(url)
{
	http = ajax_get_http();
	http.open("GET", url, false);
    http.send(null);

	return ajax_getResponse(http, 1);
}

// ------------------------------------------------------------------

/**
 *	
 */
function ajax_getSContent(url, type)
{
	http = ajax_get_http();
	http.open("GET", url, false);
    http.send(null);

	return ajax_getResponse(http, type);
}

// ------------------------------------------------------------------

/**
 *	
 */
function ajax_getSContentByObj(url, type, obj)
{
	var paramStr = ajax_getParamStr(obj);
	
	url = url + "?" + paramStr;
	
	http = ajax_get_http();
	http.open("GET", url, false);
    http.send(null);

	return ajax_getResponse(http, type);
}

// ------------------------------------------------------------------

/**
 *	
 */
function ajax_getParamStr(obj)
{
	var paramStr = "";
	
	var i = 1;
	for (var key in obj) 
	{
		if(i > 1) { paramStr += "&"; }
		paramStr += key + "=" + encodeURIComponent(obj[key]);
		i++;
	}

	return paramStr;
}

// ------------------------------------------------------------------

/**
 *	
 */
function ajax_getResponse(http, type)
{
	if (http.readyState == 4 && http.status == "200") 
	{   
    	if(type == 2) 
		{
			return http.responseXML;
		}
		
		return http.responseText;
	}
	
	return "";
}

// ------------------------------------------------------------------

/**
 *	
 */
function ajax_postSContent(url, type, obj)
{
	var paramStr = ajax_getParamStr(obj);

	http = ajax_get_http();
	http.open("POST", url, false);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", paramStr.length);
    http.send(paramStr);
	
	return ajax_getResponse(http, type);
}

// ------------------------------------------------------------------
// ------------------------------------------------------------------

/**
 *
 */
function common_getArrayJoin(elems, sep, type) 
{
	var text = "";

	var i = 0;
	for(var elem in elems)
	{
		if(i) { text += sep; }
		if(type == 1) { text += elem; }
		else if(type == 2) { text += elems[elem]; }
	
		i++;
	}
	
	return text;
}


function cloneObject( srcObj ) {
  if( srcObj == null ) { return srcObj; } //null, undefined

  var newObject;
  switch (typeof(srcObj)) {
    case "object":
      newObject = new srcObj.constructor();
      for( var property in srcObj ) {
       if( srcObj.hasOwnProperty(property) || typeof( srcObj[property] ) === 'object' ) { //собственное свойство или объект
         newObject[property] = cloneObject( srcObj[property] );
         }
       }
      break;

    default:
      newObject = srcObj;
      break;
    }

  return newObject;
  }

// ------------------------------------------------------------------
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// ------------------------------------------------------------------


