// OTHER FUNCTIONS // MISC.


function fullscreen(){
//	var iheight=(screen.height);
//	var iwidth=(screen.width);
window.moveTo(0,0); 
window.resizeTo( screen.availWidth, screen.availHeight);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

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];}
}

function trim(sTr){
	sTr += "";
	sTr = sTr.replace(/^\s*/, "");
	sTr = sTr.replace(/\s*$/, "");
	return (sTr);
}
function isEmailAddress(strValue)
{
       var j,strTemp;
       strTemp = strValue;
       if (strTemp != '')
       {
               var nCountC = 0;
               for ( j = 0; j< strTemp.length; j++ ){
                       c = strTemp.charAt(j);
                       if ( !( c>='0' && c<='9' || c>='a' && c<='z' || c>='A' && c<='Z' || c == '@' || c == '.' || c =='_' || c =='-') )
                               return false;
                       if (c == '@') nCountC  = nCountC + 1;
               }// End for
       if (nCountC != 1)return false;
       if (strTemp.charAt(strTemp.length - 1) == '@' || strTemp.charAt(0) == '@' || strTemp.charAt(strTemp.length - 1) == '.' || strTemp.charAt(0) == '.')
               return false;
       }
          return true;
}



function isValidDate( s ){ //check if the input date is in the format d/m/yyyy
	var sDay, sMonth, sYear, nMonth, nDay, nYear, dateArr;
	s = trim(s);
	if (s == "") {
		return false;
	}
	dateArr = s.split("/");
	if ( dateArr.length != 3 ){
		return false;
	}
	sDay = trim(dateArr[0]);	sMonth = trim(dateArr[1]);	sYear = trim(dateArr[2]);
	if ( !sMonth.length || !sDay.length || sYear.length <4){
		return false;
	}
	// isNaN(empty) is false
	if ( isNaN(sMonth) || isNaN(sDay) || isNaN(sYear) ){
		return false;
	}
	nMonth = parseInt(sMonth,10); nDay = parseInt(sDay,10); nYear = parseInt(sYear,10);//convert from a string to interger
	if ( nMonth<=0 || nDay<=0 || nYear<0 ) {
		return false;
	}
	if ( nMonth > 12 || nDay > 31) {
	    return false;
	}
	if ((nMonth==4 || nMonth==6 || nMonth==9 || nMonth==11) && (nDay > 30)) {
		return false;
	}
	if (nMonth==2) {
		if (isLeapYear(nYear)) { // leap year
	    	if ( nDay > 29 ) {
	        	return false;
	        }
	    } 
		else {
			if ( nDay > 28 ){
	    		return false;
			}
	    }
	}
	return true;
}

function isLeapYear(intYear){
	intYear = Number(intYear);
	if (intYear % 4 != 0) {
		return false;
	}
	if (intYear % 400 == 0) {
		return true;
	}
	if (intYear % 100 == 0) {
		return false;
	}
	return true;
}

function compareDate(d1, d2)
{var out;
	var arr1 = d1.split("/");
	var arr2 = d2.split("/");
	
	var day1 = parseInt(arr1[0],10);
	var month1 = parseInt(arr1[1],10);
	var year1 = parseInt(arr1[2],10);
	
	var day2 = parseInt(arr2[0],10);
	var month2 = parseInt(arr2[1],10);
	var year2 = parseInt(arr2[2],10);
	
	if(year1 < year2)
	{
		out = 1;
	}
	else if(year1 > year2)
	{
		out = -1;
	}
	else if(year1 == year2)
	{
		if(month1 < month2)
		{
			out = 1;
		}
		else if(month1 > month2)
		{
			out = -1;
		}
		else if(month1 == month2)
		{
			if(day1 < day2)
			{
				out = 1;
			}
			else if (day1 > day2)
			{
				out = -1;
			}
			else if (day1 == day2)
			{
				out = 0;
			}
		}
	}
	return out;
}

function isPhone(str){
var bol=true; 
 var Stand_str="0123456789- "; 	
  if(str.length>12||str.length<3){
   bol=false;
  }
  if (str=="")
  {
   bol=false;
  }

 for(var i= 0; i< str.length; i++){
	var tmp= str.charAt(i);
	if (Stand_str.indexOf(tmp)==-1){
		bol=false;
		break;
	}
 }
return bol;
}

function page(id){
	var st = String(document.location.href);
	var temp = st.split('?');
	document.location.href=temp[0] + '?page=' + id;

}

function PopupImage(img) {
	var top=(screen.height-240)/2;
	var left=(screen.width-320)/2;
	window.open('popup.php?img='+img,'','top='+top+',left='+left+',width=320,height=240','menubar=no,scrollbars=no,statusbar=no');
}



