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 IsEmail(obj, msgstr)
{
    if(obj.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)!= -1)
        return true;
    else
	{
		obj.focus();
        return false;
	}
}

function DateFormat(obj)
{
    var f = eval(obj);
    var f_val = f.value;
    ind1 = f_val.charAt(2);
    ind2 = f_val.charAt(5);
    if(f_val!= "" && ind1!="-" && ind2!="-")
    {
        if(f_val.length < 8)
        {
            alert("Date must have at least 8 digits (MMDDYYYY).")
            f.focus();

		}
        else{
            f.value = f_val.substring(0,2) +"-"+ f_val.substring(2,4) +"-"+ f_val.substring(4,f_val.lenght);
    	 }
	}
}
function IsBlank(obj)
{
    if(Trim(obj.value)=="")
    {
        obj.focus();
        return false;
    }
    return true;
}
function Trim(str)
{
    return str.replace(/\s/g,"");
}
function IsNumeric(obj)
{
    if(obj.value.search(/[^0-9]/) != -1) // only number checking
    {
        alert('The field must contain number only');
        obj.value="";
        obj.focus();
        return false;
    }
    return true;
}
function Validate_image(obj)
 {
    var objUpload=eval(obj);
    var sUpload=objUpload.value;
	 if(sUpload=="")
	  return true;
     else
        {
      	var iDot=sUpload.indexOf(".");
        if(iDot > 0)
           {
           var vv=sUpload.toLowerCase();
            var aUpload=vv.split(".");
            if(aUpload[aUpload.length-1]=="jpg" || aUpload[aUpload.length-1]=="gif" || aUpload[aUpload.length-1]=="bmp" || aUpload[aUpload.length-1]=="png"){
                return true;
			}else{
                objUpload.focus();
                return false;
            }

        }

    }

}
function Validate_pdf(obj)
 {
    var objUpload=eval(obj);
    var sUpload=objUpload.value;
	 if(sUpload=="")
	  return true;
     else
        {
       		var iDot=sUpload.indexOf(".");
        if(iDot > 0)
           {
           var vv=sUpload.toLowerCase();
            var aUpload=vv.split(".");
            if(aUpload[aUpload.length-1]=="pdf"){
                return true;
			}else{
                objUpload.focus();
                return false;
            }

        }

    }

}
//fo admin login
function loginValidation()
{
	var d = document.loginForm;
	
	if(!IsBlank(d.username))
	{
		alert("Username cannot be left blank");
		return false;
	}
	if(!IsBlank(d.password))
	{
		alert("Password cannot be left blank");
		return false;
	}
	return true;
}
function deleteValidation(id)
{
	var d = document.categoryForm;
	if(!confirm("Are You Sure You want to delete?"))
			return true;
	d.del_val.value=id;
	d.submit();
	return true;	
}

function imageValidation(obj)
{
	if(!Validate_image(obj))
		{
			alert('Please Upload Only jpeg, jpg, gif, bmp and png type Image!!');
			obj.focus();
			obj.value="";
			return false;
		}
}
//for page
function pageValidation()
{
	var d = document.pageForm;
	
	if(!IsBlank(d.name))
	{
		alert("Name cannot be left blank");
		return false;
	}
	return true;
}

function deletePageValidation(id)
{
	var d = document.pageForm;
	if(!confirm("Are You Sure You want to delete?"))
			return true;
	d.del_val.value=id;
	d.submit();
	return true;	
}
function popupImage(path,w,h)
{

window.open(path,"Window1",
"menubar=no,toolbar=no, width="+w+" ,height="+h+",scrollbars=yes");
		
}
function open_popup(img,w,h)
{
w=w+30;
h=h+30;
window.open("mypop?pt="+img,"Window1",
"menubar=no,width="+w+" ,height="+h+",toolbar=no, scrollbars=yes");
}
//Check Select All
function selectCheckAll(type) {
	var checks = document.getElementsByName('chk_action[]');
	var boxLength = checks.length;
		if(type=="checkall")
		{
			 for ( i=0; i < boxLength; i++ ) {
				checks[i].checked = true;
			  }
		}
		else//uncheckall
		{
			 for ( i=0; i < boxLength; i++ ) {
				checks[i].checked = false;
			  }
		}
		 
}
//general 
function getValidateFax(obj)
{
	if(!isInteger(obj.value))
	{
		alert("Fax must be Number");
		obj.focus();
		return false;
	}
	else if(obj.value.length!=10)
	{
		alert("Fax must be 10 digits Number");
		obj.focus();
		return false;
	}
		else return true;
}
function getValidatePhone(obj)
{
	if(!isInteger(obj.value))
	{
		alert("Phone must be Number");
		obj.value="";
		obj.focus();
		return false;
	}
	else if(obj.value.length!=10)
	{
		alert("Phone must be 10 digits Number");
		obj.value="";
		obj.focus();
		return false;
	}
		else return true;
}
function getValidateMobile(obj)
{
	if(!isInteger(obj.value))
	{
		alert("Mobile must be Number");
		obj.value="";
		obj.focus();
		return false;
	}
	else if(obj.value.length!=10)
	{
		alert("Mobile must be 10 digits Number");
		obj.value="";
		obj.focus();
		return false;
	}
		else return true;
}
function getValidatePostcode(obj)
{
	if(!isInteger(obj.value))
	{
		alert("Postcode must be Number");
		obj.value="";
		obj.focus();
		return false;
	}
	else if(obj.value.length!=4)
	{
		alert("Postcode must be 4 digits Number");
		obj.value="";
		obj.focus();
		return false;
	}
	else return true;
}
//for pdf uplaod
function pdfValidation(obj)
{
	if(!Validate_pdf(obj))
		{
			alert('Please Upload Only pdf file!!');
			obj.focus();
			obj.value="";
			return false;
		}
}

//for this site only
function validateContactUs()
{
	var d=document.frmContact;
	if(!IsBlank(d.fromEmail))
	{
		alert("From Email cannot be left blank");
		d.fromEmail.focus();
		return false;
	}
	else if(!IsEmail(d.fromEmail))
	{
		alert("Please Enter valid Email!");
		d.fromEmail.focus();
		return false;
	}

	else if(!IsBlank(d.name))
	{
		alert("Name cannot be left blank");
		d.name.focus();
		return false;
	}
	else if(!IsBlank(d.mobile))
	{
		alert("Mobile cannot be left blank");
		d.mobile.focus();
		return false;
	}
	else if(!getValidateMobile(d.mobile))
	{
			return false;
	}
	else return true;
}
function validateBooking()
{
	var d=document.frmBooking;
	if(!IsBlank(d.name))
	{
		alert("Name cannot be left blank");
		d.name.focus();
		return false;
	}
	else if(!IsBlank(d.email))
	{
		alert("Email cannot be left blank");
		d.email.focus();
		return false;
	}
	else if(!IsEmail(d.email))
	{
		alert("Please Enter valid Email!");
		d.email.focus();
		return false;
	}
	else if(!IsBlank(d.address))
	{
		alert("Address cannot be left blank");
		d.address.focus();
		return false;
	}
	else if(!IsBlank(d.phone))
	{
		alert("Phone cannot be left blank");
		d.phone.focus();
		return false;
	}
	else if(!getValidatePhone(d.phone))
	{
			return false;
	}
	else if(!IsBlank(d.vehicle_make))
	{
		alert("Vehicle Make cannot be left blank");
		d.vehicle_make.focus();
		return false;
	}
	else if(!IsBlank(d.model))
	{
		alert("Model cannot be left blank");
		d.model.focus();
		return false;
	}
	else if(!IsBlank(d.year_of_manufacture))
	{
		alert("Year of Manufacture cannot be left blank");
		d.year_of_manufacture.focus();
		return false;
	}
	else return true;
}
function validateQuote()
{
	var d=document.frmQuote;
	
	if(!IsBlank(d.type_of_repairs_or_service))
	{
		alert("Type of Repairs cannot be left blank");
		d.type_of_repairs_or_service.focus();
		return false;
	}
	else if(!IsBlank(d.name))
	{
		alert("name cannot be left blank");
		d.name.focus();
		return false;
	}
	else if(!IsBlank(d.phone))
	{
		alert("Phone cannot be left blank");
		d.phone.focus();
		return false;
	}
	else if(!getValidatePhone(d.phone))
	{
			return false;
	}
	else if(!IsBlank(d.email))
	{
		alert("Email cannot be left blank");
		d.email.focus();
		return false;
	}
	else if(!IsEmail(d.email))
	{
		alert("Please Enter valid Email!");
		d.email.focus();
		return false;
	}
	else if(!IsBlank(d.suburb))
	{
		alert("Suburb cannot be left blank");
		d.suburb.focus();
		return false;
	}
	else if(!IsBlank(d.postcode))
	{
		alert("Postcode cannot be left blank");
		d.postcode.focus();
		return false;
	}
	else if(!getValidatePostcode(d.postcode))
	{
			return false;
	}
	else if(!IsBlank(d.vehicle_make))
	{
		alert("Vehicle Make cannot be left blank");
		d.vehicle_make.focus();
		return false;
	}
	else if(!IsBlank(d.model))
	{
		alert("Model cannot be left blank");
		d.model.focus();
		return false;
	}
	else if(!IsBlank(d.year_of_manufacture))
	{
		alert("Year of Manufacture cannot be left blank");
		d.year_of_manufacture.focus();
		return false;
	}
	else return true;
}




