/**
 * Sets/unsets the pointer in browse mode
 *
 * @param   object   the table row
 * @param   object   the color to use for this row
 * @param   object   the background color
 *
 * @return  boolean  whether pointer is set or not
 */
 
 function m_link(prog_id,temp){	
 	//opener.location.href=prog_id+'?'+url;
 	window.open(prog_id, temp, 'top=100,left=100,location=no,scrollbars=yes,status=no');
 	window.refresh();					
 	window.close();		
}

function m_link2(prog_id,temp){
 	opener.location.href=prog_id;
 	//window.open(prog_id, temp, 'top=100,left=100,location=no,scrollbars=yes,status=no');
 	//window.refresh();
        opener.focus();					
        window.close();
}

function ViewResults(link){
        window.open(link,"ProductPicture","scrollbars=yes,toolbar=no,menubar=no,status=no,resizable=no,directories=no,width=500,height=500");
}

function submitsearch(frm){
        document.forms[frm].submit();
}


function setPointer_sel2(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor,prog_id,url){
var theCells = null;
	    if ((thePointerColor == '' && theMarkColor == '') || typeof(theRow.style) == 'undefined') {
		return false;
	    }

	    if (typeof(document.getElementsByTagName) != 'undefined') {
		theCells = theRow.getElementsByTagName('td');
	    }else if (typeof(theRow.cells) != 'undefined') {
		theCells = theRow.cells;
	    }else {
		return false;
	    }

	    var rowCellsCnt  = theCells.length;
	    var domDetect    = null;
	    var currentColor = null;
	    var newColor     = null;

	    currentColor = theCells[0].getAttribute('bgcolor');
	    currentColor = theCells[0].style.backgroundColor;
	    domDetect    = true;

	    if (currentColor.indexOf("rgb") >= 0){
		var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,currentColor.indexOf(')'));
		var rgbValues = rgbStr.split(",");
		currentColor = "#";
		var hexChars = "0123456789ABCDEF";
		for (var i = 0; i < 3; i++){
		    var v = rgbValues[i].valueOf();
		    currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
		}
	    }

		if (theAction == 'over' && thePointerColor != '') {
		    newColor              = thePointerColor;
		}else if (theAction == 'out') {
		    newColor              = theDefaultColor;			   
		}else if (theAction == 'click'){
				opener.location.href=prog_id+'?'+url;					
				opener.focus();					
				window.close();
		}

	  if (newColor) {
		var c = null;
		if (domDetect) {
		    for (c = 0; c < rowCellsCnt; c++) {
			theCells[c].setAttribute('bgcolor', newColor, 0);
		    }
		}else {
		    for (c = 0; c < rowCellsCnt; c++) {
			theCells[c].style.backgroundColor = newColor;
		    }
		}
	    }
	    return true;
}
 
function setPointer(theRow, thePointerColor, theNormalBgColor)
{
    var theCells = null;

    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {
        return false;
    }
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    var rowCellsCnt  = theCells.length;
    var currentColor = null;
    var newColor     = null;
    // Opera does not return valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
                     ? theNormalBgColor
                     : thePointerColor;
        for (var c = 0; c < rowCellsCnt; c++) {
            theCells[c].setAttribute('bgcolor', newColor, 0);
        } // end for
    }
    else {
        currentColor = theCells[0].style.backgroundColor;
        newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
                     ? theNormalBgColor
                     : thePointerColor;
        for (var c = 0; c < rowCellsCnt; c++) {
            theCells[c].style.backgroundColor = newColor;
        }
    }

    return true;
} // end of the 'setPointer()' function




function setPointer_sel(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor,prog_id,url){
	var theCells = null;
		    if ((thePointerColor == '' && theMarkColor == '') || typeof(theRow.style) == 'undefined') {
			return false;
		    }		
		    
		    if (typeof(document.getElementsByTagName) != 'undefined') {
			theCells = theRow.getElementsByTagName('td');
		    }else if (typeof(theRow.cells) != 'undefined') {
			theCells = theRow.cells;
		    }else {
			return false;
		    }
		    
		    var rowCellsCnt  = theCells.length;
		    var domDetect    = null;
		    var currentColor = null;
		    var newColor     = null;

		    currentColor = theCells[0].getAttribute('bgcolor');
		    currentColor = theCells[0].style.backgroundColor;
		    domDetect    = true;

		    if (currentColor.indexOf("rgb") >= 0){
			var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,currentColor.indexOf(')'));
			var rgbValues = rgbStr.split(",");
			currentColor = "#";
			var hexChars = "0123456789ABCDEF";
			for (var i = 0; i < 3; i++){
			    var v = rgbValues[i].valueOf();
			    currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
			}
		    }

			if (theAction == 'over' && thePointerColor != '') {
			    newColor              = thePointerColor;
			}else if (theAction == 'out') {
			    newColor              = theDefaultColor;			   
			}else if (theAction == 'click'){
					opener.location.href=prog_id+'?'+url;					
					opener.focus();					
					window.close();
		    	}
		    
		  if (newColor) {
			var c = null;
			if (domDetect) {
			    for (c = 0; c < rowCellsCnt; c++) {
				theCells[c].setAttribute('bgcolor', newColor, 0);
			    }
			}else {
			    for (c = 0; c < rowCellsCnt; c++) {
				theCells[c].style.backgroundColor = newColor;
			    }
			}
		    }
		    return true;
}

function confirmLink(theLink, theSqlQuery)
{
	// Confirmation is not required 
	// return true;	
	//var confirmMsg   = '';
        //alert(theSqlQuery);
        var is_confirmed = confirm(theSqlQuery);
        if (is_confirmed) {
            theLink.href += '&is_js_confirmed=1';
        }
        return is_confirmed;
} // end of the 'confirmLink()' function

function confirmLink2(theLink, theSqlQuery)
{
	// Confirmation is not required 
	// return true;	
	var confirmMsg   = '????????';
    var is_confirmed = confirm(confirmMsg + ' :\n' + theSqlQuery);
    if (is_confirmed) {
        window.location.href =theLink;
    }
} // end of the 'confirmLink()' function


function alert_confirm(theLink, theSqlQuery)
{
    var confirmMsg   = '????????';
    var is_confirmed = confirm(confirmMsg + ' :' + theSqlQuery);
    if (is_confirmed) {
    	opener.location.reload();
    	window.close();
        OpenWindow2(theLink);
        //window.location.href =theLink;
    }
    else {
    	opener.location.reload();
	opener.focus();
	window.close();
    }

    return is_confirmed;
} // end of the 'alert_confirm' function

function confirmButton(theLink, theSqlQuery)
{
	var confirmMsg   = '????????';
    var is_confirmed = confirm(confirmMsg + ' :\n' + theSqlQuery);
    if (is_confirmed) {
        OpenWindow(theLink);
    }

    return is_confirmed;
} // end of the 'confirmLink()' function

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/*function OpenWindow(url,temp){    
	if (temp=='') temp ='temp'
    temp415=window.open(url, temp, 'resizable,scrollbars=yes,statusbars=yes');
    temp415.focus();
  }*/
 
  function OpenWindow(url,temp){
  	var resolution_height = screen.availHeight;
  	var resolution_width  = screen.availWidth;
  	var win_height =600;
  	var win_width =  800;
  	var xpos  = ( resolution_width  - win_width  ) / 2;
        var ypos  = ( resolution_height - win_height ) / 2;

  	if (temp=='') temp ='temp'
  
  	//alert(temp);
  	windows_parameter = 'scrollbars=yes,resizable,width='+win_width+', height='+win_height+',left='+xpos.toFixed(0)+',top='+ypos.toFixed(0);
   	temp415= window.open(url,temp, windows_parameter);
  	temp415.focus();	
}


function OpenReload() {
	opener.location.reload();
	opener.focus();
	window.close();
}
function CloseWindow() {	
	opener.focus();
	window.close();
}
function OpenWindow2(url, height, width){    
    temp416=window.open(url, 'temp2', 'width=' + width + ',height=' + height + ',resizable,scrollbars=yes');
    temp416.focus();
}
function OpenWindow3(url,temp){    
	if (temp=='') temp ='temp'
    temp415=window.open(url, temp);
    temp415.focus();
}
function LinkWindow(theLink,confirm){
	if(confirm =='yes'){
		var confirmMsg   = '????????';
    	var is_confirmed = confirm(confirmMsg + ' :\n' + theSqlQuery);
    	if (is_confirmed) {
		    window.location.href =theLink;
    	}
	}
	window.location.href =theLink;
}

function txt2lst(txt,lst)
{
var sel;
	sel = 0;
	//alert("koh");
	
	txt = document.form1.elements[txt];	
	lst = document.form1.elements[lst];
	
	//alert(txt.value);
	//alert(lst.value);
	if (txt.value != "")
	{
		len = lst.length;
		if (len != 0)
		{
			word = txt.value;
			word_len = word.length;
			lst.options[sel].selected = false;
			for(i=0;i<len;i++)
			{
				if (word.toUpperCase() == lst.options[i].text.substring(0,word_len).toUpperCase())
				{
					sel = i;
				    	lst.options[i].selected = true;
				  	i = len;
				}
			}
		}
	}
}

function lst2txt(txt,lst)
{
	//alert("koh");exit;
	txt = document.form1.elements[txt];	
	lst = document.form1.elements[lst];	
	txt.value = lst.value	
//	txt.value = lst.options[lst.value - 1].text
}


function check1(theform,box_name){
    /*theform =document.forms[theform];
    clearCheckboxes(theform,box_name);
    for (var i=0; i<20; i++) {
        //alert(theform.elements[box_name].checked);
        //theform.elements[insert[i]].checked=true;
    }*/
}

function clearCheckboxes(theform,box_name){
   /* theform =document.forms[theform];
    for (var i=0; i < 20; i++) {		
        //theform.elements[box_name[i]].checked=false;
    }*/
}

function check_all(theform,signalbox,box_name){
    var c,s;
  	theform =document.forms[theform];
  	if (theform.elements[signalbox].checked) c =true;
  	else c=false;
	for (var i=0; i < theform.length; i++) {		
	    var e = theform.elements[i];	    	    
	    if (e.type == 'checkbox' && e.style.display !='none') {	    	
	      e.checked = c;
	      continue;
	    }
	}		
  	return true;
}

function check_all2(theform,signalbox,box_name) 
{
var c,s;
        //alert(box_name);
  	theform =document.forms[theform];
  	if (theform.elements[signalbox].checked) c=true;
  	else c=false;
        //alert(theform.elements[box_name].length);
        
	for (var i=0; i < theform.length; i++) {		
	    var e = theform.elements[i];
            //alert(e.name+" : "+box_name[i]);
	    if (e.name != box_name[i]) continue;
	    s = s + e.name;	    	    
	    if (e.type == 'checkbox' && e.style.display !='none') {	    	
	      e.checked = c;
	      continue;
	    }
	}		
//alert(s);	
  	return true;
}

function errortrap(msg,url,line){
//    alert(msg);
    return true;
}
onerror=errortrap;


function addRow(id){
    var tbl = document.getElementById(id)
    var tbody = tbl.getElementsByTagName("TBODY")[0];
    var row = document.createElement("TR")
    var td1 = document.createElement("TD")+document.createElement()
    var td2 = document.createElement("TD")
    var td3 = document.createElement("TD")
    var lastRow = tbl.rows.length

    td1.appendChild(document.createTextNode("column " + lastRow))
    td2.appendChild (document.createTextNode("column " + lastRow ))
    td3.appendChild (document.createTextNode("column " + lastRow ))
    row.appendChild(td1);
    row.appendChild(td2);
    row.appendChild(td3);
    tbody.appendChild(row);
 }

 function removeRow(id,rowid){
    var table = document.getElementById(id)
    var rowid = document.getElementById(rowid)
    table.deleteRow(rowid.value)
 } 

 var gFiles = 0;
 function addFile() {
        /*var myRow = document.all.myTable.insertRow();
        var myCell = myRow.insertCell();
        myCell.innerText = "The added cell";*/
        
        var li = document.createElement('<div>');	 
        li.setAttribute('id', 'file-' + gFiles);
        li.innerHTML = '<tr><td><input type="text" name="name[]"></td>'
                        +'<td><input type="text" name="sur[]"></td>'
                        +'<td><input type="text" name="old[]"></td>'
                        +'<td><input type="text" name="old2[]"></td>'
                        +'<td><input type="text" name="old3[]"></td>'
                        +'<td><span onclick="removeFile(\'file-' + gFiles + '\')" style="cursor:pointer;"><img src="images/b_drop.png"></span></td>'
                        ;
	 document.getElementById('files-root').appendChild(li);
	 gFiles++;
 }

 function removeFile(aId) {
	 var obj = document.getElementById(aId);
	 obj.parentNode.removeChild(obj);
 }
 
 function function1(){
    var myNode = document.createTextNode("New Text Node");
    document.body.appendChild(myNode); 

}


