/*	sIFR 2.0.2
	Copyright 2004 - 2006 Mike Davidson, Shaun Inman, Tomas Jogin and Mark Wubben

	This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/

var hasFlash=function()
{
	var a=6;	
	
	
	if(navigator.appVersion.indexOf("MSIE")!=-1&&navigator.appVersion.indexOf("Windows")>-1)
	{
		document.write('<script language="VBScript"\> \non error resume next \nhasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & '+a+'))) \n</script\> \n');
		
		if(window.hasFlash!=null)return window.hasFlash
	}
	
	if(navigator.mimeTypes&&navigator.mimeTypes["application/x-shockwave-flash"]&&navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)
	{		
		var b=(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]).description;
		return parseInt(b.charAt(b.indexOf(".")-1))>=a
	}return false}();
	
	String.prototype.normalize=function()
	{
		return this.replace(/\s+/g," ")
	};
	
	if(Array.prototype.push==null)
	{
		
		Array.prototype.push=function()
		{
			var i=0,a=this.length,b=arguments.length;
			while(i<b){this[a++]=arguments[i++]}return this.length
		}
	}
	
	if(!Function.prototype.apply)
	{
		Function.prototype.apply=function(a,b)
		{
			var c=[];var d,e;if(!a)a=window;if(!b)b=[];
			
			for(var i=0;i<b.length;i++)
			{
				c[i]="b["+i+"]"
			}e="a.__applyTemp__("+c.join(",")+");";
			
			a.__applyTemp__=this;			
			d=eval(e);a.__applyTemp__=null;return d
		}
	}
	
	function named(a)
	{		
		return new named.Arguments(a)
	}
	
	named.Arguments=function(a)
	{
		
		this.oArgs=a
	};
	
	
	
	named.Arguments.prototype.constructor=named.Arguments;named.extract=function(a,b){var c,d;var i=a.length;while(i--){d=a[i];if(d!=null&&d.constructor!=null&&d.constructor==named.Arguments){c=a[i].oArgs;break}}if(c==null)return;for(e in c)if(b[e]!=null)b[e](c[e]);return};var parseSelector=function(){var a=/^([^#.>`]*)(#|\.|\>|\`)(.+)$/;function r(s,t){var u=s.split(/\s*\,\s*/);var v=[];for(var i=0;i<u.length;i++)v=v.concat(b(u[i],t));return v}function b(c,d,e){c=c.normalize().replace(" ","`");var f=c.match(a);var g,h,i,j,k,n;var l=[];if(f==null)f=[c,c];if(f[1]=="")f[1]="*";if(e==null)e="`";if(d==null)d=document;switch(f[2]){case "#":k=f[3].match(a);if(k==null)k=[null,f[3]];g=document.getElementById(k[1]);if(g==null||(f[1]!="*"&&!o(g,f[1])))return l;if(k.length==2){l.push(g);return l}return b(k[3],g,k[2]);case ".":if(e!=">")h=m(d,f[1]);else h=d.childNodes;for(i=0,n=h.length;i<n;i++){g=h[i];if(g.nodeType!=1)continue;k=f[3].match(a);if(k!=null){if(g.className==null||g.className.match("(\\s|^)"+k[1]+"(\\s|$)")==null)continue;j=b(k[3],g,k[2]);l=l.concat(j)}else if(g.className!=null&&g.className.match("(\\s|^)"+f[3]+"(\\s|$)")!=null)l.push(g)}return l;case ">":if(e!=">")h=m(d,f[1]);else h=d.childNodes;for(i=0,n=h.length;i<n;i++){g=h[i];if(g.nodeType!=1)continue;if(!o(g,f[1]))continue;j=b(f[3],g,">");l=l.concat(j)}return l;case "`":h=m(d,f[1]);for(i=0,n=h.length;i<n;i++){g=h[i];j=b(f[3],g,"`");l=l.concat(j)}return l;default:if(e!=">")h=m(d,f[1]);else h=d.childNodes;for(i=0,n=h.length;i<n;i++){g=h[i];if(g.nodeType!=1)continue;if(!o(g,f[1]))continue;l.push(g)}return l}}function m(d,o){if(o=="*"&&d.all!=null)return d.all;return d.getElementsByTagName(o)}function o(p,q){return q=="*"?true:p.nodeName.toLowerCase().replace("html:", "")==q.toLowerCase()}return r}();var sIFR=function(){var a="http://www.w3.org/1999/xhtml";var b=false;var c=false;var d;var ah=[];var al=document;var ak=al.documentElement;var am=window;var au=al.addEventListener;var av=am.addEventListener;var f=function(){var g=navigator.userAgent.toLowerCase();var f={a:g.indexOf("applewebkit")>-1,b:g.indexOf("safari")>-1,c:navigator.product!=null&&navigator.product.toLowerCase().indexOf("konqueror")>-1,d:g.indexOf("opera")>-1,e:al.contentType!=null&&al.contentType.indexOf("xml")>-1,f:true,g:true,h:null,i:null,j:null,k:null}; f.l=f.a||f.c;f.m=!f.a&&navigator.product!=null&&navigator.product.toLowerCase()=="gecko";if(f.m&&g.match(/.*gecko\/(\d{8}).*/))f.j=new Number(g.match(/.*gecko\/(\d{8}).*/)[1]);f.n=g.indexOf("msie")>-1&&!f.d&&!f.l&&!f.m;f.o=f.n&&g.match(/.*mac.*/)!=null;if(f.d&&g.match(/.*opera(\s|\/)(\d+\.\d+)/))f.i=new Number(g.match(/.*opera(\s|\/)(\d+\.\d+)/)[2]);if(f.n||(f.d&&f.i<7.6))f.g=false;if(f.a&&g.match(/.*applewebkit\/(\d+).*/))f.k=new Number(g.match(/.*applewebkit\/(\d+).*/)[1]);if(am.hasFlash&&(!f.n||f.o)){var aj=(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]).description;f.h=parseInt(aj.charAt(aj.indexOf(".")-1))}if(g.match(/.*(windows|mac).*/)==null||f.o||f.c||(f.d&&(g.match(/.*mac.*/)!=null||f.i<7.6))||(f.b&&f.h<7)||(!f.b&&f.a&&f.k<312)||(f.m&&f.j<20020523))f.f=false;if(!f.o&&!f.m&&al.createElementNS)try{al.createElementNS(a,"i").innerHTML=""}catch(e){f.e=true}f.p=f.c||(f.a&&f.k<312);return f}();function at(){return{bIsWebKit:f.a,bIsSafari:f.b,bIsKonq:f.c,bIsOpera:f.d,bIsXML:f.e,bHasTransparencySupport:f.f,bUseDOM:f.g,nFlashVersion:f.h,nOperaVersion:f.i,nGeckoBuildDate:f.j,nWebKitVersion:f.k,bIsKHTML:f.l,bIsGecko:f.m,bIsIE:f.n,bIsIEMac:f.o,bUseInnerHTMLHack:f.p}}if(am.hasFlash==false||!al.getElementsByTagName||!al.getElementById||(f.e&&(f.p||f.n)))return{UA:at()};function af(e){if((!k.bAutoInit&&(am.event||e)!=null)||!l(e))return;b=true;for(var i=0,h=ah.length;i<h;i++)j.apply(null,ah[i]);ah=[]}var k=af;function l(e){if(c==false||k.bIsDisabled==true||((f.e&&f.m||f.l)&&e==null&&b==false)||(al.body==null||al.getElementsByTagName("body").length==0))return false;return true}function m(n){if(f.n)return n.replace(new RegExp("%\d{0}","g"),"%25");return n.replace(new RegExp("%(?!\d)","g"),"%25")}function as(p,q){return q=="*"?true:p.nodeName.toLowerCase().replace("html:", "")==q.toLowerCase()}function o(p,q,r,s,t){var u="";var v=p.firstChild;var w,x,y,z;if(s==null)s=0;if(t==null)t="";while(v){if(v.nodeType==3){z=v.nodeValue.replace("<","&lt;");switch(r){case "lower":u+=z.toLowerCase();break;case "upper":u+=z.toUpperCase();break;default:u+=z}}else if(v.nodeType==1){if(as(v,"a")&&!v.getAttribute("href")==false){if(v.getAttribute("target"))t+="&sifr_url_"+s+"_target="+v.getAttribute("target");t+="&sifr_url_"+s+"="+m(v.getAttribute("href")).replace(/&/g,"%26");u+='<a href="asfunction:_root.launchURL,'+s+'">';s++}else if(as(v,"br"))u+="<br/>";if(v.hasChildNodes()){y=o(v,null,r,s,t);u+=y.u;s=y.s;t=y.t}if(as(v,"a"))u+="</a>"}w=v;v=v.nextSibling;if(q!=null){x=w.parentNode.removeChild(w);q.appendChild(x)}}return{"u":u,"s":s,"t":t}}function A(B){if(al.createElementNS&&f.g)return al.createElementNS(a,B);return al.createElement(B)}function C(D,E,z){var p=A("param");p.setAttribute("name",E);p.setAttribute("value",z);D.appendChild(p)}function F(p,G){var H=p.className;if(H==null)H=G;else H=H.normalize()+(H==""?"":" ")+G;p.className=H}function aq(ar){var a=ak;if(k.bHideBrowserText==false)a=al.getElementsByTagName("body")[0];if((k.bHideBrowserText==false||ar)&&a)if(a.className==null||a.className.match(/\bsIFR\-hasFlash\b/)==null)F(a, "sIFR-hasFlash")}function j(I,J,K,L,M,N,O,P,Q,R,S,r,T){if(!l())return ah.push(arguments);aq();named.extract(arguments,{sSelector:function(ap){I=ap},sFlashSrc:function(ap){J=ap},sColor:function(ap){K=ap},sLinkColor:function(ap){L=ap},sHoverColor:function(ap){M=ap},sBgColor:function(ap){N=ap},nPaddingTop:function(ap){O=ap},nPaddingRight:function(ap){P=ap},nPaddingBottom:function(ap){Q=ap},nPaddingLeft:function(ap){R=ap},sFlashVars:function(ap){S=ap},sCase:function(ap){r=ap},sWmode:function(ap){T=ap}});var U=parseSelector(I);if(U.length==0)return false;if(S!=null)S="&"+S.normalize();else S="";if(K!=null)S+="&textcolor="+K;if(M!=null)S+="&hovercolor="+M;if(M!=null||L!=null)S+="&linkcolor="+(L||K);if(O==null)O=0;if(P==null)P=0;if(Q==null)Q=0;if(R==null)R=0;if(N==null){N="#FFFFFF";}if(T=="transparent")if(!f.f)T="opaque";else N="transparent";if(T==null)T="transparent";var p,V,W,X,Y,Z,aa,ab,ac;var ad=null;for(var i=0,h=U.length;i<h;i++){p=U[i];if(p.className!=null&&p.className.match(/\bsIFR\-replaced\b/)!=null)continue;V=p.offsetWidth-R-P;W=p.offsetHeight-O-Q;aa=A("span");aa.className="sIFR-alternate";ac=o(p,aa,r);Z="txt="+m(ac.u).replace(/\+/g,"%2B").replace(/&/g,"%26").replace(/\"/g, "%22").normalize() + S + "&w=" + V + "&h=" + W + ac.t;F(p,"sIFR-replaced");if(ad==null||!f.g){if(!f.g){if(!f.n)p.innerHTML=['<embed class="sIFR-flash" type="application/x-shockwave-flash" src="',J,'" quality="best" wmode="',T,'" bgcolor="',N,'" flashvars="',Z,'" width="',V,'" height="',W,'" wmode="transparent" sifr="true"></embed>'].join("");else p.innerHTML=['<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" sifr="true" width="',V,'" height="',W,'" class="sIFR-flash"><param name="movie" value="',J,"?",Z,'"></param><param name="quality" value="best"></param><param name="wmode" value="transparent"></param><param name="bgcolor" value="',N,'"></param> </object>'].join('')}else{if(f.d){ab=A("object");ab.setAttribute("data",J);C(ab,"quality","best");C(ab,"wmode",T);C(ab,"bgcolor",N)}else{ab=A("embed");ab.setAttribute("src",J);ab.setAttribute("quality","best");ab.setAttribute("flashvars",Z);ab.setAttribute("wmode",T);ab.setAttribute("bgcolor",N)}ab.setAttribute("sifr","true");ab.setAttribute("type","application/x-shockwave-flash");ab.className="sIFR-flash";if(!f.l||!f.e)ad=ab.cloneNode(true)}}else ab=ad.cloneNode(true);if(f.g){if(f.d)C(ab,"flashvars",Z);else ab.setAttribute("flashvars",Z);ab.setAttribute("width",V);ab.setAttribute("height",W);ab.style.width=V+"px";ab.style.height=W+"px";p.appendChild(ab)}p.appendChild(aa);if(f.p)p.innerHTML+=""}if(f.n&&k.bFixFragIdBug)setTimeout(function(){al.title=d},0)}function ai(){d=al.title}function ae(){if(k.bIsDisabled==true)return;c=true;if(k.bHideBrowserText)aq(true);if(am.attachEvent)am.attachEvent("onload",af);else if(!f.c&&(al.addEventListener||am.addEventListener)){if(f.a&&f.k>=132&&am.addEventListener)am.addEventListener("load",function(){setTimeout("sIFR({})",1)},false);else{if(al.addEventListener)al.addEventListener("load",af,false);if(am.addEventListener)am.addEventListener("load",af,false)}}else if(typeof am.onload=="function"){var ag=am.onload;am.onload=function(){ag();af()}}else am.onload=af;if(!f.n||am.location.hash=="")k.bFixFragIdBug=false;else ai()}k.UA=at();k.bAutoInit=true;k.bFixFragIdBug=true;k.replaceElement=j;k.updateDocumentTitle=ai;k.appendToClassName=F;k.setup=ae;k.debug=function(){aq(true)};k.debug.replaceNow=function(){ae();k()};k.bIsDisabled=false;k.bHideBrowserText=true;return k}();

	
if(typeof sIFR == "function" && !sIFR.UA.bIsIEMac){
sIFR.setup();
};/*	sIFR 2.0.1 Official Add-ons 1.2
	Copyright 2005 Mark Wubben

	This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/

if(typeof sIFR=="function")(function(){var j=document;var h=j.documentElement;sIFR.removeDecoyClasses=function(){function a(b){if(b&&b.className!=null)b.className=b.className.replace(/\bsIFR-hasFlash\b/,"")}return function(){a(h);a(j.getElementsByTagName("body")[0])}}();sIFR.preferenceManager={storage:{sCookieId:"sifr",set:function(a){var b=new Date();b.setFullYear(b.getFullYear()+3);j.cookie=[this.sCookieId,"=",a,";expires=",b.toGMTString(),";path=/"].join("")},get:function(){var a=j.cookie.match(new RegExp(";?"+this.sCookieId+"=([^;]+);?"));if(a!=null&&a[1]=="false")return false;else return true},reset:function(){var a=new Date();a.setFullYear(a.getFullYear()-1);j.cookie=[this.sCookieId,"=true;expires=",a.toGMTString(),";path=/"].join("")}},disable:function(){this.storage.set(false)},enable:function(){this.storage.set(true)},test:function(){return this.storage.get()}};if(sIFR.preferenceManager.test()==false){sIFR.bIsDisabled=true;sIFR.removeDecoyClasses()}sIFR.rollback=function(){function a(b){var c,d,e,f,g,h;var l=parseSelector(b);var i=l.length-1;var m=false;while(i>=0){c=l[i];l.length--;d=c.parentNode;if(c.getAttribute("sifr")=="true"){h=0;while(h<d.childNodes.length){c=d.childNodes[h];if(c.className=="sIFR-alternate"){e=c;h++;continue}d.removeChild(c)}if(e!=null){f=e.firstChild;while(f!=null){g=f.nextSibling;d.appendChild(e.removeChild(f));f=g}d.removeChild(e)}if(!sIFR.UA.bIsXML&&sIFR.UA.bUseInnerHTMLHack)d.innerHTML+="";d.className=d.className.replace(/\bsIFR\-replaced\b/,"")};m=true;i--}return m}return function(k){named.extract(arguments,{sSelector:function(a){k=a}});if(k==null)k="";else k+=">";sIFR.removeDecoyClasses();sIFR.bHideBrowserText=false;if(a(k+"embed")==false)a(k+"object")}}()})()//*********************************************************************
// File Name               : common_script.js
// Scope Of Program        : validation script for  blank, numeric,
//			     alpha-numeric,email id form field.
// Created On              : 10/03/2004
// Modified On             : 11/03/2004
// Reason of Modification  : Add date validation function
// Special Remark          :
//*********************************************************************

/* Function to display java Popup for calendar */

function javaCal(fld)
{
	/* Name		: javaCal						 */
	/* Purpose	: Creates a popup Window for selecting the date. The
			  selected date is set in the textfield.		 */
	/* Inputs	: fld = textfield for setting the date			 */
	/* Outputs	: Calendar Popup					 */
	/* Calls	: calnav.htm						 */
	/* Called By	: 							 */


	tmp_dt_today= new Date();
	tmp_str_dt  = tmp_dt_today.getDate();
        tmp_str_mon = tmp_dt_today.getMonth();
        tmp_str_yr  = tmp_dt_today.getFullYear();

	var tmp_dt_timeStamp  = new Date(tmp_str_yr,tmp_str_mon,tmp_str_dt,0,0,0);
	var tmp_int_todaySecs = Date.parse(tmp_dt_timeStamp);

	/* allowPast = 1 allows selection of past dates
	   allowPast = 0 does not allow selection of past dates
	*/

	doc = "./include/inc_common/calnav.htm?frmField="+fld+"&tmp_int_todaySecs="+tmp_int_todaySecs+"&allowPast=1";

	//alert(doc);
	window.open(doc,"Calendar","toolbar=0, location=0,directories=0,resizable=no,status=0,menubar=0,scrollbars=no,width=275,height=275,screenX=0,screenY=0");

}

//************** function restricts user from entering blank string and
// from entering only white speces.*****************

function isBlank(tmp_str)
{
// Name      : isBlank.

// Purpose   : keeping validation for blank field.

// Inputs    : tmp_str -> string for validation

// Outputs   : return the value of veriable newString.
//             if newString = "" returns null

var newString  = ''; //trim value of given string
var substring  = ''; // temporary string for checking white spaces in string.
beginningFound = false; // position of white space

// copy characters over to a new string
// retain whitespace characters if they are between other characters

for (var i = 0; i < tmp_str.length; i++)
 {
	// copy non-whitespace characters
	// hold whitespace characters in a temporary string if they follow a non-whitespace character

	if (tmp_str.charAt(i) != ' ' && tmp_str.charCodeAt(i) != 9)
	{
		// if the temporary string contains some whitespace characters, copy them first
		if (substring != '')
		{
			newString += substring;
			substring = '';
		}
		newString += tmp_str.charAt(i);
		 if (beginningFound == false)
		 {
		   beginningFound = true;
		 }
	}

	else if (beginningFound == true)
	{
	   substring += tmp_str.charAt(i);
	}
  }

  return newString;

}

//function to check whether a number is integer or not
function isInt1(strng,msg,msg1) 
{
	var error = "";
	var x=0;

	if (strng.length != 0) 
	{
		if (isNaN(strng)==true) 
		{
			
			error = msg+"\n";

		}
		else
		{
		    x=parseInt(strng);
		}
		
		if(x<=0)
		{
			error="Please enter non-negative value "+msg1+"\n";
		}
		else
		{
			var arrParts = strng.split('.');
			if(arrParts.length > 1)        
			{             
				error="Please enter non-decimal value in "+msg1+"\n";    
			}
			
		}
		/*else if(parseInt(strng)==0)
		{
			error=msg+"\n";

		}*/

	}
	else
	{
	error=msg1+"\n"; 
	}
	
	return error;	

}

//************** function for allowing only Alpha-Numeric String *****************

function isAlphaNumeric(tmp_str)
{
  // Name      : isAlphanumeric.

  // Purpose   : allow user to enter only Alpha(A-Z)-Numeric(0-9) values.
  // Inputs    : tmp_str -> string for validations.
  // Outputs   : return 1 -> if form field is alphanumeric
  //		 return -1 -> if form field is not alphanumeric

//ignore validation if tmp_str is blank.
if(tmp_str != "")
 {
  // searching whole string word by word
    if (tmp_str.search)
      {
        //checking the words in string.
        //  if string contains the non Alpha-Nemeric value, return -1.
        //  else return 1.

	 if ((tmp_str.search(/[^\w\s]/) != -1) || (tmp_str.search(/\W/) != -1))
	  {
	 	return -1;
	  }
      }
 }
 return 1;
}


//************** function for allowing only Numeric String *****************


//************** function for allowing only Alpha String *****************

function isAlpha(tmp_str)
{
  // Name      : isAlpha.

  // Purpose   : allow user to enter only Alpha(A-Z) values.
  // Inputs    : tmp_str -> string for validations.
  // Outputs   : return 1 -> if form field is alphabetic
  //		 return -1 -> if form field is not alphabetic

//ignore validation if tmp_str is blank.
if(tmp_str != "")
 {
  // searching whole string word by word
    if (tmp_str.search)
    {
        //checking the words in string.
        //  if string contains the non alphabetic value, return -1.
        //  else return 1.

	  	if ((tmp_str.search((/[a-zA-Z]/)) != -1) && (tmp_str.search((/[0-9]/)) == -1)&& (tmp_str.search(/[^\w\s]/) == -1))
	  	{
	 		return 1;
	  	}
	  	else
	  	{
	  		return -1;
	  	}
	  	
    }
 }
 return 1;
}


//************** function for allowing only String *****************


function isNumeric(tmp_int)
{
  // Name      : isNumeric.

  // Purpose   :allow user to enter only Numeric(0-9) values.
  // Inputs    : tmp_int -> string for validations.
  // Outputs   : return 1 -> if form field is Numeric
  //		 return -1 -> if form field is not Numeric

//ignore validation if tmp_int is blank.

if(tmp_int != "")
 {
   // searching whole string word by word
    if (tmp_int.search)
     {
        //checking the words in string.
        //  if string contains the non Nemeric value, return -1.
        //  else return 1.

	if (tmp_int.search((/[^\d]/)) != -1)
	{
		return -1;
	}
     }
 }
 return 1;
}


function check_mobile_phone(val,string,category,extrastring)
{

if(val=="")
{
return string;
}
else if(isNumeric(val)==-1)
{
return category+" for "+extrastring+" Should not be AlphNumeric \n"; 
}
return "";
}


//************** function for allowing only Numeric String *****************
function isEmailId(tmp_str)
{
  // Name      : isEmailId.
  // Purpose   : allow user to enter value in email id format(xxx@kk.com).
  // Inputs    : tmp_str -> string for validation.
  // Outputs   : return 1 -> if form field is as email id format.
  //		 return -1 -> if form field is not as email id format.


//ignore validation if tmp_str is blank.

if(tmp_str != "")
  {
     // searching whole string word by word

       if (tmp_str.search)
        {
          //checking the words in string.
          //  if given string is not in email id format(xxx@zzz.com), return -1.
          //  else return 1.

       	       fsign = tmp_str.indexOf("@");
       	       ssign = tmp_str.indexOf(".");

	       if(fsign <= 0 || ssign <= 0)
	       {
		     return -1;
	       }
        }
  }
 return 1;
}

/********* Function Validate date ***************/

function isDate(dateStr,formatStr)
{

  // Name      : isDate.

  // Purpose   : validate Date.

  // Inputs    : dateStr-> Date Value, formatStr -> format of date.

  // Outputs   : return null -> if user enter enter validate data
  //             else return error text

  // Calls     : buildDate(dateStr,formatStr)
  //             datestr = date value
  //             formatStr = date format


  //calls function for validating date
  
  var myObj = buildDate(dateStr,formatStr);

  //returns the correct date
  //else returns the appropriate error message

   if (typeof myObj == "object")
   {

   // We got a Date object, so good.

    myObj = "";
    return myObj;
   }
   else
   {

   // We got an error string.

    return myObj;
   }
}

function isFile(tmp_str,fileTyp)
{
  // Name      : isFile.
  // Purpose   : validation for File extention
  // Inputs    : tmp_str -> string for validations.
  //	         fileTyp -> file extention type.
  // Outputs   : return 1 -> if form field is valid
  //		 return -1 -> if form field is unvalid

//ignore validation if tmp_str is blank.
if(tmp_str != "")
 {
	var validExt = "no";
	fileStr   = tmp_str;
	intstrLen = fileStr.length;
	intLoc    = fileStr.lastIndexOf(".");
	extVal    = fileStr.substring(intLoc,intstrLen);
	extVal	  = extVal.toLowerCase();
        valExt    = fileTyp;
	var extArry   = valExt.split('#');
	var maxLng    = extArry.length;

        //alert(maxLng);

	for(i=0;i<maxLng;i++)
	{
	   //alert(extVal);
		if(extArry[i] == extVal)
		{

			validExt  = "yes";
		}
	}
	if(validExt == "no")
	{
	  return -1;
	}
 }
 return 1;
}

//************** Price validation *****************

function isPrice(numval)
{
 itPr = 1;

 //alert("sss");

  num = numval;

  PRLen = num.length;
  Len  = num.lastIndexOf(".");
  Len1  = num.lastIndexOf("-");
  extVal = num.substring(Len,PRLen);

  num = num.toString().replace(/\$|\,/g,'');

  if(isNaN(num))
  num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10)
  cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  num = num.substring(0,num.length-(4*i+3))+','+
  num.substring(num.length-(4*i+3));
  newprice = (num + '.' + cents);
  //alert (newprice);
  //alert(Len1);
  if(newprice == "0.00")
  {
  itPr = 0;
  }

 if((Len != -1)&&(extVal.length > 3))
 {
  itPr  = 0;
 }

 if(Len1 >= 0)
  {
    itPr = 0;
  }

  return itPr;
}

function getPathStr(tmp_str_path)
{
/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

  Name  : getPathStr()
  Purpose : To get path of the image for validation Img's width
      & height
  Inputs  : tmp_str_path => path of the file selected for upload
  Outputs : formated path string
  Calls  : None
  Called By :

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/

    /* convert the path to form required for Image object */
    tmp_str_imgStr = new String(tmp_str_path);

    tmp_arr_imgStr =  tmp_str_imgStr.split("\\");

    tmp_str_imgStr = "";
    for(i=0;i< tmp_arr_imgStr.length; i++)
    {
     tmp_str_imgStr += tmp_arr_imgStr[i]+"/";
    }

    tmp_int_len = tmp_str_imgStr.length;
    tmp_str_imgStr = tmp_str_imgStr.substring(tmp_str_imgStr,tmp_int_len-1);

    tmp_str_imgStr = tmp_str_imgStr.replace(":","|");
    tmp_str_imgStr = "file:///"+tmp_str_imgStr;

    return tmp_str_imgStr;
}

function preImg(doc,tmp_str_fld)
{
/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

  Name  : preImg()
  Purpose : To create Img obj & check file typ before submitting
          the form.
  Inputs  : form obj
  Outputs : Nothing
  Calls  : getPathStr()
  Called By :

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/
   eval("tmp_str_img = doc."+tmp_str_fld+".value");

   /* get formated path string required for Image object */
   tmp_str_imgStr = getPathStr(tmp_str_img);

   /* create an Image obj & assign the selected image as its source */
   img = new Image();
   img.src = tmp_str_imgStr;
}



function isImage(doc,frmVal,maxWidth,maxHeight)
{
/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

  Name         : val_image
  Purpose      : Function to check the image height and weidth
  Inputs       : doc,maxWidth,maxHeight
  Outputs      : retuns error or successfull flag
  Calls        : getPathStr() for getting image path
  Called By    :

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/

tmpRetVal = 1;

/* get formated path string required for Image object */
   tmp_str_imgStr = getPathStr(frmVal);

   /* create an Image obj & assign the selected image as its source */
   img = new Image();
   img.src = tmp_str_imgStr;
   //alert("tmp_str_imgStr="+img.src );
   tmp_int_wd = img.width;
   tmp_int_ht = img.height;
   //alert("width="+img.width);
   //alert("img.height="+img.height);
   tmp_int_maxWd = maxWidth;
   tmp_int_maxHt = maxHeight;
  // alert("maxWidth="+maxWidth );
   //alert("maxHeight="+maxHeight);

   /* if Image width is more than tmp_int_maxWd  display error */
   //if((tmp_int_wd != tmp_int_maxWd) || (tmp_int_ht != tmp_int_maxHt))
   if((tmp_int_wd > tmp_int_maxWd) || (tmp_int_ht > tmp_int_maxHt))
   {
     tmpRetVal = -1;
   }

  return tmpRetVal;
}

//************** function for validation Phone numbers *****************
function isPhoneNo(tmp_str)
{
  // Name      : isPhoneNo
  // Purpose   : allow user to enter value in phone numbers with only "-" and "." .
  // Inputs    : tmp_str -> string for validation.
  // Outputs   : return 1 -> if form field is as phone no format.
  //		 return -1 -> if form field is not as phone no format.

 Chars = "0123456789+-.";
 flag=0;

      for (i = 0; i < tmp_str.length; i++)
      {
          // Check that current character is number.
          var c = tmp_str.charAt(i);

          if (Chars.indexOf(c) == -1)
          	flag = 1;
      }
      if(flag)
      {
	  return true;
      }
}

//************** function for validates the form feilds *****************

function validate_form(doc)
{
  //On Error Resume Next;

  // Name      : validate_form.

  // Purpose   : validate the form fields.

  // Inputs    : all form feilds values

  // Outputs   : return true -> if user enter enter validate data
  //             else return false
  //             alert box displays with error message.
  // Calls     : isBlank(tmp_str) -> checks the field is blank or containing
  //		                       only white speces.
  //             isAlphaNemeric(tmp_str) -> checks the feild is Alpha-Nemeric
  //		 isNumeric(tmp_int) -> checks the field is nemeric
  //		 isEmailId(tmp_str) -> checks the field is in email id
  //		                        format(xxx@yyy.com)



 //declearing veriables

 var str;                     // stores error messages.
 var blank_field;             // stores a string of form fields and error lable for
                              // blank validation.
 var numeric_field;           // stores a string of form fields and error lable for
                              // numeric[0-9] validation.
 var AlphaNumeric_field;      // stores a string of form fields and error lable for
                              // Alpha-Numeric[A-Z]and[0-9] validation.

 var Alpha_field;     		 // stores a string of form fields and error lable for
                              // Alpha-Numeric[A-Z]and[0-9] validation.                              
 var email_field;             // stores a string of form fields and error lable for
                              // email[xxx@zz.com] validation.
 var date_field               // stores a string of form date fields and error lable for
                              // date validation
 var file_field;              // stores a string of form file fields and error lable for
                              // date validation valid extentions
 var price_field;             // stores a string of form fields and error lable for
                              // price validation
 var image_field;             // stores a string of image's maximum width and height & name

 var phone_field;             // stores a value of phone no


 			      // of form field and error lable for image validation
 var str_blank_field;         // array in which value of blank_field stored by
                              // comma separating.
 var str_numeric_field;       // array in which value of numeric_field stored by
                              // comma separating.
 var str_alphanumeric_field;  // array in which value of AlphaNumeric_field stored by
                              // comma separating.
 var str_alpha_field; 		 // array in which value of AlphaNumeric_field stored by
                              // comma separating.
                              
 var str_email_field;         // array in which value of email_field stored by
                              // comma separating.
 var str_date_field;          // array in which value of date_field stored by
                              // comma separating.
 var str_file_field;          // array in which value of file_field stored by
                              // comma separating.  allowd file extetions are
 			      // seperated by #.
 var str_price_field;         // array in which value of price_field stored by
                              // comma separating.
 var str_image_field;         // array in which value of image_field stored by
                              // comma separating.
 var arr_phone_field;         // stores a form field details of Phone fields bycomma seperated

 var tmp_valFile;             // veriable related with file and image size and width .

 tmp_valFile = "";




/* if form field is not aailable setts the null value **/
  if(typeof doc.js_Blank == "undefined")
  {
    blank_field = "";
  }
  else
  {
    blank_field = doc.js_Blank.value;
  }

  if(typeof doc.js_Numeric == "undefined")
  {
     numeric_field = "";
  }
  else
  {
      numeric_field = doc.js_Numeric.value;
  }

  if(typeof doc.js_AlphaNumeric == "undefined")
  {
      AlphaNumeric_field = "";
  }
  else
  {
      AlphaNumeric_field = doc.js_AlphaNumeric.value;
  }

if(typeof doc.js_Alpha == "undefined")
  {
      Alpha_field = "";
  }
  else
  {
      Alpha_field = doc.js_Alpha.value;
  }


  if(typeof doc.js_Email == "undefined")
  {
      email_field = "";
  }
  else
  {
      email_field = doc.js_Email.value;
  }


  if(typeof doc.js_Date == "undefined")
  {
      date_field = "";
  }
  else
  {
      date_field = doc.js_Date.value;
      
  }

  if(typeof doc.js_File == "undefined")
  {
    file_field = "";
  }
  else
  {
    file_field = doc.js_File.value;
  }

 if(typeof doc.js_Price == "undefined")
  {
    price_field = "";
  }
 else
  {
    price_field = doc.js_Price.value;
  }

  if(typeof doc.js_Image == "undefined")
  {
    image_field = "";
  }
 else
  {
    image_field = doc.js_Image.value;
  }

 if(typeof doc.js_Phone == "undefined")
  {
    phone_field = "";
  }
 else
  {
    phone_field = doc.js_Phone.value;
  }

   str = "";

   //calls function is_blank for blank validation, if blank_field is not null

     if(blank_field != "")
     {

       //creats array in which values stores without comma
        str_blank_field = blank_field.split(",");

        //loop for getting value from array for validating fields.
        for(a=0; a<str_blank_field.length; a++)
         {

            //getting error lables for messages
            tmp_str_FlType = str_blank_field[a];

             a=a+1;
             //alert(tmp_str_FlType);

            //getting field name
             tmp_str_FldName = str_blank_field[a];

            //getting value of form fields
            if(tmp_str_FlType != "mul")
            {
              tmp_str_value = eval('document.'+doc.name+'.'+str_blank_field[a]+'.value');
            }
            else
            {
              tmp_str_value = "";
            }
             a=a+1;
            //getting error lables for messages
            tmp_err_Mess2 = str_blank_field[a];

           //calls function for blank validation

             switch(tmp_str_FlType)
	     {
                case 'text':
                 tmp_Blank_validate = isBlank(tmp_str_value);
                 tmp_str_Mess1 = "Please enter ";
  	        break;
                case 'check':
                 tmp_Blank_validate = "checked";
                 if(eval('document.'+doc.name+'.'+tmp_str_FldName+'.checked') == false)
                 {
                   tmp_Blank_validate = "";
                   tmp_str_Mess1 = "Please check ";
                 }
                break;
                case 'radio':
                 tmp_Blank_validate = "";
                 tmp_str_Mess1 = "Please check ";

                 radiogroup = eval('document.'+doc.name+'.elements[tmp_str_FldName]');
                  for(var r = 0 ; r < radiogroup.length ; ++r)
	           {
	            if(radiogroup[r].checked)
	            {
	              tmp_Blank_validate = "checked";
	            }
	           }
                break;
	        case 'select':
                 tmp_Blank_validate = "selected";
                 if((eval('document.'+doc.name+'.'+tmp_str_FldName+'.selected') == true) || (tmp_str_value == ""))
                 {
                   tmp_Blank_validate = "";
                   tmp_str_Mess1 = "Please select ";
                 }
                break;
	        case 'mul':
                 tmp_Blank_validate = "selected";
                 mulCnt  = eval('document.'+doc.name+'["'+tmp_str_FldName+'"].length');
                 selMulCnt = 0;
		  /* loop through the selected titles.  */
		  for(m=0; m<mulCnt; m++)
		  {
		    tmp_str_value
		    if(eval('document.'+doc.name+'["'+tmp_str_FldName+'"]['+m+'].selected') == true)
		    {
		      if(eval('document.'+doc.name+'["'+tmp_str_FldName+'"]['+m+'].value' != ""))
		      {
		        selMulCnt++;
		      }  
		    }
		  }
		  if(selMulCnt == 0)
		  {
		    tmp_Blank_validate = "";
	            tmp_str_Mess1      = "Please select ";
                  }
                break;
            }
          //if value of tmp_validate = "", sets the error message.
          if(tmp_Blank_validate == "")
           {
              str +=  tmp_str_Mess1 + tmp_err_Mess2 + "\n";
           }
         }
     }

//calls function isNumeric for numeric validation, if numeric_field is not null

     if(numeric_field != "")
     {
       //creats array in which values stores without comma
       str_numeric_field = numeric_field.split(",");

       //loop for getting value from array for validating fields.
       for(a=0; a<str_numeric_field.length; a++)
       {
         //getting value of form fields
	 tmp_str = eval('document.'+doc.name+'.'+str_numeric_field[a]+'.value');

	  a=a+1;

	 //getting error lables for messages
	 tmp_err_message = str_numeric_field[a];



	   //calls function for Numeric(0-9) validation
	   tmp_validate = isNumeric(tmp_str);

	//if value of tmp_validate = -1 setting error message.
	if(tmp_validate == -1)
	   {
	      str += "Please enter valid " + tmp_err_message + "\n";
	   }
       }
      }

  //calls function isAlphaNumeric for AlphaNumeric validation, if AlphaNumeric_field is not null

      if(AlphaNumeric_field != "")
      {

        //creats array in which values stores without comma
        str_alphanumeric_field = AlphaNumeric_field.split(",");

         //loop for getting value from array for validating fields.
         for(a=0; a<str_alphanumeric_field.length; a++)
          {

            //getting value of form field
            tmp_str = eval('document.'+doc.name+'.'+str_alphanumeric_field[a]+'.value');

            a=a+1;

            //getting error lables for messages
            tmp_err_message = str_alphanumeric_field[a];

           //calls function for Alpha Numeric(A-Z and 0-9)  validation

           tmp_validate = isAlphaNumeric(tmp_str);

          //if value of tmp_validate = -1 setting error message
           if(tmp_validate == -1)
            {
               str += "Please enter valid" + tmp_err_message + "\n";
            }
          }
       }


  //calls function isAlpha for Alphabetic validation, if Alpha_field is not null

      if(Alpha_field != "")
            {
     
              //creats array in which values stores without comma
              str_alpha_field = Alpha_field.split(",");
      	
               //loop for getting value from array for validating fields.
               for(a=0; a<str_alpha_field.length; a++)
                {
      
                  //getting value of form field
                  tmp_str = eval('document.'+doc.name+'.'+str_alpha_field[a]+'.value');
      
                  a=a+1;
      
                  //getting error lables for messages
                  tmp_err_message = str_alpha_field[a];
      
                 //calls function for Alpha Numeric(A-Z and 0-9)  validation
      		
                 tmp_validate = isAlpha(tmp_str);
      
      
                //if value of tmp_validate = -1 setting error message
                 if(tmp_validate == -1)
                  {
                     str += "Please enter valid " + tmp_err_message + "\n";
                  }
                }
             }







 //calls function isEmailId for Email Id validation, if email_field is not null


     if(email_field != "")
     {
       //creats array in which values stores without comma
       str_email_field = email_field.split(",");

       //loop for getting value from array for validating fields.
       for(a=0; a<str_email_field.length; a++)
        {

          //getting value of form field
	  tmp_str = eval('document.'+doc.name+'.'+str_email_field[a]+'.value');

	  a=a+1;

	  //getting error lables for messages
	  tmp_err_message = str_email_field[a];



	 //calls function for Email ID(xxx@yyy.com) validation

	 tmp_validate = isEmailId(tmp_str);

	 //if value of tmp_validate = -1 setting error message
	  if(tmp_validate == -1)
	    {
	       str += "Please enter valid " + tmp_err_message + " \n";
            }
        }
     }

      //calls function isDate for Date validation, if date_field is not null

       if(date_field != "")
          {
            //creats array in which values stores without comma
            str_date_field = date_field.split(",");

            //loop for getting value from array for validating fields.
            for(a=0; a<str_date_field.length; a++)
             {

             //getting date format
             tmp_date_format = str_date_field[a];

             a=a+1;

            //getting value of form field
     	    tmp_str = eval('document.'+doc.name+'.'+str_date_field[a]+'.value');

     	    a=a+1;

     	  //getting error lables for messages
     	  tmp_err_message = str_date_field[a];



     	 //calls function for date validation

     	 tmp_validate = isDate(tmp_str,tmp_date_format);

     	 //if value of tmp_validate = -1 setting error message

         if (tmp_str  != "")
         {
     	  if(tmp_validate != "")
     	    {
     	       str += "Please enter "+ tmp_err_message + " in DD-MM-YYYY format. \n";
            }
         }
        }
     }

 //calls function isFile for file extention validation, if file_field is not null

       if(file_field != "")
          {
           tmp_valFile = "";
            //creats array in which values stores without comma
            str_file_field = file_field.split(",");

            //loop for getting value from array for validating fields.
            for(a=0; a<str_file_field.length; a++)
             {
              //getting file extention format
              tmp_file_extention = str_file_field[a];
              a=a+1;

             //getting value of form field

     	     tmp_str = eval('document.'+doc.name+'.'+str_file_field[a]+'.value');

     	    a=a+1;

     	  //getting error lables for messages
     	  tmp_err_message = str_file_field[a];

     	 if(tmp_str != "")
     	 {
     	 //calls function for file validation

     	 tmp_validate = isFile(tmp_str,tmp_file_extention);

     	 //alert(tmp_validate);

     	 //if value of tmp_validate = -1 setting error message

     	  if(tmp_validate == -1)
     	    {
     	       /* Replace the # TAGs with "," */
	       var brk       = new RegExp('#','gi');
	       tmp_file_extention = tmp_file_extention.replace(brk,", ");

     	       str += "please upload "+tmp_file_extention+" extension file for "+tmp_err_message+ "\n";
            }
          else
            {
              tmp_valFile = "done";
            }
          }
         }
     }

 //calls function isPrice for Price validation, if price_field is not null

     if(price_field != "")
     {
       //creats array in which values stores without comma
       str_price_field = price_field.split(",");

       //loop for getting value from array for validating fields.
       for(a=0; a<str_price_field.length; a++)
        {
          //getting value of form field
	  tmp_str = eval('document.'+doc.name+'.'+str_price_field[a]+'.value');
	  a=a+1;

	  //getting error lables for messages
	  tmp_err_message = str_price_field[a];

	 //calls function for Price(99.99) validation

	 if(tmp_str != "")
	 {
	   tmp_validate = isPrice(tmp_str);

	 //if value of tmp_validate = 0 setting error message
	  if(tmp_validate == 0)
	    {
	       str += "Please enter "+tmp_err_message+" Price in 9.99(Price) format.\n";
            }
         }

        }
     }

 //calls function isImage for image height and width validation, if image_field is not null

      //alert(tmp_valFile);

       if((image_field != "") && (tmp_valFile == "done"))
          {
            //creats array in which values stores without comma
            arr_image_field = image_field.split(",");

            //loop for getting value from array for validating fields.
            for(a=0; a<arr_image_field.length; a++)
             {
              //getting the images height and width
              tmp_image_dim = arr_image_field[a];
              a=a+1;

              tmp_arr_dimention = tmp_image_dim.split("#");
              tmp_int_width = tmp_arr_dimention[0];
              tmp_int_height = tmp_arr_dimention[1];

             //getting value of form field
     	     tmp_str = eval('document.'+doc.name+'.'+arr_image_field[a]+'.value');
     	     a=a+1;

     	  //getting error lables for messages
     	  tmp_err_message = arr_image_field[a];
     	  //alert(tmp_err_message);

     	    if(tmp_str != "")
             {
     	         //calls function for file validation

     	          tmp_validate = isImage(doc,tmp_str,tmp_int_width,tmp_int_height);

     	          //if value of tmp_validate = -1 setting error message

     	          if(tmp_validate == -1)
     	          {
     	            str += tmp_err_message+" image width and height should be "+tmp_int_width+" by "+tmp_int_height+" pixels. \n";
                  }
             }
          }
     }

//calls function isPhoneNo for validating values for phone numbers
     if(phone_field != "")
     {
       //creats array in which values stores without comma
       arr_phone_field = phone_field.split(",");

       //loop for getting value from array for validating fields.
       for(a=0; a<arr_phone_field.length; a++)
       {
         //getting value of form fields
	 tmp_str = eval('document.'+doc.name+'.'+arr_phone_field[a]+'.value');

	  a=a+1;

	 //getting error lables for messages
	 tmp_err_message = arr_phone_field[a];


	   //calls function for phone no. validation
	   tmp_validate = isPhoneNo(tmp_str);

	//if value of tmp_validate = -1 setting error message.
	if(tmp_validate)
	   {
	      str += "Please enter valid " + tmp_err_message + "\n";
	   }
       }
      }

// if str contains the error messages return false
// else return true

   if(str)
    {
       alert(str);
       return false;
    }
   else
    {
       return true;
    }

}

function valid_char(doc)
{
	txtChar = doc.value;
	txtVal  = new String(txtChar);
	txtLen  = txtVal.length;


	txtArr  = txtVal.split("\n");
	brkNum  = txtArr.length;
	manLine = brkNum;

	for(i=0;i<brkNum;i++)
	{

		if(txtArr[i].length < 24)
		{
			txtLen = txtLen + (23 - (txtArr[i].length));
		}

		if(txtArr[i].length > 23)
		{
			parLine = txtArr[i].length;
			manLine = manLine + Math.ceil(parLine/23);
		}

	}

	if(txtLen >= 235 || manLine > 13)
	{
	   alert("Maximum 235 characters including white space and line breaks are allowed");
	   doc.focus();
	   return false;
	}
}

function valid_space(doc)
{
	txtChar = doc.value;
	txtVal = new String(txtChar);
	txtLen = txtVal.length;

	if(txtLen > 18)
	{
		txtArr  = txtVal.split("\n");
		brkNum  = txtArr.length;

		for(j=0;j<brkNum;j++)
		{

			spcArr  = txtArr[j].split(" ");
			spcNum  = spcArr.length;

			for(i=0;i<spcNum;i++)
			{
				if(spcArr[i].length > 18)
				{
					alert("Please write 'Description' text with word spacing and line break.\n Words having 18 or more letters can break the site design.");
					doc.focus();
					return false;
				}
			}
		}
	}
}

function submit_form(frm_name)
{   
  eval('frm_name.submit();');
}

function setaccept(frm,accept)
{
	eval("thisDoc = document."+frm)
	thisDoc['accept'].value = accept;
	return true;
}
function isDeleteRec(frm,name)
{
	eval("thisDoc = document."+frm)
	
	if(confirm("Are you sure you want to delete?"))
	{
		thisDoc[name].value = "yes";
		return true;
	}
	else
	{
		return false;
	}
}
  /* 
 * Cross-browser event handling, by Scott Andrew
 */
function addEvent(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return true;
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return r;
    } else {
        return false;
    }
}

/* 
 * Kills an event's propagation and default action
 */
function knackerEvent(eventObject) {
    if (eventObject && eventObject.stopPropagation) {
        eventObject.stopPropagation();
    }
    if (window.event && window.event.cancelBubble ) {
        window.event.cancelBubble = true;
    }
    
    if (eventObject && eventObject.preventDefault) {
        eventObject.preventDefault();
    }
    if (window.event) {
        window.event.returnValue = false;
    }
}

/* 
 * Safari doesn't support canceling events in the standard way, so we must
 * hard-code a return of false for it to work.
 */
function cancelEventSafari() {
    return false;        
}

/* 
 * Cross-browser style extraction, from the JavaScript & DHTML Cookbook
 * <http://www.oreillynet.com/pub/a/javascript/excerpt/JSDHTMLCkbk_chap5/index5.html>
 */
function getElementStyle(elementID, CssStyleProperty) {
    var element = document.getElementById(elementID);
    if (element.currentStyle) {
        return element.currentStyle[toCamelCase(CssStyleProperty)];
    } else if (window.getComputedStyle) {
        var compStyle = window.getComputedStyle(element, '');
        return compStyle.getPropertyValue(CssStyleProperty);
    } else {
        return '';
    }
}

/* 
 * CamelCases CSS property names. Useful in conjunction with 'getElementStyle()'
 * From <http://dhtmlkitchen.com/learn/js/setstyle/index4.jsp>
 */
function toCamelCase(CssProperty) {
    var stringArray = CssProperty.toLowerCase().split('-');
    if (stringArray.length == 1) {
        return stringArray[0];
    }
    var ret = (CssProperty.indexOf("-") == 0)
              ? stringArray[0].charAt(0).toUpperCase() + stringArray[0].substring(1)
              : stringArray[0];
    for (var i = 1; i < stringArray.length; i++) {
        var s = stringArray[i];
        ret += s.charAt(0).toUpperCase() + s.substring(1);
    }
    return ret;
}

/*
 * Disables all 'test' links, that point to the href '#', by Ross Shannon
 */
function disableTestLinks() {
  var pageLinks = document.getElementsByTagName('a');
  for (var i=0; i<pageLinks.length; i++) {
    if (pageLinks[i].href.match(/[^#]#$/)) {
      addEvent(pageLinks[i], 'click', knackerEvent, false);
    }
  }
}

/* 
 * Cookie functions
 */
function createCookie(name, value, days) {
    var expires = '';
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days*24*60*60*1000));
        var expires = '; expires=' + date.toGMTString();
    }
    document.cookie = name + '=' + value + expires + '; path=/';
}

function readCookie(name) {
    var cookieCrumbs = document.cookie.split(';');
    var nameToFind = name + '=';
    for (var i = 0; i < cookieCrumbs.length; i++) {
        var crumb = cookieCrumbs[i];
        while (crumb.charAt(0) == ' ') {
            crumb = crumb.substring(1, crumb.length); /* delete spaces */
        }
        if (crumb.indexOf(nameToFind) == 0) {
            return crumb.substring(nameToFind.length, crumb.length);
        }
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, '', -1);
}
addEvent(window, 'load', init, false);

function init() {
    var formInputs = document.getElementsByTagName('input');
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        
        if (theInput.type == 'text' && theInput.className.match(/\bcleardefault\b/)) {  
            /* Add event handlers */          
            addEvent(theInput, 'focus', clearDefaultText, false);
            addEvent(theInput, 'blur', replaceDefaultText, false);
            
            /* Save the current value */
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
        }
        
        if (theInput.type == 'password' && theInput.className.match(/\bcleardefault\b/)) {  
       
	            /* Add event handlers */          
	            addEvent(theInput, 'focus', clearDefaultText, false);
	            addEvent(theInput, 'blur', replaceDefaultText, false);
	            
	            /* Save the current value */
	            if (theInput.value != '') {
	                theInput.defaultText = theInput.value;
	            }
        }
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
    }
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function compare_dates(dat1,dat2,age,gender)
{
//alert(dat1+"\n"+dat2);
  var flag = 0;

  dat1 = dat1.toString();
  var dtSplt1 = dat1.split("/");
  dat2 = dat2.toString();
  var dtSplt2 = dat2.split("/");

  var eYr = parseInt(dtSplt2[0],10);
  var eMn = parseInt(dtSplt2[1],10);
  var eDy =parseInt(dtSplt2[2],10);

  var sYr = parseInt(dtSplt1[0],10);
  var sMn = parseInt(dtSplt1[1],10);
  var sDy = parseInt(dtSplt1[2],10);


    if(eYr > sYr)
    {
      diff=eYr-sYr;

      if(diff<age)
      {
      return gender+" age should be equal to or more than "+age+"\n";
      }
      else
      {
      return "";
      }
    }
    else
    {
    return gender+" age should be equal to or more than "+age+"\n";
    }

    
}
function check_box(dml,chkName,msg)
{
	len = dml.elements.length;
	var i=0;
	var p=0;
	for( i=0 ; i<len ; i++)
	{
	
		if ((dml.elements[i].name==chkName) && (dml.elements[i].checked==true))
		
		{

		p=1;
			
		}
	}
	if(p!=1)
	{
	return(msg)
	}
	else
	{
	return ""
	}
}
function checkcheckbox(checkvalue,msg1)
{

	var error="";
	if((checkvalue!="true") && (checkvalue!="1"))
	{
	error="Please check "+msg1;
	}
	return error;
}
function isFile(tmp_str,fileTyp)
{
  // Name      : isFile.
  // Purpose   : validation for File extention
  // Inputs    : tmp_str -> string for validations.
  //	         fileTyp -> file extention type.
  // Outputs   : return 1 -> if form field is valid
  //		 return -1 -> if form field is unvalid



if(tmp_str != "")
 {
	var validExt = "no";
	fileStr   = tmp_str;
	intstrLen = fileStr.length;
	intLoc    = fileStr.lastIndexOf(".");
	extVal    = fileStr.substring(intLoc,intstrLen);
	extVal	  = extVal.toLowerCase();
        valExt    = fileTyp;
	var extArry   = valExt.split('//');
	var maxLng    = extArry.length;


	for(i=0;i<maxLng;i++)
	{
	   //alert(extVal);
		if(extArry[i] == extVal)
		{

			validExt  = "yes";
		}
	}
	if(validExt == "no")
	{
	  return -1;
	}
 }
 return 1;
}

function image_validate2(image,msg,ext)
{
var error="";
	if(image.value!="")
	{
	
	var image_field;
	var str_image_field;
	
	var str_file_field = new Array();
	jsfile=ext+", "+image.value+", "+msg;
	
	file_field_id = jsfile;
	tmp_valFile = "";
	str_file_field = file_field_id.split(",");
	
	for(a=0; a<str_file_field.length; a++)
      	{
        	
        	tmp_file_extention = str_file_field[a];
        	
        	
        	a=a+1;
        	tmp_str = str_file_field[a];
        	
        	a=a+1;
        	tmp_err_message = str_file_field[a];
        	if(tmp_str != "")
        	{
        		tmp_validate = isFile(tmp_str, tmp_file_extention);
        		if(tmp_validate == -1)
			{
				var brk       = new RegExp('//','gi');
				tmp_file_extention = tmp_file_extention.replace(brk,", ");
				error  = "Please upload "+tmp_file_extention+" extension file for"+msg+"\n";
			        
          		}
        	}
        	else
		{
		       tmp_valFile = "done";
          	}
      	}
      	}
 	return error;
}


// to set the form checked and unchecked.

function SetChecked(val,chkName) 
{
	dml=document.forms[form];
	len = dml.elements.length;
	var i=0;
	for( i=0 ; i<len ; i++) {
	if (dml.elements[i].name==chkName) {
	dml.elements[i].checked=val;
	}
	}
}
function getconfirmation(theform)
{
	
	theform.pagenavigate.value="confirmation";	
	theform.prod_id.value=theform.productid.value;
	theform.catid.value=theform.catid.value;
	theform.submit();
}
function getprodimg(theform)
{

	theform.pagenavigate.value="imageform";
	
	theform.catid.value=theform.catid.value;
	theform.productid.value=theform.productid.value;
	theform.subprodid.value=theform.subprodid.value;
	theform.parent_catid.value=theform.parent_catid.value;
	theform.action.value=theform.action.value;
	
	theform.submit();
}



function getprod_info(theform)
{

	if(theform.action.value=="add")
	{
	theform.pagenavigate.value="Addprodinfo";
	}
	if(theform.action.value=="modify")
	{
	theform.pagenavigate.value="modifyprodinfo";
	}
	//theform.category_ids.value=theform.chk_cat.value;
	theform.submit();
}
function getprodinfo(theform)
{

	if(theform.action.value=="add")
	{
	theform.pagenavigate.value="Addprodinfo";
	}
	if(theform.action.value=="modify")
	{
	theform.pagenavigate.value="modifyprodinfo";
	}
	theform.category_ids.value=theform.catid.value;
	theform.catid.value=theform.catid.value;
	theform.submit();
}
function submit_login_form1()
{
	return check_blank(document.frmlogin.uname,"Enter Username");
	return check_blank(document.frmlogin.pwd,"Enter Password");
}

function check_blank1(object,msg)
{
	if(object.value=="")
	{
		alert(msg);
		object.focus();
		return false;
	}
}

function addsubcategory(catid)
{

	document.frmcat.pagenavigate.value="Add";
	document.frmcat.category_ids.value=catid;
	document.frmcat.submit();
}

function changecat()
{


	document.frmcategory.parent_catid.value=document.frmcategory.parent_ids.value;
	document.frmcategory.catid.value=document.frmcategory.catid.value;
	document.frmcategory.childcat.value=document.frmcategory.childcat.value;
	if(document.frmcategory.action.value=="Add")
	{
		document.frmcategory.pagenavigate.value="Addlist";
	}
	if(document.frmcategory.action.value=="Modify")
	{
		document.frmcategory.pagenavigate.value="Modifylist";
	}
	document.frmcategory.submit();
}

function changeprodcat(theform)
{


	theform.parent_catid.value=theform.parent_id.value;
	theform.productid.value=theform.productid.value;
	if(theform.action.value=="add")
	{
		theform.pagenavigate.value="Addlist";
	}
	if(theform.action.value=="modify")
	{
		theform.pagenavigate.value="Modifylist";
	}
	theform.submit();
}



function checkform(theForm) {
    var why = "";
    why += checkEmail(theForm.email.value);
    why += checkPhone(theForm.phone.value);
    why += checkPassword(theForm.password.value);
    why += checkUsername(theForm.username.value);
    why += isEmpty(theForm.notempty.value);
    why += isDifferent(theForm.different.value);
    for (i=0, n=theForm.radios.length; i<n; i++) {
        if (theForm.radios[i].checked) {
            var checkvalue = theForm.radios[i].value;
            break;
        } 
    }
    why += checkRadio(checkvalue,"Please check");
    why += checkDropdown(theForm.choose.selectedIndex);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

// delete product
function deleteproduct(prod_id)
{
	if(confirm("Are you sure to delete?"))
	{

	document.frmproduct.pagenavigate.value="deleteprod";
	document.frmproduct.prod_id.value=prod_id;
	document.frmproduct.leftcatid.value=document.frmproduct.leftcatid.value;
	document.frmproduct.submit();
	}
}

// modify image
function editimage(prod_id,catid)
{

	document.frmproduct.pagenavigate.value="imageform";
	document.frmproduct.prod_id.value=prod_id;
	document.frmproduct.chk_catidarray.value=catid;
	document.frmproduct.catid.value=catid;
	document.frmproduct.action_edit.value="modify";	
	document.frmproduct.submit();
}



// modify product info
function editproduct(prod_id,catid)
{

	document.frmproduct.pagenavigate.value="modifyprodinfo";
	document.frmproduct.prod_id.value=prod_id;
	document.frmproduct.leftcatid.value=document.frmproduct.leftcatid.value;
	
	//document.frmproduct.catid.value=catid;
	document.frmproduct.action_edit.value="modify";	
	document.frmproduct.submit();
}

// image validation

function image_validate(image,imagetype)
{
 var error = "";
	if(image.value=="")
	{
	error="Please attach an image.\n";
	}
	return error;
}

function image_validate21(image,imagetype)
{
 var error = "";
	if(image.value!="")
	{
		var image1 = new Image();
		image1.src = image.value;
		width=image1.width;
		height=image1.height;
		alert(imagetype);
		if (!/(\.(imagetype))$/i.test(image.value))
		{
		error ="Please attach "+imagetype+" image.\n";
		//image.focus();
		//return false;
		}
		return error;
	}
	else
	{
		return error;
	}
	
}

// calls form login page
function submit_login_form(theForm) {
    var why = "";

    why += isEmpty(theForm.uname.value,"Please enter username");
	//why += checkUsername(theForm.uname.value);
why += isEmpty(theForm.pwd.value,"Please enter password");
	//why += checkPassword(theForm.pwd.value);
    if (why != "") 
    {
       alert(why);
       return false;
    }   
return true;
}// end of submit_login_form




// calls from submit_change_pwd() from clschangepwd.php
function submit_change_pwd(theForm) {
    var why = "";
    why += isEmpty(theForm.oldpwd.value,"Please enter current password");
    why += isEmpty(theForm.newpwd.value,"Please enter new password");
    why += isEmpty(theForm.confirmpwd.value,"Please enter confirm password");
    if((theForm.newpwd.value!="")&&(theForm.confirmpwd.value!=""))
    {
    why += compareValues(theForm.newpwd.value,theForm.confirmpwd.value,"New and confirm password should be same");
    }
    if (why != "") 
    {
       alert(why);
       return false;
    }   
return true;
}// end of submit_login_form



// check two values should be same
function compareValues(firstval,secondval,msg)
{
var error="";
	if(firstval!=secondval)
	{
	error=msg;	
	}
	return error;
}

// email

function checkEmail(mailids) {
var error="";
if (mailids == "") {
   error = "You didn't enter an email address.\n";
}

    var error = "";
var arr = new Array('.com','.net','.org','.biz','.coop','.info','.museum','.name','.pro'
,'.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag','.ai','.al',
'.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw','.az','.ba','.bb',
'.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm','.bn','.bo','.br','.bs',
'.bt','.bv','.bw','.by','.bz','.ca','.cc','.cd','.cf','.cg','.ch','.ci',
'.ck','.cl','.cm','.cn','.co','.cr','.cu','.cv','.cx','.cy','.cz','.de',
'.dj','.dk','.dm','.do','.dz','.ec','.ee','.eg','.eh','.er','.es','.et',
'.fi','.fj','.fk','.fm','.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh',
'.gi','.gl','.gm','.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy',
'.hk','.hm','.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io',
'.iq','.ir','.in','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki',
'.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li','.lk',
'.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg','.mh','.mk',
'.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt','.mu','.mv','.mw',
'.mx','.my','.mz','.na','.nc','.ne','.nf','.ng','.ni','.nl','.no','.np',
'.nr','.nu','.nz','.om','.pa','.pe','.pf','.pg','.ph','.pk','.pl','.pm',
'.pn','.pr','.ps','.pt','.pw','.py','.qa','.re','.ro','.rw','.ru','.sa',
'.sb','.sc','.sd','.se','.sg','.sh','.si','.sj','.sk','.sl','.sm','.sn',
'.so','.sr','.st','.sv','.sy','.sz','.tc','.td','.tf','.tg','.th','.tj',
'.tk','.tm','.tn','.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug',
'.uk','.um','.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu',
'.ws','.wf','.ye','.yt','.yu','.za','.zm','.zw','.co','.uk');
 
var mai = mailids;
var val = true;
var beforeat="";
var afterat="";
var afterat2="";
 
var dot=mai.lastIndexOf(".");
var con=mai.substring(dot, mai.length);
con=con.toLowerCase();
con=con.toString();
 
for(var i=0;i<(arr.length);i++)
{
 
 if(con == arr[i])
 {
  //alert(arr[i]);
  val=true;
  break;
 }
 else
 {
  //alert(con + " " +arr[i]);
  val=false;
 }
}
 
var att=mai.lastIndexOf("@");
beforeat=mai.substring(0,att);
beforeat=beforeat.toLowerCase();
beforeat=beforeat.toString();
var asci1=beforeat.charCodeAt(0);
 
afterat=mai.substring(att+1, dot);
afterat=afterat.toLowerCase();
afterat=afterat.toString();
 
afterat2=mai.substring(att+1, mai.length);
afterat2=afterat2.toLowerCase();
afterat2=afterat2.toString();
 
if(beforeat=="" || afterat=="" || beforeat.length>30)
 val=false;
 
if(afterat2.length>64 || afterat.length<2)
 val=false;
 
if((afterat.charCodeAt(0))==45 || (afterat.charCodeAt(afterat.length-1))==45)
 val=false;
 
if(val==true)
{
 if(asci1 > 47 && asci1 < 58)
  val=false;
 //alert(val);
  
 if(asci1 < 48 || asci1 > 57)
 {
  for(var i=0; i<=beforeat.length-1; i++)
  {
   var asci2=beforeat.charCodeAt(i);
   if((asci2<=44 || asci2==47) || (asci2>=58 && asci2<=94) || (asci2==96) || (asci2>=123 && asci2<=127))
   {
    val=false;
    break;
   }
  }
  //alert(val);
  
  for(var j=0; j<=afterat.length-1; j++)
  {
   var asci3=afterat.charCodeAt(j);
   //alert(asci3);
   if((asci3<=44)   || (asci3==47) || (asci3>=58 && asci3<=96) || (asci3>=123 && asci3<=127))
   {
    val=false;
    break;
   }
  } 
   
 }
}
 
if(val==false)
{
  error = "Please enter a valid email address.\n";
 
}
return error;  
}


function checkEmail_notcomp(mailids,msg1) {

var error = "";
if (mailids != "") 
{

var arr = new Array('.com','.net','.org','.biz','.coop','.info','.museum','.name','.pro'
,'.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag','.ai','.al',
'.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw','.az','.ba','.bb',
'.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm','.bn','.bo','.br','.bs',
'.bt','.bv','.bw','.by','.bz','.ca','.cc','.cd','.cf','.cg','.ch','.ci',
'.ck','.cl','.cm','.cn','.co','.cr','.cu','.cv','.cx','.cy','.cz','.de',
'.dj','.dk','.dm','.do','.dz','.ec','.ee','.eg','.eh','.er','.es','.et',
'.fi','.fj','.fk','.fm','.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh',
'.gi','.gl','.gm','.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy',
'.hk','.hm','.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io',
'.iq','.ir','.in','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki',
'.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li','.lk',
'.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg','.mh','.mk',
'.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt','.mu','.mv','.mw',
'.mx','.my','.mz','.na','.nc','.ne','.nf','.ng','.ni','.nl','.no','.np',
'.nr','.nu','.nz','.om','.pa','.pe','.pf','.pg','.ph','.pk','.pl','.pm',
'.pn','.pr','.ps','.pt','.pw','.py','.qa','.re','.ro','.rw','.ru','.sa',
'.sb','.sc','.sd','.se','.sg','.sh','.si','.sj','.sk','.sl','.sm','.sn',
'.so','.sr','.st','.sv','.sy','.sz','.tc','.td','.tf','.tg','.th','.tj',
'.tk','.tm','.tn','.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug',
'.uk','.um','.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu',
'.ws','.wf','.ye','.yt','.yu','.za','.zm','.zw','.co','.uk');
 
var mai = mailids;
var val = true;
var beforeat="";
var afterat="";
var afterat2="";
 
var dot=mai.lastIndexOf(".");
var con=mai.substring(dot, mai.length);
con=con.toLowerCase();
con=con.toString();
 
for(var i=0;i<(arr.length);i++)
{
 
 if(con == arr[i])
 {
  //alert(arr[i]);
  val=true;
  break;
 }
 else
 {
  //alert(con + " " +arr[i]);
  val=false;
 }
}
 
var att=mai.lastIndexOf("@");
beforeat=mai.substring(0,att);
beforeat=beforeat.toLowerCase();
beforeat=beforeat.toString();
var asci1=beforeat.charCodeAt(0);
 
afterat=mai.substring(att+1, dot);
afterat=afterat.toLowerCase();
afterat=afterat.toString();
 
afterat2=mai.substring(att+1, mai.length);
afterat2=afterat2.toLowerCase();
afterat2=afterat2.toString();
 
if(beforeat=="" || afterat=="" || beforeat.length>30)
 val=false;
 
if(afterat2.length>64 || afterat.length<2)
 val=false;
 
if((afterat.charCodeAt(0))==45 || (afterat.charCodeAt(afterat.length-1))==45)
 val=false;
 
if(val==true)
{
 if(asci1 > 47 && asci1 < 58)
  val=false;
 //alert(val);
  
 if(asci1 < 48 || asci1 > 57)
 {
  for(var i=0; i<=beforeat.length-1; i++)
  {
   var asci2=beforeat.charCodeAt(i);
   if((asci2<=44 || asci2==47) || (asci2>=58 && asci2<=94) || (asci2==96) || (asci2>=123 && asci2<=127))
   {
    val=false;
    break;
   }
  }
  //alert(val);
  
  for(var j=0; j<=afterat.length-1; j++)
  {
   var asci3=afterat.charCodeAt(j);
   //alert(asci3);
   if((asci3<=44)   || (asci3==47) || (asci3>=58 && asci3<=96) || (asci3>=123 && asci3<=127))
   {
    val=false;
    break;
   }
  } 
   
 }
}
 
if(val==false)
{
  error = msg1+"\n";
 
}
}
return error;
}



function checkboxvalidate(dml,chkName,chkboxvalidation){

len = dml.elements.length;
var i=0;
for( i=0 ; i<len ; i++) {
if ((dml.elements[i].name==chkName) && (dml.elements[i].checked==1)) return true
}
	retrun(chkboxvalidation);

}

// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng,msg) {
var error = "";
if (strng == "") {
   error = "Please Enter a "+msg+" number.\n";
}
else
{
var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The "+msg+" number contains illegal characters.\n";
  
    }
}	
   /* if (!(stripped.length == 10)) {

	error = "The "+msg+" contact number should be equal to 10 characters\n";
    } */
return error;
}


// password - between 5 chars, uppercase, lowercase, and numeral

function checkPassword (strng) {
var error = "";
if (strng == "") {
   error = "Please enter a password.\n";
}
else{
    var illegalChars = /[\W_]/; // allow only letters and numbers
    
   if ((strng.length < 6) || (strng.length > 14)) {
    //if (strng.length < 6) {
       error = "The password is of wrong length.It should be greater than 5 and less than 14\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
    } 
   // else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
       //error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    //} 
}	
return error;    
} 

// password - between 5 chars, uppercase, lowercase, and numeral

function checknewPassword (strng) {
var error = "";
if (strng == "") {
   error = "Please enter a New password.\n";
}
else{
    var illegalChars = /[\W_]/; // allow only letters and numbers
    
   if ((strng.length < 6) || (strng.length > 14)) {
    //if (strng.length < 6) {
       error = "The password is of wrong length.It should be greater than 5 and less than 14\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
    } 
   // else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
       //error = "New password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    //} 
}	
return error;    
} 

// for confirmed password - between 5 chars, uppercase, lowercase, and numeral

function checkPasswordConfirm (strng) {
var error = "";
if (strng == "") {
   error = "Please enter confirm password.\n";
}
else
	{
    var illegalChars = /[\W_]/; // allow only letters and numbers
    
    //if ((strng.length < 6) || (strng.length > 8)) {
     if (strng.length < 6) {
       error = "The confirm password is of wrong length.It should be greater than 5\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The confirm password contains illegal characters.\n";
    } 
    //else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
     //  error = "The confirm password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    //}  
}
return error;    
} 

// username - 4-10 chars, uc, lc, and underscore only.

function checkUsername (strng) {

var error = "";
if (strng == "") {
   error = "Please enter a username.\n";
}
else{

    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 6) || (strng.length > 14)) {
       error = "The username is the wrong length.It should be greater than 5 and less than 14\n";
    }
    else if (illegalChars.test(strng)) {
    error = "The username contains illegal characters.\n";
    } 
}
return error;
}       


// non-empty textbox

function isEmpty(strng,msg) {
strng = trim(strng);
var error = "";
  if (strng.length == 0) {
     error = msg+"\n";
  }
return error;	  
}

// non-empty textbox

function isInt(strng,msg) 
{
	var error = "";

	if (strng.length != 0) 
	{
		if (isNaN(strng)==true) 
		{
		
			error = msg+"\n";

		}
		else if(parseInt(strng)==0)
		{
			error=msg+"\n";

		}

	}
	return error;	

}

function isInt_noNeg(strng,msg,msg1) 
{
	var error = "";

	if (strng.length != 0) 
	{
		if (isNaN(strng)==true) 
		{
		
			error = msg+"\n";

		}
		else if(strng<0)
		{
					error="Please enter non-negative value in "+msg1+"\n";
		}
		else if(parseInt(strng)==0)
		{
			error=msg+"\n";
		}
	}
	return error;	
}

function isInt1(strng,msg,msg1) 
{
	var error = "";
    	
	if (strng.length != 0) 
	{
		if (isNaN(strng)==true) 
		{
			
			error = msg+"\n";

		}
		else if(strng<0)
		{
			error="Please enter non-negative value in "+msg1+"\n";
		}
		else
		{
			var arrParts = strng.split('.');
			if(arrParts.length > 1)        
			{             
				error="Please enter non-decimal value in "+msg1+"\n";    
			}
			
		}
		/*else if(parseInt(strng)==0)
		{
			error=msg+"\n";

		}*/

	}
	else
	{
	error=msg1+"\n"; 
	}
	return error;	

}

function isInt2(strng,msg,msg1) 
{
	var error = "";
    var quantity=0;	
		
	if (strng.length != 0) 
	{
		if (isNaN(strng)==true) 
		{
			
			error = msg+"\n";

		}
		
		quantity=parseInt(strng);
		
		if(quantity<0)
		{
			error=msg+"\n";
		}
		else
		{
			var arrParts = strng.split('.');
			if(arrParts.length > 1)        
			{             
				error="Please enter non-decimal value in "+msg1+"\n";    
			}
			
		}
		/*else if(parseInt(strng)==0)
		{
			error=msg+"\n";

		}*/

	}
	else
	{
	error=msg1+"\n"; 
	}
	return error;	

}


//compare greater values
function compareGreterValues(min,max,string)
{

min=parseInt(min);
max=parseInt(max);
if((min!="")&&(max!=""))
{
if(!((isNaN(min))&&(isNaN(max))))
{
if(max<min)
{
return string+"\n";
}
else
{
return "";
}
}
}

}


//  price validation
function isPrice(strng,msg,msg1) 
{
	var error = "";
	var x=0;
	
	if (strng.length==0) {
	
	     error = msg1+"\n";
 	 }
	 else
	 {
	 x=parseInt(strng);
	if(isPrice_check(strng)==1)
	{
		error= msg+" Should be in format for eg. 12.00 "+"\n";
	}
	 }
	
 	 
	
	return error;
}

function isPrice_check(numval)
{
 itPr = 1;

 //alert("sss");
if(numval==0)
{
itPr = 1;
}
else
{
  num = numval;

  PRLen = num.length;
  Len  = num.lastIndexOf(".");
  Len1  = num.lastIndexOf("-");
  extVal = num.substring(Len+1,PRLen);

  if(Len>0)
  {
  	tmp_int_digit = (PRLen-Len);
  }
  else
  {
  	tmp_int_digit = 0;
  }

  //alert(tmp_int_digit);

  num = num.toString().replace(/\$|\,/g,'');
  //num = num.toString().replace(/\$|/g,'');


  if(isNaN(num))
  num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10)
  cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  num = num.substring(0,num.length-(4*i+3))+','+
  num.substring(num.length-(4*i+3));
  newprice = (num + '.' + cents);
  //alert (newprice);
  //alert(Len1);

  //alert(sign);


  if(newprice == "0.00")
  {
  itPr = 1;
  }

 if((Len != -1)&&(extVal.length > 1))
 {
  itPr  = 0;
 }
}

  return itPr;
}

// was textbox altered

function isDifferent(strng) {
var error = ""; 
  if (strng != "Can\'t touch this!") {
     error = "You altered the inviolate text area.\n";
  }
return error;
}

// exactly one radio button is chosen

function checkRadio(checkvalue,msg) {
var error = "";
   if (!(checkvalue)) {
       error = msg+".\n";
    }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice,listname) {

var error = "";
    if (choice == 0) {
    error="Please select "+listname+"\n";
    }    
return error;
}    

// checking new and confirm password are 

function chkNewConfirmPwd(strng1,strng2,msg) {

var error = "";
  if (strng1 != strng2) 
  {
     error = msg+"\n";
  }
 
return error;	  
}


 // username - 4-10 chars, uc, lc, and underscore only.
 
 function CurrencyType(strng) {
 
 var error = "";
 if (strng == "") {
    error = "Please enter a currency type.\n";
 }
 else
 {	 
     var illegalChars = /\W/; // allow letters, numbers, and underscores
     if (illegalChars.test(strng)) {
     error = "The currency type contains illegal characters.\n";
     }

	/*var re = /^[A-Za-z]\w{6,}[A-Za-z]$/;
	if (!re.test(strng)) {
		error = "Please enter a valid currency type!\n";
		}*/

	 //var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
	   //if (isNaN(parseInt(stripped))) {
      // error = "The phone number contains illegal characters.";
    //  }
 }

 return error;
 }       
function checkEmail1(mailids,msg1)
{
 var error = "";
var arr = new Array('.com','.net','.org','.biz','.coop','.info','.museum','.name','.pro'
,'.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag','.ai','.al',
'.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw','.az','.ba','.bb',
'.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm','.bn','.bo','.br','.bs',
'.bt','.bv','.bw','.by','.bz','.ca','.cc','.cd','.cf','.cg','.ch','.ci',
'.ck','.cl','.cm','.cn','.co','.cr','.cu','.cv','.cx','.cy','.cz','.de',
'.dj','.dk','.dm','.do','.dz','.ec','.ee','.eg','.eh','.er','.es','.et',
'.fi','.fj','.fk','.fm','.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh',
'.gi','.gl','.gm','.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy',
'.hk','.hm','.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io',
'.iq','.ir','.in','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki',
'.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li','.lk',
'.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg','.mh','.mk',
'.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt','.mu','.mv','.mw',
'.mx','.my','.mz','.na','.nc','.ne','.nf','.ng','.ni','.nl','.no','.np',
'.nr','.nu','.nz','.om','.pa','.pe','.pf','.pg','.ph','.pk','.pl','.pm',
'.pn','.pr','.ps','.pt','.pw','.py','.qa','.re','.ro','.rw','.ru','.sa',
'.sb','.sc','.sd','.se','.sg','.sh','.si','.sj','.sk','.sl','.sm','.sn',
'.so','.sr','.st','.sv','.sy','.sz','.tc','.td','.tf','.tg','.th','.tj',
'.tk','.tm','.tn','.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug',
'.uk','.um','.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu',
'.ws','.wf','.ye','.yt','.yu','.za','.zm','.zw','.co','.uk');
 
var mai = mailids;
var val = true;
var beforeat="";
var afterat="";
var afterat2="";
 
var dot=mai.lastIndexOf(".");
var con=mai.substring(dot, mai.length);
con=con.toLowerCase();
con=con.toString();
 
for(var i=0;i<(arr.length);i++)
{
 
 if(con == arr[i])
 {
  //alert(arr[i]);
  val=true;
  break;
 }
 else
 {
  //alert(con + " " +arr[i]);
  val=false;
 }
}
 
var att=mai.lastIndexOf("@");
beforeat=mai.substring(0,att);
beforeat=beforeat.toLowerCase();
beforeat=beforeat.toString();
var asci1=beforeat.charCodeAt(0);
 
afterat=mai.substring(att+1, dot);
afterat=afterat.toLowerCase();
afterat=afterat.toString();
 
afterat2=mai.substring(att+1, mai.length);
afterat2=afterat2.toLowerCase();
afterat2=afterat2.toString();
 
if(beforeat=="" || afterat=="" || beforeat.length>30)
 val=false;
 
if(afterat2.length>64 || afterat.length<2)
 val=false;
 
if((afterat.charCodeAt(0))==45 || (afterat.charCodeAt(afterat.length-1))==45)
 val=false;
 
if(val==true)
{
 if(asci1 > 47 && asci1 < 58)
  val=false;
 //alert(val);
  
 if(asci1 < 48 || asci1 > 57)
 {
  for(var i=0; i<=beforeat.length-1; i++)
  {
   var asci2=beforeat.charCodeAt(i);
   if((asci2<=44 || asci2==47) || (asci2>=58 && asci2<=94) || (asci2==96) || (asci2>=123 && asci2<=127))
   {
    val=false;
    break;
   }
  }
  //alert(val);
  
  for(var j=0; j<=afterat.length-1; j++)
  {
   var asci3=afterat.charCodeAt(j);
   //alert(asci3);
   if((asci3<=44)   || (asci3==47) || (asci3>=58 && asci3<=96) || (asci3>=123 && asci3<=127))
   {
    val=false;
    break;
   }
  } 
   
 }
}
 
if(val==false)
{
  error = msg1+"\n";
 
}
return error;
 
}
 
 function submitsearch()
 {
document.frmsearch.submit();
 }
