// JavaScript Document

function validate_contact(){
var why = "";
var show = false;
var feildfocus = false;
boxone=false; boxtwo=false;  boxthree=false; boxfour=false; boxfive=false; boxsix=false;boxseven=false;boxeight=false;
 if(document.contactUsForm.name.value == ""){
 why+="Please enter name \n";
 show = true;
 boxone=true;
 }

if(document.contactUsForm.suburb.value == ""){
 why+="Please enter suburb \n";
 show = true;
 boxtwo=true;
}

if(document.contactUsForm.state.value == ""){
 why+="Please enter state \n";
 show = true;
 boxfive=true;
}

if(isEmail(document.contactUsForm.email.value)==false){
 why+="Please enter email \n";
 show = true;
 boxthree=true;
}

if(document.contactUsForm.phone.value.length<1 || (CheckPhoneNumber(document.contactUsForm.phone.value)==false)){
 why+="Please enter a valid phone number\n";
 show = true;
 boxfour=true;
}



 if(show){
   alert(why);
   if(boxfive){
   document.contactUsForm.state.focus();}
   if(boxfour){
   document.contactUsForm.phone.focus();}
   if(boxthree){
   document.contactUsForm.email.focus();}
   if(boxtwo){
   document.contactUsForm.suburb.focus();}
   if(boxone){
   document.contactUsForm.name.focus();}
  return false;
 }
 document.contactUsForm.submit();
}
function isEmail( strValue) {
 var objRegExp = /^[a-z]\w*([.\-]\w+)*@[a-z]\w*([.\-]\w+)*\.[a-z]{2,3}$/i;
 return objRegExp.test(strValue);
}
function CheckPhoneNumber(TheNumber) {
 var valid = 1
 var GoodChars = "0123456789()-+ "
 var i = 0
 if (TheNumber=="") {
 // Return false if number is empty
 valid = 0
 }
 for (i =0; i <= TheNumber.length -1; i++) {
 if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
// Note: Remove the comments from the following line to see this
// for loop in action.
// alert(TheNumber.charAt(i) + " is no good.")
 valid = 0
 } // End if statement
 } // End for loop
 return valid
}
function isValidSiteUrl(pmUrl){
	/*var urlPattern= /^(http:\/\/|https:\/\/|www.){1}([\w]+)(.[\w]+){1,2}$/;
	//var urlPattern=  '/^((ht|f)tp(s?)\:\/\/|~/|/)?([\w]+:\w+@)?([a-zA-Z]{1}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?((/?\w+/)+|/?)(\w+\.[\w]{3,4})?((\?\w+(=\w+)?)(&\w+(=\w+)?)*)?/';
	var vRegExp = new RegExp(urlPattern);
	return (vRegExp.test(pmUrl));*/
	if (pmUrl.indexOf(" ")!=-1) return false;
	var urlPat=/^(http:\/\/)|(\w*)\.([\-\+a-z0-9]*)\.(\w*)/;
	//var urlPat=/^(http:\/\/){1}(\w*)\.([\-\+a-z0-9]*)\.(\w*)/;
	if ( pmUrl.match(urlPat) == null ) return false;
	return true;
}

function extractNumber(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
}
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	if (isNaN(key)) return true;
	if(key==45) return true;
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}

function ShowDiv(divid)
{
	document.getElementById(divid).style.display='block';
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    } else {
        opacity(id, 100, 0, millisec);
    }
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}

var xmlHttp

function showPreview(str,currentImage)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
 _current = currentImage;
// alert("<?php echo $this->baseUrl;?>/media/images/loadinggif.gif");
document.getElementById("ajaxdisplay").innerHTML="<img src='/media/images/loadinggif.gif' width='350' height='260'>";

var url="/server-scripts/getContent1.php";
url=url+"?str="+str;

xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{ 
//opacity('imageid', 100, 0, 500);
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("ajaxdisplay").innerHTML=xmlHttp.responseText;
		//shiftOpacity('imageid',1000);
	}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


var _current=0;
//document.getElementById('total').innerHTML=ArrayImage.length;

function next()
{
if( _current < (ArrayImage.length-1))
{
_current=_current+1;
showPreviewpre(_current);
}

}


function prev()
{
if ( _current > 0)
{
_current=_current-1;
showPreviewpre(_current);
}
}

function showPreviewpre(id)
{
//var url='http://baypainting.com.au/'+ArrayImage[id]
//alert (url);
//document.getElementById('blendimage').style.display='none';
_current=id;
_actual=_current+1;
showPreview(ArrayImage[id],_current);
}
