// display decision alert box
function decision(message, url){
	if(confirm(message)) location.href = url;
}

// open browser window
function openPopUp(url, windowName, w, h, scrollbar) {

           var winl = (screen.width - w) / 2;
           var wint = (screen.height - h) / 2;
           winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbar+',resizable=yes';
		   win = window.open(url, windowName, winprops);
           if (parseInt(navigator.appVersion) >= 4) { 
              	win.window.focus(); 
           } 
}

function jumpMenu(target,object,restore){ 
  eval(target+".location='"+object.options[object.selectedIndex].value+"'");
  if (restore) object.selectedIndex=0;
}

function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function getImage(imageName)
{
		findObj('img').src = imageName;
}

function submitDoc(formName) { 
  var obj;
 
	if (obj=findObj(formName)!=null) 
	{
		findObj(formName).submit(); 
	}
	else 
	{
		alert('The form you are attempting to submit called \'' + formName + '\' couldn\'t be found. Please make sure the submitDoc function has the correct id and name.');
	}

}

/**
 * @Author: Saurabh Verma
 * @Created on: March 16th, 2010
 *
 * validate email address.
 */
 function checkMail(email)
 {
	 //var email = ele(emailId).value;
	 if (email != '')
	 {
	 	var regex = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
	 	var check=regex.test(email);
	 	
		if(check==false)
	    {
//	    	alert("Enter a valid email address");
//	    	ele(emailId).select();
	   		return false;
		}
	 }
	 return;
 }
 
/**
 * @Author: Saurabh Verma
 * @Created on: March 16th, 2010
 *
 * Shortcut functions for document.getElementById()
 * and alert().
 */
 function a(alertMesg)
 {
	alert(alertMesg);
 }
 function ele(eleId)
 {
	return document.getElementById(eleId);	 
 }
 
/* Number validation on keypress */
//USAGE: <input type="text" onkeypress="return onlyNumbers(event);">
function onlyNumbers(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode;

	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;

	return true;

}

/**
 * @Saurabh (March 25th 2010)
 * To check a valid number / float / phone / mobile /...etc.
 * @Usage: checkValidEntry('232432453fg', '0123456789'); //eg: for numbers validation.
 */
function checkValidEntry(str, digits)
{
	if( typeof digits == 'undefined' )
		digits = '0123456789.';
	
	var flg = 0;
	for (var i = 0; i < str.length; i++)
	{
		var temp = str.substring(i, i+1);
		if (digits.indexOf(temp) == -1 && str != "")
		{
			flg++;
			//return false;
			break;
			//alert("The numerical text must be a number.");
			//return false;
		}
	}
	
	if( flg > 0 )
	{
		return false;
	}
	return true;
}

 /**
  * Invalid file(image) extension checking.
  *
  * @Usage:
  * <form 
	 onsubmit="return validateFileExtension('fileField')">
	<p>
	<input type="file" name="fileField"
	 onchange="return validateFileExtension('fileField')">
	<input type="submit" value="Submit">
	</p>
	</form>
  *
  */
  function validateImageExtension(fldId, formId)
  {//a(fldId);
		if( typeof formId == 'undefined' )
			formId = 'frm'; //by default.
	
		var fldVal = ele(fldId).value;
		
		if( fldVal == "" )
		{
			a("Please select any image to upload !");
			return false;
		}
		else if(!/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i.test(fldVal))
		{
			alert("Invalid image file type.");
			ele(formId).reset(); //reset current form (as we can reset file field individually).
			//fld.focus();
			return false;
		}
		return true; 
  }
  
  
 /**
  * Invalid file(csv) extension checking.
  *
  * @Usage:
  * <form 
	 onsubmit="return validateCSVExtension('fileField')">
	<p>
	<input type="file" name="fileField"
	 onchange="return validateCSVExtension('fileField')">
	<input type="submit" value="Submit">
	</p>
	</form>
  *
  */
  function validateCSVExtension(fldId, formId)
  {//a(fldId);
		if( typeof formId == 'undefined' )
			formId = 'frm'; //by default.
	
		var fldVal = ele(fldId).value;
		
		if( fldVal == "" )
		{
			a("Please select any csv file to upload !");
			return false;
		}
		else if(!/(\.csv)$/i.test(fldVal))
		{
			alert("Invalid csv file!");
			ele(formId).reset(); //reset current form (as we can reset file field individually).
			//fld.focus();
			return false;
		}
		return true; 
  }
  
 /**
  * To show or hide any field.
  * [Saurabh: Apr 20th, 2010]
  */
	function showHide(inID) 
	{
		 if (document.getElementById(inID).style.display == 'none') 
		 {
			  document.getElementById(inID).style.display = 'block';
		 } 
		 else 
		 {
			  document.getElementById(inID).style.display = 'none';
		 }
	}
	
/**
 * To confirm delete (when no any checkbox is selected).
 * @Usage: onclick="return isselect('frm_addItem', 'Are you sure you want to add selected product(s) to eBay?');".
 */
function isselect(formId, confirmMesg, checkAllId)
{
	var total = 0
	
	if( typeof checkAllId == 'undefined' )
		checkAllId = 'chk_all';
	
	if( ele(formId).length )
	{
		for(var i = 0; i < ele(formId).length; i++ )
		{
			if( (ele(formId).elements[i].type == 'checkbox') && (ele(formId).elements[i].checked == true)
				&& ele(formId).elements[i].name != checkAllId )
			{
				total=1;
				break;
			}
		}
	}
	
	if(parseInt(total) == 1)
	{
		return confirm(confirmMesg);
	}
	else
	{
		a('Please select a record!');
		return false;
	}
}

