/////////////////////////////////////////////////////////////////////////////
//  Common Java Script Functions
//////////////////////////////////////////////////////////////////////////////
//		
//	Created by:		Dmitry Shats
//	Created Date:	Dec 29, 2003
//	Edited by:		Dmitry Shats
//	Edited Date:	Feb 24, 2004
//		
////////////////////////////////////////////////////////////////////////////	
//
//	-------------------------------------------------------------------------------------------------------------------------
//	|	DATE	|				Function				| 							DESCRIPTION								|
//	-------------------------------------------------------------------------------------------------------------------------
//	| 12/29/03	| documenT_print()						|	Call Print Dialog Box											|
//	|-----------|---------------------------------------|-------------------------------------------------------------------|
//	| 12/29/03	| form_submit() 						|	Submit current form												|
//	|-----------|---------------------------------------|-------------------------------------------------------------------|
//	| 12/29/03	| form_reset()							|	Reset current form												|																				|
//	|-----------|---------------------------------------|-------------------------------------------------------------------|
//	| 12/29/03	| newwin(url,w,h,scrl)					|	Open new window with:											|
//	| 			| 										|		URL 		- 	Location									|
//	| 			| 										|		W			- 	Width										|
//	| 			| 										|		H			- 	Heigh										|
//	| 			| 										|		scrl		- 	Scroo										|
//	| 			| 										|	newwin("http://www.msn.com",640,480,"yes");						|
//	|-----------|---------------------------------------|-------------------------------------------------------------------|
//	| 12/29/03	| newimagewin(image,w,h,title)			|	Open an image in new window										|
//	| 			| 										|		IMAGE 		- 	Location									|
//	| 			| 										|		W			- 	Width										|
//	| 			| 										|		H			- 	Height										|
//	| 			| 										|		TITLE		- 	Image Title									|
//	| 			| 										|	newimagewin("images\top.jpg",640,480,"My Project : Title");		|
//	|-----------|---------------------------------------|-------------------------------------------------------------------|
//	| 01/08/04	| validate (obj,type,objtitle,req,		|   Validate form and write error message in a division and 		|
//	| 			| ErrMsg)								|	give the result for an alert box								|
//	| 			| 										|		OBJ			- 	Object ID									|
//	| 			| 										|		TYPE		- 	Object Type									|
//	| 			| 										|		OBJTITLE	- 	Object Title for Alert Message(box)			|
//	| 			| 										|		REQ			-	Object Required (Y/N)						|
//	| 			| 										|		ERRMSG		- 	Error Message. If not exist the default		|
//	| 			| 										|						message will appear							|
//	| 			| 										|	TYPE:															|
//	| 			| 										|		'email'		- 	E-Mail										|
//	| 			| 										|		'phone'		- 	Phone Number								|
//	| 			| 										|		'password'	-	Password: must be at least 8 characters 	|
//	| 			| 										|						long and start and end with a letter		|
//	| 			| 										|		'any'		-	Must be not be emty value					|
//	| 			| 										|	validate(this,'email','E-Mail','y','Wrong E-Mail');		|
//	| 			| 										|	RETURN ErrorMessage as 'alert(ErrorMessage)';					|
//	|-----------|---------------------------------------|-------------------------------------------------------------------|
//	| 02/24/04	| onKeyDown="javascript:return dFilter 	| Input Mask																	|
//	| 			| (event.keyCode, this, '##/##');"		|																	|
//	| 			| 										|																	|
//	| 			| 										|																	|


function documenT_print()
	{
		window.print();
	}
function form_submit() 
	{ 
		document.forms[0].submit();
	}	
	
function form_reset()
	{
		document.forms[0].reset();
	}
function newwin(url,w,h,scrl)
	{
	screenleft=(screen.width/2)-(w/2);
	screentop=(screen.height/2)-(h/2);
				
	if (window.win!=null)
		{
	 		window.win.close();
			win=window.open(url,"winnd","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars="+scrl+",resizeable=0,width="+w+",height="+h+",top="+screentop+",left="+screenleft)
		} 
			else
		{
				win=window.open(url,"winnd","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars="+scrl+",resizeable=0,width="+w+",height="+h+",top="+screentop+",left="+screenleft)
	 	}
	}
			
			
function newimagewin(image,w,h,title)
			{
				screenleft=(screen.width/2)-(w/2);
				screentop=(screen.height/2)-(h/2);
				

						win=window.open("","winnd","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizeable=0,width="+w+",height="+h+",top="+screentop+",left="+screenleft);
						window.win.document.writeln("<TITLE>"+title+"</TITLE>");
						window.win.document.writeln("<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>");
						window.win.document.writeln("<DIV ID='Layer1' STYLE='position:absolute; left:0; top:0; width:100%; height:10; z-index:1'>");
  						window.win.document.writeln("<DIV ALIGN='RIGHT' CLASS='Text-Regular'><img STYLE='cursor:hand' SRC='../ew_images/close.gif' WIDTH='44' HEIGHT='20' onClick='window.close();'></DIV>");
						window.win.document.writeln("</DIV>");
						window.win.document.writeln("<img src=../ew_images/"+image+">");
						window.win.document.writeln("</BODY>");
						
			}
			
function Validator(f,otitle,re,eMsg,ru,r,divid){// Internal function for 'validate'
	//var f = eval("document.forms[0]."+f);
	var myErr="";
	var fv=f.value;
	var rex=new RegExp(unescape(re));
	var t=eval(ru+rex.test(fv));

		if(f.value.length <=0 ||!t)
		{
			document.getElementById(divid).innerHTML = "<FONT COLOR='#66000'>"+ eMsg+"</FONT>";
			document.forms[0].haserror.value = parseInt(document.forms[0].haserror.value) - 1;
			//alert("HasError - 1: "+ErrorMessage);
			ErrorMessage=(ErrorMessage+"\n - "+otitle+": "+eMsg);
		}
	else 
			document.getElementById(divid).innerHTML ='';
			//document.forms[0].haserror.value = parseInt(document.forms[0].haserror.value) + 1;
			//alert("HasError + 1: "+document.forms[0].haserror.value);
	
	}
<!--

function validate (obj,type,objtitle,req,ErrMsg)
{
//alert('Validate');

var form = document.forms[0];
var	obj = obj;							//Object name
var	type = type;						//Object Type
var	divid = "div_"+obj.name;			//Div Name where error message will be shoun
var	req = req;							//Object Required (Y/N)
var objtitle = objtitle; 				//Object Title for error message
var	ErrMsg = ErrMsg;					//Error Message	

	
if (type == 'email')
	{
	if (!ErrMsg)
		{
			ErrMsg='Enter a valid email address';
		}
	if (req == 'y')
		{
			Validator(obj,objtitle,'%5E%5B%5Cw%5C.=-%5D%2B@%5B%5Cw%5C.-%5D%2B%5C.%5Ba-z%5D%7B2,3%7D$',ErrMsg,'','1',divid);
		}
		else
		{
			if (obj.value != "")
				{
					Validator(obj,objtitle,'%5E%5B%5Cw%5C.=-%5D%2B@%5B%5Cw%5C.-%5D%2B%5C.%5Ba-z%5D%7B2,3%7D$',ErrMsg,'','1',divid);
				}
				else
				{
					document.getElementById(divid).innerHTML ='';
				}
		}
	}
	
	
if (type == 'phone')
	{
	if (!ErrMsg)
		{
			ErrMsg='Enter a valid phone number';
		}
	if (req == 'y')
		{
			Validator(obj,objtitle,'%5E(%5Cd%7B10%7D|%5Cd%7B3%7D-%5Cd%7B3%7D-%5Cd%7B4%7D|%5C(%5Cd%7B3%7D%5C)%5Cs*%5Cd%7B3%7D-%5Cd%7B4%7D)$',ErrMsg,'','1',divid);	

		}
		else
		{
			if (obj.value != "")
				{
					Validator(obj,objtitle,'%5E(%5Cd%7B10%7D|%5Cd%7B3%7D-%5Cd%7B3%7D-%5Cd%7B4%7D|%5C(%5Cd%7B3%7D%5C)%5Cs*%5Cd%7B3%7D-%5Cd%7B4%7D)$',ErrMsg,'','1',divid);	

				}
				else
				{
					document.getElementById(divid).innerHTML ='';
				}
		}
	}
	
	
if (type == 'password')
	{
	var re = /^[A-Za-z]\w{6,}[A-Za-z]$/; // Version 1 - password must be at least 8 characters long and start and end with a letter
	//var re = /^\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*$/	// Version 2 - length doesn't matter, but the password must contain at least 1 number, at least 1 lower case letter, and at least 1 upper case letter. 

	if (!ErrMsg)
		{
			ErrMsg='Enter a valid password';
		}
		if (!re.test(obj.value)) 
			{  
				document.getElementById(divid).innerHTML = "<FONT COLOR='#FF000'>"+ ErrMsg+"</FONT>";
				document.forms[0].haserror.value = parseInt(document.forms[0].haserror.value) - 1;
				ErrorMessage=(ErrorMessage+"\n - "+objtitle+": "+ErrMsg);
			}
		else
			{
				document.getElementById(divid).innerHTML ='';			
			}	
	}

if (type == 'any')
	{
//	alert('any');
	if (!ErrMsg)
		{
			ErrMsg=objtitle+" must not be empty";
		}
		if (obj.value == "") 
			{  
				document.getElementById(divid).innerHTML = "<FONT COLOR='#FF000'>"+ ErrMsg+"</FONT>";
				document.forms[0].haserror.value = parseInt(document.forms[0].haserror.value) - 1;
				ErrorMessage=(ErrorMessage+"\n - "+objtitle+": "+ErrMsg);
			}
		else
			{
				document.getElementById(divid).innerHTML ='';			
			}	
	}

}// And of the Validate


function documenT_back()
{
	window.history.back();
}
function documenT_forward()
{
	window.history.forward();
}	
function documenT_refresh()
{
	var sURL = unescape(window.location.pathname);
    window.location.replace( sURL );
}		
function fullscreen()
{
	window.moveTo(0,0);
	window.resizeTo(screen.width,screen.height);
}

var dat = "";
var error="none";
var days = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
function errorMessage(message)
{
	if (message != "none")
	{
		document.getElementById('dateerror').innerHTML = "<FONT COLOR='#ff000'>"+ message+"</FONT>";
		error = "yes";
	}else{
		document.getElementById('dateerror').innerHTML = "";
		error = "none";
	}
}
function DateMask (key, obj)
{
dat = obj.value;
//alert("Dat: "+dat);
	if (key==9)return true; // Tab
	else if (key==220 || key==32 || key==191 || key==189 || key==190 || key==16) // Delimetr
		{
			if (dat.length == 1)dat="0"+dat+"-";
			if (dat.length == 4)
				{
		   			dat1 = dat.substring(0,2);dat2 = dat.substring(3,4);dat=dat1+"-0"+dat2+"-";
				}	  
			obj.value = dat;
			}
        else if (key==8&&dat.length!=0)
			{
				
				dat = dat.substring(0,dat.length-1);//BackSpace
				obj.value = dat;
			}
		else if (((key>47&&key<58)||(key>95&&key<106))&& dat.length<10)
			{
				(key<58)?(keyf = key):(keyf = key-48);
				(dat.length != 2 && dat.length != 5)?dat=dat+String.fromCharCode(keyf):dat=dat+"-"+String.fromCharCode(keyf);
				if (dat.length <=2 && dat >12)
				{
					errorMessage("Month should be between 1 and 12");
					dat = dat.substring(0,1);
				}else errorMessage("none");
				if (dat.length ==5 && dat.substring(3,dat.length)>days[dat.substring(0,2)-1])
				{
					errorMessage("Day should be between 1 and "+days[dat.substring(0,2)-1]);
					dat = dat.substring(0,4);
				}
				if (dat.length == 2 )dat = dat+"-";
				if (dat.length == 5)dat = dat+"-";
				obj.value = dat;
          	}
		return false;
}
