
  var winURL = '';
  var winTarget = '';
  var winWidth = '';
  var winHeight = '';
  var winLeft = '';
  var winTop = '';
  var winRes = '';
  var winScroll = '';
  var winLoc = '';
  var winStat = '';
  var winMenu = '';
  var winTool = '';
  
  function openWindow(winURL, winTarget, winWidth, winHeight, winLeft, winTop, winRes, winScroll, winLoc, winStat, winMenu, winTool)
    
  {
             
    // Universal Window Loader
        
    wwinRes = 'no';  // Resizable
    wwinScroll = 'no';  // Scrollbars
    wwinLoc = 'no';  // Location / Address
    wwinStat = 'no';  // Status bar
    wwinMenu = 'no';  // Menu bar
    wwinTool = 'no';  // Tool bar
    
    if (winRes == '1')
    {
      wwinRes = 'yes';
    }

    if (winScroll == '1')
    {
      wwinScroll = 'yes';
    }
    
    if (winLoc == '1')
    {
      wwinLoc = 'yes';
    }
    
    if (winStat == '1')
    {
      wwinStat = 'yes';
    }
    
    if (winMenu == '1')
    {
      wwinMenu = 'yes';
    }
    
    if (winTool == '1')
    {
      wwinTool = 'yes';
    }
             
         
    var winProp = 'left=' + winLeft + ',top=' + winTop + ',width=' + winWidth + ',height=' + winHeight + ',resizable=' + wwinRes + ',scrollbars=' + wwinScroll + ',location=' + wwinLoc + ',status=' + wwinStat + ',menubar=' + wwinMenu + ',toolbar=' + wwinTool;
    aPopUp = window.open(winURL, winTarget, winProp);
  
}

function isNum()
{
// This Function Prevents A User From Entering
// Non Numerical Values In A Text Field Via
// An onkeypress Event - onkeypress="return isNum(this);"
// Example:
// <input type="text" onkeypress="return isNum(this);">	
    if ((event.keyCode < 48) || (event.keyCode > 57))
    {
        return false;
    }
}

// Date Tools Start //

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s)
{
	// Check For Empty String
	if (s.length == 0)
	{
		return false;
	}
	
	var i;
    for (i = 0; i < s.length; i++){   
        // Check That Current Character Is Numeric.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All Characters Are Numeric.
    return true;
}

function stripCharsInBag(s, bag)
{
	var i;
    var returnString = "";
    // Parse The String
    // If The Character Is Not In Bag, Append To returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary(year)
{
	// February Has 29 Days In Any Year Evenly Divisible By Four,
    // EXCEPT For Centurial Years Which Are Not Also Divisible By 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n)
{
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr, region)
{
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)

	var strMonth = '';
	var strDay = '';
	var strYear = '';

    if (region == 1)
    {
    	strMonth=dtStr.substring(0,pos1)
	    strDay=dtStr.substring(pos1+1,pos2)
	    strYear=dtStr.substring(pos2+1)
    }
    else
    {
        strDay=dtStr.substring(0,pos1)
    	strMonth=dtStr.substring(pos1+1,pos2)	    
	    strYear=dtStr.substring(pos2+1)
    }

	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1)
    {
        if (region == 1)
        {
		    alert("The date format should be : mm/dd/yyyy")
        }
        else
        {
            alert("The date format should be : dd/mm/yyyy")
        }
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function ValidateDate(obj, region, comp)
{

    // comp = 0 - Allow Empty Field
    // comp = 1 - Force Date Validation, Do Not Allow Empty Field

    // region = 1 US Date Format (MM/DD/YYYY)
    // region = 2 UK / Aus Date Format (DD/MM/YYYY)

    var blnCheck = false;
    var txtValue = obj.value;

    if (comp == 1)
    {    
        blnCheck = true;
    }
    else
    {
        if (txtValue != '')
        {
            blnCheck = true;
        }
    }

    if (blnCheck == true)
    {
    	    if (isDate(txtValue, region)==false){
	    	    obj.focus()
		        return false
	        }
            return true
    }
    else
    {
        return true
    }
        
}

function timeTillDate(startDate, endDate, region)

{
	var thisMonth = 0;
	var thisDay = 0;
	var thisYear = 0;
	var whenMonth = 0;
	var whenDay = 0;
	var whenYear = 0;

	var pos1=startDate.indexOf(dtCh)
	var pos2=startDate.indexOf(dtCh,pos1+1)

    if (region == 1)
    {
    	thisMonth=parseInt(startDate.substring(0,pos1))
	    thisDay=parseInt(startDate.substring(pos1+1,pos2))
	    thisYear=parseInt(startDate.substring(pos2+1))

    	whenMonth=parseInt(endDate.substring(0,pos1))
	    whenDay=parseInt(endDate.substring(pos1+1,pos2))
	    thisYear=parseInt(endDate.substring(pos2+1))
    }
    else
    {
    	thisDay=parseInt(startDate.substring(0,pos1))
	    thisMonth=parseInt(startDate.substring(pos1+1,pos2))
	    thisYear=parseInt(startDate.substring(pos2+1))

    	whenDay=parseInt(endDate.substring(0,pos1))
	    whenMonth=parseInt(endDate.substring(pos1+1,pos2))
	    thisYear=parseInt(endDate.substring(pos2+1))
    }

    var yearsDifference = whenYear - thisYear, monthsDifference = 0;
    var daysDifference = 0;
    var string = '';

    if (whenMonth >= thisMonth) monthsDifference = whenMonth - thisMonth;
    else { yearsDifference--; monthsDifference = whenMonth + 12 - thisMonth; }

    if (whenDay >= thisDay)daysDifference = whenDay - thisDay;
    else {
        if (monthsDifference > 0) monthsDifference--;
        else { yearsDifference--; monthsDifference+=11; }
        daysDifference = whenDay + 31 - thisDay;
    }

    if (yearsDifference < 0) return '';

    if ((yearsDifference == 0) && (monthsDifference == 0) && (daysDifference == 0))
        return '';

    if (yearsDifference > 0) {
        string = yearsDifference + ' year';
        if (yearsDifference > 1) string += 's';
        string += ' ';
    }

    if (monthsDifference > 0) {
        string += monthsDifference + ' month';
        if (monthsDifference > 1) string += 's';
        string += ' ';
    }

    if (daysDifference > 0) {
        string += daysDifference + ' day';
        if (daysDifference > 1) string += 's';
        string += ' ';
    }

    var difference = Date.UTC(now.getYear(),now.getMonth(),now.getDate(),now.getHours(),
                     now.getMinutes(),now.getSeconds()) -
                     Date.UTC(now.getYear(),now.getMonth(),now.getDate(),0,0,0);
                     
    difference = 1000*60*60*24 - difference;

    var hoursDifference = Math.floor(difference/1000/60/60);
    difference = difference - hoursDifference*1000*60*60
    var minutesDifference = Math.floor(difference/1000/60);
    difference = difference - minutesDifference*1000*60
    var secondsDifference = Math.floor(difference/1000);

    if (hoursDifference > 0) {
        string += hoursDifference + ' hour';
        if (hoursDifference > 1) string +='s';
        string += ' ';
    }

    if (minutesDifference > 0) {
        string += minutesDifference + ' minute';
        if (minutesDifference > 1) string +='s';
        string += ' ';
    }

    if (secondsDifference > 0) {
        string += secondsDifference + ' second';
        if (secondsDifference > 1) string +='s';
        string += ' ';
    }

    return string;
}

// Date Tools End //

// Email Validation Start
// The Following Functions Are Used To Validate Email Address
// Delimited With A Character Defined By chrSearch.

function splitEmail(strInput, chrSearch) 

{                        
            var strNewString = strInput.split(chrSearch);
            var intMax = strNewString.length;

            for (i=0; i < intMax; i++) 
            {
                        if (checkEmail(trunc(strNewString[i])) == false) 
                        {
                                   alert("Invalid email detected!");
                                   break;
                        }           
            }           
}

function checkEmail(src) 

{
  var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  return regex.test(src);
}

// Email Validation End

