
var xmlHttp


function replaceSubstring(inputString, fromString, toString) {
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { 
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { 
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";

      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } 

      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }

      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } 
   return temp; 
}

function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") {
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") {
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) {
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue;
}

//****************************************************


function datediff(date1,date2)
{
	var temp1	 = new Array();
	var temp2	 = new Array();	
	temp1		 = date1.split("index.html")
	temp2		 = date2.split("index.html")	

	//Set the two dates
	var millennium =new Date(temp1[2], temp1[0]-1, temp1[1]) //Month is 0-11 in JavaScript
	today=new Date(temp2[2], temp2[0]-1, temp2[1])
	//Get 1 day in milliseconds
	var one_day=1000*60*60*24

	//Calculate difference btw the two dates, and convert to days
	return (Math.ceil((today.getTime()-millennium.getTime())/(one_day)))

	
}

//****************************************************

function isArray(obj)
{
	return(typeof(obj.length)=="undefined")?false:true;
}

//****************************************************

function SelectRadio(ctrl,num,tmp_value)
{
	for (i=0 ; i<num ; i++)
	{	
		if (ctrl(i).value == tmp_value) 
			ctrl(i).checked = true;
	}
}

//****************************************************


//****************************************************


function chkCost(val)
{
	var re = /^[0-9\.\\]*$/;
	if (!val.match(re)) 
		return 0;
	else
		return 1;
}


function chkDiscCode(val)
{
	var re = /^[0-9\.\\]*$/;
	if (!val.match(re)) 
		return 0;
	else
		return 1;
}

function chkUserID(val)
{
	var re = /^[a-z0-9A-Z\-\_\\]*$/;
	if (!val.match(re)) 
	return 0;
	else
	return 1;

}

function chkpage_name(val)
{
	var re = /^[a-z0-9A-Z\-\ \_\.\\]*$/;
	if (!val.match(re)) 
	return 0;
	else
	return 1;

}

//*************************************************************//

function chkEmpty(txt)
{
if (txt=="")
   return 0;
else
  return 1;

}

//*************************************************************//

function chkEmail(eml)
{
	var re = /^[0-9a-zA-Z\-\.\_]+@[0-9a-zA-Z\-]+\.[0-9a-zA-Z\-\.]+$/;
	if (!eml.match(re)) 
		return 0;
	else
		return 1;

}

//*************************************************************//

function chkCityName(val)
{
	var re = /^[a-zA-Z\ \\]*$/;
	if (!val.match(re)) 
		return 0;
	else
		return 1;

}


function chkChrOnly(val)
{
	var re = /^[a-zA-Z\\]*$/;
	if (!val.match(re)) 
		return 0;
	else
		return 1;

}

function CheckTitle(val)
{
	var re = /^[a-zA-Z\.\ \\]*$/;
	if (!val.match(re)) 
		return 0;
	else
		return 1;

}

//*************************************************************//
function chkPhone(val)
{
	var re = /^[0-9\-\\]*$/;
	if (!val.match(re)) 
		return 0;
	else
		return 1;
}


function chkNum(val)
{
	var re = /^[0-9\\]*$/;
	if (!val.match(re)) 
		return 0;
	else
		return 1;
}

//*************************************************************//
//*************************************************************//

function chkOnlyNum(val)
{
	var re = /^[0-9\\]*$/;
	if (!val.match(re)) 
		return 0;
	else
		return 1;
}

//*************************************************************//

function chkRadio(valz,num)
{
	for (i=0 ; i<num ; i++)
	{	
		if (valz[i].checked) 
			return 1;
	}
	return 0;
}


//*************************************************************//

function chkChrNumOnly(val)
{
	var re = /^[a-zA-Z0-9\\]*$/;
	if (!val.match(re)) 
		return 0;
	else
		return 1;

}

//************************************************************//
function chkZipCode(val)
{
	var re = /^[a-z0-9A-Z\-\\]*$/;
	if (!val.match(re)) 
		return 0;
	else
		return 1;

}


function chkName(val)
{
	var re = /^[a-z0-9A-Z\ \\]*$/;
	if (!val.match(re)) 
		return 0;
	else
		return 1;

}


// Function for CompanyName in all advertiser signup. (public/admin section)
function chkComapnyName(val)
{
	var re = /^[a-z0-9A-Z\,\.\- \\]*$/;
	if (!val.match(re)) 
		return 0;
	else
		return 1;

}

function chk_US_TelFax(val)
{
	var re = /^[0-9\-\\]*$/;
	if (!val.match(re)) 
		return 0;
	else
		return 1;

}

//************************************************************//
function formreset(frmID){
	
		var e
		e = 0;

		while (frmID.elements.length > e ){

				if (frmID.elements[e].type == "text" || frmID.elements[e].type == "password" || frmID.elements[e].type == "textarea" || frmID.elements[e].type == "hidden" ){

					frmID.elements[e].value = "";
					}
				else 
					if (frmID.elements[e].type == "select-one" ){
					if (frmID.elements[e].name != "cboPackage" )
	///				frmID.elements[e].selectedIndex = 0;
					frmID.elements[e].value = 0;
					}
				else 
					if (frmID.elements[e].type == "checkbox"  ){
					frmID.elements[e].checked = false;
					}
				else 
					if (frmID.elements[e].type == "radio" )
					document.getElementById(frmID.elements[e].name).checked = true;
				
				e = e + 1;
		}

}
//************************************************************//

function isLeapYear(Year) 
{
if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) {
return true;
}
}

//************************************************************//

//*******************************************************************//
/**
 * strPad
 *
 * Pad a string to a certain length with another string
 *
 * This functions returns the input string padded on the left, the right, or both sides
 * to the specified padding length. If the optional argument pad_string is not supplied,
 * the output is padded with spaces, otherwise it is padded with characters from pad_string
 * up to the limit.
 *
 * The optional argument pad_type can be STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH.
 * If pad_type is not specified it is assumed to be STR_PAD_RIGHT.
 *
 * If the value of pad_length is negative or less than the length of the input string,
 * no padding takes place.
 *
 * object string
 * return string
 *
 * examples:
 *   var input = 'foo';
 *   input.strPad(9);                      // returns "foo      "
 *   input.strPad(9, "*+", STR_PAD_LEFT);  // returns "*+*+*+foo"
 *   input.strPad(9, "*", STR_PAD_BOTH);   // returns "***foo***"
 *   input.strPad(9 , "*********");        // returns "foo******"
 */

var STR_PAD_LEFT  = 0;
var STR_PAD_RIGHT = 1;
var STR_PAD_BOTH  = 2;

String.prototype.strPad = function(pad_length, pad_string, pad_type)
{
  /* Helper variables */
  var num_pad_chars   = pad_length - this.length;/* Number of padding characters */
  var result          = '';                       /* Resulting string */
  var pad_str_val     = ' ';
  var pad_str_len     = 0;                        /* Length of the padding string */
  var pad_type_val    = pad_type;            /* The padding type value */
  var i               = 0;
  var left_pad        = 0;
  var right_pad       = 0;
  var error           = false;
  var error_msg       = '';
  var output           = this;

  if (arguments.length < 2 || arguments.length > 4)
  {
    error     = true;
    error_msg = "Wrong parameter count.";
  }


  else if(isNaN(arguments[0]) == true)
  {
    error     = true;
    error_msg = "Padding length must be an integer.";
  }
  /* Setup the padding string values if specified. */
  if (arguments.length > 2)
  {
    if (pad_string.length == 0)
    {
      error     = true;
      error_msg = "Padding string cannot be empty.";
    }
    pad_str_val = pad_string;
    pad_str_len = pad_string.length;

    if (arguments.length > 3)
    {
      pad_type_val = pad_type;
      if (pad_type_val < STR_PAD_LEFT || pad_type_val > STR_PAD_BOTH)
      {
        error     = true;
        error_msg = "Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH."
      }
    }
  }

  if(error) throw error_msg;

  if(num_pad_chars > 0 && !error)
  {
    /* We need to figure out the left/right padding lengths. */
	
    switch (pad_type_val)
    {
      case STR_PAD_RIGHT:
        left_pad  = 0;
        right_pad = num_pad_chars;
        break;

      case STR_PAD_LEFT:
        left_pad  = num_pad_chars;
        right_pad = 0;
        break;

      case STR_PAD_BOTH:
        left_pad  = Math.floor(num_pad_chars / 2);
        right_pad = num_pad_chars - left_pad;
        break;
    }

    for(i = 0; i < left_pad; i++)
    {
      output = pad_str_val.substr(0,num_pad_chars) + output;
    }

    for(i = 0; i < right_pad; i++)
    {
      output += pad_str_val.substr(0,num_pad_chars);
    }
  }

  return output;
}


///////////////////////////////////////////////////////
function getDays(month, year) {
  // create array to hold number of days in each month
  var ar = new Array(12);
  ar[0] = 31; // January
  ar[1] = (isLeapYear(year)) ? 29 : 28; // February
  ar[2] = 31; // March
  ar[3] = 30; // April
  ar[4] = 31; // May
  ar[5] = 30; // June
  ar[6] = 31; // July
  ar[7] = 31; // August
  ar[8] = 30; // September
  ar[9] = 31; // October
  ar[10] = 30; // November
  ar[11] = 31; // December

  // return number of days in the specified month (parameter)
  return ar[month];
}


//************************************************************//
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

function isFunction(a) {
    return typeof a == 'function';
}

//************************************************************//

	//---------------selected value for ddl-------------------
	//------parameter-------(valueto be selected, object)-----
	function SelectDD(cnt,obj)
	{
		if(cnt != "")
		{
			for (i = 0 ; i < obj.length ; i++)
			{
				if (obj.options[i].value == cnt)
				{
					obj.options[i].selected = true ;
					break;
				}
			}
		}
	}
//************************************************************//

//---------------On category changed it will displays the jobs according to Category-------------------

function show_jobs()
{
	var frm = document.frm_view_job
 	cat_id	= frm.cat_id.value
	frm.action = 'http://www.teem-ortho.com/view_jobs.php?cat_id='+cat_id;    
	frm.submit()
}


function ChkDel()
{
	var j=0;
	for (var i=0  ; i<document.frm_view_job.length ; i++)
	{
        if (document.frm_view_job[i].checked)
		{
            j++;
        }
    }
	
	if (j > 0)
	{
		result=confirm("Are you sure you want to permanently delete the selected Job(s)?");
			
		if (result)
		{
			document.frm_view_job.action = "http://www.teem-ortho.com/save_job.php?act=del&amp;cat_id=<?=$temp_cat_id?>";
			document.frm_view_job.submit();
		}	
	}
	else
	{
		alert("Please Select A Job");
	}
}

function ChkDel_cat()
{

	var j=0;
	for (var i=0  ; i<document.frm_view_category.length ; i++)
	{
        if (document.frm_view_category[i].checked)
		{
            j++;
        }
    }
	
	if (j > 0)
	{
		result=confirm("Are you sure you want to permanently delete the selected Job(s)?");
			
		if (result)
		{
			document.frm_view_category.action = "http://www.teem-ortho.com/save_category.php?act=update&amp;act=del&amp;cat_id=<?=$temp_cat_id?>";
			document.frm_view_category.submit();
		}	
	}
	else
	{
		alert("Please Select A Job");
	}

}

