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 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=600,height=450');
	WindowXPosition(600,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");
}