/*javascript utils			*/
var WindowObjectReference = null; // global variable


function launchCenter(url, name, height, width) {
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
	
	
	//window.open(url, '', str);
	
  return window.open(url, '', str);
}


function openWindow(strFileURL,title,h,w)
{

  if(WindowObjectReference == null || WindowObjectReference.closed)
  /* if the pointer to the window object in memory does not exist
     or if such pointer exists but the window was closed */

  {
  
    WindowObjectReference = launchCenter(strFileURL,title, h, w);
    
    /* then create it. The new window will be created and
       will be brought on top of any other window. */
        
  }
  else
  {
    WindowObjectReference.focus();
    
    /* else the window reference must exist and the window
       is not closed; therefore, we can bring it back on top of any other
       window with the focus() method. There would be no need to re-create
       the window or to reload the referenced resource. */
  };
}
function setDOTNETControl(strName,strValue)
{
	var i;
	var str;
	
	//document.Form1.length
	i=0;
	do 
	{
		str = document.Form1.elements[i].id;
		str = str.substring(document.Form1.elements[i].id.length-strName.length,document.Form1.elements[i].id.length);
		i = i + 1; 
	}
	while ((str!=strName) && (i < document.Form1.length))

	if (str==strName) {document.Form1.elements[i-1].value = strValue;}
	//Form1.submit();
}

 
 function setDOTNETImage(strName,strValue)
 {
 
 	var i;
	var str;
	
	//document.Form1.length
	i=0;
	do 
	{
		str = document.images[i].id;
		str = str.substring(document.images[i].id.length-strName.length,document.images[i].id.length);
		i = i + 1; 
	}
	while ((str!=strName) && (i < document.images.length))

	if (str==strName) {
	document.images[i-1].src = strValue;
		
	}
 }
 
function reloadImage(id) {
     im = document.getElementById(id);
     src = im.srcl
     im.src = '';
     im.src = src;
  } 
  
  
 window.onload=function(){
 document.onmousedown=startDrag;
 document.onmouseup=stopDrag;
}

function startDrag(e){
 // determine event object
 if(!e){var e=window.event};
 // determine target element
 var targ=e.target?e.target:e.srcElement;
 if(targ.className!='AdvertMiddleRightSponsor'){return};
 // calculate event X,Y coordinates
     offsetX=e.clientX;
     offsetY=e.clientY;
 // assign default values for top and left properties
 if(!targ.style.left){targ.style.left='775px'};
 if(!targ.style.top){targ.style.top='0px'};
 // calculate integer values for top and left properties
     coordX=parseInt(targ.style.left);
     coordY=parseInt(targ.style.top);
     drag=true;
 // move div element
     document.onmousemove=dragDiv;
}

function dragDiv(e){
 if(!drag){return};
 if(!e){var e=window.event};
 var targ=e.target?e.target:e.srcElement;
 // move div element
   targ.style.left=coordX+e.clientX-offsetX+'px';
   targ.style.top=coordY+e.clientY-offsetY+'px';
   return false;
}

function stopDrag(){
 drag=false;
 //save cords here
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0


  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
//this function displays a confirmation box then forces the on click event for actual
//button in .net that does the code behind.
//we set the actual .net button to style of hidden
function ForceClick(strName)
{
	var i;
	var str;
		
	i=0;
	do 
	{
		str = document.Form1.elements[i].id;
		str = str.substring(document.Form1.elements[i].id.length-strName.length,document.Form1.elements[i].id.length);
		i = i + 1; 
	}
	while ((str!=strName) && (i < document.Form1.length))

	if (str==strName) 
	{
	var agree=confirm("Are you sure ?. Your changes will be lost and you will not be able to undo this.");
		if (agree)	document.Form1.elements[i-1].click();
	
	}
}
//this function gets a confirmation. this is used with HTML buttons only
//if button is DOTNET then use ForceClick function
function Confirmation()
{

var agree=confirm("Are you sure ?. Your changes will be lost and you will not be able to undo this.");
	return agree;
	
}


function ObjectClick(strName)
{
	var obj;
	obj=document.getElementById(strName)
	obj.click();
	
}

//this function returns the correct control name for a .net generated control
//we take in the control name in .net ie DIV1 and the tag type ie div
function FindDOTNETObject(strName,strType)
{
var str;
var doc = document.getElementsByTagName(strType);
var i;
i=0;

do
	{
		str2 = doc[i].id;
		str = doc[i].id;
		str = str.substring(doc[i].id.length-strName.length,doc[i].id.length);
		i = i + 1;
	}
while ((str!=strName) && (i < doc.length))
return str2
	
}

function HideLayer(obj,show)
{

	var newobj;
	newobj=FindDOTNETObject(obj,'div');
	if (document.getElementById)
	{

	// this is the way the standards work
	
	document.getElementById(newobj).style.visibility = show;
	
	}
	else
	{
		if (show='hidden') {show='none'} else {show=''};
		var el = document.getElementById(newobj);
		if ( el.style.display!= "none" ) {	el.style.display = 'none';	}
		else {	el.style.display = '';	}
	}
}

function SETObjectFocus(obj)
{
	document.getElementById(obj).setfocus();
}

function f_setfocus()
{

var form = document.Form1
var i
i = 0

	try
	{
		for (i = 0; form.elements.length-1; i++)
		{
	  		 
		if (form.elements[i].tabIndex == 1) 
  			{	
			form.elements[i].focus(); 
  			break;
			} //end if
			

	 
		} //end for
	} //try
	catch(err)
			{
			//error 
			}
}


function resetDynamicFields()
{
	document.Form1.OrderId.value=Math.round(Math.random()*10000000000);
	setDOTNETControl('OrderId',Math.round(Math.random()*10000000000));
	
	document.Form1.TimeStamp.value=new Date().valueOf();
	setDOTNETControl('TimeStamp',new Date().valueOf());
}