
function printwindow(printdocument){
if(!printdocument) printdocument = document;
w = 500;
h = 400;
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
var printwindow = window.open ('', 'printwindow', config='height='+h+',width='+w+' , left='+LeftPosition+' , top='+TopPosition+' , toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, directories=no, status=no');
var head = printdocument.getElementsByTagName('head')[0].innerHTML;
var html = '<html><head>'+ head + '</head><body><div id="noprint"><center style="clear:both"><input type="button" value="Print" onclick="window.print()" /></center><hr /></div>'+ printdocument.getElementById('print_body').innerHTML;
/* html    += "<script>window.print()</script>"; */
html    += "</body></html>";

//variable name of window must be included for all three of the following methods so that
//javascript knows not to write the string to this window, but instead to the new window

printwindow.document.open();
printwindow.document.write(html);
printwindow.document.close();
return false;
}

function quickpopup(url , name){
w = 300;
h = 250;
if(!name) name = 'quickpopup';
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
var printwindow = window.open (url, name , config='height='+h+',width='+w+' , left='+LeftPosition+' , top='+TopPosition+' , toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, directories=no, status=no');

//variable name of window must be included for all three of the following methods so that
//javascript knows not to write the string to this window, but instead to the new window

return false;
}	


function uploadbox_popup(url){
w = 500;
h = 320;
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
var printwindow = window.open (url, 'quickuploadpopup', config='height='+h+',width='+w+' , left='+LeftPosition+' , top='+TopPosition+' , toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, directories=no, status=no');

//variable name of window must be included for all three of the following methods so that
//javascript knows not to write the string to this window, but instead to the new window

return false;
}

function ftpbox_popup(url){
w = 500;
h = 320;
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
var printwindow = window.open (url, 'quickftppopup', config='height='+h+',width='+w+' , left='+LeftPosition+' , top='+TopPosition+' , toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, directories=no, status=no');

//variable name of window must be included for all three of the following methods so that
//javascript knows not to write the string to this window, but instead to the new window

return false;
}

var ftpbox_target_field = '';

function ftpbox_savefiles(files){
	for(i=0; i< files.length ; i++)
	{
	if(files[i] != null)
		if($(ftpbox_target_field).tagName == "SELECT"){
			selectInsert($(ftpbox_target_field) , files[i], files[i]);
		}else{
			$(ftpbox_target_field).value = files[i];
			break;
		}
	}
}

var uploadbox_target_field = '';

function uploadbox_savefiles(files){
	for(i=0; i< files.length ; i++)
	{
	if(files[i] != null)
		if($(uploadbox_target_field).tagName == "SELECT"){
			selectInsert($(uploadbox_target_field) , files[i], files[i]);
		}else{
			$(uploadbox_target_field).value = files[i];
			break;
		}
	}
}


function $() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);
    if (arguments.length == 1)
      return element;
    elements.push(element);
  }
  return elements;
}

function confirm_delete_msg(msg , url){
var answer = confirm(msg);
if (answer) 
	location = url;
	
return false;
}

function confirm_delete(url)
{
var answer = confirm('Are you sure you want to delete?');
if (answer) 
	location = url;
	
return false;
}


function ask(a_message,a_url)
{
	var answer=prompt(a_message)
	if (answer !="")
 		{
			if(answer)
			{
			location = (a_url+answer);
			}
		}
		else
		{
			alert("Invalid entry !");
		}
}


function checkall(table , allcheckbox){
  uri_text = '';
    for (var i = 0; i < 1000; i++) {
	 if(!$(table + '_ids_' + i)) break;
     if(allcheckbox.checked)
         $(table + '_ids_' + i).checked = true;
     else
         $(table + '_ids_' + i).checked = false;
    }

  return false;
}

function deleteselected(table , nomsg){
  uri_text = '';
  firsti = true;
    for (var i = 0; i < 1000; i++) {
    if(!$(table + '_ids_' + i)) break;
    if($(table + '_ids_' + i).checked == true){
     separator = ',';
	 if(firsti) { firsti = false; separator = ''; }
	 uri_text  = uri_text  +  separator + $(table + '_ids_' + i).value;
	}
    }
  
  if(uri_text == ''){
   alert('Nothing was selected to delete !!');
   return false;
  }
  if(nomsg){ location = path + '/delete/' + uri_text; return false; }
  else return confirm_delete( path + '/delete/' + uri_text );
}


function editselected(table){
  uri_text = '';
  firsti = true;
    for (var i = 0; i < 1000; i++) {
    if(!$(table + '_ids_' + i)) break;
    if($(table + '_ids_' + i).checked == true){
     separator = ',';
	 if(firsti) { firsti = false; separator = ''; }
	 uri_text = uri_text  + separator +  $(table + '_ids_' + i).value ;
	}
    }
  
  if(uri_text == ''){
   alert('Nothing was selected to modify !!');
   return false;
  }
  
  location = path + '/edit/' + uri_text;
  return false;
}

function withselected(table , url){
  uri_text = '';
  firsti = true;
    for (var i = 0; i < 1000; i++) {
    if(!$(table + '_ids_' + i)) break;
    if($(table + '_ids_' + i).checked == true){
     separator = ',';
	 if(firsti) { firsti = false; separator = ''; }
	 uri_text = uri_text  + separator +  $(table + '_ids_' + i).value ;
	}
    }
  
  if(uri_text == ''){
   alert('You select nothing !!');
   return false;
  }
  
  location = path + '/' + url + '/' + uri_text;
  return false;
}


function public_url(url){
prompt('Preview link is', url );
return false;
}

function cancel_form(url , nomsg){
if(!nomsg)
var answer=confirm('You may did some modifications to the form, Are you sure to cancel?');
if(answer || nomsg) location = url;
return false;
}

function cancel_form2(url , nomsg){
if(!nomsg)
var answer=confirm('You may have made changes to this form. Are you sure you want to cancel?');
if(answer || nomsg) location = url;
return false;
}


function fieldAlert(myFields , myAlerts){
 	window.onload = function() {
		to_alert = "";
		for(i=0 ; i< myFields.length ; i++){
			if(document.getElementsByName(myFields[i]).item(0)){
				var newPara = document.createElement("div");
				newPara.className = 'input-error';
				newPara.innerHTML = myAlerts[i];
				var insertHere = document.getElementsByName(myFields[i]).item(0);
				insertHere.parentNode.appendChild(newPara);
				insertHere.style.border = '1px red solid';
			}else
				to_alert = to_alert + myAlerts[i] + "\n";
		}
		if(to_alert != "")
			alert(to_alert);
		
	}
}

// Example:

// alert( readCookie("myCookie") );

function readCookie(name)

{

  var cookieValue = "";

  var search = name + "=";

  if(document.cookie.length > 0)

  { 

    offset = document.cookie.indexOf(search);

    if (offset != -1)

    { 

      offset += search.length;

      end = document.cookie.indexOf(";", offset);

      if (end == -1) end = document.cookie.length;

      cookieValue = unescape(document.cookie.substring(offset, end))

    }

  }

  return cookieValue;

}


// Example:

// writeCookie("myCookie", "my name", 24);

// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.

function writeCookie(name, value, hours)

{

  var expire = "";

  if(hours != null)

  {

    expire = new Date((new Date()).getTime() + hours * 3600000);

    expire = "; expires=" + expire.toGMTString();

  }

  document.cookie = name + "=" + escape(value) + expire;

}


function hl_blinker(objID){
if(!$(objID)) return false;
var oldBg   = $(objID).style.background;  for(i=0; i<=6; i++) {   if (i%2 == 0)    clr = "#FFFFFF";   else  clr = "#FFFFCC";    timeOut = (250+(i*250));  setTimeout("$('"+objID+"').style.background='"+clr+
"'",timeOut);  }  setTimeout("$('"+objID+"').style.background='"+oldBg
+"'",(timeOut+100));   }


function hl_dimmer(objID){ 
if(!$(objID)) return false;
var arrTemp = 
["0","1","2","3","4","5","6","7", "8" ,"9","A","B","C","D","E","F"];
var oldBg   = $(objID).style.background;  var timeOut; for(i=0; i<arrTemp.length; i++) {  clr = "#FFFF"+arrTemp[i]+""+arrTemp[i];  timeOut = (i*80);  setTimeout("$('"+objID+"').style.background='"+clr+
"'",timeOut);  }  setTimeout("$('"+objID+"').style.background='"+oldBg
+"'",(timeOut+100)); }



// Set the horizontal and vertical position for the popup

PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 100;
defaultHeight = 100;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
function viewpic(imageURL){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Preview</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');
writeln('width=300-(document.body.clientWidth-document.images[0].width);');
writeln('height=300-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
writeln('function doTitle(){document.title="'+imageURL+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body style="padding:0px; margin:0px" bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
close();		
}
return false;
}



function disable(id){
	
var nodes;
	if($(id)){
		nodes = $(id).childNodes;
		 for(i in nodes)
		 {
		  if($(id).childNodes[i] && $(id).childNodes[i].nodeType==1){
			$(id).childNodes[i].disabled = true;
		  }
		 }
		$(id).disabled = true;	 
	}

}

function enable(id){
var nodes;
	if($(id)){
		nodes = $(id).childNodes;
		 for(i in nodes)
		 {
		  if($(id).childNodes[i] && $(id).childNodes[i].nodeType==1)
			$(id).childNodes[i].disabled = false;
		}
		$(id).disabled = false;		
	}
}

function switch_disable(checked, element){
	if(checked) disable(element);
	else		 enable(element);
}
function switch_enable(checked, element){
	if(checked) enable(element);
	else		 disable(element);
}


function display(id){
	if($(id)){
		$(id).style.visibility = 'visible';	 
		$(id).style.display    = 'block';	 
	}

}

function hide(id){
	if($(id)){
		$(id).style.visibility = 'hidden';	 
		$(id).style.display    = 'none';		
	}
}

function switch_display(checked, element){
	if(checked) display(element);
	else		 hide(element);
}

function switch_hide(checked, element){
	if(checked) hide(element);
	else		 display(element);
}


//specify whether contents should be auto copied to clipboard (memory)
//Applies only to IE 4+
//0=no, 1=yes
var copytoclip=1

function HighlightAll(tempval) {
tempval.focus();
tempval.select();
if (document.all&&copytoclip==1){
therange=tempval.createTextRange();
therange.execCommand("Copy");
}
}