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



function timestamp()
{
	var now = new Date();
	var ts = "&uqtimestamp=" + now.getTime()
	return ts
}


function getUrl(url,pars,div)
{	
	if(typeof div == "string")
		var div = $(div) 
		
	div.innerHTML = "<img src='/media/img/loading-circle.gif' border='0'>"		
	pars = pars + timestamp()
	//alert(pars)
	
	var myAjax = new Ajax.Updater( 		  
	    {  success: div },  
       	url, 
       	{ 
           	method: 'get',
			parameters: pars,
			evalScripts: true,
			//onComplete: alert('done'),
			onFailure: function(req){ div.innerText = req.responseText },
			onException: function(req){ div.innerText = req.responseText }
       	});
}	

function postUrl(url,pars,div)
{	
	if(typeof div == "string")
		var div = $(div) 
	
	div.innerHTML = "<img src='/media/img/loading-circle.gif' border='0'>"		
	pars = pars + timestamp()
	//alert(pars)
	
	var myAjax = new Ajax.Updater( 		  
	    {  success: div },  
       	url, 
       	{ 
           	method: 'post',
			parameters: pars,
			evalScripts: true,
			//onComplete: alert('done'),
			onFailure: function(req){ div.innerText = req.responseText },
			onException: function(req){ div.innerText = req.responseText }
       	});
}	

function postUrlRequest(url,pars,oFunct)
{	
	if(typeof oFunct == "string")
		var oFunct = $(oFunct) 	
	
	var erDiv = $('ajViewReturn')
	pars = pars + timestamp()
	//alert(pars)
	
	var myAjax = new Ajax.Request( 				   
       	url, 
       	{ 
           	method: 'post',
			parameters: pars,
			onComplete: oFunct,
			onFailure: function(req){ erDiv.innerText = req.responseText },
			onException: function(req){ erDiv.innerText = req.responseText }
       	});
}	




function postUrlRequestAsync(url,pars,oFunct)
{	
	//var erDiv = $('ajaxError')
	pars = pars + timestamp()
	//alert(pars)
	//alert(url)
	var myAjax = new Ajax.Request( 				   
       	url, 
       	{ 
           	method: 'post',
			asynchronous: true,
			parameters: pars,
			onSuccess: function(r){ alert("onSuccess: "+r)  },
			onFailure: function(r){ alert("onFailure: "+r)  },
			onException: function(r,s){ alert("onException: " + r + " | " + s )}
       	});
	//alert("after the request call")
}	




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;
}
/* Functions that swaps images. */
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;
}

/* Functions that handle preload. */
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];}}
}

var picwin = null;
function openwin(name,passwindowprops)
{
  if ( ( picwin == null )
    || picwin.closed )
  {
    // the window has been closed, or never opened yet
    // --> open it
    if(passwindowprops==0){
        var windowprops = "width=750,height=650,toolbar=0,location=0,directories=0,status=0,menuBar=1,scrollBars=1,resizable=1,top=15,left=15";
    } else {
        var windowprops = passwindowprops;
    }  
		//var windowprops = "width=420,height=625,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1,top=15,left=15";    
    picwin = window.open(name,'picWindow',windowprops);
  }
  else
  {
    // window is opened somewhere -> bring it in front
    picwin.location.href=name;
		picwin.focus();
  }
}

/*  ================================================================
    FUNCTION:  isCreditCard(st)
 
    INPUT:     st - a string representing a credit card number

    RETURNS:  true, if the credit card number passes the Luhn Mod-10
		    test.
	      false, otherwise
    ================================================================ */

function isCreditCard(st) {
  // Encoding only works on cards with less than 19 digits
  if (st.length > 19){
	  alert('The Credit Card field contains some invalid values:\n\n');
    return (false);
  }
	// 
  if (st.length == 0 || st.value ==''){
	  alert('The Credit Card field is required:\n\n');
    return (false);
  }
  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }
  
  if ((sum % 10) == 0){
    return (true);
  }else{
	  alert('The Credit Card field contains some invalid values:\n\n');
    return (false);
  }
} // END FUNCTION isCreditCard()



function viewHideLink(obj,linkId)
{
	if(obj.style.display == "none")
	{
		obj.style.display = ""
		if($(linkId))
		{
			var ntxt = $(linkId).innerHTML.replace(/view/,"hide")	
			$(linkId).innerHTML = ntxt
		}
	}
	else if(obj.style.display == "")
	{
		obj.style.display = "none"
		if($(linkId))
		{
			var ntxt = $(linkId).innerHTML.replace(/hide/,"view")	
			$(linkId).innerHTML = ntxt			
		}			
	}
} 




function viewHideLinkSelector(parent,selector,linkId)
{
	var objArray = $(parent).getElementsBySelector(selector)
	
	//alert(objArray)
	if(objArray.length)
	{
		//alert(objArray.length)
		for(i=0;i<objArray.length;i++)
		{
			var obj = objArray[i]			
			if(obj.style.display == "none")
			{
				obj.style.display = ""
				if($(linkId))
				{
					var ntxt = $(linkId).innerHTML.replace(/view/,"hide")	
					$(linkId).innerHTML = ntxt
				}
			}
			else if(obj.style.display == "")
			{
				obj.style.display = "none"
				if($(linkId))
				{
					var ntxt = $(linkId).innerHTML.replace(/hide/,"view")	
					$(linkId).innerHTML = ntxt			
				}			
			}
		}	
	}	
}

