// functions

function openWindow(url,winname,width,height,resizeble,top,left){
//window.open(url,"WatchMaker",'resizable=1,top=120,left=200,width=500,height=500')
window.open(url,winname,'resizable='+resizeble+',top='+top+',left='+left+',width='+width+',height='+height)
}


// Check Form Field Is Empty
function isEmpty(value)
{	
	if (trim(value) == "")
	{
		return true;	
	}
	return false;
}

// Trim White Spaces
function trim(strText) 
{ 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
}

function checkempty_type(thisfield, fieldname, ext) 
{
   var array_extensions = ext.split("|")
   var notvalidext = 0

   if (thisfield.value.length != 0) 
   {
      for (var i=0; i<array_extensions.length; i++)
      {
         if (!filterFileType(thisfield, array_extensions[i]))
         {
            notvalidext++;
         }
      }
   }

   if (notvalidext != 0)
   {
      if (notvalidext == array_extensions.length)
      {
         alert("Please submit ." + ext + " only type files for " + fieldname + ".");
         thisfield.focus();
         thisfield.select();
         return false;
      }
   }
   
   return true;
   
}

function filterFileType(field, ext) {
	if (field.value.indexOf('.' + ext) == -1) {
		return false;
	}
	return true;
}

function IsValidDate(intDay, intMonth, intYear)
{
	// Check for the month of February
	if (intMonth == 2)
	{
		// Leap Year
		if ((intYear % 4) == 0)
		{
			if (intDay > 29)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		else // Non-Leap Year
		{
			if (intDay > 28)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
	}
	// Check for months with 30 days
	else if (intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11)
	{
		if (intDay > 30)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else // Check for months with 31 days
	{
		if (intDay > 31)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
} // IsValidDate()


function Date1IsGreaterThanDate2(intDay1, intMonth1, intYear1, intDay2, intMonth2, intYear2)
{
	// First we compare the Year
	if (intYear1 > intYear2)
	{
		return true;
	}
	else if (intYear1 < intYear2)
	{
		return false;
	}
	else // intYear1 == intYear2
	{
		// If both Years are the same, we compare the Month
		if (intMonth1 > intMonth2)
		{
			return true;
		}
		else if (intMonth1 < intMonth2)
		{
			return false;
		}
		else // intMonth1 == intMonth2
		{
			// If both Months are the same, we compare the Day

			if (intDay1 > intDay2)
			{
				return true;
			}
			else if(intDay1 < intDay2)
			{
				return false;
			}
			else // intDay1 == intDay2
			{
				return true 
			}
		}
	}
} // Date1IsGreaterThanDate2()

function isNotNumeric(value)
{
    
	var num;
	for(var i=0; i<value.length;i++)
	{
	
		if(isNaN(value.charAt(i)))
		{
		   num = true;
		   break;
		}
		else
		{
			   num = false;
		}
	}	  
	if(num == true)
	    return true;
} // numberOnly

function hasSpecialChar(str1)
{
	var iChars = "!%^&*()+=-[]\\\';,./{}|\":<>?\`";
	var i = 0;
	var sLength = str1.length;
	var flag = false;
	//alert(str1);

	  for (i = 0; i < sLength; i++) {
		if (iChars.indexOf(str1.charAt(i)) != -1) {
			//alert(i+" : is special char.");
			flag = true;
			break;
		}	
	  }
	  return flag;
} // hasSpecialChar(str1)

function invalidCharsURL(str1)
{
	var iChars = "!^*()+-[]\\\';,{}|\"<>\`";
	var i = 0;
	var sLength = str1.length;
	var flag = false;
	//alert(str1);

	  for (i = 0; i < sLength; i++) {
		if (iChars.indexOf(str1.charAt(i)) != -1) {
			//alert(i+" : is special char.");
			flag = true;
			break;
		}	
	  }
	  return flag;
} // invalidCharsURL(str1)

function invalidCharsEmail(str1)
{
	var iChars = "!%^&*()+=-[]\\\';,{}|\":<>?\`";
	var i = 0;
	var sLength = str1.length;
	var flag = false;
	//alert(str1);

	  for (i = 0; i < sLength; i++) {
		if (iChars.indexOf(str1.charAt(i)) != -1) {
			//alert(i+" : is special char.");
			flag = true;
			break;
		}	
	  }
	  return flag;
} // invalidCharsEmail(str1)

function isEmail(s)
{  
	// there must be >= 1 character before @, so we
	// start looking at character position 1 
	// (i.e. second character)
	var i = 1;
	var sLength = s.length;

	// look for @
	while ((i < sLength) && (s.charAt(i) != "@"))
	{ i++ }

	if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	else i += 2;

	// look for .
	while ((i < sLength) && (s.charAt(i) != "."))
	{ i++ }

	// there must be at least one character after the .
	if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	else return true;
} // isEmail(s)

function isNotImage(strText)
{
	splitString = strText.split(".");
	if  ((splitString[1] != "JPG") && (splitString[1] != "jpg") && (splitString[1] != "GIF") && (splitString[1] != "gif"))
	{
		return true;
	}
	else
		return false;
} // isNotImage()

function getSelectedCheckbox(buttonGroup) 
{
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function check_radio_button(strText)
{
	// set var radio_choice to false
	var radio_choice = false;
	
	// Loop from zero to the one minus the number of radio button selections
	for (counter = 0; counter < strText.length; counter++)
	{
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (strText[counter].checked)
			radio_choice = true; 
	}
	return radio_choice;
}

function IsValidDate(intDay, intMonth, intYear)
{
	// Check for the month of February
	if (intMonth == 2)
	{
		// Leap Year
		if ((intYear % 4) == 0)
		{
			if (intDay > 29)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		else // Non-Leap Year
		{
			if (intDay > 28)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
	}
	// Check for months with 30 days
	else if (intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11)
	{
		if (intDay > 30)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else // Check for months with 31 days
	{
		if (intDay > 31)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
} // IsValidDate()

Date.prototype.add = function (sInterval, iNum){
  var dTemp = this;
  if (!sInterval || iNum == 0) return dTemp;
  switch (sInterval.toLowerCase()){
    case "ms":
      dTemp.setMilliseconds(dTemp.getMilliseconds() + iNum);
      break;
    case "s":
      dTemp.setSeconds(dTemp.getSeconds() + iNum);
      break;
    case "mi":
      dTemp.setMinutes(dTemp.getMinutes() + iNum);
      break;
    case "h":
      dTemp.setHours(dTemp.getHours() + iNum);
      break;
    case "d":
      dTemp.setDate(dTemp.getDate() + iNum);
      break;
    case "mo":
      dTemp.setMonth(dTemp.getMonth() + iNum);
      break;
    case "y":
      dTemp.setFullYear(dTemp.getFullYear() + iNum);
      break;
  }
  return dTemp;
}