/**********************sof string functions**********************************************/
String.prototype.count=function(s1) { 
	return (this.length - this.replace(new RegExp(s1,"g"), '').length) / s1.length;
}
String.prototype.countChar=function(c) { 
	var vlen = this.length;
	var j=0;
	if(this.indexOf(c) > -1){
		for(var i=0;i<vlen;i++){
			if(c == this.charAt(i)){
				j++;	
			}	
		}
	}
	return j;
}

String.prototype.trim =function(){ return this.replace(/^\s+|\s+$/g,"")};
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim =function(){ return this.replace(/^\s+/,"")};
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
String.prototype.rtrim =function(){ return this.replace(/\s+$/,"")};
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
String.prototype.trimall = function(){ return trimall(this)};
function trimall(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
/***********************eof string function**************************************/

var brs = {
	Browser: (function(){
    var ua = navigator.userAgent;
    var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]';
    return {
      IE:             !!window.attachEvent && !isOpera,
      Opera:          isOpera,
      WebKit:         ua.indexOf('AppleWebKit/') > -1,
      Gecko:          ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') === -1,
      MobileSafari:   /Apple.*Mobile.*Safari/.test(ua)
    }
  })()
};
function brsVersion(){
	var ua      = navigator.userAgent.toLowerCase();
	var msip = ua.indexOf('msie');
	var msiv      = ua.substring(msip,msip+8);
	var msiarr = msiv.split(" ");
	var msiarr1 = msiarr[1].split(".");	
	return msiarr1[0];
}
function addLoadEvent(func) {
  var existonload = window.onload;
  if (typeof window.onload != 'function') {
	if (window.addEventListener) 
	{
		window.addEventListener('load', func, false); 
	} 
	else if (window.attachEvent) // for IE
	{
		window.attachEvent('onload', func);
	}
    //window.onload = func;
  } else {
	  
    /*window.onload = function() {
      if(oldonload){oldonload();}
      func();
    }*/
  
  	if (window.addEventListener) 
	{
		if(existonload){window.addEventListener('load', existonload, false);}
		window.addEventListener('load', func, false); 
	} 
	else if (window.attachEvent) // for IE
	{
		if(existonload){window.attachEvent('onload', existonload);}
		window.attachEvent('onload', func);
	}
  }
}
function requried()
{
	
	var i=0;
	var arr = new Array();
	var y=0;
	var email=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
	var emailvalue = document.getElementById('txtsemail').value;
	var digit=/[\d]/;
	var ph =document.getElementById('txtsphone').value;
	
	arr[0] ='txtsname';
	arr[1] ='txtsphone';
	arr[2] ='txtsemail';
	arr[3] ='txtsaddress';
	arr[4] ='txtrname';
	arr[5] ='txtrphone';
	arr[6] ='txtremail';
	arr[7] ='txtraddress';
	arr[8] ='txtfloswercode';
	arr[9] ='txtdescqnty';
	arr[10] ='txtdatedel';
	arr[11] ='txtmsg';
	
	var j=12;
	for(i;i<arr.length;i++)
	{
		if(IsEmpty(arr[i]))
		{
			
			document.getElementById('div'+arr[i]).style.display='inline';
			document.getElementById('div'+arr[i]).innerHTML=" Required";
		}
		else
		{
			if(arr[i]=='txtsemail' || arr[i]=='txtremail' || arr[i]=='txtdatedel')
			{
				emailvalue = document.getElementById(arr[i]).value;
				dt = document.getElementById(arr[i]).value;
				if(email.test(emailvalue))
				{
					j--;
					document.getElementById('div'+arr[i]).style.display='none';
				}
				else if(arr[i]=='txtdatedel')
				{
					
					if(validDate(dt))
					{
						j--;
						document.getElementById('div'+arr[i]).style.display='none';
					}
					else
					{
						document.getElementById('div'+arr[i]).style.display='inline';
						document.getElementById('div'+arr[i]).innerHTML="Invalid Date";	
					}
				}
				else
				{
					document.getElementById('div'+arr[i]).style.display='inline';
					document.getElementById('div'+arr[i]).innerHTML="Invalid Email";	
				}
				
			}
			else
			{
				j--;
				document.getElementById('div'+arr[i]).style.display='none';	
			}
		}
	}
	y=j;
	//alert(y);
	if(y==0)
	{
		return true;
	}
	else
	{
		return false;
	}
	
}



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;
var maxDigitsInIPhoneNumber =15;
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 countChar(val, c){
	var vlen = val.length;
	var j=0;
	if(val.indexOf(c) > -1){
		for(var i=0;i<vlen;i++){
			if(c == val.charAt(i)){
				j++;	
			}	
		}
	}
	return j;
}
function phoneValidator(phoneValue){
	var strPhone = phoneValue;
	var bracket=5;
	strPhone=trimall(strPhone);
	var lbrn= strPhone.countChar("(");
	var rbrn= strPhone.countChar(")");
	//alert(lbrn%rbrn);
	if(lbrn>0 && lbrn%rbrn !=0) return false;
	if(lbrn>0 && rbrn%lbrn !=0) return false;
	if(lbrn>0 && rbrn%lbrn ==0){
		for(var i=0;i<strPhone.length;i++){
			if(strPhone.charAt(i)=="(" && strPhone.charAt(i+1) == "(")return false; 
			if(strPhone.charAt(i)==")" && strPhone.charAt(i+1) == ")")return false; 
			if(strPhone.charAt(i)=="(" && strPhone.charAt(i+1) == ")")return false; 
			 
		}	
		
	}
	if(strPhone.indexOf("+")>1) return false;
	if(strPhone.countChar("+")>1)return false;
	
	if(strPhone.indexOf("-")!=-1)bracket=bracket+1;
	if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false;
	var brchr=strPhone.indexOf("(");
	var rbac = strPhone.indexOf(")");
	
	if(strPhone.indexOf("-")!=-1 && (strPhone.indexOf("-")==(brchr+1) || strPhone.indexOf("-")== (brchr -1)))return false;
	if(strPhone.indexOf("-")!=-1 && (strPhone.indexOf("-")==(rbac+1) || strPhone.indexOf("-")== (rbac -1)))return false;
	if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+4)!=")")return false;
	
	if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false;
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	//alert(s.length);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber && s.length <= maxDigitsInIPhoneNumber );
}
function chkPhone(obj){
	var id = obj;
	if(typeof obj == 'object'){
		id = obj.id;
	}
	var y;
	var Phone = $(id);
	
	var Novalidate = "not-required";
	var noval = $HC(id,Novalidate);
	if(noval==true && Phone.value==""){
		return true;
	}
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number");
		Phone.focus();
		return false;
	}
	if (phoneValidator(Phone.value)==false){
		alert("Please Enter a Valid Phone Number");
		//Phone.value="";
		Phone.focus();
		return false;
	}
	return true;
}
function phone(myfield, e){
	
	var key;
	var keychar;
	var fieldid = myfield.id;
	
	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) ||
		(key==40) || (key==41) || (key==32)||
		(key==43)|| (key==45))
	  { 
	  	 return true;
	  }
	
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	  { 
		  if($('div'+fieldid)){
			removeElement('div'+fieldid);
		  }
	  	 removeErrorBorder(fieldid);
		
	 	 return true;
	  
	  }
	
	
	
	else
	 {  return false;}
}


function numbersonly(myfield, e)
{
	var key;
	var keychar;
	var fieldid = myfield.id;
	
	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
	  { 
		 return true;
	  }
	
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	  { 
		  if($('div'+fieldid)){
			removeElement('div'+fieldid);
		  }
	  	 removeErrorBorder(fieldid);
		
	 	 return true;
	  
	  }
	
	
	
	else
	 {  return false;}
}

function decimalNumber(obj, e){
	var key;
	var keychar;
	var fieldid = obj.id;
	var txtnv = $v(fieldid);
	var arrn = txtnv.split(".");
	var arrnlen = arrn.length;
	
	if(window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	
	if(chIN(key, keychar)==true){
		if($('div'+fieldid)){
			removeElement('div'+fieldid);
		}
		return true;
	}
	else if(keychar=="."){
		if(arrnlen==1){
			
			return true;
		}
		else{return false;}
	}
	else{return false;}
}

function chIN(key, keychar){
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
	{ 
		 return true;
	}
	else if ((("0123456789").indexOf(keychar) > -1)){ 
		return true;
	}
	else{return false;}
}

function chkNumber(val){
	var len = val.length;
	var char='';
	var rev = false;
	var j=0;
	for(var i=0; i<len; i++){
		
		char = val.substr(i, 1);
		
		if ((("0123456789").indexOf(char) > -1)){
			j++;
		}
	}
	if(len>0 && j==len){rev = true;}
	
	return rev;
}

/*********************************************************************************************** 
	This validate function is calling from the formsubmit event of the form 
	and its takes form name or the form object as an argument and validate the 
	form elements of input type{ text and file}, and tagname textarea. if you are
	not specifing any class like{required} in the element it will validate every elements
	in the form. if you specify {not-required} as class then it leaves the element and 
	validate the next element. you can validate email address and date by specifying {email} 
	and {valid-date} as class in the element. 
************************************************************************************************/

function validate(frmobj)
{
	//alert(frmobj.name);
	var formName=frmobj;
	var formId;
	if(typeof formName == 'object'){
		formName = frmobj.name;
		formId = frmobj.id;
	}
	formId = document.forms[formName].id;
	
	var formlength = document.forms[formName].elements.length;//document.frmoder.elements.length;
	//alert(formlength);
	var str=str1='';
	var strtag ='';
	var tiem=0;
	var uelm=0;
	var rev = false;
	var msgBox = false;
	var Novalidate = "not-required";
	var Valdate = "required"; 
	var hasVal = true;
	var emailClass ="email";
	var dateClass = "valid-date";
	var otherClass ="gencode";
	var numberClass ="numbers";
	var otherId = "btngencode";
	var passcom = "passcom";
	var objarrp = Array();
	var email=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
	var errdistypeClass = 'errorinmsgbox';
	var peles = $EBC("passcom");//$EC(passcom);
	var plen =0;
	if(peles.length>0)plen=peles.length; 
	// alert(plen);
	msgBox = $HC(formId, errdistypeClass);
	var num_yesval =0;
	for(var i=0; i<formlength; i++){
		var obj = document.forms[formName].elements[i];//document.frmoder.elements[i];
		if(obj.id)
		var id = obj.id;
		if($HC(id,Valdate)){
			num_yesval +=1;	
		}
	}
	//alert(num_yesval);
	for(var i=0; i<formlength; i++)
	{
		var obj = document.forms[formName].elements[i];//document.frmoder.elements[i];
		if(obj.id)
		if(obj.type=="text")
		{
			
			tiem +=1;
			uelm +=1;
			//alert('text '+tiem);
			var id = obj.id;
			var noval = $HC(id,Novalidate);
			var yesval =$HC(id,Valdate);
			//alert(yesval);
			if(yesval == true || num_yesval==0){
				if(!noval){
					if(IsEmpty(id))
					{
						var otheri = $HC(id,otherClass);
						if(otheri){
							if(msgBox){
								showMsgFocus(id, 'Field should not be empty !');
							}
							else{
								addElement(otherId, ' Required');
							}
						errorBorder(id);
							if(msgBox){break;}
						}else{
								if(msgBox){
									showMsgFocus(id, 'Field should not be empty !');
								}
								else{
									addElement(id, ' Required');
								}
								
							errorBorder(id);
							if(msgBox){break;}
						}
						/*$('div'+id).style.display='inline';
						$('div'+id).innerHTML="Required";*/
						
					}
					else
					{
						if(msgBox == false){
							removeElement('div'+id);
						}
						removeErrorBorder(id);
						
						//str +=id+' '+i+',';
						var eti = $HC(id,emailClass);
						var dti = $HC(id, dateClass);
						var otheri = $HC(id,otherClass);
						var numOnly = $HC(id, numberClass);
						if(eti)
						{ 
							emailvalue = $v(id);
							if(email.test(emailvalue))
							{
								uelm -=1;
								if(msgBox == false){
									removeElement('div'+id);
								}
								removeErrorBorder(id);
								if($('div'+id))
								$('div'+id).style.display='none';
							}
							else
							{
								if(msgBox){
									showMsgFocus(id, 'Invalid Email Address is entered !');	
									errorBorder(id);
									break;
								}
								else{
									addElement(id, ' Invalid Email');
								}
								errorBorder(id);
								
							}
						}
						else if(dti)
						{
							dt = $v(id);
							
							if(validDate(dt))
							{
								uelm -=1;
								if(msgBox == false){
									removeElement('div'+id);
								}
								removeErrorBorder(id);
							}
							else
							{
								if(msgBox){
									showMsgFocus(id, 'Invalid Date is entered !');	
								}
								else{
									addElement(id, 'Invalid Date');
								}
								errorBorder(id);
							}
						}
						else if(otheri){
							uelm -=1;
							if(msgBox == false){
								removeElement('div'+otherId);
							}
							
							removeErrorBorder(id);
						}
						else if(numOnly){
							var nmonly = chkNumber($v(id));
							if(nmonly){
								uelm -=1;
								if(msgBox == false){
									if($('div'+id)){removeElement('div'+id);}
								}
								removeErrorBorder(id);
							}
							else{
								if(msgBox){
									showMsgFocus(id, 'Please enter Number only!');	
								}
								else{
									addElement(id, 'Invalid Number');
								}
								errorBorder(id);	
								if(msgBox){break;}
							}
						}
						else
						{
							uelm -=1;
							if(msgBox == false){
								if($('div'+id))
								removeElement('div'+id);
							}
							
						}
					
					}
				}
				else{
					uelm -=1;
				}
			}
			else{
				uelm -=1;	
			}
		}
		else if(obj.type=="password"){
			id = obj.id;
			tiem +=1;
			uelm  +=1;
			//alert('pwd '+tiem);
			var noval = $HC(id,Novalidate);
			var yesval =$HC(id,Valdate);
			var spv = $HC(id,passcom);
			
			if(yesval == true || num_yesval==0){
				if(!noval){
					
					if(!IsEmpty(id)){
						if(msgBox == false){
							removeElement('div'+id);
						}
						removeErrorBorder(id);
						if(spv==true){
							objarrp.push(id);
							//alert(objarrp.length);
							var pwdarrlen = objarrp.length;
							if(pwdarrlen==plen){
								
								if(pwdTest(objarrp)== true){
									uelm -=pwdarrlen;
								}
								else{
									for(var pai=0;pai<pwdarrlen;pai++){
										if(!msgBox){
											addElement(objarrp[pai], ' Not Matched');
										}
										errorBorder(objarrp[pai]);
									}
									if(msgBox){
										showMsgFocus(objarrp[pwdarrlen-1], 'Re type password is not mathced with the password!');		
									}
								}
							}
							
						}
						else{uelm -=1;}
						
					
					}
					else{
						
						if(msgBox){
							showMsgFocus(id, 'Field should not be empty !');	
						}
						else{
							addElement(id, ' Required');	
						}
						errorBorder(id);
						if(msgBox){break;}
					
					}
				
				}
				else{uelm -=1;}
				}
			else{
				uelm -=1;
			}
		}
		else if(obj.type=="file"){
			id = obj.id;
			tiem +=1;
			uelm  +=1;
			var noval = $HC(id,Novalidate);
			var yesval =$HC(id,Valdate);
			if(yesval == true || num_yesval==0){
				if(!noval){
					if(!IsEmpty(id)){
						uelm -=1;
						if(msgBox == false){
							removeElement('div'+id);
						}
						removeErrorBorder(id);
					}
					else{
						if(msgBox){
							showMsgFocus(id, 'Field should not be empty !');	
						}
						else{
							addElement(id, ' Required');	
						}
						errorBorder(id);
						if(msgBox){break;}
					}
				}
				else{uelm -=1;}
				}
			else{
				uelm -=1;
			}
		}
		
		else
		{
			id = obj.id;
			strtag1 = obj.tagName;
			//alert(strtag1);
			strtag1 = strtag1.toLowerCase();
			//alert(strtag1);
			if(strtag1=='textarea'){
				//strtag += strtag1;
				tiem +=1;
				uelm  +=1;
				var noval = $HC(id,Novalidate);
				var yesval =$HC(id,Valdate);
				if(yesval == true || num_yesval==0){
					if(!noval){
						if(!IsEmpty(id)){
							uelm -=1;
							if(msgBox == false){
								removeElement('div'+id);
							}
							removeErrorBorder(id);
						}
						else
						{
							if(msgBox){
								showMsgFocus(id, ' Field should not be empty !');	
							}
							else{
								addElement(id, ' Required');	
							}
							
							errorBorder(id);
							if(msgBox){break;}
						}
					}
					else{
						uelm -=1;	
					}
					}
				else{
					uelm -=1;	
				}
			}
			else if(strtag1=='select'){
				//strtag += strtag1;
				tiem +=1;
				uelm  +=1;
				var noval = $HC(id,Novalidate);
				var yesval =$HC(id,Valdate);
				if(yesval == true || num_yesval==0){
					if(!noval){
						
						if(!EmptySelectBox(id)){
							uelm -=1;
							if(msgBox == false){
								removeElement('div'+id);
							}
							removeErrorBorder(id);
						}
						else
						{
							if(msgBox){
								showMsgFocus(id, ' Please select a value !');	
							}
							else{
								addElement(id, ' Required');	
							}
							
							errorBorder(id);
							if(msgBox){break;}
						}
					}
					else{
						uelm -=1;	
					}
					}
				else{
					uelm -=1;	
				}
			}
			
			
		}
		
		
	}
	//alert('Total No. of Elements: '+tiem+'\n\n Total No. of unfilled elements: '+uelm);
	
	if(tiem>0 && uelm==0){
		rev = true;
	}
	//alert(str+'\n\n'+str1+'\n\n'+strtag+'\n\n'+tiem);
	//alert(rev);
	return rev;
}

function IsEmpty(id) {
	
	var value = trim($(id).value);
   if ((value.length==0) ||
	(value.length==' ') ||
   (value==null)) {
      return true;
   }
   else { return false; }
   
}
function EmptySelectBox(id){
	var index = $(id).selectedIndex;
	var seltext = $(id).options[index].text;
	var selvalue = $(id).options[index].value;
	var selectt = seltext.toLowerCase();
	var selectv = seltext.toLowerCase();
	//alert(selvalue+'\n h: '+seltext+'\n h: '+selectv);
	var ind = selectt.indexOf('select');
	var ind1 = selectv.indexOf('select');
	if(seltext=='' || seltext.length==0 || ind> -1 ){
		if(ind == -1 ){return false;}
		return true;
	}
	else{return false;}
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
function emailTest(emv)
{
	var email=/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
	return email.test(emv);
}

/*check the password field have the same value.*/
function pwdTest(pwdarr){
	if(pwdarr.length>0){
		var palen = pwdarr.length;
		var pwd1val = $v(pwdarr[0]);
		var pwdt =0;
		for(var i=0; i<palen; i++){
			var pwdval = $v(pwdarr[i]);
			if(pwd1val==pwdval) pwdt++;
		}
		if(palen==pwdt){return true;}
		else{return false;}
	}
	else{return false;}
}
document.getElementsByClassName = function(className){
    var nodes = document.getElementsByTagName('*');
    var matches = new Array();
    for(i=0;i<nodes.length;i++){
        var tmp = nodes[i].getAttribute('class') || nodes[i].getAttribute('className');
        if(tmp == className) matches[matches.length] = nodes[i];
    }
    return matches;
}
document.hasClassName = function(element, className) {
    if (!(element = $(element))) return;
    var elementClassName = element.className;
    return (elementClassName.length > 0 && (elementClassName == className ||
      new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
  }
 
var $HC = function(element, className) {
    if (!(element = $(element))) return;
    var elementClassName = element.className;
    return (elementClassName.length > 0 && (elementClassName == className ||
      new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
}

var $EC = function(className){
	var nodes = document.getElementsByTagName('*');
    var matches = new Array();
    for(i=0;i<nodes.length;i++){
        var tmp = nodes[i].getAttribute('class') || nodes[i].getAttribute('className');
        if(tmp == className) matches[matches.length] = nodes[i];
    }
    return matches;
}
function $EBC(className){
	var nodes = document.getElementsByTagName('*');
    var matches = new Array();
    for(i=0;i<nodes.length;i++){
		var id = nodes[i].id;
       
		if((id!="" || id !=" " || id!="undefined") && id.length>0){
			var tmp1 = $HC(id, className);
			//alert(tmp1);
			if(tmp1 == true){ 
				//matches.push(nodes[i]);
				matches[matches.length] = nodes[i];
			}
		}
    }

    return matches;
}

function $(element) {
	if (arguments.length > 1) {
    for (var i = 0, elements = [], length = arguments.length; i < length; i++)
      elements.push($(arguments[i]));
    return elements;
	}
	else{
		if(isString(element))
		element = document.getElementById(element);
		return element;
	}
}
function $v(element){
	return $(element).value;
}
function isString(a) {
    return typeof a === 'string';
}
function validDate(v)
{
	var regex = /^(\d{2})\-(\d{2})\-(\d{4})$/;
	if(!regex.test(v)) return false;
	var d = new Date(v.replace(regex, '$2/$1/$3'));
	return s=( parseInt(RegExp.$2, 10) == (1+d.getMonth()) ) && 
				(parseInt(RegExp.$1, 10) == d.getDate()) && 
				(parseInt(RegExp.$3, 10) == d.getFullYear() );
}
function removeElement(rmvelm)
{
	var y=0;
	
	if(typeof rmvelm != 'object'){
		if($(rmvelm)){
		rmvelm = $(rmvelm);
		y=1;
		}
	}
	
	if(typeof rmvelm == 'object'){
		y=1;
	}
	if(y>0){
 	var parent = rmvelm.parentNode;
  	parent.removeChild(rmvelm);
	}
}
function insertAfter(newElement,targetElement)
{
	if(typeof newElement != 'object'){
		newElement = $(newElement); 	
	}
	if(typeof targetElement != 'object'){
		targetElement = $(targetElement); 	
	}
	
	var parent = targetElement.parentNode;
	//if the parents lastchild is the targetElement...
	
	if(parent.lastchild == targetElement) 
	{
		//add the newElement after the target element.
		parent.appendChild(newElement);
	}
	else
	{
		// else the target has siblings, insert the new element between the target and it's next sibling.
		parent.insertBefore(newElement, targetElement.nextSibling);
	}
	
}

function addElement(obj,txtmsg)
{
	//alert(obj);
	var space = "";
	var targetElement = $(obj);
	var newdiv = document.createElement('div');
	var newdiv_id = newdiv.tagName.toLowerCase()+obj;
	
	newdiv.setAttribute('id', newdiv_id);

	if(this.brs.Browser.IE){
		if(brsVersion()<=7){
			newdiv.setAttribute('className', 'validation-advice');
		}
		else{
			newdiv.setAttribute('class', 'validation-advice');
		}
	}
	else{
		newdiv.setAttribute('class', 'validation-advice');
	}
	
	newdiv.innerHTML =space+space+txtmsg;
	
    
	if(!$(newdiv_id))
	insertAfter(newdiv, targetElement);
	
	return newdiv_id;
}
function setAtt(obj, atttype, attval){
	var obj = obj;
	if(typeof obj != 'object'){
		if($(obj))
		obj = $(obj);
	}
	
	var getatt = obj.getAttribute(atttype);
	obj.setAttribute(atttype, attval, getatt);
}
function setText(obj, txtmsg, cssClass)
{
	if($(obj)){
		var obj = $(obj);
		obj.innerHTML = txtmsg;
		if(this.brs.Browser.IE){
			if(brsVersion()<=7){
				obj.setAttribute('className', cssClass);
			}
			else{
				obj.setAttribute('class', cssClass);		
			}
		}
		else{
			obj.setAttribute('class', cssClass);
		}
	}
}

function c()
{
	var objhead = document.getElementsByTagName('head');
	var style = document.createElement('style');
	insertAfter(style, objhead);
}

function chkLogin(txtuname, txtpwd){
	var rev = false;
	if($(txtuname) && $(txtpwd)){
		if(!IsEmpty(txtuname) && !IsEmpty(txtpwd)){rev=true;}
		else{
			var fid = (IsEmpty(txtuname))? txtuname : txtpwd;
			var fidlabel = (IsEmpty(txtuname))? "User Name" : "Password";
			showMsgFocus(fid,  fidlabel+' should not be empty !');
		}
	}
	return rev;
}

function logOut(){
	var url = 'action.php?signout'
	window.location.href  = url;
}
function redirect(url){
	
	window.location  = url;
}
function formSubmit(frm, url){
	var form = document.forms[frm];
	//alert(url);
	if(typeof form == 'object'){
		var y = false;
		if(url=='undefined'){url=""; y=true;}
		else{
			
			var df = url.indexOf('delete')
			var ef = url.indexOf('edit')
			if((df>0) || (ef>0)){
				
				var ceo = checkElement("radio",frm);
				var cec = checkElement("checkbox",frm);
				if(ceo==true){
					
					var cv = confirm("Do you really want this action ");
					if(cv==true){y=true;}
					else{y=false;}
				}
				else if(cec==true){
					var cv = confirm("Do you really want this action ");
					if(cv==true){y=true;}
					else{y=false;}
				}
				else{
					alert("No records are selected \n please select one.");
				}
			}
			else{y=true;}
		}
		
		if(y==true){
			
			form.action =url;
			disf = form.id.indexOf('dis'); 
			//alert(form);
			if(disf<=0){
				if(validate(form)){
					form.submit();
				}
			}else{
				form.submit();
			}
		}
	}
}

function checkOrderDelboy(frm){
	var ckd = checkElement("checkbox",frm);
	if(ckd==true){
		var form = document.forms[frm];	
		form.action ="action.php";
		form.submit();
	}
	else{alert("No records are selected \n please select one.");return false;}
}
function checkElement(eleType,frm){
	var formName=frm;
	if(typeof formName == 'object'){
		formName = formName.name;; 	
	}
	var formlength = document.forms[formName].elements.length;
	var y=false;
	for(i=0; i<formlength; i++)
	{
		var obj = document.forms[formName].elements[i];//document.frmoder.elements[i];
		if(obj.id)
		if(obj.type==eleType)
		{
			var id = obj.id;
			if($(id).checked){
				y=true;
				break;
			}
			else{y=false;}
			
		}
	}
	return y;
}

function setProdCode(txtid, selid){
	var txtid = txtid;
	if(typeof txtid == 'object'){
		txtid = txtid.id;
	}
	var selid = selid;
	if(typeof selid == 'object'){
		selid = selid.id;	
	}
	
	var index = $(selid).selectedIndex;
	var selvalue = $(selid).options[index].text;
	var tblname = "products";
	var colname = "prod_code";
	var suffix = "-";
	var genlen = 3;
	if(selvalue!=''){
		var url ='ied.php?gencode='+selvalue+'&tblname='+tblname+'&colname='+colname+'&suffix='+suffix+'&genlen='+genlen;
		//alert(url);
		new Ajax.Request(url,
		{
			method:'get',
			onSuccess: function(transport){
			var response = transport.responseText || "no response text";
			//alert(response);
			var prodcode ='';
			var str = response.split("-");
			if(str.length>1){
				prodcode = response;
				$(txtid).value=prodcode;
			}
			else{
				//$(txtid).value=str;
				
				//alert('Something went wrong...Hello');
			}
			
		},
		onFailure: function(){ alert('Something went wrong...'); }
		});
		
	}
	else{
		alert("Please select a category \n for generating the Product Code");	
	}
	
	
	
}
function showMsgFocus(obj, msg){
	alert(msg);
	$(obj).focus();
}
function errorBorder(obj){
	$(obj).style.border='1px solid #F49A9A';
}
function removeErrorBorder(obj){
	$(obj).style.border='1px solid #999999';	
}
function redirectUsingVal(url, id){

	var surl='';
	var rev = false;
	if($(id).type=="text"){
		if(!IsEmpty(id)){
			surl = url+$v(id);
			rev = true;
		}
	}
	else{
		var index = $(id).selectedIndex;
		var selvalue = $(id).options[index].value;
		surl= url+selvalue; 
		rev=true;
	}
	if(rev==true){
		redirect(surl);
	}
}
/* this addAttByClassName function add attribute by class name 
by taking 3 arguments{classname, attribute type and attribute value}*/
function addAttByClassName(className, attType, attValue){
	var numOfForms = document.forms.length;
	var nfelm=0;
	//alert('Number of form: '+numOfForms);
	
	
	for(f=0; f<numOfForms; f++){
		nfelm = document.forms[f].elements.length;
		nf = f+1;
		//alert('Number of element in the form no. '+nf+' is: '+nfelm);	
		for(i=0;i<nfelm; i++){
			var obj = document.forms[f].elements[i];
			if(obj.id)
			var id = obj.id;
			var hsc = $HC(id, className);
			if(hsc){
				//alert('class '+className+' position is: '+i);
				setAtt(id, attType, attValue);
				
			}
		}
	}

}
function addFunToElement(){
	var numarr = $EBC("numbers");
	var decarr = $EBC("decimals");
	var phonearr = $EBC("phone");
	if(phonearr.length>0){
		addAttByClassName("phone", "onkeypress", "return phone(this, event);");
		addAttByClassName("phone", "onblur", "return chkPhone(this);");
	}
	if(numarr.length>0){
		addAttByClassName("numbers", "onkeypress", "return numbersonly(this, event);");
	}
	if(decarr.length>0){
		addAttByClassName("decimals", "onkeypress", "return decimalNumber(this, event);");
	}
}
function addNumCheckToElement(){
	
	addAttByClassName("numbers", "onkeypress", "return numbersonly(this, event);");
}
function disInPos(obj){
	if(typeof obj != 'object'){
		obj =  $(obj);
	}
	
	var val = obj.value;
	var elmId = 'txtname'+val;
	
	if($(elmId))
	$(elmId).style.display='inline';
	setAtt(elmId, "onkeypress", "return numbersonly(this, event);");
	
	var objasdf = $EC('prodpos');
	
	var elemlen = objasdf.length;
	for(i=0; i<elemlen;i++){
		var emId = objasdf[i].id;
		if(emId!=elmId){
			$(emId).style.display='none';
		}
	}
}


function disProdEle(obj){
	
	var id = obj.id;
	var arr = id.split("_");
	var prodid = arr[1];
	
	var radioId ='rdo'+prodid;
	if($(radioId)){
		//alert(radioId);
		$(radioId).checked="checked";
	}
	var divid ='divposin_'+prodid;
	var btnid = 'btnsetpos'+prodid;
	var txtid = 'txtprodpos_'+prodid;
	if($(divid)){
		$(divid).style.visibility="visible";
		
		if($(txtid)){
			$(txtid).style.display='inline';
			setAtt(txtid, "onkeypress", "return numbersonly(this, event);");
		}
		if($(btnid)){
			$(btnid).style.display='inline';
		}
	}
	var objarr = $EC('divprodpos');
	
	var elemlen = objarr.length;
	for(i=0; i<elemlen;i++){
		var emId = objarr[i].id;
		
		if(emId!=divid){
			$(emId).style.visibility='hidden';
			var arrele = emId.split("_");
			var proId = arrele[1];
			if($('txtprodpos_'+proId))$('txtprodpos_'+proId).style.display='none';
			if($('btnsetpos'+proId))$('btnsetpos'+proId).style.display='none';
		}
	}
	
}
function dis_cpc_cpp(selid){
	chkProdPos(selid);
	discpc(selid);
}
function discpc(selid){
	var selid = selid;
	
	if(typeof selid != 'object'){
		if($(selid))
		selid = $(selid);
	}
	
	var index = $(selid).selectedIndex;
	var selvalue = $(selid).options[index].value;
	if(selvalue!=''){
		var url ='ied.php?cpc&cat_id='+selvalue;
		//alert(url);
		new Ajax.Updater('divcpc', url, { method: 'get' });
		
	}
}
function chkProdPos(selid){
	var selid = selid;
	
	if(typeof selid != 'object'){
		if($(selid))
		selid = $(selid);
	}
	
	var index = $(selid).selectedIndex;
	var selvalue = $(selid).options[index].value;
	
		if(selvalue!=''){
		var url ='ied.php?chkProdPos&cat_id='+selvalue;
		//alert(url);
		new Ajax.Request(url,
		{
			method:'get',
			onSuccess: function(transport){
			var response = transport.responseText || "no response text";
			//alert(response);
			
			var prodpos = 0;
			prodpos = trim(response);
			if(chkNumber(prodpos)){
				
				$('divchkprodpos').innerHTML='(Please enter 1 to '+prodpos+' in the Textbox)';
			}
			else{
				//$(txtid).value=str;
				
				//alert('Something went wrong...Hello');
			}
			
		},
		onFailure: function(){ alert('Something went wrong...'); }
		});
		
	}
		
}
function setTXT(obj,text){
	if($(obj)){
		$(obj).value = text;	
	}
}
function setSTT(selid, txtid,tv){
	
	var index = $(selid).selectedIndex;
	var selvalue ='';
	if(tv=='text'){
		selvalue = $(selid).options[index].text;
	}
	else{
		selvalue = $(selid).options[index].value;
	}
	$(txtid).value=selvalue;

}

function getText(id){
	return $(id).value;	
}

function addMoreField(txtid, divclass){
	var space = "";
	var divelem = $EBC(divclass);
	alert(divelem.length);
	/*var targetElement = $(obj);
	var newdiv = document.createElement('div');
	var newdiv_id = newdiv.tagName.toLowerCase()+obj;
	
	newdiv.setAttribute('id', newdiv_id);

	if(this.brs.Browser.IE){
		if(brsVersion()<=7){
			newdiv.setAttribute('className', 'validation-advice');
		}
		else{
			newdiv.setAttribute('class', 'validation-advice');
		}
	}
	else{
		newdiv.setAttribute('class', 'validation-advice');
	}
	
	newdiv.innerHTML =space+space+txtmsg;
	
    
	if(!$(newdiv_id))
	insertAfter(newdiv, targetElement);
	
	return newdiv_id;*/
}

function divshow(divid,divin, divins){
	// this function takes div id and the id initial
	var divs = document.getElementsByTagName('div');
	var divlen = divs.length;
	if($(divid)){
		$(divid).style.display ='block';
		$(divins).style.display ='block';
		for(var i=0; i<divlen ; i++){
			var divid1 = divs.item(i).id;
			var index = divid1.indexOf(divin);
			if(divid1 != divid && index != -1){
				$(divid1).style.display = 'none';	
			}
		}
	}
	else{
		$(divins).style.display ='none';
		for(var i=0; i<divlen ; i++){
			var divid1 = divs.item(i).id;
			var index = divid1.indexOf(divin);
			if(index != -1){
				$(divid1).style.display = 'none';	
			}
		}	
	}

}

function test(obj){
		disProdEle(obj);
}


//for login username and password

function loginsubmit()
{
    var idcardno,password;
    idcardno=document.getElementById('textfield').value;
    password=document.getElementById('textfield2').value;
     var  id=idcardno.toUpperCase();
     var pass=password.toUpperCase();
    
    if(id=="" && pass=="")
    {
        window.alert("Enter Username & Password");
        document.forms[0].textfield.focus();
        return  false;
        
    }
    
     if(id=="" && pass!="")
    {
        window.alert("Enter Username");
        document.forms[0].textfield.focus();
        return  false;
    }
    
    if(id!="" && pass=="")
    {
        window.alert("Enter Password");
        document.forms[0].textfield2.focus();
        return  false;
    }
    
    
    if(idcardno.length>10 )
    {
        window.alert("Invalid Username");
        document.forms[0].textfield.value="";
        document.forms[0].textfield.focus();
        return false;
    }
   if(id.indexOf("ALTER")>=0 || id.indexOf("DROP")>=0 || id.indexOf("UPDATE")>=0 || id.indexOf("INSERT")>=0 || id.indexOf("DELETE")>=0 || id.indexOf("TRUNCATE")>=0 || id.indexOf("SP_")>=0 || id.indexOf("SELECT")>=0)
    {
        window.alert('Invalid Username');
        document.forms[0].textfield.value="";
        document.forms[0].textfield.focus();
        return false;
    }
    if(pass.indexOf("ALTER")>=0 || pass.indexOf("DROP")>=0 || pass.indexOf("UPDATE")>=0 || pass.indexOf("INSERT")>=0 || pass.indexOf("DELETE")>=0 || pass.indexOf("TRUNCATE")>=0 || pass.indexOf("SP_")>=0 || pass.indexOf("SELECT")>=0)
    {
        window.alert('Invalid Password');
        document.forms[0].textfield2.focus();
        return false;
    }
    if(id.indexOf(".")>=0 || id.indexOf("-")>=0 || id.indexOf("'")>=0 || id.indexOf("@")>=0 || id.indexOf("&")>=0 )
    {
        window.alert('Invalid Username');
        document.forms[0].textfield.value="";
         document.forms[0].textfield.focus();
        return false;
    }
    if(pass.indexOf(".")>=0 || pass.indexOf("-")>=0 || pass.indexOf("'")>=0 || pass.indexOf("@")>=0 || pass.indexOf("&")>=0 )
    {
        window.alert('Invalid Password');
        document.forms[0].textfield2.focus();
        return false;
    }
    
        document.getElementById('form1').method="post";
        document.getElementById('form1').action="login_check.asp";
        document.getElementById('form1').submit();
}
//end


//for appoint form validation

function appointment_validate()
{
    
    var name=document.getElementById('txtname').value;
    var center=document.getElementById('center').value;
    var dates=document.getElementById("dates").value;
    var slots=document.getElementById('slots').value;
    var txtquery=document.getElementById('txtquery').value;
    
     
     if(slots=="" || slots=="0")
    {
        window.alert("Please select appointment Time");
        document.form2.slots.focus();
        return  false;
    }
    
     if(txtquery=="")
    {
        window.alert("Enter your cause to meet our Principal or Teacher");
        document.form2.txtquery.focus();
        return  false;
        
    }
    
    if(txtquery.length>300 )
    {
        window.alert("allowed length of the cause is max of 300 charcters only ");
        document.form2.txtquery.value="";
        document.form2.txtquery.focus();
        return false;
    }
   if(name.indexOf("ALTER")>=0 || name.indexOf("DROP")>=0 || name.indexOf("UPDATE")>=0 || name.indexOf("INSERT")>=0 || name.indexOf("DELETE")>=0 || name.indexOf("TRUNCATE")>=0 || name.indexOf("SP_")>=0 || name.indexOf("SELECT")>=0)
    {
        window.alert('Invalid Name');
        document.form2.txtname.value="";
        document.form2.txtname.focus();
        return false;
    }
    if(txtquery.indexOf("ALTER")>=0 || txtquery.indexOf("DROP")>=0 || txtquery.indexOf("UPDATE")>=0 || txtquery.indexOf("INSERT")>=0 || txtquery.indexOf("DELETE")>=0 || txtquery.indexOf("TRUNCATE")>=0 || txtquery.indexOf("SP_")>=0 || txtquery.indexOf("SELECT")>=0)
    {
        window.alert('Invalid query');
        document.form2.txtquery.focus();
        return false;
    }
    if(name.indexOf(".")>=0 || name.indexOf("-")>=0 || name.indexOf("'")>=0 || name.indexOf("@")>=0 || name.indexOf("&")>=0 )
    {
        window.alert('Invalid Name');
        document.form2.txtname.value="";
         document.form2.txtname.focus();
        return false;
    }
    
    
   if(confirm('Kindly check if you have given the correct info for an appointment with the principal/teachers!'))
			    {
				   document.getElementById('form2').method="post";
				    document.getElementById('form2').action="save_appointment_details.asp";
				    document.getElementById('form2').submit();
			    }
}

//end


//for rescheduling an appointment


function appointment_validate1()
{
    
    var name=document.getElementById('txtname').value;
    var center=document.getElementById('center').value;
    var dates=document.getElementById("dates").value;
    var slots=document.getElementById('slots').value;
    var txtquery=document.getElementById('txtquery').value;
    
     
     if(slots=="" || slots=="0")
    {
        window.alert("Please select appointment Time");
        document.form2.slots.focus();
        return  false;
    }
    
     if(txtquery=="")
    {
        window.alert("Enter your cause to meet our Principal or Teacher");
        document.form2.txtquery.focus();
        return  false;
        
    }
    
    if(txtquery.length>300 )
    {
        window.alert("allowed length of the cause is max of 300 charcters only ");
        document.form2.txtquery.value="";
        document.form2.txtquery.focus();
        return false;
    }
   if(name.indexOf("ALTER")>=0 || name.indexOf("DROP")>=0 || name.indexOf("UPDATE")>=0 || name.indexOf("INSERT")>=0 || name.indexOf("DELETE")>=0 || name.indexOf("TRUNCATE")>=0 || name.indexOf("SP_")>=0 || name.indexOf("SELECT")>=0)
    {
        window.alert('Invalid Name');
        document.form2.txtname.value="";
        document.form2.txtname.focus();
        return false;
    }
    if(txtquery.indexOf("ALTER")>=0 || txtquery.indexOf("DROP")>=0 || txtquery.indexOf("UPDATE")>=0 || txtquery.indexOf("INSERT")>=0 || txtquery.indexOf("DELETE")>=0 || txtquery.indexOf("TRUNCATE")>=0 || txtquery.indexOf("SP_")>=0 || txtquery.indexOf("SELECT")>=0)
    {
        window.alert('Invalid query');
        document.form2.txtquery.focus();
        return false;
    }
    if(name.indexOf(".")>=0 || name.indexOf("-")>=0 || name.indexOf("'")>=0 || name.indexOf("@")>=0 || name.indexOf("&")>=0 )
    {
        window.alert('Invalid Name');
        document.form2.txtname.value="";
         document.form2.txtname.focus();
        return false;
    }
    
    
   if(confirm('If you provide correct information,so please consider carefull. Do you want to the principal/teachers appointment!'))
			    {
				   document.getElementById('form2').method="post";
				    document.getElementById('form2').action="update_appointment_details.asp";
				    document.getElementById('form2').submit();
			    }
}

//end




/***************************Load the addFunToElement function to the window event load.*********************************/
addLoadEvent(function() {
		addFunToElement();
});
/**************************************eof load event******************************************************************/
