/******************************************
Date created : 21st September 2006
Date last modified : 21st September 2006
Author : Mohit Malik
Last modified by : Mohit Malik
Comments : JavaScript Common Function File
******************************************/


/******************************************
Function name : toggleOption
Return type : None
Date created : 21st September 2006
Date last modified : 21st September 2006
Author : Mohit Malik
Last modified by : Mohit Malik
Comments : Function will toggle the select all checkbox option.
User instruction : toggleOption(spanChk)
******************************************/
function toggleOption(spanChk)
{
	var xState=spanChk.checked;
	var theBox=spanChk;

	elm=theBox.form.elements;
	for(i=0;i<elm.length;i++)
	{
		if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
		{
			if(xState == false)
				elm[i].checked = false;
			else
				elm[i].checked = true;
		}
	}
}

/******************************************
Function name : checkPhone
Return type : boolean
Date created : 21st September 2006
Date last modified : 21st September 2006
Author : Mohit Malik
Last modified by : Mohit Malik
Comments : Function will return the true or false according to phone field validation
User instruction : checkPhone(phone)
******************************************/
function checkPhone(phone)
{
	var phoneRequired = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,3})|(\(?\d{2,3}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/
	if(!phoneRequired.test(phone))
		return false;
	return true;
}

/******************************************
Function name : checkEmail
Return type : boolean
Date created : 21st September 2006
Date last modified : 21st September 2006
Author : Mohit Malik
Last modified by : Mohit Malik
Comments : Function will return the true or false according to email field validation
User instruction : checkEmail(address)
******************************************/
function checkEmail(address)
{
	if ((address == "") || (address.indexOf ('@') == -1) || (address.indexOf ('.') == -1))
		return false;
	return true;
}

/******************************************
Function name : getMasterString
Return type : boolean
Date created : 21st September 2006
Date last modified : 21st September 2006
Author : Mohit Malik
Last modified by : Mohit Malik
Comments : Function will return the main string
User instruction : getMasterString()
******************************************/
function getMasterString()
{
	return "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n";
}

/******************************************
Function name : checkError
Return type : boolean
Date created : 21st September 2006
Date last modified : 21st September 2006
Author : Mohit Malik
Last modified by : Mohit Malik
Comments : Function will return the true or false acording to form validation
User instruction : checkError(error)
******************************************/
function checkError(error)
{
	var flag=false;
	var MasterString = getMasterString();
	
	if(error != "")
	{
		MasterString = MasterString + error;
		flag=true;
	}
	
	if(flag == true)
	{
		alert(MasterString);
		return false;
	}
	else
		return true;
}

/******************************************
Function name : askConfirm
Return type : boolean
Date created : 21st September 2006
Date last modified : 21st September 2006
Author : Mohit Malik
Last modified by : Mohit Malik
Comments : Function will return the true or false after asking for confirmation
User instruction : askConfirm(type)
******************************************/
function askConfirm(type)
{
	var sen = "Are you sure you want to  "+type+" this record.";
	if(confirm(sen))
		return true;
	else
		return false;
}

/******************************************
Function name : validator
Return type : boolean
Date created : 21st September 2006
Date last modified : 21st September 2006
Author : Mohit Malik
Last modified by : Mohit Malik
Comments : Function will return the true or error message after validating checkboxes
User instruction : validator(btnType)
******************************************/
var btnType;
function validator(btnType,formname)
{
	
	var obj = formname;
	var error="", flagCheck=0;
	
	var len = obj.elements.length;
	var i=0;
	for(i=0;i<len;i++) 
	{
		if(obj.elements[i].type=='checkbox')
		{
			if(obj.elements[i].checked)
			{
				//if(btnType == 'Delete')
					return askConfirm(btnType);
				//else
					//return true;
			}
			else
				flagCheck = 1;
		}
	}
	
	if(flagCheck == 1)
		error += "\nPlease select at least one record.";
			
	return checkError(error);
}



function openInNewWindow(newWin,winTitle) 
{
	var newWindow = window.open(newWin, winTitle,'height=600 , width=500');
	if (newWindow) 
	{
		if (newWindow.focus) 
		{
		newWindow.focus();
		}
		return false;
	}
	return true;
}
