var newwindow;

function modal_pop( url,reload ){
    var m_args = "dialogHeight:600px;dialogWidth:800px;center:yes;resizable:yes;scroll:yes;toolbar:no;menubar:no;location:no;directories:no;";
    var r_args = "height=600,width=800,center=yes,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,modal=yes";
    var ret;
    if( window.showModalDialog ){
        ret = window.showModalDialog( url,"text_edit",m_args );
    } else {
        ret = window.open( url,"text_edit",r_args );
    }
    
    if( reload == '1' )document.location.reload();
    
}
function pop_product( url,reload ){
    var m_args = "dialogHeight:400px;dialogWidth:450px;center:yes;resizable:no;scroll:yes;toolbar:no;menubar:no;location:no;directories:no;";
    var r_args = "height=400,width=450,center=yes,resizable=no,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,modal=yes";
    var ret;
    if( window.showModalDialog ){
        ret = window.showModalDialog( url,"text_edit",m_args );
    } else {
        ret = window.open( url,"text_edit",r_args );
    }
    
    if( reload == '1' )document.location.reload();
    
}
 function pop( url ){
    newwindow=window.open(url,'name','scrollbars=yes,toolbar=yes,menubar=yes,location=yes,directories=yes,dependant=yes');
	if (window.focus) {newwindow.focus()}
}

 function pop_call_window( url ){
 
    var m_args = "dialogHeight:60px;dialogWidth:80px;center:yes;resizable:no;scroll:no;toolbar:no;menubar:no;location:no;directories:no;";
    var r_args = "height=60,width=80,center=yes,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no";
    var ret;
    if( window.showModalDialog ){
       // ret = window.showModalDialog( url,"text_edit",m_args );
		 newwindow=window.open( url,'call_window',m_args );
    } else {
       // ret = window.open( url,"text_edit",r_args );
		 newwindow=window.open( url,'call_window',r_args );
    }
	if (window.focus) {newwindow.focus()}
}

function alternateRowColors() {
	var className = 'box_table';
	var rowcolor = '#eaeaea';
	var rows, arow;
	var tables = document.getElementsByTagName("table");
	var rowCount = 0;
	for(var i=0;i<tables.length;i++) {
		//dump(tables.item(i).className + " " + tables.item(i).nodeName + "\n");
		if(tables.item(i).className == className) {
			atable = tables.item(i);
			rows = atable.getElementsByTagName("tr");
			for(var j=0;j<rows.length;j++) {
				arow = rows.item(j);
				if(arow.nodeName == "TR") {
					if(rowCount % 2) {
						arow.style.backgroundColor = rowcolor;
					} else {
						// default case
					}
					rowCount++;
				}
			}
			rowCount = 0;
		}
	}
}

function SetUniqueRadioButton(nameregex, current)
{
   re = new RegExp(nameregex);
   for(i = 0; i < document.forms[0].elements.length; i++)
   {
      elm = document.forms[0].elements[i]
      if (elm.type == 'radio')
      {
         if (re.test(elm.name))
         {
            elm.checked = false;
         }
      }
   }
   current.checked = true;
}

function StopPropogation(e,objTextArea)
{
	alert( e.keyCode );
	if(e.keyCode == '13')
	{
	  objTextArea.value += '\r\n';
	  return false;
	}
	return true;
}

//  keeps track of the delete button for the row
//  that is going to be removed
var _source;
// keep track of the popup div
var _popup;

function showConfirm(source){
    this._source = source;
    this._popup = $find('mdlPopup');
    
    //  find the confirm ModalPopup and show it    
    this._popup.show();
}

function okClick(){
    //  find the confirm ModalPopup and hide it    
    this._popup.hide();
    //  use the cached button as the postback source
    __doPostBack(this._source.name, '');
}

function cancelClick(){
    //  find the confirm ModalPopup and hide it 
    this._popup.hide();
    //  clear the event source
    this._source = null;
    this._popup = null;
}



var MAX_DUMP_DEPTH = 10;
function dumpObj(obj, name, indent, depth) {
  if (depth > MAX_DUMP_DEPTH) {
         return indent + name + ": <Maximum Depth Reached>\n";
  }
  if (typeof obj == "object") {
         var child = null;
         var output = indent + name + "\n";
         indent += "\t";
         for (var item in obj)
         {
               try {
                      child = obj[item];
               } catch (e) {
                      child = "<Unable to Evaluate>";
               }
               if (typeof child == "object") {
                      output += dumpObj(child, item, indent, depth + 1);
               } else {
                      output += indent + item + ": " + child + "\n";
               }
         }
         return output;
  } else {
         return obj;
  }
}