function WindowXPosition(widthX,heightX,windowName)
{
	var width = (screen.width);
	var height = (screen.height - 25);
	var centerleft = 0;
	var centertop = 0;
	var centerleft = (width/2) - (widthX/2);
	var centertop = (height/2) - (heightX/2);
	var width=widthX;
	var height=heightX;
	windowName.moveTo(centerleft,centertop);
	windowName.resizeTo(width, height);
	windowName.focus();
}

function WindowXXPosition(widthX,heightX,windowName) //same as above, only it takes %age vals as params for width n height
{
	var width = (screen.width);
	var height = (screen.height - 25);
		
	var wt = (width * widthX) / 100;
	var ht = (height * heightX) / 100;

	var centerleft = (width/2) - (wt/2);
	var centertop = (height/2) - (ht/2);

	windowName.resizeTo(wt, ht);
	windowName.moveTo(centerleft,centertop);
	windowName.focus();
}

function CheckRealNum(obj)
{
	regExpr=new RegExp(/^-?\d*(\.\d{1,2})?$/);
	
	if(str_trim(obj.value)!="")
	{
		if(!regExpr.test(obj.value))
		{
			alert("Please Enter Valid Amount");
			obj.value="0";		
		}
	}
	else
		obj.value="0";		
}
function checkNum()
{
	var carCode = event.keyCode;
	
	if ((carCode < 48) || (carCode > 57))
	{
		//alert(carCode);
		alert('Please enter only numeric values.');
		event.cancelBubble = true;
		event.returnValue = false;
	}
} 

function CheckNum(obj)
{
	regExpr = new RegExp(/^\d*$/);

	if(str_trim(obj.value)!="")
	{
		if(!regExpr.test(obj.value))
		{
			alert("Please Enter Valid Numbers");
			obj.value="0";		
		}
	}
	else
		obj.value="0";		
}

function CheckIfImageFile(path)
{
	if(path!="")
	{
		index=path.lastIndexOf(".");
		ext=path.substr(index);
		if(ext!='.jpg'&&ext!='.gif'&&ext!='.jpeg'&&ext!='.png'&&ext!='.JPG'&&ext!='.PNG')
		{
			alert("Please Enter only Image files");
			return 1;
		}
	}
	return 0;

}// JavaScript Document

function CheckIfWordFile(path)
{
	if(path!="")
	{
		index=path.lastIndexOf(".");
		ext=path.substr(index);
		if(ext!='.doc'&&ext!='.DOC')
		{
			alert("Please Enter only MS Word files!");
			return 1;
		}
	}
	return 0;

}// JavaScript Document

function CheckIfPDFFile(path)
{
	if(path!="")
	{
		index=path.lastIndexOf(".");
		ext=path.substr(index);
		if(ext!='.pdf'&&ext!='.PDF')
		{
			alert("Please Enter only PDF files!");
			return 1;
		}
	}
	return 0;

}// JavaScript Document


function checkEmail(x)
{
	a=new Array();
	s=x.value;
	
	for(i=0; i<s.length; i++)
		a[i]=s.charAt(i);

	dot = s.indexOf(".");
	at   = s.indexOf("@");

	if (dot == -1 || at == -1)
	{
		x.focus()
		alert ("Please Check Email Address");
		return 1;
	}

	str1=s.substring(dot+1,s.length);
	str2=s.substring(at+1, dot);
	str3=s.substring(0,at);

	if((str1.length==0)||(str2.length==0)||(str3.length==0))
	{
		x.focus()     
		alert ("Please Check Email Address");
		return 1;
	}

	return 0;
}

function ValidateEmail(ctrl) 
{               
	var strMail = ctrl.value       
	var regMail = /^\w+([-.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;        
	
	if (regMail.test(strMail))        
	{           
		return true;        
	}       
	else        
	{            
		ctrl.value = "";            
		ctrl.focus();            
		alert("Invalid email format.\nPlease enter a valid email in the format user@host.domain.");            
		return false;       
	}
}

function IsNumeric(obj)
{   
	var sText = obj.value;
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 

		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
			obj.value="";
			obj.focus();
			alert("Please Enter Numerics Only");
		}
	}
	return IsNumber;   
}

function doHourglass()
{
	document.body.style.cursor = 'wait';
}

function undoHourglass()
{
	document.body.style.cursor = 'default';
}

//given the value, str_trim trims down the string from all padded whitespaces...
function str_trim(str)
{	
	if(str.length > 0)
		while(str.charAt(0)==' ')
			str = str.substr(1);
		
	if(str.length > 0)
		while(str.charAt((str.length - 1))==' ')
			str = str.substring(0, str.length-1);
	
	return str;
}

function DeleteData(txt)
{
	var msg = "You Are About To Delete this " + txt + "! Continue?";

	if(confirm(msg))
		return true;
	else
		return false;
}

function GoToPage(page)
{
	window.document.location.href=page;
}

function DeleteDataAndGoToPage(txt, page)
{
	var msg = "You Are About To Delete this " + txt + "! Continue?";

	if(confirm(msg))
		window.document.location.href=page;
}

function ChangeRank(mode, val,type)
{
	id_param = "";
	tp_param = "";
	if(val!='')
		id_param = "&id="+val;
	if(type != '')
		tp_param = "&type="+type;
		
	var file = "changerank.php?mode1="+mode+id_param+tp_param;
	win = window.open(file,'ChangeRank','scrollbars=1,width=700,height=450');
	WindowXPosition(700,450,win);
}

function OpenPopup(file)
{
	win = window.open(file,'Popup','width=600,height=450,scrollbars=1');
	WindowXPosition(600,450,win);
}

function SetFocus(obj)
{
	obj.focus();
	obj.select();
}

function validate_email(email_txt) 
{
	var emailReg = "^[\\w-_\.]*[\\w-_\.]\@([\\w].+)\.[\\w]$";
	var regex = new RegExp(emailReg);
	return regex.test(email_txt);
}

function checkYear(year) { 
return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0;
}


function IsNumeric(obj)
{   
	var sText = obj.value;
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 

		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
			obj.value="";
			obj.focus();
			alert("Please Enter Numerics Only");
		}
	}
	return IsNumber;   
}

function select(field) {
  field.focus()
  field.select()
}

function UploadMailerPics()
{
	info="mailer_pics.php";
	window.open(info,"","menubars=0,width=500,height=550,scrollbars=1");
}

function DeleteFunc(rec,mode,id,frm)
{
	 if(confirm('Are You Sure You want to Delete '+ rec +'?'))
	 {
	 	document.getElementById('mode').value = mode;
		document.getElementById('id').value = id;
		
		frm.submit();
	 }
	 else
	 	return false;
	 
}

function GeneratePass(temp,rand)
{
	var pattern = new Array('4321','3214','2143','1432','4231','2314','3142','1423','4123','1234','2341','3412','4132','1324','3241','2413');

	 var ranvar    = Math.round(Math.random() * 15);
	 var mypattern = pattern[ranvar];
	 
	 var temparr   = new Array();
	 
	 temparr[1] = temp.substr(0,8);
	 temparr[2] = temp.substr(8,8);
	 temparr[3] = temp.substr(16,8);
	 temparr[4] = temp.substr(24,8);
	 
	 passwordstr = rand+temparr[mypattern.substr(0,1)]+rand+temparr[mypattern.substr(1,1)]+rand+temparr[mypattern.substr(2,1)]+rand+temparr[mypattern.substr(3,1)]+mypattern;
	 
	 return passwordstr;
}

function chkimg(filename)
{
	var typarr = new Array(/.gif/i,/.png/i,/.jpeg/i,/.jpg/i);
	
	for(i=0;i<typarr.length;i++)
	{
		var inx = filename.search(typarr[i]);
		if(inx >= 1)
			break;
	}	
	
	if(inx == -1)
		return false;
	else if(inx >= 1)
		return true;
		
	//alert("File Type Not Supported!!");	
}

function chkfile(filename)
{
	var typarr = new Array(/.txt/i,/.doc/i,/.pdf/i,/.xls/i);
	
	for(i=0;i<typarr.length;i++)
	{
		var inx = filename.search(typarr[i]);
		if(inx >= 1)
			break;
	}	
	
	if(inx == -1)
		return false;
	else if(inx >= 1)
		return true;
		
	//alert("File Type Not Supported!!");	
}


function GetFileType(filename)
{
	var pos  = filename.lastIndexOf(".");
	var type = filename.substr(pos+1);    
	
	return type;
}
