function gEBI(str){//shortcut for document.getElementById(strID)
	return document.getElementById(str);
}

function gEBN(str){//shortcut for document.getElementsByName(strID)
	return document.getElementsByName(str);
}

function gEBT(str){//shortcut for document.getElementsByTagName(strID)
	return document.getElementsByTagName(str);
}

function DisableListingItemAs(pItemId, pFlag)
{
	var lStr1 = '';
	if (pFlag == 'on')
	{
		if (!confirm("Do you really want to disable this listing?"))
		{
			return false;
		}
	}
	lStr1 = 'action=dodisablelisting&returnto=async&itemid=' + pItemId + '&flag='+pFlag;
	lStr1 = sendXmlHttpRequest('/listingmanager.php', lStr1);
	if (lStr1 != 'ok')
	{
		alert(lStr1);
		return;
	}
	window.location.reload(true);
}


function PauseListingItemAs(pItemId, pFlag)
{

	//alert(pItemId);

	var lStr1 = '';
	if (pFlag == 'on')
	{
		if (!confirm("Do you really want to pause this listing?"))
		{
			return false;
		}
	}
	lStr1 = 'action=dopauselisting&returnto=async&itemid=' + pItemId + '&flag='+pFlag;
	lStr1 = sendXmlHttpRequest('/listingmanager.php', lStr1);
	if (lStr1 != 'ok')
	{
		alert(lStr1);
		return;
	}
	window.location.reload(true);
}


function getChildByIdOrName(parentNode, strId, bDeep)
{
	for(var i=0;i<parentNode.childNodes.length;i++)
	{
		var current = parentNode.childNodes[i];
		if(current.nodeType != 1) //if not element
			continue;
		
		if(strId == current.id)
			return current;
		
		if(strId == getNameAttribute(current))
			return current;
		
		//if deep child was requested then make a recursive call
		if(bDeep && current.tagName.toUpperCase() != "SELECT")
		{
			var oNode = getChildByIdOrName(current, strId, bDeep);
			if(null != oNode)
				return oNode;
		}
	}
	return null;
}


function getNameAttribute(Node)
{
	var nattr = Node.getAttribute("name");
	if("" == nattr)
		return Node.getAttribute("oname"); //Opera support: bug with name attribute
	else
		return nattr;
}

	
function EnableObjectById(pObjectID)
{
	var lObj1 = gEBI(pObjectID)
	if (null != lObj1)
	{
		EnableObject(lObj1);
	}
}


function DisableObjectById(pObjectID)
{
	var lObj1 = gEBI(pObjectID)
	if (null != lObj1)
	{
		DisableObject(lObj1);
	}
}


function EnableObject(pObject)
{
	for (var lCnt1 = 0; lCnt1 < arguments.length; lCnt1++)
	{
		arguments[lCnt1].removeAttribute('disabled');
	}
}


function DisableObject()
{
	for (var lCnt1 = 0; lCnt1 < arguments.length; lCnt1++)
	{
		arguments[lCnt1].setAttribute('disabled','disabled');
	}
}

// 10x to http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
function WindowSize() 
{
	var lPoint = new Object();
  var lWidth = 0, lHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    lWidth = window.innerWidth;
    lHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    lWidth = document.documentElement.clientWidth;
    lHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    lWidth = document.body.clientWidth;
    lHeight = document.body.clientHeight;
  }
  lPoint.width = lWidth;
  lPoint.height = lHeight;
  return lPoint;
}


// craete an timer and start it
function TimerStart(pFunction, pInterval) 
{
   return setTimeout(pFunction, pInterval);
}

// stop the timer
function TimerStop(pTimerId) 
{
   if(pTimerId) 
   {
      clearTimeout(pTimerId);
      pTimerId	= 0;
   }
}

function AppendTimeOffset2Form(pName)
{
	//alert('add new hidden id = ' + pId + '; Name = ' + pName + '; Value = ' + pValue);
	var lForm1 = gEBI(pName);
	var lDate1 = new Date();
	
	var lField	= document.createElement('input'); 
	lField.setAttribute('type', 'hidden'); 
	lField.setAttribute('name', 'timeoffsetForm'); 
	lField.setAttribute('value', lDate1.getTimezoneOffset()); 
	lField.setAttribute('id', 'timeoffsetForm'); 
	lForm1.appendChild(lField);
	return lField;
}

function CreateHiddenInputElement(pId, pName, pValue)
{
	//alert('add new hidden id = ' + pId + '; Name = ' + pName + '; Value = ' + pValue);
	var lField = null;
	try
	{
		lField	= document.createElement('<input type="hidden" name="' + pName + '"></input>'); 
	}
	catch(err)
	{
		lField = document.createElement('input');
		lField.type = 'hidden';
		lField.name = pName;
	}
	lField.value = pValue;
	lField.id = pId;
	return lField;
}

function sendXmlHttpRequest(strURL, strRequest)
{
	var xmlHttp = null;
	try{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e){
		xmlHttp = new XMLHttpRequest();
	}

	if(null == xmlHttp)
	{
		alert("Failed to create XmlHttp object!");
		return "";
	}

	//if no request body is specified, then we change method from POST to GET 
	var strMethod = "POST";
	if("" == strRequest || null == strRequest)
	{
		strMethod = "GET";
		strRequest = null;
	}

	xmlHttp.open(strMethod, strURL, false);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		
	xmlHttp.send(strRequest);
	if(500 == xmlHttp.status)
	{
		var msgSrc = xmlHttp.statusText;			//page where error originated
		var msgCode = xmlHttp.status;				//error code
		var msgDetails = xmlHttp.responseText;		//detailed error information
		window.location="MessageCenter.aspx?msgSrc="+msgSrc+"&msgCode="+msgCode+"&msgDetails="+msgDetails;
		return "";
	}
	if(400 == xmlHttp.status)
	{
		alert(xmlHttp.statusText);
		return "";
	}
	if(200 == xmlHttp.status)
		return xmlHttp.responseText;
	
	alert( xmlHttp.status)	;
	return "";
}

function getChildrenByPartialIdOrName(parentNode, strId)
{
    var bDeep = arguments[2];
    var retArray = new Array();
    var cnt = 0;
    
    if(parentNode==null) return retArray;
    if(parentNode.childNodes==null) return retArray;
    //loop through all children
    for(var i=0;i<parentNode.childNodes.length;i++)
    {
         var current = parentNode.childNodes[i];
         if(current.nodeType != 1) //if not element
              continue;
         var bFoundInId = false;
         //if ids partially match, add object to return array
         if(checkPartialMatch(strId, current.id))
         {
              bFoundInId = true;
              retArray[cnt] = current;
              cnt++;
         }
         
         if(!bFoundInId && checkPartialMatch(strId, getNameAttribute(current)))
         {
              retArray[cnt] = current;
              cnt++;
         }
         if(bDeep)
         {
              var nodes = getChildrenByPartialIdOrName(current, strId, bDeep);
              if((null != nodes)&&(nodes.length>0))
                   retArray = retArray.concat(nodes);
         }
    }
    
    return retArray;
}

function checkPartialMatch(str1, str2)
{
     //if either is null return false
     if(null == str1 || null == str2)
          return false;
     if(0 == str1.length || 0 == str2.length )
          return false;
     
     //determine shorter and longer strings
     var tempShorter = str1.length > str2.length?str2:str1;
     var tempLonger = str1.length > str2.length?str1:str2;
     
     if(tempShorter == tempLonger.substr(0, tempShorter.length))
          return true;
     else
          return false;
}

function addLoadEvent(func) 
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function') 
  {
    window.onload = func;
  } 
  else 
  {
    window.onload = function() 
    {
      oldonload();
      func();
    }
  }
}

String.prototype.lTrim =
     function()
      {
       return this.replace(/^\s+/,'');
      }
String.prototype.rTrim =
     function()
      {
       return this.replace(/\s+$/,'');
      }
String.prototype.trim =
     function()
      {
       return this.replace(/^\s+|\s+$/g,'');
      } 
      
	/**
	*/
	function ImgResize(pObj, pMaxX, pMaxY)
	{
		var lWidth = pObj.width;
		var lHeight = pObj.height;
		var lQ1 = 1;
		if (lWidth > pMaxY)
		{
			lQ1 = pMaxX / lWidth;
			lWidth = lWidth * lQ1;
			lHeight = lHeight * lQ1;
		}
		if (lHeight > pMaxY)
		{
			lQ1 = pMaxY / lHeight;
			lWidth = lWidth * lQ1;
			lHeight = lHeight * lQ1;
		}
		
		//alert(pObj.width + ' : ' + lWidth + ' : ' + pMaxX + ';' + pObj.height + ' : ' + lHeight + ' : ' + pMaxY);
		
		pObj.style.height = lHeight + 'px';
		pObj.style.width = lWidth + 'px';
	}
	
	/**
	
			Funtion will resize given image and will draw the KS meter bar after the image is resized.
			For IE it will occure with a small delay. (for stupid browser to think a bit)
			 
	*/
	function ImgResizeWitkKSMeter(pObj, pMaxX, pMaxY, pKSMeterId)
	{
		var ua = navigator.userAgent.toLowerCase(); 
		if ( ua.indexOf( "msie" ) != -1 ) 
		{
			window.setTimeout(function()
				{
					//alert('delayed');
					ImgResize(pObj, pMaxX, pMaxY);
					//pObj.style.display = 'block;';
					ResizeKSMeter(pKSMeterId);
				}
			, 200
			);
		}
		else
		{
			//pObj.style.display = 'block';
			ResizeKSMeter(pKSMeterId);
		}
	}
	
	function ResizeKSMeter(pId)
	{
		var lElem =  gEBI(pId);
		var lKS = '';
		var lSize1 = 0;
		if (null == lElem) 
		{
			alert('element not found: ' + pId);
			return false;
		}
		else
		{
			lKS = lElem.getAttribute('kscore');
			//alert(pId + ': ' + lKS);
	
			lSize1 = lElem.parentNode.offsetHeight;
			lKS = (lKS * lSize1 / 100)
			lElem.style.height = lKS + 'px';
			lElem.style.display = 'block';
		}
	}   