/*
	function funtionFormat()
	{
		try
		{
		}
		catch(e)
		{
			alert(e);
			return false;
		}
	}
	*/
/*
	Basic Functions
		Trim(trimstr)
		RTrim(VALUE)
		LTrim(VALUE)
		checkAllCheckBoxes()
		checkSpecialCharacter(str)
		isValidURL(url)
		checkIt(evt,var1,var2,var3,var4,var5)
		checkNumbers(evt,var1,var2,var3,var4,var5)
		check_phone_mobile(evt) 
		allow_only_number(evt)
		textLimit(field, maxlen) 
		hasWhiteSpace(s) 
		clear_search(varUrl)
		formatCurrency(num) 
*/

//-------------------------------------------------------------------------------// 
	function Trim(trimstr)
	{
		if(trimstr.length < 1)
		{
				 return"";
		}
		trimstr = RTrim(trimstr);
		trimstr = LTrim(trimstr);
		if(trimstr=="")
		{
				 return "";
		}
		else
		{
				 return trimstr;
		}
	} 
	
//-------------------------------------------------------------------------------// 
	function RTrim(VALUE)
	{
		var w_space = String.fromCharCode(32);
		var v_length = VALUE.length;
		var strTemp = "";
		if(v_length < 0)
		{
				 return"";
		}
		var iTemp = v_length -1;

		while(iTemp > -1)
		{
				 if(VALUE.charAt(iTemp) == w_space)
				 {
				 }
				 else
				 {
							 strTemp = VALUE.substring(0,iTemp +1);
							 break;
				 }
				 iTemp = iTemp-1;
		} //End While
		return strTemp;
	} 
	
//-------------------------------------------------------------------------------// 	
	function LTrim(VALUE)
	{
		var w_space = String.fromCharCode(32);
		if(v_length < 1)
		{
				 return"";
		}
		var v_length = VALUE.length;
		var strTemp = "";

		var iTemp = 0;
		while(iTemp < v_length)
		{
				 if(VALUE.charAt(iTemp) == w_space)
				 {
				 }
				 else
				 {
							 strTemp = VALUE.substring(iTemp,v_length);
							 break;
				 }
				 iTemp = iTemp + 1;
		} //End While
		return strTemp;
	}

//-------------------------------------------------------------------------------// 
	function checkAllCheckBoxes()
  {
		frmCheckform =document.frmMain;
		var chks = document.getElementsByName('chkId[]');
		var hasChecked = false;
		for (var i = 0; i < chks.length; i++)
		{
			if(frmCheckform.CheckAll.checked)
			 {
				chks[i].checked=true;
				
			 }
			else	
			 {
				 chks[i].checked=false;
			 }
		}
	}


	
//-------------------------------------------------------------------------------// 	
	function checkSpecialCharacter(str)
	{
      var iChars = "!@#$%^&*()+=[]\\;/{}|\":<>?";
      for (var i = 0; i < str.length; i++)
      {
           if (iChars.indexOf(str.charAt(i)) != -1)
           {
                 return false;
           }
      }
	}

//-------------------------------------------------------------------------------// 	
	function isValidURL(url)
	{
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url)){
        return true;
    }else{
        return false;
    }
	} 
//-------------------------------------------------------------------------------// 	
	function checkIt(evt,var1,var2,var3,var4,var5)
   {
	    //'webPageValidation','webpageLink','<?=$var4?>',this.value,'<?=$postLink?>',
	    
	    //showMessages1(var1,var2,var3,var4,var5);
			evt = (evt) ? evt : window.event
       var charCode = (evt.which) ? evt.which : evt.keyCode
			 //alert("test" + charCode);
       if ((charCode >= 97 && charCode <= 122) || (charCode >= 65 && charCode <= 90) || (charCode >= 48 && charCode <= 57) || (charCode==45) || (charCode==95) || (charCode==8) ) {
          var  status = "This field accepts numbers only."
					//showMessages1(var1,var2,var3,var4,var5);
          return true;
        }
				else
				 return false;
	 
	 }
	
//-----------------------------------------------------------------------------------------------------------
  function checkNumbers(evt,var1,var2,var3,var4,var5)
   {
	    //'webPageValidation','webpageLink','<?=$var4?>',this.value,'<?=$postLink?>',
	    
	    //showMessages1(var1,var2,var3,var4,var5);
			evt = (evt) ? evt : window.event
       var charCode = (evt.which) ? evt.which : evt.keyCode
			 //alert("test" + charCode);
       if ((charCode >= 48 && charCode <= 57) || (charCode==8) ) {
          var  status = "This field accepts numbers only."
					//showMessages1(var1,var2,var3,var4,var5);
          return true;
        }
				else
				 return false;
	 
	 }

//-----------------------------------------------------------------------------------------------------------
	function check_phone_mobile(evt) 
	{
  //alert("hi");
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
		
    if ((charCode > 31 && (charCode < 48 || charCode > 57)) && (charCode!=43) && (charCode!=32) && (charCode!=45) && (charCode!=40) && (charCode!=41) && (charCode!=46) && (charCode!=47) &&  (charCode!=58) && (charCode!=44))  {
        
        return false
    }
    
    return true;
	}

//--------------------------------------------------------------------------------------------------------------------
// allow_only_number(evt) 
function allow_only_number(evt) {
  //alert("hi");
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
		//alert("hi"+charCode);
    if ((charCode < 48 || charCode > 57) && charCode!=8)  {
        
        return false
    }
    
    return true;
}


//--------------------------------------------------------------------------------------------------------------------
// textLimit(field, maxlen) 
function textLimit(field, maxlen) 
{
if (field.value.length > maxlen + 1)
alert('Maximum Word Limit reached.');
if (field.value.length > maxlen)
field.value = field.value.substring(0, maxlen);
}

//--------------------------------------------------------------------------------------------------------------------
// hasWhiteSpace(s) 

function hasWhiteSpace(s) 
{
 
     reWhiteSpace = new RegExp(/^\s+$/);
 
     // Check for white space
     if (reWhiteSpace.test(s)) {
          alert("Please remove the spaces from the link field");
					document.frm_main.postLink.focus();
          return false;
     }
return true;
} 


	  
//--------------------------------------------------------------------------------------------------------------------
	function clear_search(varUrl)
	{
			 //alert(varUrl);
			 document.frmMain.action=varUrl+"&clear=1";;
			 document.frmMain.submit();
		
	}

//--------------------------------------------------------------------------------------------------------------------
	function formatCurrency(num) 
	{
		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));
		return (((sign)?'':'-') + '$' + num + '.' + cents);
	}

//-------------------------------------------------------------------------------// 	

<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
// Date Validation Start here
/**
 * DHTML date validation script for dd/mm/yyyy. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

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++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
	return true
	}
	
	
	//----------------------------Telephone Numbers ------------------------------------------//
	
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trimString(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;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone)
{
	var bracket=3
	strPhone=trimString(strPhone)
	if(strPhone.indexOf("+")>1) return false
	if(strPhone.indexOf("-")!=-1)bracket=bracket+1
	if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
	var brchr=strPhone.indexOf("(")
	//if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
	//if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}


function textCounter(field,maxlimit) 
{
	if (field.value.length > maxlimit) // if too long...trim it!
	{
		field.value = field.value.substring(0, maxlimit);
	}
}
// Implode
function implode (glue, pieces) {
    // Joins array elements placing glue string between items and return one string  
    // 
    // version: 1004.2314
    // discuss at: http://phpjs.org/functions/implode    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Waldo Malqui Silva
    // +   improved by: Itsacon (http://www.itsacon.net/)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: implode(' ', ['Kevin', 'van', 'Zonneveld']);    // *     returns 1: 'Kevin van Zonneveld'
    // *     example 2: implode(' ', {first:'Kevin', last: 'van Zonneveld'});
    // *     returns 2: 'Kevin van Zonneveld'
    var i = '', retVal='', tGlue='';
    if (arguments.length === 1) {        pieces = glue;
        glue = '';
    }
    if (typeof(pieces) === 'object') {
        if (pieces instanceof Array) {            return pieces.join(glue);
        }
        else {
            for (i in pieces) {
                retVal += tGlue + pieces[i];                tGlue = glue;
            }
            return retVal;
        }
    }    else {
        return pieces;
    }
}
//explode
// Splits a string on string separator and return array of components. If limit is positive only limit number of components is returned. If limit is negative all components except the last abs(limit) are returned.  
    // 
    // version: 1004.2314
    // discuss at: http://phpjs.org/functions/explode    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)    // *     
		//example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
function explode (delimiter, string, limit) 
{
	var emptyArray = { 0: '' };
	// third argument is not required
	if ( arguments.length < 2 ||typeof arguments[0] == 'undefined' ||        typeof arguments[1] == 'undefined' ) 
	{
		return null;
	}

	if ( delimiter === '' ||        delimiter === false ||delimiter === null ) 
	{
		return false;
	}
	if ( typeof delimiter == 'function' ||typeof delimiter == 'object' ||typeof string == 'function' ||typeof string == 'object' ) 
	{
		return emptyArray;    
	}

	if ( delimiter === true ) 
	{
		delimiter = '1';
	}    
	if (!limit) 
	{
		return string.toString().split(delimiter.toString());
	} 
	else 
	{
		// support for limit argument        var splitted = string.toString().split(delimiter.toString());
		var partA = splitted.splice(0, limit - 1);
		var partB = splitted.join(delimiter.toString());
		partA.push(partB);
		return partA;   
	}
}
//-----------------------------------------------------------------------------------------------------------
	function validateEmail(strEmail,msg1,strFocus)
	{
		try
		{
				
				returnVal="YES";
			// alert(returnVal+"-1-"+strEmail);	
			/*
		 if(strEmail=="")
			{
			 alert("Please enter email address.");
			 return false;
			}
			*/
			//alert(strEmail);
			var emailaddr = strEmail;
			if (emailaddr == '') 
			{
				alert(alertMessages[msg1]);
				//return false;
				strFocus.focus();
				return returnVal="NO";
				
			}

			//if (emailaddr == '') return true;
			var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
			for (i=0; i<invalidChars.length; i++) 
			{
				 if (emailaddr.indexOf(invalidChars.charAt(i),0) > -1) 
				 {
						alert(alertMessages[241]);
						strFocus.focus();
						//return false;
						return returnVal="NO";
						
				 }
			}
			for (i=0; i<emailaddr.length; i++) 
			{
				 if (emailaddr.charCodeAt(i)>127) 
				 {
					alert(alertMessages[242]);
					strFocus.focus();
					//return false;
					return returnVal="NO";
					
				 }
			}
		
			var atPos = emailaddr.indexOf('@',0);
			if (atPos == -1) 
			{
				alert(alertMessages[243]);
				strFocus.focus();
				 //return false;
				 return returnVal="NO";
			}
			if (atPos == 0) 
			{
				alert(alertMessages[244]);
				strFocus.focus();
				//return false;
				return returnVal="NO";
			}
			if (emailaddr.indexOf('@', atPos + 1) > - 1) 
			{
				alert(alertMessages[245]);
				strFocus.focus();
				 //return false;
				 return returnVal="NO";
			}
			if (emailaddr.indexOf('.', atPos) == -1) 
			{
				alert(alertMessages[380]);
				strFocus.focus();
				//return false;
				return returnVal="NO";
			}
			if (emailaddr.indexOf('@.',0) != -1) 
			{
				alert(alertMessages[247]);
				strFocus.focus();
				//return false;
				return returnVal="NO";
			}
			if (emailaddr.indexOf('.@',0) != -1)
			{
				alert(alertMessages[248]);
				strFocus.focus();
				//return false;
				return returnVal="NO";
			}
			if (emailaddr.indexOf('..',0) != -1) 
			{
				alert(alertMessages[249]);
				strFocus.focus();
				//return false;
				return returnVal="NO";
			}			
			 //alert(returnVal+"-2-"+strEmail);
			 return returnVal;
		}
		catch(e)
		{
			alert(e);
			return false;
		}
	}

