
/*

<script language="JavaScript" src="../include/validation.js"></script>
<script Language="JavaScript">

function frmindex_Validate(frm)
{
	with (frm)
	{
		if
		(
			isNotEmpty(frm,txtCCNumber,'Please Enter Number !') && 
			isNotEqual(frm,txtPassword,txtConfirmPassword,'Please Confirm Password Properly !') && 
			isNumeric(frm,txtCCNumber,'Please Enter a Numeric Number !') && 
			isOfExactLength(frm,txtCCNumber,'Please Enter a Numeric 16-digit Number !',16) && 
			isOfMinLength(frm,txtCCNumber,'Please Enter a Numeric minimum 16-digit Number !',16) && 
			isOfMaxLength(frm,txtCCNumber,'Please Enter a Numeric maximum 16-digit Number !',16) && 
			isValidEmail(frm,txtEmail,'Please Enter a Valid E-mail Address !') &&
			isSingleSel(frm,selAlpha,'Please Select Alphabet !') && 
			isMultipleSel(frm,selState,'Please Select atleast one State !')
		)
			return true;
		return false;
	}
}

</script>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="SetFocus('txtName')">

<form name="frmindex" method="post" action="" onSubmit="return frmindex_Validate(this);">

*/
// Discard space at starting and ending if any
function trim(str) 
{ 
    return str.replace(/^\s+|\s+$/g,''); 
}

function SelectCheckBox(element)
{
	/*if(document.getElementById(element).checked==true)
		document.getElementById(element).checked=false;
	else
		document.getElementById(element).checked=true;*/
}

function SelectCheckBox1(name,alertbox)
{
	if(document.getElementById('chkTerms').checked==true)
		return true;
	else
		alert(alertbox);
		focus;
		return false;
}


function SelectRadioBotton(alertbox)
{
	//if(document.getElementById(element).checked==true)
		//document.getElementById(element).checked=false;
	//else
		if (document.getElementById("radSize").checked==true)
		{
			return true;
		}
		else
			alert(alertbox);
			focus;
			return false;
}

function SetFocus(element)
{
	document.getElementById(element).focus();
}

//Level indepenncy
function levelInDep(le,en)
{
	var res = eval('document.'+le.name+'.'+en.name);
	//var res = eval('document.getElementById('+en.name+')');
	return res;	
}

//Level indepenncy
function levelInDep1(le,en)
{
	var res = eval('document.'+le.name+'.'+'mulUserType');
	//var res = eval('document.getElementById("mulUserType")');
	return res;	
}


// Check whether the value of an object is empty/null 
function isNotEmpty(frm,ctrl,msg)
{
	var obj = levelInDep(frm,ctrl);
	with (obj)
	{
		if (value==null || trim(value)=="")
		{
			if (msg!="") 
				alert(msg);
			else
				alert("Validation Error ! ");
			focus();
			return false;
		}
		return true;
	}
}

// Check whether the value of an object is numeric
function isNumeric(frm,ctrl,msg)
{	
	var obj = levelInDep(frm,ctrl);
	with (obj)
	{
		if (isNaN(value) == true)
		{
			if (msg!="") 
				alert(msg);
			else
				alert("Validation Error ! ");
			focus();
			return false;
		}
		return true;
	}
}

function isPositive(frm,ctrl,msg)
{
	var obj = levelInDep(frm,ctrl);
	with (obj)
	{
		if (parseInt(value) < 0)
		{
			if (msg!="") 
				alert(msg);
			else
				alert("Validation Error ! ");
			focus();
			return false;
		}
		return true;
	}
}

function isalphabet(frm,ctrl,msg)
{
	var obj = levelInDep(frm,ctrl);
	var noalpha = /^[a-zA-Z]*$/;
	with (obj)
	{
		if (!noalpha.test(trim(value)))
		{
			if (msg!="") 
				alert(msg);
			else
				alert("Validation Error ! ");
			focus();
			return false;
		}
		return true;
	}
//	if (!noalpha.test(document.frm.fieldname.value)) 
//	{
//		 alert(msg);
//		 document.frm.fieldname.focus();
//		 return false;
//	}
}// Check whether the value of an object is numeric
function isOfExactLength(level,entered, alertbox,num)
{	
	var obj = levelInDep(level,entered);
	with (obj)
	{
		if (value.length < num || value.length > num)
		{
			if (alertbox!="") 
			{
				alert(alertbox);
			}
			focus();
			return false;
		}
		else 
		{
			return true;
		}
	}

}

// Check whether the value of an object is numeric
function isOfMinLength(level,entered, alertbox,num)
{	
	var obj = levelInDep(level,entered);
	with (obj)
	{
		if (value.length < num)
		{
			if (alertbox!="") 
			{
				alert(alertbox);
			}
			focus();
			return false;
		}
		else 
		{
			return true;
		}
	}
}

// Check whether the value of an object is numeric
function isOfMaxLength(level,entered, alertbox,num)
{	
	var obj = levelInDep(level,entered);
	with (obj)
	{
		if (value.length > num)
		{
			if (alertbox!="") 
			{
				alert(alertbox);
			}
			focus();
			return false;
		}
		else 
		{
			return true;
		}
	}
}

// Check whether the value of either of the two control blank or not
function isAtleastOneNotEmpty(frm,ctrl1,ctrl2,msg)
{
	var obj1 = levelInDep(frm,ctrl1);
	var obj2 = levelInDep(frm,ctrl2);
	with (obj1)
	{
		if (value=="" && obj2.value=="")
		{
			if (msg!="") 
				alert(msg);
			else
				alert("Validation Error ! ");
			focus();
			return false;
		}
		return true;
	}
}

// Check whether the value of two control equals or not
function isNotEqual(frm,ctrl1,ctrl2,msg)
{
	var obj1 = levelInDep(frm,ctrl1);
	var obj2 = levelInDep(frm,ctrl2);
	with (obj2)
	{
		if (value!=obj1.value)
		{
			if (msg!="") 
				alert(msg);
			else
				alert("Validation Error ! ");
			focus();
			return false;
		}
		return true;
	}
}

// Check whether an Email address is valid
function isValidEmail(frm,ctrl,msg)
{	
	var obj = levelInDep(frm,ctrl);
	with (obj)
	{
		//var regexp =  /^\w(\.?\w)*@\w(\.?[-\w])*\.[a-z]{2,4}$/i;
		var regexp = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		
		if (regexp.test(trim(value)) != true)
		{
			if (msg!="") 
				alert(msg);
			else
				alert("Validation Error ! ");
			focus();
			return false;
		}
		return true;
	}
}

// Check whether the something is selected in the list or not
function isSingleSel(level,entered, alertbox) 
{ 
	var obj = levelInDep(level,entered);
	with (obj)
	{
		if (selectedIndex != 0)
		{
			return true;
		}
		else 
		{
			if (alertbox!="") 
			{
				alert(alertbox);
			}
			focus();
			return false;
		}
	}
} 

// Check whether the something is selected in the multi select list or not
function isMultipleSel(level,entered, alertbox) 
{ 
	var obj = levelInDep1(level,entered);
	with (obj)
	{
		if (selectedIndex != 0)
		{
			return true;
		}
		else 
		{
			if (alertbox!="") 
			{
				alert(alertbox);
			}
			focus();
			return false;
		}
	}
} 
function isValidURL(frm,ctrl,msg)
    { 
 		var obj = levelInDep(frm,ctrl);
		with (obj)
		{
 			var regexp =  /(http|ftp|https):\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?\+%&=]*)?$/i;
			if (regexp.test(trim(value)) != true)
			{
				if (msg!="") 
				alert(msg);
			else
				alert("Validation Error ! ");
				focus();
				return false;
			}
		return true;
		}
   }

function ChkEmail(mail)
{
		var str=mail;
				
		if (!str=="")
		{
			if (str.indexOf("@",1) == -1)
			{
				alert("That is not a valid Email address. Please enter again.");
				return false;
			}
			if (str.indexOf("@",1)== 0)
			{
				alert("That is not a valid Email address. Please enter again.");
				return false;
			}
			if (str.indexOf(".")== 0)
			{
				alert("That is not a valid Email address. Please enter again.");
				return false;
			}
			if (str.indexOf(".",1) == -1)
			{
				alert("That is not a valid Email address. Please enter again.");
				return false;
			}
		
			// extra validation
			var posat=str.indexOf("@");
			var posdot=str.indexOf(".");
			var rposdot=str.lastIndexOf(".");
			if(rposdot==posdot)
			if((posdot < posat) || (posdot-posat < 3))
			{
				alert("That is not a valid Email address. Please enter again.");
				return false;
			}
			if(str.charAt(str.length-1)==".")
			{
				alert("That is not a valid Email address. Please enter again.");
				return false;
			}
			if(str.charAt(str.length-1)=="@")
			{
				alert("That is not a valid Email address. Please enter again.");
				return false;
			}
			var j=0;
			for( var i=0;i<str.length;i++)
			{
				if(str.charAt(i) == "@")
				j++;
			}
			if(j > 1)
			{
			alert("That is not a valid Email address. Please enter again.");
			return false;
			}
		}
		return true;
}


/*
  Function for checking if one or more value is selected in a multi select list box
  
  arguments: listbox id, alert message
*/

function isNotEmptyListBox(lisBoxId, alertMsg)
{
 	var listBox = document.getElementById(lisBoxId);
	
	var b;
	for (i = 0; i < listBox.options.length; i++) {
    	if (listBox.options[i].selected) { var b = 1 }
	}
    if (!b) {
            alert(alertMsg);
            listBox.focus();
            return false;
      } else if (b == 1) {
            return true;
    }
}

/* To validate if a check box is checked */
function isCheckedCheckBox(ChkBoxId, AlertMsg)
{
	var chkBox = document.getElementById(ChkBoxId);
	if(chkBox.checked==true)
		return true;
	else
	{
		alert(AlertMsg);
		chkBox.focus();
		return false;
	}
}

function isCheckedMultiCheckBox(frm, ChkBoxName, AlertMsg)
 {
	 count=0;
	 
	 var obj = levelInDep(frm,ChkBoxName);
	 
	 len=obj.length;
	 
	 for(i=0;i<len;i++)
	 {
		 if(obj[i].name==ChkBoxName)
		 {
			 if(obj[i].checked==true)
			 {
				 count=1;
				 break;
			 }
		 }
	 }
	 if(count!=1)
	 {
		 alert(AlertMsg);
		 return false;
	 }
	 return true;
 }

function hasNoSpecialCharecters(TxtBoxId, AlertMsg)
{
	var txtBox = document.getElementById(TxtBoxId);
	var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
	
	if(AlertMsg.length == 0)
		AlertMsg = "Special charecters are not allowed. Please remove them and try again.";

	for (var i = 0; i < txtBox.value.length; i++) {
		if (iChars.indexOf(txtBox.value.charAt(i)) != -1) {
			//alert ("Your username has special characters. \nThese are not allowed.\n Please remove them and try again.");
			alert(AlertMsg);
			txtBox.focus();
			return false;
		}
	}
	return true;
}

function isValidUsername (TxtBoxId, AlertMsg)
{
	var error = "";
	var fld = document.getElementById(TxtBoxId);
	if(AlertMsg.length == 0)
		AlertMsg = "This field contains illegal characters.\n\nOnly letters, numbers and underscores are allowed.";	
	
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow';		
        alert(AlertMsg);
		fld.focus();
		return false;
    }
	else
	{
		fld.style.background = 'White';
		return true;
	}
}

function isValidPassword (TxtBoxId, AlertMsg)
{
	var fld = document.getElementById(TxtBoxId);
	if(AlertMsg.length == 0)
		AlertMsg = "This field contains illegal characters.\nOnly letters and numbers are allowed.";	
	
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow';		
        alert(AlertMsg);
		fld.focus();
		return false;
    }
	else

	{
		fld.style.background = 'White';
		return true;
	}
}

// to get if a field created by tinymce is blank
function isNotEmpty_tinyMCE(elmID, alertMsg)
{
	var value = tinyMCE.get(elmID).getContent();

	if(alertMsg.length == 0)
		alertMsg = "Please Enter "+elmID;
	
	if (value==null || trim(value)=="")
	{
		if (alertMsg!="")
		{			
			tinyMCE.execCommand('mceFocus', true, elmID);
			alert(alertMsg);
		}
		return false;
	}
	return true;
}

// check if number entered
// use:  onkeypress="return isNumberKey(event)"
function isNumberKey(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57))
	{
    	alert("Enter only numbers in this field.");
        return false;
    }
    return true;
}

// use: <input name="number"  onKeyPress="return numbersonly(event, false)">
function numbersonly(e, decimal) {
	var key;
	var keychar;
	
	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) ) {
	   return true;
	}
	else if ((("0123456789").indexOf(keychar) > -1)) {
	   return true;
	}
	else if (decimal && (keychar == ".")) { 
	  return true;
	}
	else
	{
	   alert("Enter only numeric values in this field.");
	   return false;
	}
}

// check minimum length
function checkMinLength (TxtBoxId, len, AlertMsg)
{
	var error = "";
	var fld = document.getElementById(TxtBoxId);
	if(AlertMsg.length == 0)
		AlertMsg = "Please enter atleast "+len+" charecters.\n";	
	
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value.length < len) {
        fld.style.background = 'Yellow';		
        alert(AlertMsg);
		fld.focus();
		return false;
    }
	else
	{
		fld.style.background = 'White';
		return true;
	}
}

// Check whether an Email address is valid
function isEmail(EmailID)
{	
	//var regexp = /^\w(\.?\w)*@\w(\.?[-\w])*\.[a-z]{2,4}$/i;
	var regexp = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if (regexp.test(trim(EmailID)) != true)
		return false;
	return true;
}

function init_TinyMCE(elms)
{
		tinyMCE.init({
		theme : "advanced",
		mode: "exact",
		elements : elms,
		skin : "o2k7", skin_variant : "silver",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,ibrowser",

		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,|,ibrowser",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_toolbar: false,
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
		
		forced_root_block : false,
		force_br_newlines : true,
		force_p_newlines : false,
		
		extended_valid_elements : "div[class|style],span[class|style],code[class],iframe[src|width|height|name|align|frameborder|scrolling]",
		
		width : "650",
		height : "450",
		
		//file_browser_callback : "tinyBrowser",
		
		content_css : "../../css/style.css",
		convert_urls : false
	});
}

// proceed to next control on enter key press and disable form submit
function handleEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
		if (field == field.form.elements[i])
		break;
		i = (i + 1) % field.form.elements.length;
		if(i > 0)
			field.form.elements[i].focus();
		return false;
	} 
	else
	return true;
}

// add the current page in bookmark in IE/FF/Opera
function addBookmarkThisPage(){
  title = document.title;
  url = self.location;
  if(window.sidebar){ // Firefox
    window.sidebar.addPanel(title, url,'');
  }else if(window.opera){ //Opera
    var a = document.createElement("A");
    a.rel = "sidebar";
    a.target = "_search";
    a.title = title;
    a.href = url;
    a.click();
  } else if(document.all){ //IE
    window.external.AddFavorite(url, title);
  }
  else
  	alert("Please use 'Ctrl+D' to bookmark this page.");
}

function remName(a, b){
	if(a.value==b){
		a.value='';
	}else if(a.value==''){
		a.value=b;
	}else{
		a.value=a.value;
	}
}

function chkName(a, b){
	if(a.value==''){
		a.value=b;
	}else{
		a.value=a.value;
	}
}

//  Encodes an ISO-8859-1 string to UTF-8
function utf8_encode ( argString ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: sowberry
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // +   improved by: Yves Sucaet
    // +   bugfixed by: Onno Marsman
    // +   bugfixed by: Ulrich
    // *     example 1: utf8_encode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'

    var string = (argString+''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");

    var utftext = "";
    var start, end;
    var stringl = 0;

    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;

        if (c1 < 128) {
            end++;
        } else if (c1 > 127 && c1 < 2048) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }

    if (end > start) {
        utftext += string.substring(start, string.length);
    }

    return utftext;
}

UTF8 = {
	encode: function(s){
		for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
			s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
		);
		return s.join("");
	},
	decode: function(s){
		for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
			((a = s[i][c](0)) & 0x80) &&
			(s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
			o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
		);
		return s.join("");
	}
};

function loadScript(url)
{
  document.write('<script src="', url, '" type="text/javascript"></script>');
}

function staticLoadScript(url)
{
   document.write('<script src="', url, '" type="text/JavaScript"><\/script>');
}

function dhtmlLoadScript(url)
{
   var e = document.createElement("script");
   e.src = url;
   e.type="text/javascript";
   document.getElementsByTagName("head")[0].appendChild(e);
}
