// Global variables:

//this is used only on newsletter page
function MouseOverIcon(str,id) {
	
	//alert(id);
	document.getElementById(id).src = str + '-highlight.png';
	
}

function MouseOutIcon(str,id) {
	
	//alert(icon);
	document.getElementById(id).src = str;
	
}

//--------------------------------Veriffy Newsletter Email address -------------------------------->

//this is used only on newsletter page
function VerifyNewsletter() {

	var themessage = "no errors";
	
	//first construct the message
	
	if (ValidateForm() == false) {
		themessage = "Please provide a valid Email Address \neg: name@domain.com";
		document.form1.email.focus();
		document.form1.email.select();
	}
	
	//decide to submit or not
	if (themessage == "no errors") {
		document.form1.submit();
		return false;
	} else { 
		alert(themessage);
		return false;
   }
   
}

//---------------Verify Contact Deatils field boxes----------------------------------------
//verify information on the contact details page
function VerifyContact() {

	var themessage = "Please fill in the following fields: \n\n";
	
	//first construct the message
	if (document.form1.name.value == "") {
		themessage = themessage + " - Name\n";
	}
	
	if (ValidateForm() == false) {
		themessage = themessage + " - Email Address eg. yourname@domain.com \n";
	}
	
	if (document.form1.comment.value == ""){
		themessage = themessage + " - Comment\n";
	}
	
	//then set the focus in the right order
	if (document.form1.comment.value == "") {
		document.form1.comment.focus();
		//document.form1.first_name.select();
	}
	
	if (ValidateForm() == false) {
		document.form1.email.focus();
		document.form1.email.select();
	}
	
	if (document.form1.name.value == ""){
		document.form1.name.focus();
		document.form1.name.select();
	}
	
	//decide to submit or not
	if (themessage == "Please fill in the following fields: \n\n") {
		document.form1.submit();
		return false;
	} else { 
		alert(themessage);
		return false;
   }
   
}

//---------------Verify Quote fields----------------------------------------

function VerifyQuote() {

	var themessage = "Please fill in the following fields: \n\n";
	
	//first construct the message
	if (document.form1.name.value == "") {
		themessage = themessage + " - Name\n";
	}
	
	if (ValidateForm() == false) {
		themessage = themessage + " - Email Address eg. yourname@domain.com \n";
	}
	
	if (document.form1.subject.value == ""){
		themessage = themessage + " - Subject\n";
	}
	
	if (document.form1.comment.value == ""){
		themessage = themessage + " - Comment\n";
	}
	
	//then set the focus in the right order
	if (document.form1.comment.value == "") {
		document.form1.comment.focus();
		//document.form1.first_name.select();
	}
	
	if (ValidateForm() == false) {
		document.form1.email.focus();
		document.form1.email.select();
	}
	
	if (document.form1.name.value == ""){
		document.form1.name.focus();
		document.form1.name.select();
	}
	
	//decide to submit or not
	if (themessage == "Please fill in the following fields: \n\n") {
		document.form1.submit();
		return false;
	} else { 
		alert(themessage);
		return false;
   }
   
}

//---------------Verify Careers field boxes----------------------------------------

function VerifyCareers() {

	var themessage = "Please fill in the following fields: \n\n";
	
	//first construct the message
	if (document.form1.name.value == "") {
		themessage = themessage + " - Name\n";
	}
	
	if (document.form1.comment.value == ""){
		themessage = themessage + " - Comment\n";
	}
	
	//then set the focus in the right order
	if (document.form1.comment.value == "") {
		document.form1.comment.focus();
		//document.form1.first_name.select();
	}

	if (document.form1.name.value == ""){
		document.form1.name.focus();
		document.form1.name.select();
	}
	
	//decide to submit or not
	if (themessage == "Please fill in the following fields: \n\n") {
		document.form1.submit();
		return false;
	} else { 
		alert(themessage);
		return false;
   }
   
}

//---------------Verify RM field boxes----------------------------------------
//This is the right menu inlcude on the services pages
//verify information on the contact enquiry form
function rmVerify() {

	var themessage = "Please fill in the following fields: \n\n";
	
	//first construct the message
	if (document.form1.name.value == "" || document.form1.name.value == "Name") {
		themessage = themessage + " - Name\n";
	}
	
	if (ValidateForm() == false) {
		themessage = themessage + " - Email Address eg. yourname@domain.com \n";
	}
	
	if (ValidateForm() == false) {
		document.form1.email.focus();
		document.form1.email.select();
	}
	
	if (document.form1.name.value == "" || document.form1.name.value == "Name") {
		document.form1.name.focus();
		document.form1.name.select();
	}
	
	//decide to submit or not
	if (themessage == "Please fill in the following fields: \n\n") {
		document.form1.submit();
		return false;
	} else { 
		alert(themessage);
		return false;
   }
   
}

//---------------Email Address Validation --------------------------
//validate email address
function ValidateForm() {

	var emailID = document.getElementById('email');

	if ((emailID.value==null)||(emailID.value=="")){
		return false;
	}
	if (echeck(emailID.value)==false){
		return false;
	}
	
	return true;
 }
 
//validate email address continued
function echeck(str) {
		
		//alert("part2");
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		
		if (str.indexOf(at)==-1){
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false;
		 }

 		 return true;				
	}

//---------------Clear Email address--------------------------
//Found on the newsletter page
//Clear the email box when it is cicked for the first time
function ClearEmailBox() {
	if (document.getElementById('email').value == "Enter your email address") {
		document.getElementById('email').value = '';
	}
}

//---------------Max length of text input-------------------------
//sets the max length of the textinput in contact page
function ismaxlength(obj){

	var mlength=500;

	if (obj.getAttribute && obj.value.length>mlength) {
		obj.value=obj.value.substring(0,mlength);
	}
}

//---------------Change Quote Subject--------------------------

//Chnage the Icon Image
function ChangeQuote(subject) {
	
	//alert(document.getElementById('subject').value);
	document.getElementById('subject').value = subject;
	
	switch (document.getElementById('subject').value) {
		
		case "iphone":
			document.getElementById('ImageIcon').src = 'contact/images/quote-iphone-application-development.png';
			break;
			
		case "ipad":
			document.getElementById('ImageIcon').src = 'contact/images/quote-ipad-application-development.png';
			break;
			
		case "web":
			document.getElementById('ImageIcon').src = 'contact/images/quote-web-development.png';
			break;
			
		case "facebook":
			document.getElementById('ImageIcon').src = 'contact/images/quote-facebook-application-development.png';
			break;
			
		case "design":
			document.getElementById('ImageIcon').src = 'contact/images/quote-design.png';
			break;
			
		case "3d":
			document.getElementById('ImageIcon').src = 'contact/images/quote-3d-modeling.png';
			break;
			
		case "general":
			document.getElementById('ImageIcon').src = 'contact/images/quote-custom-software-development.png';
			break;
	}
}


//---------------Clear the RM field boxes----------------------------------------
//Services pages - clear default values of the input fields
function rmFieldOnFocus(id,FieldValue,action) {
	
	if (action == "focus") {
		if (document.getElementById(id).value == FieldValue) {
			document.getElementById(id).value = "";
		}
	}
	
	if (action == "blur") {
		if (document.getElementById(id).value == '') {
			document.getElementById(id).value = FieldValue;
		}
	}
}

//---------------Select Box Seletced----------------------------------------
//Make sure the right option in the select box is selected
//when the page loads
function PreselectMyItem(itemToSelect) {

    // Get a reference to the drop-down
    var myDropdownList = document.getElementById('subject');

    // Loop through all the items
    for (iLoop = 0; iLoop< myDropdownList.options.length; iLoop++) {    
      	  
	  if (myDropdownList.options[iLoop].value == itemToSelect) {
        // Item is found. Set its selected property, and exit the loop
        myDropdownList.options[iLoop].selected = true;
        break;
      }
	  
    }

}





















