﻿function getDecimalValue(oElement){
    var iReturn = 0.00;
    if (oElement){
	    iReturn = parseFloat(oElement.value);
    }
    if (!isNaN(iReturn))
	    return iReturn;
    else
	    return 0.00;
}

function multiply (sElementID) {        
    var element = document.getElementById (sElementID);
    element.value = getDecimalValue(element) * 12;
}
    
function validateDecimal(sender, args)
{  
    var value = args.Value.toString();    
    if (value.replace(/\s+/g,'')=='' || isNaN (value))
        args.IsValid = false;
    else
        args.IsValid = true;    
}

function validateCurrency(sender, args)
{
    var value = args.Value.toString();    
    value = value.replace(/\s+/g,'');
    value = value.replace(/£+/g,'');
    value = value.replace(/,+/g,'');
    
    if (value=='' || isNaN (value))
        args.IsValid = false;
    else
        args.IsValid = true;
}

function validateInteger(sender, args)
{  
    var value = args.Value.toString();    
    if (value.replace(/\s+/g,'')=='' || isNaN (value))
        args.IsValid = false;
    else
    {
        if (value.indexOf(".") > -1)
            args.IsValid = false;
        else
            args.IsValid = true;    
    }
}

function changeLinkState(elHoldingDiv, enabled){

      holdingDiv = document.getElementById (elHoldingDiv);
      a=holdingDiv.getElementsByTagName('a');
      
      for(var i=0; i < a.length; i++){              
        var anchor = a[i];
            if (!enabled) {
                anchor._onclick = anchor.onclick;
                anchor.onclick = function(){return false;};
            } else{
                if (anchor._onclick!=undefined ) 
                    anchor.onclick = anchor._onclick;
            }        
      }
}

function changeElementState(elName,enabled){
    try{
        document.getElementById(elName).disabled = !enabled;        
        if (document.getElementById(elName).nodeName=='A') {       
            var anchor = document.getElementById(elName);
            if (!enabled) {
                anchor._onclick = anchor.onclick;
                anchor.onclick = function(){return false;};
            } else{
                if (anchor._onclick!=undefined ) 
                    anchor.onclick = anchor._onclick;
            }        
        }                   
    }
    catch (e){}
    finally{}
}    
    
function changeElementVisibility(elName,visible){
    try{
        if (visible)
            document.getElementById(elName).style.display = '';
        else       
            document.getElementById(elName).style.display = 'none';
    }
    catch (e){}
    finally{}
}    

function displayDebug(textBox) {      
   var content = document.getElementById (textBox)
   pWin = window.open('','pWin','location=0,menubar=0,toolbar=0,scrollbars=1,resizable=1,width=600,height=400');
   pWin.document.open();
   pWin.document.write('<html><head></head><body style=\'font-size:10px;font-family:arial;\'>');
   pWin.document.write(content.value);
   pWin.document.write('</body></html>');
   pWin.focus();
}

function showToolTip(e,text){         
    if (text=='')
        return;
    
    //alert (document.body.scrollLeft);
    //alert (e.clientX+15+document.body.scrollLeft);   
    //alert (e.clientY+document.body.scrollTop);             
    //alert (e.x + 15 + document.body.scrollLeft);
    var ToolTip = document.getElementById ("ToolTip");
    ToolTip.innerHTML=text; 
    ToolTip.style.left=(e.clientX+15+document.body.scrollLeft + "px"); 
    ToolTip.style.top=(e.clientY+document.body.scrollTop + "px"); 
    ToolTip.style.visibility="visible"; 
} 

function hideToolTip(){ 
    var ToolTip = document.getElementById ("ToolTip");
    ToolTip.style.visibility="hidden"; 
} 

function findPos(obj) {

	var curleft = 0;
	var curtop = 0;
	
	curleft = obj.offsetLeft
	curtop = obj.offsetTop

	while (obj = obj.offsetParent) {		    		
		curleft += obj.offsetLeft
		curtop += obj.offsetTop
	}
		
	return [curleft,curtop];
}

function debug (text){
    var divDebug = document.getElementById ("divDebug");
    divDebug.innerHTML+=text + '<br>';
}

function setupProgressIndicator() {
    
    var divProgress = document.getElementById ("divProgress");
    var divHolder = document.getElementById ('divHolder');    
    var pos = findPos(divHolder);                  
    
    var left = (pos[0] + divHolder.offsetWidth)/2;
    var top = (pos[1] + divHolder.offsetHeight)/2;
    
    divProgress.style.left = left;
    divProgress.style.top = top;

}

function updateProgress(message)   
{   
//    if (message!=null && message!='')
//        $get('UpdateStatus').innerHTML = message;       
//    else
//        $get('UpdateStatus').innerHTML = 'Processing, please wait';       
}   

function updateProgressCompleted() {
//    $get('UpdateStatus').innerHTML = 'Processing, please wait';       
}


function showGuide (guideID) {

}
