//--------------------  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) 

	{

		if(tempobj.alt)

		{

			shortFieldName=tempobj.alt ; 

		}

		else if(tempobj.title)

		{

			shortFieldName=tempobj.title ; 

		}

		else

		{

			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 checkrequiredRadio(tempobj) 

{ 



	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(); 

			alert("Please make sure the "+shortFieldName+" field was properly completed."); 

			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 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 onkey(e,obj)

	{

		var keyascii;

		

		if(window.event) // IE

		{

			keyascii = e.keyCode;

		}else

			keyascii = e.which

		var str=obj.value

		

		if(keyascii==46)

		{ 

			if (str.indexOf(".")>=0)

			{

			

				

				if(window.event) // IE

				{

					e.keyCode = 0;

				}else

					return false

					

				//window.event.keyCode = 0;

				return false

			}

		}

		else {

				

				if ((keyascii < 48) || (keyascii > 57))

				{

					if(window.event) // IE

					{

						e.keyCode = 0;

						return false ;	

					}else if(keyascii !=8  )

						return false ;

						//window.event.keyCode = 0;

				}

				return;

			}

	}



//----------------- 

// <input type="text" onkeypress="return noNumbers(event)" />

//-----------------



	

	function noNumbers(e)

	{

	var keynum

	var keychar

	var numcheck

	

	if(window.event) // IE

	{

	keynum = e.keyCode

	}

	else if(e.which) // Netscape/Firefox/Opera

	{

	keynum = e.which

	}

	if(keynum == 8)

	return true;

	keychar = String.fromCharCode(keynum)

	numcheck = /\d/

	return numcheck.test(keychar)

	}



//-----------------------------------------------------------------

	function onkeyPlus(obj)

	{

		var keyascii;

		keyascii = window.event.keyCode;



		var str=obj.value

		if(keyascii!=43 && keyascii!=45)

		{ 

			window.event.keyCode = 0;

			return false

		}

		return true;

	}

//-----------------------------------------------------------------

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)

	{

		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)

	}

//----------------------------------------------------------------------

  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", "GIF","JPG","JPEG", ];

		flag=0;

		for(i=0;i<6;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 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 ;

			}

	}



//----------------------------------------------------------------------

	function chkSelectedRecord(form)

	{

		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)

		{

				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();

	}	



//----------------------------------------------------------------------



function DeleteCartCheck() 

	{

		var Verify=confirm("Are you sure you want to empty cart?");

		if (Verify == true)

		{

		//	document.frmDelete.MemberCode.value=Code;

		//	document.frmDelete.submit();

			return true;			

		}

		else {

			return false;			

		}

	}

//-------------------------------------------------------------

function days_between(date1, date2) 

	{

		// The number of milliseconds in one day

		var ONE_DAY = 1000 * 60 * 60 * 24

	

		// Convert both dates to milliseconds

		var date1_ms = date1.getTime()

		var date2_ms = date2.getTime()

	

		// Calculate the difference in milliseconds

		var difference_ms = Math.abs(date1_ms - date2_ms)

		

		// Convert back to days and return

		return Math.round(difference_ms/ONE_DAY)

	}

//----------------------------------------------------------

  

  function Csvval(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=["csv"];

		flag=0;

		for(i=0;i<3;i++)

		  {

				if(marray[i]==data)

				   flag=1;

		  }

		if(flag==0)

		  {

				alert("Please upload valid photo (csv)");

				obj.focus();

				return false;

		  }

	  }

  }



//----------------------------------------------------------------------

function roundNumber(num, dec) {

	alert(num+' '+dec) ;

	

	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);

	alert(result) ;

	return result;

}

//----------------------------------------------------------------------

function trim (inputString) {

// Removes leading and trailing spaces from the passed string. Also removes

// consecutive spaces and replaces them with one space. If something besides

// a string is passed in (null, custom object, etc.), then return the input.

if (typeof inputString != "string") { return inputString; }

var retValue = inputString;

var ch = retValue.substring(0, 1);

while (ch == " ") { // Check for spaces at the beginning of the string

retValue = retValue.substring(1, retValue.length);

ch = retValue.substring(0, 1);

}

ch = retValue.substring(retValue.length-1, retValue.length);

while (ch == " ") { // Check for spaces at the end of the string

retValue = retValue.substring(0, retValue.length-1);

ch = retValue.substring(retValue.length-1, retValue.length);

}

while (retValue.indexOf(" ") != -1) {

// Note there are two spaces in the string

// Therefore look for multiple spaces in the string

retValue = retValue.substring(0, retValue.indexOf(" ")) +

retValue.substring(retValue.indexOf(" ")+1, retValue.length);

// Again, there are two spaces in each of the strings

}

return retValue; // Return the trimmed string back to the user

} // Ends the "trim" function

//----------------------------------------------------------------------

function removeSpaces(string) {

	var tstring = "";

	string = '' + string;

	splitstring = string.split(" ");

	for(i = 0; i < splitstring.length; i++)

	tstring += splitstring[i];

	return tstring;

}

//----------------------------------------------------

function VerifyLink(obj)

{

	if (obj.value.substring(0, 7) != 'http://' && obj.value.substring(0, 8) != 'https://' && !(obj.value.substring(0, 1) == '#' && obj.value.length==1))

	{

		alert('Enter valid link') ;

		obj.focus() ;

		return false ;

	}



	return true ;

}

//----------------------------------------------------



	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);

	}

