// JavaScript Document

function toUpper(str) {

	var pattern = /(\w)(\w*)/; // a letter, and then one, none or more letters 
	var b = new Array();
    var a = str.split(/\s+/g); // split the sentence into an array of words

    for (var i = 0 ; i < a.length ; i ++ ) {
        var parts = a[i].match(pattern); // just a temp variable to store the fragments in.

        var firstLetter = parts[1].toUpperCase();
        var restOfWord = parts[2].toLowerCase();

     b[i] = firstLetter + restOfWord;
		 // re-assign it back to the array and move on
    }
		str ='';
	for (var i = 0 ; i < a.length ; i ++ )
	{
		if(i != a.length)
		str =  str+b[i]+' ';
		else
			str =  b[i];
	}
	return str;
}
Date.prototype.defaultView=function(){
		var dd=this.getDate();
		if(dd<10)dd='0'+dd;
		var mm=this.getMonth()+1;
		if(mm<10)mm='0'+mm;
		var yyyy=this.getFullYear();
		return String(mm+"\/"+dd+"\/"+yyyy)
	}
function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
 		 return true;			
	}

function $id(id){
	return document.getElementById(id);
}


//utf8 decoding for ajax requests responses
 var l1=true;
  
   var Url = {

// public method for url encoding
encode : function (string) {
return escape(this._utf8_encode(string));
},

// public method for url decoding
decode : function (string) {
return this._utf8_decode(unescape(string));
},

// private method for UTF-8 encoding
_utf8_encode : function (string) {
string = string.replace(/\r\n/g,"\n");
var utftext = "";

for (var n = 0; n < string.length; n++) {

var c = string.charCodeAt(n);

if (c < 128) {
utftext += String.fromCharCode(c);
}
else if((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}

}

return utftext;
},

// private method for UTF-8 decoding
_utf8_decode : function (utftext) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;

while ( i < utftext.length ) {

c = utftext.charCodeAt(i);

if (c < 128) {
string += String.fromCharCode(c);
i++;
}
else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
}
else {
c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}

}

return string;
}

}

  
  
  
function trim(s)
{
	
	var l=0; 
	var r = s.length -1;
	while(l < s.length && s[l] == ' ')
	{	
		l++;
	 }
	while(r > l && s[r] == ' ')
	{	
		r--;
	}
	return s.substring(l, r+1);
}

function addslashes(str) {
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\'/g,"\\\'");
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function stripslashes(str) {

	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}
	
String.prototype.replaceAll = function(from,to)
{
	for(var i = 0 ; i < this.length; i++)
	{
		this.replace(from, to);
		//alert(this);
		//break;
	}
}
  function isPositiveInteger (s)
   {   var secondArg = false;

       if (isPositiveInteger.arguments.length > 1)
          secondArg = isPositiveInteger.arguments[1];

       // The next line is a bit byzantine.  What it means is:
       // a) s must be a signed integer, AND
       // b) one of the following must be true:
       //    i)  s is empty and we are supposed to return true for
       //        empty strings
       //    ii) this is a positive, not negative, number

       return (isSignedInteger(s, secondArg)
          && ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
   }


  function isInteger (s)
   {
      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }
function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }
   function isSignedInteger (s)
   {  	
   		if (isEmpty(s))
      if (isSignedInteger.arguments.length == 1) return false;
      else return (isSignedInteger.arguments[1] == true);

      else {
         var startPos = 0;
         var secondArg = false;

         if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

         // skip leading + or -
         if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
            startPos = 1;
			
         return (isInteger(s.substring(startPos, s.length), secondArg))
      }
   }
    function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
   }
	
	function IsPositiveFloat(str)  
	 {  
	  var check_float =new RegExp("^[0-9][0-9]*\.[0-9]+$"); 
	  x = check_float.exec(str);  
	  if (x==null)
	  return 0
	  else return 1
	 }


	// (12-05-2003) 
function IsDate(str,format)  
{  
	
  format = typeof(format) != 'undefined' ? format : 'mm-dd-yyyy';
	
  var r = null;
  var is_date = null;
  if(format=='mm-dd-yyyy')
  {
  	 r = str.match(/^(\d{1,2})(-|\/)(\d{1,2})\2(\d{1,4})$/); 
	  if(r==null)  
  	  return false;  
	 d = new Date(r[4], r[1]-1, r[3]); 
	 is_date = d.getFullYear()==r[4]&&(d.getMonth()+1)==r[1]&&d.getDate()==r[3]
  }
  if(format=='yyyy-mm-dd')
  {
  	r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/); 
	
	if(r==null)  
   	return false;  
	d = new Date(r[1], r[3]-1, r[4]);  
	is_date = d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]
  } 
  if(format=='dd-mm-yyyy')
  {
  	//r = str.match(/^([0-2]){2}(\/|-){1}([0-9]){2}(\/|-)([0-9]){4}$/); 
	r = str.match(/^(\d{1,2})(-|\/)(\d{1,2})\2(\d{1,4})$/); 
	if(r==null)  
  	return false;  
	d = new Date(r[4], r[1]-1, r[3]); 
	is_date = d.getFullYear()==r[4]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[1]
  }
    return is_date; 
}  

function findPosX(obj){
	var curleft = 0;
	if(obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function findClientXY(){
	var bodyX, bodyY;
	if (self.innerHeight) // all except Explorer
	{
		bodyX = self.innerWidth;
		bodyY = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
	{
		bodyX = document.documentElement.clientWidth;
		bodyY = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		bodyX = document.body.clientWidth;
		bodyY = document.body.clientHeight;
	}	
	var r=new Array();
	r['x'] = bodyX;
	r['y'] = bodyY;
	return r;
}// JavaScript Document

function toUpper(str) {

	var pattern = /(\w)(\w*)/; // a letter, and then one, none or more letters 
	var b = new Array();
    var a = str.split(/\s+/g); // split the sentence into an array of words

    for (var i = 0 ; i < a.length ; i ++ ) {
        var parts = a[i].match(pattern); // just a temp variable to store the fragments in.

        var firstLetter = parts[1].toUpperCase();
        var restOfWord = parts[2].toLowerCase();

     b[i] = firstLetter + restOfWord;
		 // re-assign it back to the array and move on
    }
		str ='';
	for (var i = 0 ; i < a.length ; i ++ )
	{
		if(i != a.length)
		str =  str+b[i]+' ';
		else
			str =  b[i];
	}
	return str;
}
Date.prototype.defaultView=function(){
		var dd=this.getDate();
		if(dd<10)dd='0'+dd;
		var mm=this.getMonth()+1;
		if(mm<10)mm='0'+mm;
		var yyyy=this.getFullYear();
		return String(mm+"\/"+dd+"\/"+yyyy)
	}
function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
 		 return true;			
	}

function $id(id){
	return document.getElementById(id);
}


//utf8 decoding for ajax requests responses
 var l1=true;
  
   var Url = {

// public method for url encoding
encode : function (string) {
return escape(this._utf8_encode(string));
},

// public method for url decoding
decode : function (string) {
return this._utf8_decode(unescape(string));
},

// private method for UTF-8 encoding
_utf8_encode : function (string) {
string = string.replace(/\r\n/g,"\n");
var utftext = "";

for (var n = 0; n < string.length; n++) {

var c = string.charCodeAt(n);

if (c < 128) {
utftext += String.fromCharCode(c);
}
else if((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}

}

return utftext;
},

// private method for UTF-8 decoding
_utf8_decode : function (utftext) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;

while ( i < utftext.length ) {

c = utftext.charCodeAt(i);

if (c < 128) {
string += String.fromCharCode(c);
i++;
}
else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
}
else {
c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}

}

return string;
}

}

  
  
  
function trim(s)
{
	
	var l=0; 
	var r = s.length -1;
	while(l < s.length && s[l] == ' ')
	{	
		l++;
	 }
	while(r > l && s[r] == ' ')
	{	
		r--;
	}
	return s.substring(l, r+1);
}

function addslashes(str) {
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\'/g,"\\\'");
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function stripslashes(str) {

	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}
	
String.prototype.replaceAll = function(from,to)
{
	for(var i = 0 ; i < this.length; i++)
	{
		this.replace(from, to);
		//alert(this);
		//break;
	}
}
  function isPositiveInteger (s)
   {   var secondArg = false;

       if (isPositiveInteger.arguments.length > 1)
          secondArg = isPositiveInteger.arguments[1];

       // The next line is a bit byzantine.  What it means is:
       // a) s must be a signed integer, AND
       // b) one of the following must be true:
       //    i)  s is empty and we are supposed to return true for
       //        empty strings
       //    ii) this is a positive, not negative, number

       return (isSignedInteger(s, secondArg)
          && ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
   }


  function isInteger (s)
   {
      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }
function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }
   function isSignedInteger (s)
   {  	
   		if (isEmpty(s))
      if (isSignedInteger.arguments.length == 1) return false;
      else return (isSignedInteger.arguments[1] == true);

      else {
         var startPos = 0;
         var secondArg = false;

         if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

         // skip leading + or -
         if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
            startPos = 1;
			
         return (isInteger(s.substring(startPos, s.length), secondArg))
      }
   }
    function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
   }
	
	function IsPositiveFloat(str)  
	 {  
	  var check_float =new RegExp("^[0-9][0-9]*\.[0-9]+$"); 
	  x = check_float.exec(str);  
	  if (x==null)
	  return 0
	  else return 1
	 }


	// (12-05-2003) 
function IsDate(str,format)  
{  
	
  format = typeof(format) != 'undefined' ? format : 'mm-dd-yyyy';
	
  var r = null;
  var is_date = null;
  if(format=='mm-dd-yyyy')
  {
  	 r = str.match(/^(\d{1,2})(-|\/)(\d{1,2})\2(\d{1,4})$/); 
	  if(r==null)  
  	  return false;  
	 d = new Date(r[4], r[1]-1, r[3]); 
	 is_date = d.getFullYear()==r[4]&&(d.getMonth()+1)==r[1]&&d.getDate()==r[3]
  }
  if(format=='yyyy-mm-dd')
  {
  	r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/); 
	
	if(r==null)  
   	return false;  
	d = new Date(r[1], r[3]-1, r[4]);  
	is_date = d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]
  } 
  if(format=='dd-mm-yyyy')
  {
  	//r = str.match(/^([0-2]){2}(\/|-){1}([0-9]){2}(\/|-)([0-9]){4}$/); 
	r = str.match(/^(\d{1,2})(-|\/)(\d{1,2})\2(\d{1,4})$/); 
	if(r==null)  
  	return false;  
	d = new Date(r[4], r[1]-1, r[3]); 
	is_date = d.getFullYear()==r[4]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[1]
  }
    return is_date; 
}  

function findPosX(obj){
	var curleft = 0;
	if(obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function findClientXY(){
	var bodyX, bodyY;
	if (self.innerHeight) // all except Explorer
	{
		bodyX = self.innerWidth;
		bodyY = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
	{
		bodyX = document.documentElement.clientWidth;
		bodyY = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		bodyX = document.body.clientWidth;
		bodyY = document.body.clientHeight;
	}	
	var r=new Array();
	r['x'] = bodyX;
	r['y'] = bodyY;
	return r;
}