var lastMouseX;
var lastMouseY;
var curPopupWindow = null;

var count = 0;
var temp

function __doMyPostBack(eventTarget, eventArgument)
{
    __doPostBack('ctl00$ContentPlaceHolder1$'+eventTarget, eventArgument);
}

function presubmit(){
	temp = setInterval('disableForm();',10);
}

function disableForm(){
	if(count==0){
	count = 1;
	return true;}
	else
	{
	for(x=0;x<document.forms[0].length;x++) 
		document.forms[0].elements[x].disabled=true;
	
	var input = document.forms[0].getElementsByTagName("a"); 

	var count = input.length; 

	for(var i =0; i < count; i++)
		document.forms[0].getElementsByTagName("a")[i].onclick=function () { return false };

	clearInterval(temp);
	}
}

function toggle(e,i,path){

			if (document.getElementById(e).style.display == "none"){
				document.getElementById(e).style.display = "";
				document.getElementById(i).src = path + "images/exp_minus.gif";
				document.getElementById(i).alt = "Collapse"
				}
			else{
				document.getElementById(e).style.display = "none";
				document.getElementById(i).src = path + "images/exp_plus.gif";
				document.getElementById(i).alt = "Expend"
			}
}//end toggle
		

//url = targetPath
//pWidth = popup window width (integer)
//pHeight = popup window height (integer)
//scroll = scrolling or not (YES | NO)
//closeOnLoseFocus = auto close popup windows (True | False)
//E.g. openPopup('http://www.blaxtron.com', 500, 500, 'NO', true)
function openPopup(url, pWidth, pHeight, scroll, closeOnLoseFocus) {
     
    lastMouseX = (screen.width - pWidth)/2
    lastMouseY = (screen.height - pHeight)/2		
   
    var features = "width=" + pWidth + ",height=" + pHeight + ",resizable=no,toolbar=no,status=no,scrollbars=" + scroll + ",menubar=no,directories=no,location=no,dependant=yes"
    
	closePopup();
     
    features += "screenX=" + lastMouseX + ",left=" + lastMouseX + "screenY=" + lastMouseY + ",top=" + lastMouseY;
    
    if (closeOnLoseFocus) {
        curPopupWindow = window.open(url, '_blank', features, false);
        curPopupWindow.focus ();
    } else {
        // assign the open window to a dummy var so when closePopup() is called it won't be assigned to curPopupWindow
        win = window.open(url, '_blank', features, false);
        win.focus ();
    }
}

function closePopup() {
    if (curPopupWindow != null) {
       
        if (!curPopupWindow.closed) {
            curPopupWindow.close();
        }
        curPopupWindow = null;
    }
}

function setFocus() {
    var sidebarSearch;
    // search for a tabIndexed field to focus on
    for(var firstIndex=1; firstIndex < 5; firstIndex ++ ){
        var nextIndex = firstIndex;
        for (var frm = 0; frm < document.forms.length; frm++) {
            for (var fld = 0; fld < document.forms[frm].elements.length; fld++) {
                var elt = document.forms[frm].elements[fld];
                //alert(document.forms[frm].elements.length)
                //alert(elt.id)
                //alert(fld)
                //alert(elt.disabled)
                if ( elt.tabIndex != nextIndex ) continue;
				if ((elt.type == "text" || elt.type == "textarea" || elt.type == "password")
				&& elt.name != "sbstr" &&  elt.name.indexOf("owner") != 0 && elt.disabled != true) {
					try { 
//					    elt.focus();
					    if (elt.type == "text") {
						    elt.select();
					    }
					    return true;
				    } 
                    catch (e) { 
                    }   
				} else {
					nextIndex++;
					fld = 0;
				}
            }
        }
    }

    // failed to find a tabIndexed field, try to find the field based on it's natural position.
    for (var frm = 0; frm < document.forms.length; frm++) {
        for (var fld = 0; fld < document.forms[frm].elements.length; fld++) {
            var elt = document.forms[frm].elements[fld];
            // skip buttons, radio, or check-boxes
            // to skip "select" types, remove from if statement
            if(elt.disabled == false){
				if (elt.type == "text" || elt.type == "textarea" || elt.type == "password") {
					if (elt.name == "sbstr" && document.forms[frm].name == "sbsearch") { 
						sidebarSearch = elt; 
					} else if (elt.name.indexOf("owner") != 0) {
					    try { 
//                            elt.focus();
						    // select text in text field or textarea
						    if (elt.type == "text") {
							    elt.select();
						    }
						    return true;                             
                        } 
                        catch (e) { 
                        }  
					}
				}
            }
        }
    }

    return true;
}

function mask(str,textbox,loc,delim){
    var locs = loc.split(',');

    for (var i = 0; i <= locs.length; i++){
	    for (var k = 0; k <= str.length; k++){
	        if (k == locs[i]){
	            if (str.substring(k, k+1) != delim){
	                if (event.keyCode != 8){ //backspace
	                    str = str.substring(0,k) + delim + str.substring(k,str.length);
                    }
	            }
	        }
	    }
    }

    textbox.value = str
}

function roundToPennies(n) 
        { 
           pennies = n * 100; 

           pennies = Math.round(pennies); 

           strPennies = "" + pennies; 
           len = strPennies.length; 

           first = strPennies.substring(0, len - 2) + "."; 
           last = strPennies.substring(len - 2, len); 

           if(first == ".") 
              first = "0." 

           if(last.length == 1) 
              last += "0"; 

           return first + last; 
        } 
        
function ConvertToNumber(value)
    {
        return (value == null) ? 0.00 : Number(value);
    }
