//--------------------  COMMON FUNCTION FOR WHOLE SITE ----------------------------------
function checkrequired(which) 
{ 
	var pass=true; 
	if (document.images) 
	{ 
		for (i=0;i<which.length;i++) 
		{ 
			
			var tempobj=which.elements[i]; 
			if (tempobj.name.substring(0,8)=="required") 
			{ 
				
				if ((tempobj.type=="file" || tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="password" ||tempobj.type.toString().charAt(0)=="s" ) && tempobj.value=='')
				{ 
					if(tempobj.disabled==false)
					{
						pass=false; 
						break; 
					}
				}
			} 
		} 
	} 
	if (!pass) 
	{ 
		shortFieldName=tempobj.name.substring(8,30).toUpperCase();
		shortFieldName=shortFieldName.replace("[","")
		shortFieldName=shortFieldName.replace("]","")
		alert("Please make sure the "+shortFieldName+" field was properly completed."); 
		tempobj.focus() ;						
		return false; 
				
	} else 
	
	return true; 
			
} 
//--------------------------------------------------------------
function checkrequiredRadio(tempobj,msg) 
{ 

	var pass=true; 
	if (tempobj.type!="radio")
	{
		for (i=0;i<tempobj.length;i++) 
		{ 
			if (tempobj[i].checked==true)
			{ 
				pass=true; 
				break; 
			}else
			   pass=false;
		} 
		if (!pass) 
		{ 
			shortFieldName=tempobj[0].name.substring(8,30).toUpperCase(); 
			if(msg=="")
				alert("Please make sure the "+shortFieldName+" field was properly completed."); 
			else
				alert(msg) ;
			return false; 
					
		}else 
			return true; 
	}else
		if (tempobj.checked==false)
		{
			shortFieldName=tempobj.name.substring(8,30).toUpperCase(); 
			alert("Please make sure the "+shortFieldName+" field was properly completed."); 
			return false; 
		}else
			return true ;
} 
//-------------------------------------------------------
function DeleteCheck() 
	{
		var Verify=confirm("Are you sure you want to delete this  record and all related records?");
		if (Verify == true)
		{
		//	document.frmDelete.MemberCode.value=Code;
		//	document.frmDelete.submit();
			return true;			
		}
		else {
			return false;			
		}
	}
//-------------------------------------------------------------
function DeleteCheckPDF() 
	{
		var Verify=confirm("Are you sure you want to delete this PDF?");
		if (Verify == true)
		{
		//	document.frmDelete.MemberCode.value=Code;
		//	document.frmDelete.submit();
			return true;			
		}
		else {
			return false;			
		}
	}
//-------------------------------------------------------------
	function onkey(obj)
	{
		var keyascii;
		keyascii = window.event.keyCode;
	
		var str=obj.value
		if(keyascii==46)
		{ 
			if (str.indexOf(".")>0)
			{
				window.event.keyCode = 0;
				return false
			}
		}
		else {
				if ((keyascii < 48) || (keyascii > 57))
				{
					window.event.keyCode = 0;
				}
				return;
			}
	}
//-----------------------------------------------------------------
function verifyMail(obj)
{
	if(obj.value.length != 0)
    {
      var str = obj.value;
      var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
      var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
	  if (!reg1.test(str) && reg2.test(str))
      {
		 // return true;
      }else
	  {
		 alert("\"" + str + "\" is an invalid e-mail!");
       	 obj.focus();
         return false;
	   }
	}
}
//----------------------------------------------------------------------
	function winOpen(str,Name,Resize,Width,Height,Left,Top)
	{
		win = window.open(str,Name,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable='+Resize+',width='+Width+',height='+Height+',left='+Left+',top='+Top)
		win.focus() ;
	}
//----------------------------------------------------------------------
  function Imageval(obj)
  {
	  if(obj.value!="")
	  {
		var data=obj.value;
		if (data.indexOf('%') > -1)
		{
				alert("Filename contains invalid character '%'");
				obj.focus();
				return false;
		}
		var len=data.lastIndexOf('.');
		data=data.substring(len+1);
		marray=["gif","jpg","jpeg"];
		flag=0;
		for(i=0;i<3;i++)
		  {
				if(marray[i]==data)
				   flag=1;
		  }
		if(flag==0)
		  {
				alert("Please upload valid photo (gif - jpg - jpeg)");
				obj.focus();
				return false;
		  }
	  }
  }
//----------------------------------------------------------------------
  function Pdfval(obj)
  {
	  if(obj.value!="")
	  {
		var data=obj.value;
		if (data.indexOf('%') > -1)
		{
				alert("Filename contains invalid character '%'");
				obj.focus();
				return false;
		}
		var len=data.lastIndexOf('.');
		data=data.substring(len+1);
		marray=["pdf"];
		flag=0;
		for(i=0;i<3;i++)
		  {
				if(marray[i]==data)
				   flag=1;
		  }
		if(flag==0)
		  {
				alert("Please upload valid .pdf file.");
				obj.focus();
				return false;
		  }
	  }
  }

//----------------------------------------------------------------------
  function Swfval(obj)
  {
	  if(obj.value!="")
	  {
		var data=obj.value;
		if (data.indexOf('%') > -1)
		{
				alert("Filename contains invalid character '%'");
				obj.focus();
				return false;
		}
		var len=data.lastIndexOf('.');
		data=data.substring(len+1);
		marray=["swf"];
		flag=0;
		for(i=0;i<3;i++)
		  {
				if(marray[i]==data)
				   flag=1;
		  }
		if(flag==0)
		  {
				alert("Please upload valid .swf file.");
				obj.focus();
				return false;
		  }
	  }
  }

//----------------------------------------------------------------------
	function replaceDoubleToSingle(strLoadText)
	{
		var strText ;
		out = '~"~'; // replace this
		add = "'"; // with this
		strText = "" + strLoadText; // temporary holder
		while (strText.indexOf(out)>-1)
		{
			pos= strText.indexOf(out);
			strText = "" + (strText.substring(0, pos) + add + 
			strText.substring((pos + out.length), strText.length));
		}

		return strText ;
	}

//----------------------------------------------------------------------
	function checkbody(form,msg)
	{
		if (editor.GetHTML() == "")
		{
			alert("Please make sure "+msg+" field was properly completed.")
			return false;
		}
		if (editor.GetHTML() == "<P>&nbsp;</P>")
		{
			alert("Please make sure "+msg+" field was properly completed.")
			return false;
		}
		form.Body.value = editor.GetHTML();
	}	

//----------------------------------------------------------------------
	function chkUncheck(form,no)
	{
		len = form.elements.length;
		var i=0;
		var cnt=0;
		for( i=0 ; i<len ; i++)
		{
			if (form.elements[i].type=='checkbox')
			{
				if (form.elements[i].checked==false)
					cnt++ ;
			}
		}
		if (no>cnt)
		{
				alert("Minimum "+no+" number of record/s should be unchecked.") ;
				return false ;
		}
	}
//----------------------------------------------------------------------
	function chkMaxRecord(form,no)
	{
		len = form.elements.length;
		var i=0;
		var cnt=0;
		var chkBox=0;
		for( i=0 ; i<len ; i++)
		{
			if (form.elements[i].type=='checkbox')
			{
				if (form.elements[i].checked==true)
					cnt++ ;
				chkBox++ ;
			}
		}
		if (chkBox >= no )
			if (no != cnt)
			{
					alert("User should select any "+no+" record/s.") ;
					return false ;
			}
		if ( cnt ==0)
		{
				alert("User should select any "+no+" record/s.") ;
				return false ;
		}
		return true
}

//----------------------------------------------------------------------
	function chkSelectedRecord(form,msg)
	{
		len = form.elements.length;
		var i=0;
		var Found=false;
		for( i=0 ; i<len ; i++)
		{
			if (form.elements[i].type=='checkbox')
			{
				if (form.elements[i].checked==true)
				{
					Found=true;
					break ;
				}
			}
		}
		if (Found==false)
		{
				if(msg!="" && msg != undefined)
					alert(msg)
				else	
					alert("Please select at least one record.") ;
				return false ;
		}
		return true ;
	}
//----------------------------------------------------------------------

/**
 * DHTML date validation script. 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 strMonth=dtStr.substring(0,pos1)
	var strDay=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 : mm/dd/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
}

function ValidateDate(strValue){
	if (isDate(strValue)==false){
		//obj.focus()
		return false
	}
    return true
 }
 
 	function checkZero(which) 
	{ 
		var pass=true; 
		if (document.images) 
		{ 
			for (i=0;i<which.length;i++) 
			{ 
				var tempobj=which.elements[i]; 
				if (tempobj.name.substring(0,8)=="required") 
				{ 
					if (tempobj.type=="text" && tempobj.value <=0 )
					{
						pass=false; 
						break ;
					}
						
				} 
			} 
		} 
		if (!pass) 
		{ 
			shortFieldName=tempobj.name.substring(8,30).toUpperCase(); 
			alert("Please make sure the "+shortFieldName+" field was properly completed."); 
			tempobj.focus() ;						
			return false; 
					
		} else 
			return true; 

	} 	


//----------------------------------------------------------------------
	function EditorOnSetClass(id)
	{
		if (eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.createRange().text == "")
		{
			alert("Please select text") ;
			return false;
		}
		
		if (!EditorValidateMode(id))
		{
			return;
		}

			var newclass = showModalDialog("ClassSelect.php", "", "font-family:Verdana;font-size:12;dialogWidth:13em;dialogHeight:20em;status:0;resizable:1;");

		if (newclass && newclass != "")
		 {
			var range = eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.createRange();
			//var rangeText = eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.createRange();
			if (eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.type == "Text")
			{
				var strText = range.text	
			}	

			if(range.parentElement().outerHTML.indexOf("<SPAN")==0)
			{
				if (strText == range.parentElement().innerText)
					range.parentElement().outerHTML = ""
			}
			if (eval(EDITOR_COMPOSITION_PREFIX + id).document.selection.type == "Text")
			{
				range.pasteHTML('<span ' + newclass + '>' + strText + '</span>');
				range.select();
			}
			else
			{
				range.pasteHTML('<span ' + newclass + '>' + strText + '</span>');
				range.select();
			}
			
		}
	}
//----------------------------------------------------------------------
	function checkmultibody(form,msg,Body,NewEditor)
	{
		if (NewEditor.GetHTML() == "")
		{
			alert("Please make sure "+msg+" field was properly completed.")
			return false;
		}
		if (NewEditor.GetHTML() == "<P>&nbsp;</P>")
		{
			alert("Please make sure "+msg+" field was properly completed.")
			return false;
		}
		Body.value = NewEditor.GetHTML();
	}	

//--------------- Domain Validaton -------------------------------------------------------

function checkDomain(nname,obj)
{
		
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','.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');

var mai = nname;
var val = true;

var dot = mai.lastIndexOf(".");
var dname = mai.substring(0,dot);
var ext = mai.substring(dot,mai.length);
//alert(ext);
	
if(dot>2 && dot<57)
{
	for(var i=0; i<arr.length; i++)
	{
	  if(ext == arr[i])
	  {
	 	val = true;
		break;
	  }	
	  else
	  {
	 	val = false;
	  }
	}
	if(val == false)
	{
	  	 alert("Your domain extension "+ext+" is not correct");
		 obj.focus() ;
		 return false;
	}
	else
	{
		for(var j=0; j<dname.length; j++)
		{
		  var dh = dname.charAt(j);
		  var hh = dh.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==45 || hh==46)
		  {
			 if((j==0 || j==dname.length-1) && hh == 45)	
		  	 {
		 	  	 alert("Domain name should not begin are end with '-'");
				 obj.focus() ;
			      return false;
		 	 }
		  }
		else	{
		  	 alert("Your domain name should not have special characters");
			 obj.focus();
			 return false;
		  }
		}
	}
}
else
{
 alert("Your Domain name is too short/long");
 obj.focus() ;
 return false;
}	

return true;
}

//----------------------------------------------------------

	function replaceSingleToDouble(strLoadText)
	{
		var strText ;
		out = "~'~"; // replace this
		add = '"'; // with this
		strText = "" + strLoadText; // temporary holder
		while (strText.indexOf(out)>-1)
		{
			pos= strText.indexOf(out);
			strText = "" + (strText.substring(0, pos) + add + 
			strText.substring((pos + out.length), strText.length));
		}

		return strText ;
	}
