// JavaScript Document



/***************************	Validating Email	***************************/

function emailCheck (emailStr) {

var emailPat=/^(.+)@(.+)$/

var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

var validChars="\[^\\s" + specialChars + "\]"

var quotedUser="(\"[^\"]*\")"

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

var atom=validChars + '+'

var word="(" + atom + "|" + quotedUser + ")"

var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

var matchArray=emailStr.match(emailPat)

if (matchArray==null) {

	alert("Email address seems incorrect (check @ and .'s)")

	return false

}

var user=matchArray[1]

var domain=matchArray[2]

if (user.match(userPat)==null) {

    alert("The username doesn't seem to be valid.")

    return false

}

var IPArray=domain.match(ipDomainPat)

if (IPArray!=null) {

    // this is an IP address

	  for (var i=1;i<=4;i++) {

	    if (IPArray[i]>255) {

	        alert("Destination IP address is invalid!")

		return false

	    }

    }

    return true

}

var domainArray=domain.match(domainPat)

if (domainArray==null) {

	alert("The domain name doesn't seem to be valid.")

    return false

}

var atomPat=new RegExp(atom,"g")

var domArr=domain.match(atomPat)

var len=domArr.length

if (domArr[domArr.length-1].length<2 || 

    domArr[domArr.length-1].length>4) {

   alert("Email address must end in a valid domain, or two letter country.")

   return false

}

if (len<2) {

   var errStr="Email address is missing a hostname!"

   alert(errStr)

   return false

}



   var str=emailStr; 

   if (emailStr.indexOf(" ")>=0)

		{

		alert ("Blank space not allowed inside email!");

		return false;

		}

	

		if (emailStr.indexOf("@",1) == -1)

		{

			alert("Invalid E-Mail address");

			return(false);

		}

		if (emailStr.indexOf("@") == 0)

		{

			alert("Invalid E-Mail address");

			return(false);

		}

		if (emailStr.indexOf(".",5) == -1)

		{

			alert("Invalid E-Mail address");

			return(false);

		}

		if (emailStr.indexOf(".") == 0)

		{

			alert("Invalid E-Mail address");

			return(false);

		}

		

		if ((emailStr.lastIndexOf(".")) -(emailStr.indexOf("@"))<3 )

		{

		

			alert("Invalid E-Mail address");

			return(false);

		}

		

		if ((emailStr.length)-(emailStr.indexOf("."))<2)

		{

			alert("Invalid E-Mail address");

			return(false);

		}



		var posat=str.indexOf("@");

		var posdot=str.indexOf(".");

		var rposdot=str.lastIndexOf(".");

		//alert(posat); 

		//alert(posdot);

		//alert(rposdot);

		

		

		if(rposdot==posdot)

		if((posdot < posat) || (posdot-posat < 3))

		{

		//alert("needs at last 3 cars between @ and . sign");

		alert("Invalid E-Mail address");

		return false;

		}

		

		if(str.charAt(str.length-1)==".")

		{

		//alert("cannot end with .");

		alert("Invalid E-Mail address");

		return false;

		}

		

		if(str.charAt(str.length-1)=="@")

		{

		//alert("cannot end with @");

		alert("Invalid E-Mail address");

		return false;

		}

		

		var j=0;

		for( var i=0;i<str.length;i++)

		{

		if(str.charAt(i) == "@")

		j++;

		}

		if(j > 1)

		{

		//alert("only one @ sign allowed");

		alert("Invalid E-Mail address");

		return false;

		}



return true;

}



function validate_email(email,mandatory,errmsg)

{

	if (mandatory==1 && email.value=='')

	{

		alert(errmsg);

		email.focus();

		return (false);

	}

	if (email.value!='' && !emailCheck (email.value) )

	{

		email.focus();

		email.select();

		return (false);

	}

	return(true);

}

/***************************	/Validating Email	***************************/
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function validate_ip(ip,mandatory,errmsg)

{

	if (mandatory==1 && trim(ip.value)=='')

	{

		alert(errmsg);

		ip.focus();

		return (false);

	}

	if (trim(ip.value)!='' && !verifyIP (trim(ip.value)) )

	{

		ip.focus();

		ip.select();

		return (false);

	}

	return(true);

}




/***************************	Validating Text	***************************/

function validate_text(data,mandatory,errmsg)

{

	if (mandatory==1 && data.value=='')

	{

		alert(errmsg);

		data.focus();

		//data.select();

		return (false);

	}

	

	if (data.value!='' && (data.value.replace(/^\s+|\s+$/, '').length<=0) )

	{

		alert(errmsg);

		data.focus();

		//data.select();

		return (false);

	}

	return(true);

}

/***************************	/Validating Text	***************************/





/***************************	Validating Text with no focus	***************************/

function validate_text_no_focus(data,mandatory,errmsg)

{

	if (mandatory==1 && data.value=='')

	{

		alert(errmsg);

		return (false);

	}

	

	if (data.value!='' && (data.value.replace(/^\s+|\s+$/, '').length<=0) )

	{

		alert(errmsg);

		return (false);

	}

	return(true);

}

/***************************	/Validating Text with no focus	***************************/





/***************************	Validating Numeric	***************************/

function validate_numeric(data,mandatory,errmsg)

{

	if (mandatory==1 && data.value=='')

	{

		alert(errmsg);

		data.focus();

		return (false);

	}

	if (data.value!='' && (isNaN(data.value) || (data.value<0) || (data.value.replace(/^\s+|\s+$/, '').length<=0)) )

	{

		alert(errmsg);

		data.focus();

		data.select();

		return (false);

	}

	return(true);

}

/***************************	/Validating Numeric	***************************/





/***************************	Validating Integer	***************************/

function validate_integer(data,mandatory,errmsg)

{

	if (mandatory==1 && data.value=='')

	{

		alert(errmsg);

		data.focus();

		return (false);

	}

	if (   data.value!='' && (   isNaN(data.value) || (data.value<0) || (data.value.replace(/^\s+|\s+$/, '').length<=0) || (data.value.indexOf('.')!=-1)   )   )

	{

		alert(errmsg);

		data.focus();

		data.select();

		return (false);

	}

	return(true);

}

/***************************	/Validating Integer	***************************/





/***************************	Check Minimum Length	***************************/

function validate_min_length(data,len,errmsg)

{

	if (   data.value!='' && (data.value.length<len) )

	{

		alert(errmsg);

		data.focus();

		data.select();

		return (false);

	}

	return(true);

}

/***************************	/Check Minimum Length	***************************/





/***************************	Check Maximum Length	***************************/

function validate_max_length(data,len,errmsg)

{

	if (   data.value!='' && (data.value.length>len) )

	{

		alert(errmsg);

		data.focus();

		data.select();

		return (false);

	}

	return(true);

}

/***************************	/Check Maximum Length	***************************/







/***************************	Phone number validation	***************************/



/**

 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)

 */



// Declaring required variables

var digits = "0123456789";

// non-digit characters which are allowed in phone numbers

var phoneNumberDelimiters = "()- ";

// characters which are allowed in international phone numbers

// (a leading + is OK)

var validWorldPhoneChars = phoneNumberDelimiters + "+";

// Minimum no of digits in an international phone no.

var minDigitsInIPhoneNumber = 10;



function isInteger(s)

{   var i;

    for (i = 0; i < s.length; i++)

    {   

        // Check that current character is number.

        var c = s.charAt(i);

        if (((c < "0") || (c > "9"))) return false;

    }

    // All characters are numbers.

    return true;

}



function stripCharsInBag(s, bag)

{   var i;

    var returnString = "";

    // Search through string's characters one by one.

    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)

    {   

        // Check that current character isn't whitespace.

        var c = s.charAt(i);

        if (bag.indexOf(c) == -1) returnString += c;

    }

    return returnString;

}



function checkInternationalPhone(strPhone){

s=stripCharsInBag(strPhone,validWorldPhoneChars);

return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);

}



function validate_phone_no(data,mandatory,errmsg){

	var Phone=data

	

	if (mandatory==1 && data.value=='')

	{

		alert(errmsg);

		data.focus();

		return (false);

	}

	if (   data.value!='' && checkInternationalPhone(Phone.value)==false){

		alert(errmsg);

		Phone.focus();

		Phone.select();

		return false

	}

	return true

 }

/***************************	/Phone number validation	***************************/



/***************************	Credit Card Validation	******************************/

function validateCreditCard(s) {

var v = "0123456789";

var w = "";

for (var i=0; i < s.length; i++) {

x = s.charAt(i);

if (v.indexOf(x,0) != -1)

w += x;

}

var j = w.length / 2;

if (j < 6.5 || j > 8 || j == 7) return false;

var k = Math.floor(j);

var m = Math.ceil(j) - k;

var c = 0;

for (var i=0; i<k; i++) {

a = w.charAt(i*2+m) * 2;

c += a > 9 ? Math.floor(a/10 + a%10) : a;

}

for (var i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;

return (c%10 == 0);

}



function validate_credit_card(data,mandatory,errmsg)

{

	if (mandatory==1 && data.value=='')

	{

		alert(errmsg);

		data.focus();

		return (false);

	}

	

	if (data.value!='' && (validateCreditCard(data.value)==false) )

	{

		alert(errmsg);

		data.focus();

		data.select();

		return (false);

	}

	return(true);

}



/***************************	Credit Card Validation	******************************/















//Manual...............................



// Email Verification

		//return validate_email(document.FormName.FieldName,0);	//2nd arg=if mandatory then 1 else 0

// Text Verification

		//return validate_text(document.FormName.FieldName,0,"Message..");	//2nd arg=if mandatory then 1 else 0

// Min Length Verification

		//return validate_min_length(document.FormName.FieldName,MinLen,"Message..");	//2nd arg=if mandatory then 1 else 0

// Max Length Verification

		//return validate_max_length(document.FormName.FieldName,MaxLen,"Message..");	//2nd arg=if mandatory then 1 else 0

// Numeric Verification

		//return validate_numeric(document.FormName.FieldName,0,"Message..");	//2nd arg=if mandatory then 1 else 0

// Integer Verification

		//return validate_integer(document.FormName.FieldName,0,"Message..");	//2nd arg=if mandatory then 1 else 0

// Phone number Verification

		//return validate_phone_no(document.FormName.FieldName,0,"Message..");	//2nd arg=if mandatory then 1 else 0

// Credit Card Verification

		//return validate_credit_card(document.FormName.FieldName,0,"Message..");	//2nd arg=if mandatory then 1 else 0





//-- all other common function -- may be delete for new pro



function allTrim(sString) 

{

	while (sString.substring(0,1) == ' ')

	{

	sString = sString.substring(1, sString.length);

	}

	while (sString.substring(sString.length-1, sString.length) == ' ')

	{

	sString = sString.substring(0,sString.length-1);

	}

return sString;

}



function numeric_chk(dtt,mss){



   if(dtt=="")

        {

          alert("Enter " + mss);          

          return false;

        }

    if(isNaN(dtt))

        {

          alert("Enter Numeric Value For " + mss);          

          return false;

        } 

    if(eval(dtt)<0)

        {

          alert("Enter Positive Value For " + mss);          

          return false;

        }



    return true

}



function sch_ck(){



  var a=document.skey.pkeyword.value

      //a=a.trim

  var b=a.length

  if (b<3){

    alert("Please input atleast 3 alphabets")

    document.skey.pkeyword.focus()

    return false

  }else{

    return true

  }

}



function taLimit(ele,mlen) {

	//var taObj=event.srcElement;

	var taObj=document.getElementById(ele);	

	if (taObj.value.length==mlen*1) return false;

}



function taCount(ele,visCnt,mlen) { 

	//var taObj=event.srcElement;

	var taObj=document.getElementById(ele);	

	if (taObj.value.length>mlen*1) taObj.value=taObj.value.substring(0,tmlen*1);	

	if (visCnt) document.getElementById(visCnt).innerHTML=mlen-taObj.value.length;

}



function Show_MQ(Element){



  var oId=document.getElementById(Element)

  oId.style.visibility = "visible";

  oId.style.display = "";

 }



 function Hide_MQ(Element){



  var oId=document.getElementById(Element)

  oId.style.visibility = "hidden";

  oId.style.display = "none";

 }

 

 // calendar code

 

var targetDate = new Date();

var calName;

var formName;



function setCalendar(event, f, name) {

	var el, tableEl, rowEl, cellEl, linkEl;

	var tmpDate, tmpDate2;

	var i, j;



	if (f == null) { f=1; }



	el = document.getElementById("calendarHeader_" + name).firstChild;

	el.nodeValue = targetDate.getMonthName() + "\u00a0" + targetDate.getFullYear();



	tmpDate = new Date(Date.parse(targetDate));

	tmpDate.setDate(1);



	while (tmpDate.getDay() != 0) { tmpDate.addDays(-1); }



	tableEl = document.getElementById('calendar_' + name);



	for (i = 0; i <= 5; i++) {

    rowEl = tableEl.rows[i];



    tmpDate2 = new Date(Date.parse(tmpDate));

    tmpDate2.addDays(6);

    if (tmpDate.getMonth()  != targetDate.getMonth() &&

        tmpDate2.getMonth() != targetDate.getMonth()) {

      rowEl.style.visibility = "hidden";

      if (document.all)

        for (j = 0; j < rowEl.cells.length; j++)

          rowEl.cells[j].style.borderStyle = "none";

    }

    else {

		rowEl.style.visibility = "";

		if (document.all)

			for (j = 0; j < rowEl.cells.length; j++)

				rowEl.cells[j].style.borderStyle = "";

    }



    for (j = 0; j < rowEl.cells.length; j++) {

      cellEl = rowEl.cells[j];

      linkEl = cellEl.firstChild;



      if (tmpDate.getMonth() == targetDate.getMonth()) {

        linkEl.date = new Date(Date.parse(tmpDate));

        s = tmpDate.toString().split(" ");

        linkEl.title = s[0] + " " + s[1] + " " + s[2] + ", " + s[s.length - 1];

        linkEl.firstChild.nodeValue = tmpDate.getDate();

        linkEl.style.visibility = "";

      } else {

        linkEl.style.visibility = "hidden";

	 }



      if (cellEl.oldClass == null)

        cellEl.oldClass = cellEl.className;



//      if ((Date.parse(tmpDate) == Date.parse(targetDate)) && (f == 1))

//	      cellEl.className = cellEl.oldClass; //  + " kalactive"

//      else

		cellEl.className = cellEl.oldClass;



		tmpDate.addDays(1);

    }

  }

}



function addMonths(event, n, name) {

	targetDate.addMonths(n);

	setCalendar(event, 0, name);

}



function addYears(event, n) {

	targetDate.addYears(n);

	setCalendar(event, 0);

}



function setTargetDate(event, link) {

	if (link.date != null) {

		targetDate = new Date(Date.parse(link.date));

		setCalendar(event, 1, this.formName);



		mm = String(targetDate.getMonth() + 1);

		dd = String(targetDate.getDate());

		yy = String(targetDate.getYear());



		if (dd.length == 1) dd = '0' + dd;

		if (mm.length == 1) mm = '0' + mm;



		if (this.formName != null && this.formName != ''){

			var dd = document.getElementById(this.formName + '_day').value = dd;;

			var dm = document.getElementById(this.formName + '_month').value = mm;

			var dy = document.getElementById(this.formName + '_year').value = yy;

		}



		hideCalendar(this.formName);

	}

}



function displayDate(event) {

	var gsss;



	gsss = formatDate(targetDate);

	asss = gsss.split("/");



	window.opener.document.mainform.month.value = Math.abs(asss[0]);

	window.opener.document.mainform.date.value = Math.abs(asss[1]);

	window.opener.document.mainform.year.value = Math.abs(asss[2]);

}



function formatDate() {

	var mm, dd, yyyy;

	mm = String(targetDate.getMonth() + 1);



	while (mm.length < 2)

		mm = "0" + mm;

	dd = String(targetDate.getDate());



	while (dd.length < 2)

	dd = "0" + dd;



	yyyy = String(targetDate.getFullYear());



	while (yyyy.length < 4)

		yyyy = "0" + yyyy;



	return mm + "/" + dd + "/" + yyyy;

}



Date.prototype.monthNames = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

Date.prototype.savedDate  = null;

Date.prototype.getMonthName = dateGetMonthName;

Date.prototype.getDays      = dateGetDays;

Date.prototype.addDays      = dateAddDays;

Date.prototype.addMonths    = dateAddMonths;

Date.prototype.addYears     = dateAddYears;



function dateGetMonthName() {

	return this.monthNames[this.getMonth()];

}



function dateGetDays() {

	var tmpDate, d, m;



	tmpDate = new Date(Date.parse(this));

	m = tmpDate.getMonth();

	d = 28;

	do {

		d++;

		tmpDate.setDate(d);

	} while (tmpDate.getMonth() == m);



	return d - 1;

}



function dateAddDays(n) {

	this.setDate(this.getDate() + n);

	this.savedDate = this.getDate();

}



function dateAddMonths(n) {

	if (this.savedDate == null)

		this.savedDate = this.getDate();



	this.setDate(1);

	this.setMonth(this.getMonth() + n);

	this.setDate(Math.min(this.savedDate, this.getDays()));

}



function dateAddYears(n) {

	if (this.savedDate == null)

		this.savedDate = this.getDate();



	this.setDate(1);

	this.setFullYear(this.getFullYear() + n);

	this.setDate(Math.min(this.savedDate, this.getDays()));

}



function showCalendar(name) {



	//if (this.calName != null)

	//	this.calName.style.visibility = 'hidden';



	var e = document.getElementById('cal_' + name);

	this.calName = e;

	this.formName = name;	

	

	if (name == "date"){

	   document.getElementById('cal_date1').style.visibility = 'hidden';

	}

	

	if (name == "date1"){

	   document.getElementById('cal_date').style.visibility = 'hidden';

	}



	if (e.style.visibility == 'visible')

		e.style.visibility = 'hidden';

	else

		e.style.visibility = 'visible';

}



function hideCalendar(name) {

	var e = document.getElementById('cal_' + name);

	e.style.visibility = 'hidden';

}
 /*
**************************************
* Event Listener Function v1.4       *
* Autor: Carlos R. L. Rodrigues      *
**************************************
*/
addEvent = function(o, e, f, s){
	var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
	r[r.length] = [f, s || o], o[e] = function(e){
		try{
			(e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
			e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
			e.target || (e.target = e.srcElement || null);
			e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
		}catch(f){}
		for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
		return e = null, !!d;
    }
};

removeEvent = function(o, e, f, s){
	for(var i = (e = o["_on" + e] || []).length; i;)
		if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
			return delete e[i];
	return false;
};

function formatCurrency(o, n, dig, dec){
	new function(c, dig, dec, m){
		addEvent(o, "keypress", function(e, _){
			if((_ = e.key == 45) || e.key > 47 && e.key < 58){
				var o = this, d = 0, n, s, h = o.value.charAt(0) == "-" ? "-" : "",
					l = (s = (o.value.replace(/^(-?)0+/g, "$1") + String.fromCharCode(e.key)).replace(/\D/g, "")).length;
				m + 1 && (o.maxLength = m + (d = o.value.length - l + 1));
				if(m + 1 && l >= m && !_) return false;
				l <= (n = c) && (s = new Array(n - l + 2).join("0") + s);
				for(var i = (l = (s = s.split("")).length) - n; (i -= 3) > 0; s[i - 1] += dig);
				n && n < l && (s[l - ++n] += dec);
				_ ? h ? m + 1 && (o.maxLength = m + d) : s[0] = "-" + s[0] : s[0] = h + s[0];
				o.value = s.join("");
			}
			e.key > 30 && e.preventDefault();
		});
	}(!isNaN(n) ? Math.abs(n) : 2, typeof dig != "string" ? "." : dig, typeof dec != "string" ? "," : dec, o.maxLength);
}
 // end the format currency code
 
 function popup(url,h,w) 
{
 var width  = w;
 var height = h;
 var left   = (screen.width  - width)/2;
 var top    = (screen.height - height)/2;
 var params = 'width='+width+', height='+height;
 params += ', top='+top+', left='+left;
 params += ', directories=no';
 params += ', location=no';
 params += ', menubar=no';
 params += ', resizable=yes';
 params += ', scrollbars=yes';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(url,'windowname5', params);
 if (window.focus) {newwin.focus()}
 return false;
}
function goToURL(strURL) {
	window.location = strURL; 
}

function verifyIP (IPvalue) {
errorString = "";
theName = "IPaddress";

var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
var ipArray = IPvalue.match(ipPattern);

if (IPvalue == "0.0.0.0")
errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
else if (IPvalue == "255.255.255.255")
errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
if (ipArray == null)
errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
else {
for (i = 0; i < 4; i++) {
thisSegment = ipArray[i];
if (thisSegment > 255) {
errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
i = 4;
}
if ((i == 0) && (thisSegment > 255)) {
errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
i = 4;
      }
   }
}
extensionLength = 3;
if (errorString == "")
return true;
else
alert (errorString);
}
