/* **********************************************************************
 *
 *           Copyright (c) 2002 by MillionZillion Software, Inc.
 *                     All rights reserved.
 *
 * **********************************************************************
 *
 * $Workfile: common.js $
 * $Author: Grzegorz $ & Mateusz Karwowski $
 *
 * **********************************************************************/
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function getWindowScroll() {
  return "auto";
  /*  
  if (screen.width>1024 && screen.height>768) {
    return "no";
  } else {
    return "auto";
  } 
  */
}

function getWindowSize() {
  if (screen.width>1024 && screen.height>768) {
    if(BrowserDetect.browser=="Explorer") {
      return "fullscreen=1";
    } else {
      return "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=0,height="+screen.height+",width="+screen.width;
    }  
  } else{
    if(BrowserDetect.browser=="Explorer") {
      return "fullscreen=1";  
    } else {
      return "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=0,height="+screen.height+",width="+screen.width;  
    }  
  }  
  return "";
}

function submitTo(com){
  document.mainForm.command.value=com
  document.mainForm.submit()
}

function showImgFS(link, r){
  imgWin=window.open("/doc.ws","imgWin","fullscreen=1");
  size=" height="+screen.height;
  if(Number(r)>(screen.width/screen.height)) size=" width="+screen.width
  imgWin.document.write("<html><head><title>MILZIL System</title><script language='JavaScript' type='text/javascript'></script></head><body bgcolor='#000000' marginwidth=0 marginheight=0 topmargin=0 leftmargin=0 scroll='no'><table cellpadding='0' cellspacing='0' border='0' width='100%' height='100%'><tr><td width='100%' height='100%' align='center' valign='center'><a href='javascript:self.close()' alt='Close' title='Close'><img src="+link+size+" border='0'></img></a></td></tr></table></body></html>");
  imgWin.document.close();  
}

function showIR(no, us, peek, from){
//  if(screen.width>=1024 && screen.height>=768){
    irWindow = window.open("/doc.ws","InfoRecord", getWindowSize());  
    irWindow.document.write("<html><head><title>MILZIL System</title><frameset rows='*,0' border='0' framespacing='0' frameborder='no'><frame src='ir.ws?id="+no+"&us="+us+"&peek="+peek+"&from="+from+"' name='IRWindow' scrolling='"+getWindowScroll()+"' noresize><frame src='about:blank' name='empty' scrolling='no' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>") 
    irWindow.document.close();
    irWindow.focus();
//  } else {
//    window.location="index1.html";
//  }
}

function openProfile(){
//  if(screen.width>=1024 && screen.height>=768){
    document.mainForm.scroll.value = getWindowScroll();
    document.mainForm.action="http://www.milzil.com/profile_fs.ws";
//    document.mainForm.action="/profile_fs.ws";
    document.mainForm.target="ProfileWindow";
    
    window.open("", "ProfileWindow", getWindowSize());  
    var a = window.setTimeout("document.mainForm.submit();",500); 
//  } else {
//    window.location="/index1.html";
//  }
}   

function openMilZil(){
//   if(screen.width>=1024 && screen.height>=768){
    document.mainForm.scroll.value = getWindowScroll(); 
    document.mainForm.action="/milzil_fs.ws";
    document.mainForm.target="MilZilWindow";
    
    window.open("", "MilZilWindow", getWindowSize());  
    var a = window.setTimeout("document.mainForm.submit();",500); 

//  } else {
//    window.location="/index1.html";
//  }
}

function openConsole(){
//  if(screen.width>=1024 && screen.height>=768){
    sbtsWindow = window.open("/doc.ws","MILZIL", getWindowSize());  
    sbtsWindow.document.write("<html><title>MILZIL System</title><frameset rows='*,0' border='0' framespacing='0' frameborder='no'><frame src='milzil.ws?start=&mid=' name='STSMainWindow' scrolling='"+getWindowScroll()+"' noresize><frame src='about:blank' name='empty' scrolling='no' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
    sbtsWindow.document.close();
    sbtsWindow.focus();
//  } else {
//    window.location="index1.html";
//  }
}

function enableSystem(){
  if(document.mainForm.invCode.value=="") {
      alert("Enter Code");
      return;
  }
  document.mainForm.action = "http://www.backend.milzil.com/esfp";
  document.mainForm.command.value = "enable";
  document.mainForm.submit();
}

function showExtTrade(no,ss){
  newsWindow=window.open("/shextt?uid="+no+"&ss="+ss, "extTradeWindow", "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=800,height=600,left="+getPosX(800)+",top="+getPosY(600));
  newsWindow.focus();
}

function showAdvVideo(peek, path) {
  advwindow = window.open("/sadvv?peek="+peek+"&path="+path, "advwindow" , "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=400,height=550,left="+getPosX(400)+",top="+getPosY(550));
  advwindow.focus();
}

function openVbook(link) {
  if (screen.width>=1024 && screen.height>=960){	
    vbookwindow = window.open(link, "vbookwindow" , "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=990,height=900,left="+getPosX(990)+",top="+getPosY(900));
  } else {
    vbookwindow = window.open(link, "vbookwindow" , "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=1,width="+(screen.width > 1024 ? 1024 : screen.width)+",height="+screen.height);
  }  
  vbookwindow.focus();
}

function openVexpo(link){
  vexpoWin = window.open(link,"vexpoWin","toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,"+ ((BrowserDetect.browser=="Explorer") ? ("") : ("scrollbars=1,")) +"width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  vexpoWin.focus();
}

function showVideoLarge(path) {
  previewWin = window.open("/player.ws?path="+path,"previewWin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width=640,height=504,left="+getPosX(640)+",top="+getPosY(504));
  previewWin.focus();
}

function showVideoSmall(path) {
  previewWin = window.open("/player_s.ws?path="+path,"previewWin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,width=352,height=290,left="+getPosX(352)+",top="+getPosY(290));
  previewWin.focus();
}

function showImage(peek, width, height) {
  var winWidth = width + 20;
  var winHeight = height + 20;
  var scroll = 0;
  if(width > 1024) {
    winWidth = 1024;
    scroll = 1;
  }
  if(height > 768) {
    winHeight = 768;
    scroll = 1;
  }
  previewWin = window.open("","previewWin","toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,scrollbars="+scroll+",width="+winWidth+",height="+winHeight+",left="+getPosX(winWidth)+",top="+getPosY(winHeight));
  previewWin.document.write("<html><head><title>MILZIL System</title></head><body bgcolor='#395563' onLoad='self.focus()'><center><img src='http://www.milzil.com/gr?p="+peek+"' border='0' height='"+height+"' width='"+width+"'></center></body></html>");
  previewWin.document.close();
  previewWin.focus();
}

function showFlash(peek, width, height) {
  var winWidth = width + 20;
  var winHeight = height + 20;
  var scroll = 0;
  if(width > 1024) {
    winWidth = 1024;
    scroll = 1;
  }
  if(height > 768) {
    winHeight = 768;
    scroll = 1;
  }
  previewWin = window.open("/flash.ws?path=http://www.milzil.com/gr?p="+peek+"&width="+width+"&height="+height,"previewWin","toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,scrollbars="+scroll+",width="+winWidth+",height="+winHeight+",left="+getPosX(winWidth)+",top="+getPosY(winHeight));
  previewWin.focus();
}

function findIR() {
  with(document.mainForm) {
    if(notValidIRCode(code, "Enter correct Info-Record Code."))return;
    action = "/fir";
    submit();
    code = '';
  }
}

function getPosX(width) {
  return (screen.width - width) / 2;
}

function getPosY(height) {
  return (screen.height - height) / 2;
}

function openMail(link){
 mailWindow = window.open(link, "Notice", "status=1,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,height=700,width=624,left="+getPosX(700)+",top="+getPosY(624));
 mailWindow.focus();
}

function printIR(no, uid, session){
  printWindow = window.open("/doc.ws","PRINT","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  printWindow.document.write("<html><head><title>MILZIL System</title><script type='text/javascript' src='/common/print.js'></script></head><frameset id='fsID' rows='100%,0%' border='0' framespacing='0' frameborder='no' onLoad='updateFrameSet()'><frame src='/actions/print.html' name='Info-Record Publish'><frame src='/printir?id="+no+"&uid="+uid+"&sessionid="+session+"' name='Info-Record Publish' scrolling='auto' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
  printWindow.document.close();  
  printWindow.focus();
}

function printPR(no, uid, session){
  printWindow = window.open("/doc.ws","PRINT","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  printWindow.document.write("<html><head><title>MILZIL System</title><script type='text/javascript' src='/common/print.js'></script></head><frameset id='fsID' rows='100%,0%' border='0' framespacing='0' frameborder='no' onLoad='updateFrameSet()'><frame src='/actions/print.html' name='Profile Publish'><frame src='/printpr?id="+no+"&uid="+uid+"&sessionid="+session+"' name='Profile Publish' scrolling='auto' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
  printWindow.document.close();  
  printWindow.focus();
}

function printC(ss, ord, uid, session){
  printWindow = window.open("/doc.ws","PRINT","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  printWindow.document.write("<html><head><title>MILZIL System</title><script type='text/javascript' src='/common/print.js'></script></head><frameset id='fsID' rows='100%,0%' border='0' framespacing='0' frameborder='no' onLoad='updateFrameSet()'><frame src='/actions/print.html' name='Catalog Publish'><frame src='/printc?uid="+uid+"&sessionid="+session+"&ss="+ss+"&order="+ord+"' name='Catalog Publish' scrolling='auto' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
  printWindow.document.close();  
  printWindow.focus();
}

function printC2(no, ss, porttype, uid, session){
  printWindow = window.open("/doc.ws","PRINT","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  printWindow.document.write("<html><head><title>MILZIL System</title><script type='text/javascript' src='/common/print.js'></script></head><frameset id='fsID' rows='100%,0%' border='0' framespacing='0' frameborder='no' onLoad='updateFrameSet()'><frame src='/actions/print.html' name='S-Catalog Publish'><frame src='/printc2?id="+no+"&ss="+ss+"&porttype="+porttype+"&uid="+uid+"&sessionid="+session+"' name='S-Catalog Publish' scrolling='auto' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
  printWindow.document.close();  
  printWindow.focus();
}

function printG(ss, ord, gr, tot, uid, session){
  printWindow = window.open("/doc.ws", "PRINT","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  printWindow.document.write("<html><head><title>MILZIL System</title><script type='text/javascript' src='/common/print.js'></script></head><frameset id='fsID' rows='100%,0%' border='0' framespacing='0' frameborder='no' onLoad='updateFrameSet()'><frame src='/actions/print.html' name='S-Catalog Raisonne Publish'><frame src='/printg?uid="+uid+"&sessionid="+session+"&ss="+ss+"&order="+ord+"&group="+gr+"&total="+tot+"' name='S-Catalog Raisonne Publish' scrolling='auto' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
  printWindow.document.close();  
  printWindow.focus();
}

function printG2(no, ss, porttype, gr, tot, uid, session){
  printWindow = window.open("/doc.ws","PRINT","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  printWindow.document.write("<html><head><title>MILZIL System</title><script type='text/javascript' src='/common/print.js'></script></head><frameset id='fsID' rows='100%,0%' border='0' framespacing='0' frameborder='no' onLoad='updateFrameSet()'><frame src='/actions/print.html' name='S-Catalog Raisonne Publish'><frame src='/printg2?id="+no+"&ss="+ss+"&porttype="+porttype+"&group="+gr+"&total="+tot+"&uid="+uid+"&sessionid="+session+"' name='S-Catalog Raisonne Publish' scrolling='auto' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
  printWindow.document.close();  
  printWindow.focus();
}

function printAll(ss, porttype, uid, session){
  printWindow = window.open("/doc.ws","PRINT","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  printWindow.document.write("<html><head><title>MILZIL System</title><script type='text/javascript' src='/common/print.js'></script></head><frameset id='fsID' rows='100%,0%' border='0' framespacing='0' frameborder='no' onLoad='updateFrameSet()'><frame src='/actions/print.html' name='S-Catalog Raisonne Publish'><frame src='/printall?uid="+uid+"&sessionid="+session+"&ss="+ss+"&porttype="+porttype+"' name='S-Catalog Raisonne Publish' scrolling='auto' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
  printWindow.document.close();  
  printWindow.focus();
}

function printT(uid, session){
  printWindow = window.open("/doc.ws","PRINT","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  printWindow.document.write("<html><head><title>MILZIL System</title><script type='text/javascript' src='/common/print.js'></script></head><frameset id='fsID' rows='100%,0%' border='0' framespacing='0' frameborder='no' onLoad='updateFrameSet()'><frame src='/actions/print.html' name='Sales Ticket Publish'><frame src='/printt?uid="+uid+"&sessionid="+session+"' name='Sales Ticket Publish' scrolling='auto' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
  printWindow.document.close();  
  printWindow.focus();
}

function printT2(t, uid, session){
  printWindow = window.open("/doc.ws","PRINT","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  printWindow.document.write("<html><head><title>MILZIL System</title><script type='text/javascript' src='/common/print.js'></script></head><frameset id='fsID' rows='100%,0%' border='0' framespacing='0' frameborder='no' onLoad='updateFrameSet()'><frame src='/actions/print.html' name='Sales Ticket Publish'><frame src='/printt?uid="+uid+"&sessionid="+session+"&tid="+t+"' name='Sales Ticket Publish' scrolling='auto' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
  printWindow.document.close();  
  printWindow.focus();
}

function printInv(invid, uid, session){
  printWindow = window.open("/doc.ws","PRINT","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  printWindow.document.write("<html><head><title>MILZIL System</title><script type='text/javascript' src='/common/print.js'></script></head><frameset id='fsID' rows='100%,0%' border='0' framespacing='0' frameborder='no' onLoad='updateFrameSet()'><frame src='/actions/print.html' name='Invoice Publish'><frame src='/prinv?uid="+uid+"&sessionid="+session+"&invid="+invid+"' name='Invoice Publish' scrolling='auto' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
  printWindow.document.close();  
  printWindow.focus();
}

function printAcc(uid, session){
  printWindow = window.open("/doc.ws","PRINT","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  printWindow.document.write("<html><head><title>MILZIL System</title><script type='text/javascript' src='/common/print.js'></script></head><frameset id='fsID' rows='100%,0%' border='0' framespacing='0' frameborder='no' onLoad='updateFrameSet()'><frame src='/actions/print.html' name='Finance Account Publish'><frame src='/pracc?uid="+uid+"&sessionid="+session+"' name='Finance Account Publish' scrolling='auto' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
  printWindow.document.close();  
  printWindow.focus();
}

function printIRAcc(ss, order, uid, session){
  printWindow = window.open("/doc.ws","PRINT","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  printWindow.document.write("<html><head><title>MILZIL System</title><script type='text/javascript' src='/common/print.js'></script></head><frameset id='fsID' rows='100%,0%' border='0' framespacing='0' frameborder='no' onLoad='updateFrameSet()'><frame src='/actions/print.html' name='Info-Record Account Publish'><frame src='/priracc?uid="+uid+"&sessionid="+session+"&ss="+ss+"&order="+order+"' name='Info-Record Account Publish' scrolling='auto' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
  printWindow.document.close();  
  printWindow.focus();
}

function printBB(sort, uid, session){
  printWindow = window.open("/doc.ws","PRINT","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  printWindow.document.write("<html><head><title>MILZIL System</title><script type='text/javascript' src='/common/print.js'></script></head><frameset id='fsID' rows='100%,0%' border='0' framespacing='0' frameborder='no' onLoad='updateFrameSet()'><frame src='/actions/print.html' name='Blocked Buyers List Publish'><frame src='/printbb?uid="+uid+"&sessionid="+session+"&sort="+sort+"' name='Blocked Buyers List Publish' scrolling='auto' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
  printWindow.document.close();  
  printWindow.focus();
}

function printFM(sort, uid, session){
  printWindow = window.open("/doc.ws","PRINT","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  printWindow.document.write("<html><head><title>MILZIL System</title><script type='text/javascript' src='/common/print.js'></script></head><frameset id='fsID' rows='100%,0%' border='0' framespacing='0' frameborder='no' onLoad='updateFrameSet()'><frame src='/actions/print.html' name='Featured MILZILs Publish'><frame src='/printfm?uid="+uid+"&sessionid="+session+"&sort="+sort+"' name='Featured MILZILs Publish' scrolling='auto' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
  printWindow.document.close();
  printWindow.focus();
}

function printSA(sort, uid, session){
  printWindow = window.open("/doc.ws","PRINT","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  printWindow.document.write("<html><head><title>MILZIL System</title><script type='text/javascript' src='/common/print.js'></script></head><frameset id='fsID' rows='100%,0%' border='0' framespacing='0' frameborder='no' onLoad='updateFrameSet()'><frame src='/actions/print.html' name='Sales Affiliates List Publish'><frame src='/printsa?uid="+uid+"&sessionid="+session+"&sort="+sort+"' name='Sales Affiliates List Publish' scrolling='auto' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
  printWindow.document.close();  
  printWindow.focus();
}

function printSup(sort, uid, session){
  printWindow = window.open("/doc.ws","PRINT","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  printWindow.document.write("<html><head><title>MILZIL System</title><script type='text/javascript' src='/common/print.js'></script></head><frameset id='fsID' rows='100%,0%' border='0' framespacing='0' frameborder='no' onLoad='updateFrameSet()'><frame src='/actions/print.html' name='Suppliers List Publish'><frame src='/printsup?uid="+uid+"&sessionid="+session+"&sort="+sort+"' name='Suppliers List Publish' scrolling='auto' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
  printWindow.document.close();  
  printWindow.focus();
}

function printIRStat(id, uid, session){
  printWindow = window.open("/doc.ws","PRINT","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  printWindow.document.write("<html><head><title>MILZIL System</title><script type='text/javascript' src='/common/print.js'></script></head><frameset id='fsID' rows='100%,0%' border='0' framespacing='0' frameborder='no' onLoad='updateFrameSet()'><frame src='/actions/print.html' name='Info-Record Statistics'><frame src='/printirstat?uid="+uid+"&sessionid="+session+"&id="+id+"' name='Info-Record Statistics' scrolling='auto' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
  printWindow.document.close();  
  printWindow.focus();
}

function printStat(uid, session){
  printWindow = window.open("/doc.ws","PRINT","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
  printWindow.document.write("<html><head><title>MILZIL System</title><script type='text/javascript' src='/common/print.js'></script></head><frameset id='fsID' rows='100%,0%' border='0' framespacing='0' frameborder='no' onLoad='updateFrameSet()'><frame src='/actions/print.html' name='V-Site Statistics'><frame src='/printstat?uid="+uid+"&sessionid="+session+"' name='V-Site Statistics' scrolling='auto' noresize></frameset><noframes><body bgcolor='#ffffff'>Browser not supported!</body></noframes></html>");
  printWindow.document.close();  
  printWindow.focus();
}

function startRegistration() {
  if(document.forms[0].invCode.value == '') {
    if(!confirm("WARNING\n\nThis registration is only for users that setup Private Hybrid Commerce Center for the first time.\n\nIf you already have your Center and you want to edit it, logon to your Hybrid Commerce Center and use the EDIT V-SITE service.\n\nDo you want to continue?")) return
  }
  document.forms[0].action = "http://www.setup.milzil.com/startreg";
  document.forms[0].target = "_blank";
  document.forms[0].submit();
  document.forms[0].invCode.value = '';
}

function continueRegistration() {
  document.forms[0].action = "http://www.setup.milzil.com/register?command=member_reg_edit_new";
  document.forms[0].target = "_blank";
  document.forms[0].submit();
  document.forms[0].invCode.value = '';
}

function showVsiteNews(c, uid, pos, type){
  newsWindow=window.open("/svsn?c="+c+"&m="+uid+"&p="+pos+"&t="+type, "newsWindow", "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=800,height=600");
  newsWindow.focus();
}

function uploadFile(){
  with(document.uploadForm){
    if(notValid(password,"Enter Edit Permission Code to edit the file."))return;
    if(notValid(vcFileName,"Select a file to be uploaded."))return;
    if(notValidDocument(vcFileName,"Incorrect file format.\nSubmit a proper file that must be of the:\nJPG, PNG, GIF, TIF, PCT, MP3, WMA, WAV, MOV, MPG,\nWMV, ASF, AVI, ZIP, PDF, DOC, PPT, XLS or TXT format."))return;
    wait.style.visibility="visible";
    upload.disabled=true;
    submit();
  }
}

function downloadFile(){
  with(document.mainForm){
    if(notValid(password,"Enter Read Permission Code to download the file."))return;
      submit();
    }
}

function notValidDocument(){
  notValidDocumentArgs = notValidDocument.arguments
  ext=notValidDocumentArgs[0].value.substring(notValidDocumentArgs[0].value.lastIndexOf(".")+1,notValidDocumentArgs[0].value.length).toUpperCase()
  if((ext=="JPEG")||(ext=="JPG")||(ext=="JPE")||(ext=="PNG")||(ext=="GIF")||(ext=="TIF")||(ext=="TIFF")||
     (ext=="PCT")||(ext=="PIC")||(ext=="PICT")||(ext=="MP3")||(ext=="WMA")||(ext=="WAV")||(ext=="MOV")||
     (ext=="MPG")||(ext=="MPEG")||(ext=="MPE")||(ext=="WMV")||(ext=="ASF")||(ext=="AVI")||(ext=="ZIP")||
     (ext=="PDF")||(ext=="DOC")||(ext=="PPT")||(ext=="XLS")||(ext=="TXT"))return false
  if(notValidDocumentArgs[1]){
    alert(notValidDocumentArgs[1])
    notValidDocumentArgs[0].focus()
  }
  return true;
}

function rollOn(imgObj, imgSrc){
  document.images[imgObj].src = imgSrc
}

function noise(){
  noiseDate = new Date();
  return noiseDate.getTime();
}

function ntg(){}

function swc(com){
  openPopUpWin(com)
}

function ssc(com){
  with(document.forms[0]){
    action = com
    submit() 
  }
}  

function spc(com){
  with(document.forms[0]){
    action = com
    target = "ICPParentWindow"
    submit() 
    close()
  }
}  

function openPopUpWin(){
  PopUpWinArgs = openPopUpWin.arguments
  if(PopUpWinArgs[0]) docName = PopUpWinArgs[0]; else docName = "/static/blank.ws"
  if(PopUpWinArgs[1]) winScrollbars = PopUpWinArgs[1]; else winScrollbars = 1
  if(PopUpWinArgs[2]) winWidth = PopUpWinArgs[2]; else winWidth = 550
  if(PopUpWinArgs[3]) winHeight = PopUpWinArgs[3]; else winHeight = 400
  if(PopUpWinArgs[4]) winStatus = PopUpWinArgs[4]; else winStatus = 1
  if(PopUpWinArgs[5]) winResizable = PopUpWinArgs[5]; else winResizable = 0
  if(PopUpWinArgs[6]) winName = PopUpWinArgs[6]; else winName = "PopUpWin"

  PopUpWinProp="toolbar=0,location=0,directories=0,status="+winStatus+",menubar=0,scrollbars="+winScrollbars+",resizable="+winResizable+",width="+winWidth+",height="+winHeight+",left=0,top=0,screenX=0,screenY=0";
  PopUpWin=window.open(docName,winName,PopUpWinProp);
  PopUpWin.focus();
}

function openMenuWin(docName,w,h,scrollbars,e,MenuWinName){
  var posx = 0; var posy = 0;
  if(e){
    posx = e.screenX
    posy = e.screenY
  }
  if((posy+h+55) > screen.height) posy-=(h+25)
  if((posx+w) > screen.width) posx-=(w+5)

  MenuWinProp="toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars="+scrollbars+",resizable=0,left="+posx+",top="+posy+",screenX="+posx+",screenY="+posy+",width="+w+",height="+h
  MenuWin=window.open(docName,MenuWinName,MenuWinProp)
  MenuWin.focus();
}  

function showSnap(imgname,w,h,title){
  maxHeight = 650
  defHeight = 650
  prefs="toolbar=0,location=0,directories=0,status=0,menubar=0,left=0,top=0,screenX=0,screenY=0,resizable=0,scrollbars="
  if(h > maxHeight){prefs += "1,width="+(w+16+20)+",height="+defHeight+25}else{prefs += "0,width="+(w+20)+",height="+(h+25)}
  snapWin=window.open("","snapWin",prefs);
  snapWin.document.write("<html><title>"+title+"</title><body bgcolor='#ffffff' onBlur='self.close()' onLoad='self.focus()' marginwidth=10 marginheight=12 topmargin=12 leftmargin=10><div><img src="+imgname+" border=0 height="+h+" width="+w+" alt='"+title+"'></div></body></html>");
  snapWin.document.close();
}

function openPrintWin(docName){
  printWindow=window.open(docName,"printWindow","toolbar=1,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,width=775,height=600");
}

function howManyChecked(checkboxgroup){
  checkedCount = 0
  if(checkboxgroup.length){
    for(i=0;i<checkboxgroup.length;i++)
      if(checkboxgroup[i].checked) checkedCount++;
  } else {
    if(checkboxgroup.checked) checkedCount++;
  }
  return checkedCount;
}

function isAnyChecked(checkboxgroup){
  if(checkboxgroup.length){
    for(i=0;i<checkboxgroup.length;i++)
      if(checkboxgroup[i].checked) return true;
  } else {
    if(checkboxgroup.checked) return true;
  }
  return false;
}

function isMoreChecked(checkboxgroup){
  if(checkboxgroup.length){
    more=false
    for(i=0;i<checkboxgroup.length;i++)
      if(checkboxgroup[i].checked)
        if(more) return true; else more=true
  }
  return false;
}

function revSelection(checkboxgroup){
  if(checkboxgroup.length){
    for(i=0;i<checkboxgroup.length;i++){
      if(checkboxgroup[i].checked) checkboxgroup[i].checked = false; else checkboxgroup[i].checked = true
    }
  } else {
    if(checkboxgroup.checked) checkboxgroup.checked = false; else checkboxgroup.checked = true
  }  
}

function selectGroup(checkboxgroup,newval){
  if(checkboxgroup.length){
    for(i=0;i<checkboxgroup.length;i++){
      checkboxgroup[i].checked = newval
    }
  } else {
    checkboxgroup.checked = newval
  }  
}


function valHour(hour){
  if(hour == "") return false
  if(hour.indexOf(":")==-1)return false
  if(hour.indexOf(":")!=hour.lastIndexOf(":"))return false
  h = hour.substring(0,hour.indexOf(":"))
  m = hour.substring(hour.indexOf(":")+1,hour.length)
  if(h.length>2 || m.length>2) return false
  if(!(valNo(m) && valNo(h))) return false
  if(h<0 || h>23) return false
  if(m<0 || m>59) return false
  return true
}

function valNo(No){
  if(No == "") return true
  for (i = 0;i < No.length;i++)
    if ((No.charAt(i) < "0") || (No.charAt(i) > "9")) return false
  return true
}

function valNoMinus(No){
  if(No == "") return false
  if( ((No.charAt(0) < "0") || (No.charAt(0) > "9")) && (No.charAt(0) != "-")) return false
  for (i = 1;i < No.length;i++)
    if ((No.charAt(i) < "0") || (No.charAt(i) > "9")) return false
  return true
}

function valYear(year){
  alert(year)
  if(!valNo(year)) return false
  if (year < 1000) return false
  return true
}

function valAge(age){
  if(age == "") return true
  if(!valNo(age)) return false
  if (age < 0) return false
  return true
}

function valDate(date,format){
  if(date == "") return true
  if(date.indexOf("/") == date.lastIndexOf("/")) return false
  if(format=="pl"){
    day = date.substring(0,date.indexOf("/"))
    month = date.substring(date.indexOf("/")+1,date.lastIndexOf("/"))
  }else{
    month = date.substring(0,date.indexOf("/"))
    day = date.substring(date.indexOf("/")+1,date.lastIndexOf("/"))
  }
  year = date.substring(date.lastIndexOf("/")+1,date.length)
  if( !( (valNo(month)) && (valNo(day)) && (valNo(year)) ) ) return false

  if ((day < 1) || (day > 31)) return false
  if (year < 1900) return false
  if ((month < 1) || (month > 12)) return false

  if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
    leap = true
  else leap = false

  if (((day > 31) && (month == 1)) ||
      ((day > 28) && (month == 2) && (!leap)) ||
      ((day > 29) && (month == 2) && (leap)) ||
      ((day > 31) && (month == 3)) ||
      ((day > 30) && (month == 4)) ||
      ((day > 31) && (month == 5)) ||
      ((day > 30) && (month == 6)) ||
      ((day > 31) && (month == 7)) ||
      ((day > 31) && (month == 8)) ||
      ((day > 30) && (month == 9)) ||
      ((day > 31) && (month == 10)) ||
      ((day > 30) && (month == 11)) ||
      ((day > 31) && (month == 12)))
  return false

  return true
}

function formatPhone(field){
  if(field.value == "") return
  if(field.value == "          ") return
  while(field.value.length < 10)
    field.value = " " + field.value
  field.value = "(" +  field.value.substring(0,3) + ") " + field.value.substring(3,6) + "-" + field.value.substring(6,10)
}

function unformatPhone(field){
  if(field.value == "") return
  if(field.value == "          ") return
  field.value = field.value.substring(1,4) + field.value.substring(6,9) + field.value.substring(10,14)
  field.value = field.value.substring(field.value.lastIndexOf(" ")+1,field.value.length)
}

function onlyDigits(field){
  return
  fieldTMP = ""
  for(i=0;i<field.value.length;i++){
    charTMP = field.value.charAt(i)
    if((charTMP >= "0") && (charTMP <= "9"))
      fieldTMP = fieldTMP + charTMP
  }    
  field.value = fieldTMP
}


function checkMail(mail){
/* Available Mail Host Domains
domains = new Array ("ad","ae","af","ag","ai","al","am","an","ao","aq","ar","arpa","as","at","au","aw","az","ba","bb","bd","be","bf","bg","bh","bi","bj","bm","bn","bo","br","bs","bt",
  "bv","bw","by","bz","ca","cc","cf","cd","cg","ch","ci","ck","cl","cm","cn","co","com","cr","cs","cu","cv","cx","cy","cz","de","dj","dk","dm","do","dz","ec","edu",
  "ee","eg","eh","er","es","et","fi","fj","fk","fm","fo","fr","fx","ga","gb","gd","ge","gf","gh","gi","gl","gm","gn","gov","gp","gq","gr","gs","gt","gu","gw","gy",
  "hk","hm","hn","hr","ht","hu","id","ie","il","in","int","io","iq","ir","is","it","jm","jo","jp","ke","kg","kh","ki","km","kn","kp","kr","kw","ky","kz","la","lb",
  "lc","li","lk","lr","ls","lt","lu","lv","ly","ma","mc","md","mg","mh","mil","mk","ml","mm","mn","mo","mp","mq","mr","ms","mt","mu","mv","mw","mx","my","mz","na",
  "nato","nc","ne","net","nf","ng","ni","nl","no","np","nr","nt","nu","nz","om","org","pa","pe","pf","pg","ph","pk","pl","pm","pn","pr","pt","pw","py","qa","re",
  "ro","ru","rw","sa","sb","sc","sd","se","sg","sh","si","sj","sk","sl","sm","sn","so","sr","st","su","sv","sy","sz","tc","td","tf","tg","th","tj","tk","tm","tn",
  "to","tp","tr","tt","tv","tw","tz","ua","ug","uk","um","us","uy","uz","va","vc","ve","vg","vi","vn","vu","wf","ws","ye","yt","yu","za","zm","zr","zw");
*/

  if(mail == "") return true
  if(mail.charAt(mail.length-1) == ".") mail=mail.substr(0,mail.length-1)
  if(mail.length < 6) return false
  if(mail.indexOf("@") == -1) return false

  mailHost = mail.substring(mail.indexOf("@")+1,mail.length) 
  if(mailHost.indexOf(".") == -1) return false

/* Checking Mail Host Domains
  mailHostDomain = mailHost.substring(mailHost.lastIndexOf(".")+1,mailHost.length)
  mailHostDomain = mailHostDomain.toLowerCase()
  for(i=0;i<=domains.length;i++)
    if(mailHostDomain == domains[i]) return true;
  return false
*/  

  return true;
}


function isAmount(what,decmaxlength){
  for (i=0;i<what.length;i++)
    if (!( ((what.charAt(i) >= "0") && (what.charAt(i) <= "9")) || (what.charAt(i) == "$") || (what.charAt(i) == ",") || (what.charAt(i) == "."))) return false
  if(what.indexOf("$") != what.lastIndexOf("$")) return false
  if(what.indexOf("$") > 0) return false
  if(what.indexOf(".") != what.lastIndexOf(".")) return false
  if(what.indexOf(".") == -1){
    loopStart = what.length-1
    decValue = ""
  } else {
    loopStart = what.indexOf(".")-1
    decValue = what.substring(what.indexOf(".")+1,what.length)
  }  
  if(decValue.indexOf(",") != -1) return false
  if(decValue.length > decmaxlength) return false
  commaCount = 0
  for (i=loopStart;i>=0;i--){
    if(commaCount != 3)
      if(what.charAt(i) == ",") return false; else commaCount++ 
    else {
      commaCount = 0
      if(what.charAt(i) != ",") commaCount++
    }  
  }
  return true
}

function parseAmount(what){
  if(what.value.charAt(0) == "$") what.value = what.value.substring(1,what.value.length)
  while(what.value.indexOf(",") > -1){
    what.value =  what.value.substring(0,what.value.indexOf(",")) + what.value.substring(what.value.indexOf(",")+1,what.value.length)
  }
  if(what.value == ".") what.value = "" 
//  if(what.value != "")
//    what.value = Math.round(parseFloat(what.value))
}

function notValid(){
  notValidArgs = notValid.arguments
  if(notValidArgs[0].type == "select-one"){if(notValidArgs[0].selectedIndex != 0) return false}
  if(notValidArgs[0].type == "select-multiple"){ if(notValidArgs[0].selectedIndex != -1) return false}
  if((notValidArgs[0].type == "text") || (notValidArgs[0].type == "hidden") || (notValidArgs[0].type == "password") || (notValidArgs[0].type == "file") || (notValidArgs[0].type == "textarea")){if(notValidArgs[0].value != "") return false}
  if(notValidArgs[1]){
    alert(notValidArgs[1])
    notValidArgs[0].focus()
  }  
  return true;
}

function notValidImage(){
  notValidImageArgs = notValidImage.arguments
  ext=notValidImageArgs[0].value.substring(notValidImageArgs[0].value.lastIndexOf(".")+1,notValidImageArgs[0].value.length).toUpperCase()
  if(ext=="JPEG" || ext=="JPG" || ext=="JPE")return false
  if(notValidImageArgs[1]){
    alert(notValidImageArgs[1])
    notValidImageArgs[0].focus()
  }  
  return true;
}

function notValidMovie(){
  notValidMovieArgs = notValidMovie.arguments
  ext=notValidMovieArgs[0].value.substring(notValidMovieArgs[0].value.lastIndexOf(".")+1,notValidMovieArgs[0].value.length).toUpperCase()
  if(ext=="FLV")return false
  if(notValidMovieArgs[1]){
    alert(notValidMovieArgs[1])
    notValidMovieArgs[0].focus()
  }  
  return true;
}


function notValidDesc(){//object,err msg,max length,mandatory
  notValidDescArgs = notValidDesc.arguments
  if(notValidDescArgs[3] == 1){
    if((notValidDescArgs[0].value.length <= notValidDescArgs[2]) && (notValidDescArgs[0].value != "")) return false
  }else{
    if(notValidDescArgs[0].value.length <= notValidDescArgs[2]) return false
  }  
  alert(notValidDescArgs[1])
  notValidDescArgs[0].focus()
  return true;
}


function notValidKeywords(){
  notValidKeywordsArgs = notValidKeywords.arguments
  keyWords = notValidKeywordsArgs[0].value.replace(",",";").split(";")
  for(i=0; i<keyWords.length; i++) {
    if(keyWords[i].length > notValidKeywordsArgs[2]) {
      alert(notValidKeywordsArgs[1])
      return true
    }
  }
  return false;
}


function notValidMail(){
  notValidMailArgs = notValidMail.arguments
  if(notValidMailArgs[1]) errMsg = notValidMailArgs[1]; else errMsg = "Enter correct e-mail address"
  if(notValidMailArgs[2]){
    if(notValidMailArgs[2] == 1) madatory = true; else madatory = false
  }else madatory = false
  if(madatory && (notValidMailArgs[0].value != "") && checkMail(notValidMailArgs[0].value)) return false
  if(!madatory && checkMail(notValidMailArgs[0].value)) return false
  alert(errMsg)
  notValidMailArgs[0].focus()
  return true;
}

function notValidDate(){//object, err message, mandatory, format
  notValidDateArgs = notValidDate.arguments
  if(notValidDateArgs[3]) if(notValidDateArgs[3]==0) langFormat="pl";else langFormat="en";else langFormat="en";
  if(notValidDateArgs[2]){
    if(notValidDateArgs[2] == 1) madatory = true; else madatory = false
  }else madatory = false
  if(notValidDateArgs[1]) errMsg = notValidDateArgs[1]; else errMsg = "Enter correct date"
  if(!madatory && notValidDateArgs[0].value == "") return false
  if(notValidDateArgs[0].value != ""){
    if(valDate(notValidDateArgs[0].value,langFormat)) return false
  }  
  alert(errMsg)
  notValidDateArgs[0].focus()
  return true;
}

function notValidDec(){ //object, error message, is madatory, max decimal length, max value
//jezeli nie ma maxa, to max = 10 000 000
  notValidDecArgs = notValidDec.arguments
  if(notValidDecArgs[3] || notValidDecArgs[3]==0) maxDecLength = notValidDecArgs[3]; else maxDecLength = 2
  if(notValidDecArgs[1]) errMsg = notValidDecArgs[1]; else errMsg = "Enter correct amount"
  if(notValidDecArgs[2]){
    if(notValidDecArgs[2] == 1) madatory = true; else madatory = false
  }else madatory = false
  if(!madatory && (notValidDecArgs[0].value == "")) return false
  if(notValidDecArgs[0].value=="")notValidDecArgs[0].value=0

  if(notValidDecArgs[4]) maxValue = notValidDecArgs[4]; else maxValue = 999999999
  if(isAmount(notValidDecArgs[0].value,maxDecLength)){
    parseAmount(notValidDecArgs[0])
    if(!madatory){
      if(notValidDecArgs[0].value < maxValue) return false
    }else{
      if((notValidDecArgs[0].value < maxValue) && (notValidDecArgs[0].value >= 0)) return false
    }  
  }  
  alert(errMsg)
  notValidDecArgs[0].focus()

  return true;
}

function notValidIRCode(){
  notValidIRCodeArgs = notValidIRCode.arguments
  if(notValidIRCodeArgs[1]) errMsg = notValidIRCodeArgs[1]; else errMsg = "Enter correct Info-Record Code.";
  if(notValidIRCodeArgs[0].value.length==12 && valNo(notValidIRCodeArgs[0].value.substring(6,12))) return false;
  alert(errMsg);
  notValidIRCodeArgs[0].focus();
  return true;
}


function notValidInc(){ //object, error message, is madatory, min value, max value,
  notValidIncArgs = notValidInc.arguments
  if(notValidIncArgs[1]) errMsg = notValidIncArgs[1]; else errMsg = "Enter correct value"
  if(notValidIncArgs[2]){
    if(notValidIncArgs[2] == 1) madatory = true; else madatory = false
  }else madatory = false
  if(!madatory && (notValidIncArgs[0].value == "")) return false
  if(notValidIncArgs[0].value=="")notValidIncArgs[0].value=0
  
  if(notValidIncArgs[3] || notValidIncArgs[3]==0) minValue = notValidIncArgs[3]; else minValue = -99999999999999999
  if(notValidIncArgs[4]) maxValue = notValidIncArgs[4]; else maxValue = 99999999999999999
  if(valNoMinus(notValidIncArgs[0].value)){
    if((notValidIncArgs[0].value < maxValue) && (notValidIncArgs[0].value >= minValue)) return false
  }  

  alert(errMsg)
  notValidIncArgs[0].focus()

  return true;
}

function notValidYear(){ //object, error message, is madatory, max year
  notValidYearArgs = notValidYear.arguments
  if(notValidYearArgs[1]) errMsg = notValidYearArgs[1]; else errMsg = "Enter correct year"
  if(notValidYearArgs[2]){
    if(notValidYearArgs[2] == 1) madatory = true; else madatory = false
  }else madatory = false
  if(notValidYearArgs[3]) maxYear = notValidYearArgs[3]; else maxYear = 9999
  if(maxYear=="today"){
    d = new Date()
    y = d.getFullYear()  
    maxYear=y
  }

  if(!madatory && notValidYearArgs[0].value == ""){
    return false
  }else{
    if(valNoMinus(notValidYearArgs[0].value)){
      if((notValidYearArgs[0].value >= -9999) && (notValidYearArgs[0].value <= maxYear)) {
        return false
      }
    }
  }

  alert(errMsg)
  notValidYearArgs[0].focus()
  return true;
}
  

function notValidHour(){ //object, error message, is madatory
  notValidHourArgs = notValidHour.arguments
  if(notValidHourArgs[1]) errMsg = notValidHourArgs[1]; else errMsg = "Enter correct hour"
  if(notValidHourArgs[2]){
    if(notValidHourArgs[2] == 1) madatory = true; else madatory = false
  }else madatory = false

  if(!madatory && notValidHourArgs[0].value == ""){
    return false
  }else{
    if(valHour(notValidHourArgs[0].value)) return false
  }

  alert(errMsg)
  notValidHourArgs[0].focus()
  return true;
}

function notValidZip(){
  notValidZipArgs = notValidZip.arguments
  if(notValidZipArgs[0].value == "") return false
  if((notValidZipArgs[0].value.length == 5) &&(valNo(notValidZipArgs[0].value))) return false
  alert("Enter correct Zip Code")
  notValidZipArgs[0].focus()
  return true;
}

function selectDateFrame(selectName,fieldName){
  fromField = eval("document."+fieldName+"From")
  toField = eval("document."+fieldName+"To")
  if(selectName.selectedIndex == 0){fromField.value = ""; toField.value = ""; return}
  if(selectName.selectedIndex != 8){
    fromField.value= selectName.options[selectName.selectedIndex].value.substring(0,10)
    toField.value= selectName.options[selectName.selectedIndex].value.substring(11,22)
  }else{
    fromField.value=""
    toField.value=""
    fromField.focus()
  }
}
  
function setCustomFrame(fieldName){
  eval("document."+fieldName+"Frame.selectedIndex = 8")
}  

function deselectLast(where){ if(where.options[where.options.length-1].selected) where.options[where.options.length-1].selected = false }
function deselectLastSingle(where){ if(where.selectedIndex==where.options.length-1)where.selectedIndex--;}

// Replaces all instances of the given substring.
String.prototype.replaceAll = function(strTarget, strSubString){
  var strText = this;
  var intIndexOfMatch = strText.indexOf( strTarget );
  while (intIndexOfMatch != -1){
    strText = strText.replace( strTarget, strSubString )
    intIndexOfMatch = strText.indexOf( strTarget );
  }
  return( strText );
}



///////////////////////////////////// AJAX functions ////////////////////////////////////


var xmlHttp;// global instance of XMLHttpRequest

function createXmlHttpRequest() {
    if(window.ActiveXObject) {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

    } else if(window.XMLHttpRequest) {
        xmlHttp=new XMLHttpRequest();
    }
}

// function to build POST requests
function buildPOST(formID) {
    theForm = document.forms[formID];
    var qs = ''
    for (e=0;e<theForm.elements.length;e++) {
        if (theForm.elements[e].name!='') {
            var name = theForm.elements[e].name;
            qs+=(qs=='')?'':'&'
            qs+= name+'='+encodeURIComponent(theForm.elements[e].value);
        }
    }
    //qs+="\n";
    return qs
}


//finding knowledge packs on www.find.milzil.com

function hStateChangeFindRes() {    //response handling
    if(xmlHttp.readyState==4) {
        if(xmlHttp.status==200) {

            if(xmlHttp.responseText.indexOf("&error=0&vcSecretID=")>=0) {
               //IR found
               result =  xmlHttp.responseText.substring(xmlHttp.responseText.indexOf("&error=0&vcSecretID=")+20,
                                                        xmlHttp.responseText.indexOf("&SS"));
               showIR(result,'','','milzil');

               document.mainForm.code.value = "";
               document.mainForm.peek.value = "";

            } else if(xmlHttp.responseText.indexOf("&error=0")>=0){
                //resource found
                if(document.mainForm.peek.value.substr(0,1) == 'P') {
                    //image
                    width = xmlHttp.responseText.substring(xmlHttp.responseText.indexOf("&iWidth=")+8,
                                                           xmlHttp.responseText.indexOf("&iHeight"));
                    height = xmlHttp.responseText.substring(xmlHttp.responseText.indexOf("&iHeight=")+9,
                                                            xmlHttp.responseText.indexOf("&ok=1"));

                    showImage(document.mainForm.peek.value, parseInt(width), parseInt(height));

                } else if((document.mainForm.peek.value.substr(0,1) == 'T') ||
                          (document.mainForm.peek.value.substr(0,1) == 'Z') ||
                          (document.mainForm.peek.value.substr(0,1) == 'A')) {
                    //document, zip, audio
                    resultWindow = window.open("/gr?p="+document.mainForm.peek.value, "Knowledge Pack","status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=1024,height=768,left="+getPosX(1024)+",top="+getPosY(768));
                    resultWindow.focus();

                } else if(document.mainForm.peek.value.substr(0,1) == "V") {
                    //video
                    showVideoLarge("http://www.milzil.com/gr?p="+document.mainForm.peek.value);

                } else if(document.mainForm.peek.value.substr(0,1) == 'F') {
                    //flash SWF
                    width = xmlHttp.responseText.substring(xmlHttp.responseText.indexOf("&iWidth=")+8,
                                                           xmlHttp.responseText.indexOf("&iHeight"));
                    height = xmlHttp.responseText.substring(xmlHttp.responseText.indexOf("&iHeight=")+9,
                                                            xmlHttp.responseText.indexOf("&ok=1"));

                    showFlash(document.mainForm.peek.value, parseInt(width), parseInt(height));

		} else if((document.mainForm.peek.value.substr(0,1) == "D") ||
 			  (document.mainForm.peek.value.substr(0,1) == "B")) {
                    //v-book, v-doc
                    openVbook("http://www.milzil.com/gr?p="+document.mainForm.peek.value);
				
		} else if(document.mainForm.peek.value.substr(0,1) == "E") {
                    //v-expo
                    openVexpo("http://www.milzil.com/gr?p="+document.mainForm.peek.value);
		}

                document.mainForm.code.value = "";
                document.mainForm.peek.value = "";

            } else if(xmlHttp.responseText.indexOf("&ir=1")>=0){
                //when finding IR
                alert("Requested Info-Record does not exist or is hidden.");
            } else {
                //when finding resource other than IR
                alert("Requested Knowledge Pack does not exist or is hidden.");
            }
        } else {
            alert("System Internal Error.\nPlease contact MILZIL System Treasurer for more details.");
        }
    }
}

function sendPostFindRes(formID, type) { //communication with remote script
    var xmlMessage = null;
    if(type==1) {
      if(notValidIRCode(document.mainForm.code, "Enter correct Info-Record Code."))return;
      createXmlHttpRequest();
      xmlMessage = buildPOST(formID);
      xmlHttp.open("POST", "/fir", true);
    } else {
      createXmlHttpRequest();
      xmlMessage = buildPOST(formID);
      xmlHttp.open("POST", "/fr", true);
    }
    // for ie compatability
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.onreadystatechange=hStateChangeFindRes;
    xmlHttp.send(xmlMessage);
}

