/****************************************************************************************
>> IMAGE ROTATOR << 
*****************************************************************************************/

// This script was supplied free by Hypergurl
// http://www.hypergurl.com
<!--
    // JavaScript to interpolate random images into a page.
    var ic = 4;     // Number of alternative images
    var xoxo = new Array(ic);  // Array to hold filenames   
	xoxo[0] = "/Images/Template/header/1.jpg";
	xoxo[1] = "/Images/Template/header/2.jpg";
	xoxo[2] = "/Images/Template/header/3.jpg";
	xoxo[3] = "/Images/Template/header/4.jpg";

function pickRandom(range) {
if (Math.random)
return Math.round(Math.random() * (range-1));
else {
var now = new Date();
return (now.getTime() / 1000) % range;
}
}
// Write out an IMG tag, using a randomly-chosen image name.
var choice = pickRandom(ic);
// -->

/****************************************************************************************
>> POP UP WINDOW << 
*****************************************************************************************/

/* NEW DODOSNOMARGIN SCRIPT IS MODIFIED FROM http://www.therotunda.net/code/autosized-popup-window.html */
/* http://regretless.com/dodo/newworld */
function viewPic(img)
{ 	
    picfile = new Image(); 
    picfile.src =(img); 
    fileCheck(img); 
}
function fileCheck(img)
{ 	
    if( (picfile.width!=0) && (picfile.height!=0) )
    { 
        makeWindow(img); 
    }
    else 
    {
        funzione="fileCheck('"+img+"')"; 
        intervallo=setTimeout(funzione,10); 
    }
}
function makeWindow(img)
{ 	
    ht = picfile.height;
    wd = picfile.width; 
    var args= "height=" + ht + ",innerHeight=" + ht;
    args += ",width=" + wd + ",innerWidth=" + wd;
    if (window.screen) 
    { 
        var avht = screen.availHeight; 
        var avwd = screen.availWidth;
        var xcen = (avwd - wd) / 2; 
        var ycen = (avht - ht) / 2;
        args += ",left=" + xcen + ",screenX=" + xcen;
        args += ",top=" + ycen + ",screenY=" + ycen + ",resizable=yes"; 	
    }
	popwin=window.open("","_blank",args)
	popwin.document.open()
	popwin.document.write('<html><head><title>'+img+'</title></head><body bgcolor=white scroll=no topmargin=0 leftmargin=0 rightmargin=0 bottomargin=0 marginheight=0 marginwidth=0><div style="position: absolute; top:0px;left:0px"><img src="'+img+'" width="'+wd+'" height="'+ht+'" border="0"></div></body></html>')
	popwin.document.close()
}

/****************************************************************************************
>> FORM VALIDATION << 
*****************************************************************************************/

// FUNCTION TO DEFINE AN EMPTY FIELD
function isEmpty(s) {
	  return ((s==null)||(s.length==0));
}

// FUNCTION TO CHECK FORM IS COMPLETED
function checkComplete() {  

		form_complete = 1;
		alert_message = "";
		
	 	// CHECK COMPULSORY FIELDS ARE COMPLETED ** CONTACT FORM **
		if (window.document.contact.contactDepartment.selectedIndex==0) { 
    		alert_message = alert_message + "   - Office\n";
			form_complete = 0;
		}
		if (isEmpty(window.document.contact.contactComments.value)) { 
    		alert_message = alert_message + "   - Comments\n";
			form_complete = 0;
		}	
		if (window.document.contact.contactTitle.selectedIndex==0) { 
    		alert_message = alert_message + "   - Title\n";
			form_complete = 0;
		}				
		if (isEmpty(window.document.contact.contactFirstName.value)) { 
    		alert_message = alert_message + "   - First Name\n";
			form_complete = 0;
		}				
		if (isEmpty(window.document.contact.contactLastName.value)) { 
    		alert_message = alert_message + "   - Last Name\n";
			form_complete = 0;
		}				
		checkValidEmail(window.document.contact.contactEmail.value);

		if (isEmpty(window.document.contact.contactPhone.value)) { 
    		alert_message = alert_message + "   - Phone\n";
			form_complete = 0;
		}							
		
  		// PRINT ALERT MESSAGE IF ALL IS NOT CORRECT
	    if (form_complete==0) {
    		alert ("Please enter some details into the following required fields\n" +
				   "\n" +
				   alert_message);
			return false;
		}

  		// IF ALL IS CORRECT THEN GO AHEAD
		else {
			return true;
		}
}

// FUNCTION TO CHECK FOR VALID EMAIL ADDRESS
function checkValidEmail(input) {
  ValidExtentions = new Array('.org', '.com', '.gov', '.edu', '.mil', '.net', '.co');   
  point = input.indexOf("@",0);
  if (point == -1) {
  	form_complete = 0;
	alert_message = alert_message + "   - Email " +
	"   Please enter a valid email address (e.g., user@domain.com)\n";
  }
  else {
    goodemail = 0;
  	for (i=0; i <= 7; i++) {
	  extpoint = input.indexOf(ValidExtentions[i],point);
	  if (extpoint > 0) {goodemail = 1}
	}
    if (goodemail == 0) {
      form_complete = 0;
	  alert_message = alert_message + "   - Email " +
	  "   Please enter a valid email address (e.g., user@domain.com)\n";
	}  
  }
}
