// DIV HIDE AND SHOW

var state = 'none';

function showhide(layer_ref)
	{
		if (state == 'block')
			{state = 'none';}
		else
			{state = 'block';}

		if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref + ".style.display = state");
	}
	
	if (document.layers)
		{ //IS NETSCAPE 4 or below
			document.layers[layer_ref].display = state;
		}

	if (document.getElementById &&!document.all)
		{hza = document.getElementById(layer_ref);
			hza.style.display = state;
		}
	}
// DIV END -->

//POPUP WINDOW
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height, scroll, resize)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scroll+',resizable='+resize+',copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
//POPUP WINDOW

// QUICK NAV DROP DOWN SELECTION
	<!-- Begin
	function mOveto()
		{	
			//alert (document.nav.action.value);
			if ((document.nav.action.value == '0') || (document.nav.action.value == '1'))
				{
					alert ("Please select a quick reference.");
					document.nav.action.value = '1';
					document.nav.action.focus();
					return;
				}
			else
				{
					//location.href=(document.nav.action.value);
					window.location.href=(document.nav.action.value);
				}
		}
		
		function cLientlogin()
			{
				window.location.href='clientlogin.php';
			}
	// End -->
// QUICK NAV DROP DOWN SELECTION


// REQUEST AND QUOTE FROM DIV UNHIDE IN THE REQUEST A QUOTE PAGE
	<!-- Begin
	function DisDiv()
		{
			if(document.form1.webhosting.checked == true)
			{document.getElementById("webhosting1").style.display ="block";}
			else
			{document.getElementById("webhosting1").style.display ="none";}
		}
		
	function DisDiv2()
		{
			if(document.form1.webdesign.checked == true)
			{document.getElementById("webdesign1").style.display ="block";}
			else
			{document.getElementById("webdesign1").style.display ="none";}
		}
	
	function DisDiv3()
		{
			if(document.form1.flashdesign.checked == true)
			{document.getElementById("flashdesign1").style.display ="block";}
			else
			{document.getElementById("flashdesign1").style.display ="none";}
		}
		
	function DisDiv5()
		{
			if(document.form1.corporateidentity.checked == true)
			{document.getElementById("corporateidentityblock").style.display ="block";}
			else
			{document.getElementById("corporateidentityblock").style.display ="none";}
		}
	// End -->
// REQUEST AND QUOTE FROM DIV UNHIDE IN THE REQUEST A QUOTE PAGE


//IMAGE SWAP CODE
	<!-- Begin
	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) { //v3.0
	  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); 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];}
	}
	// End -->
//IMAGE SWAP CODE


//PAGE LOAD SPEED
	// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/
	loadtime="0"
	loading=true
	s="s"
	{refresh()}
	function refresh()
	{setTimeout("count()",250)}
	function count()
	{if (loading)
	{loadtime=loadtime+++0.25;refresh()}}
	function done()
	{if (loadtime==1)
	{s=""}
	alert("It took "+loadtime+" second"+s+" to load the page");loading=false}
//PAGE LOAD SPEED


// MAIL CUBIC'S URL TO A FRIEND
	// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/
	<!-- Begin
		function mailsome1()
			{
				who=prompt("Enter recipient's email address: ","info@cubicinteractive.com");
				what=prompt("Enter the subject: ","Try out this Web Design Company");
				if (confirm("Are you sure you want to mail "+who+" with the subject of "+what+"?")==true)
					{
					parent.location.href='mailto:'+who+'?subject='+what+'';
					}
			}
	// End -->
// MAIL CUBIC'S URL TO A FRIEND	


// CURRENT DAY AND DATE - appears in the lasttable.php
var mydate=new Date()
					var theYear=mydate.getFullYear()
					var day=mydate.getDay()
					var month=mydate.getMonth()
					var daym=mydate.getDate()
				
					if (daym<10)
						daym="0"+daym
						var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
						var montharray=new Array("01","02","03","04","05","06","07","08","09","10","11","12")
// CURRENT DAY AND DATE - appears in the lasttable.php


// IP address detection script

//<!-- Begin
var ip = '<!--#echo var="REMOTE_ADDR"-->';
//alert("Your IP address is "+ip);
//window.defaultStatus = "Your IP address is "+ip;
// End -->

// IP address detection script


// UNLOAD OR CLOSE PAGE CODE
function movethere()
	{
		alert('Thank you for visiting the Cubic Website...');
		window.open('contactus-request.php','mywindow1','width=480,height=265,left=15,top=15,screenX=0,screenY=100,scrollbars=0');
		//window.open('')
		self.blur();		
		
		//location.replace("http://www.yahoo.com");
		//window.location.href="http://www.example.com/";
		//alert('out here');
	}
// UNLOAD OR CLOSE PAGE CODE



//alert ("went in to validation");
var validate;

function validate(obj)
{
	//define objects to validate
	var allElements = obj.elements;
	var coCount = 0;
	var errors = "";

	for( i=0 ; i<allElements.length; i++)
	{
		//CHECK HEADING NOT EMPTY
		if (allElements[i].type=="text" && allElements[i].name == "sp_heading")
		{
			var oFullName = allElements[i].value;
			if ( oFullName.length <= 0 )
			{
				errors += "-> Your Specials Heading is a mandatory field, please enter your Specials Heading\n";
			}			
		}	

		//CHECK HEADING NOT EMPTY
		if (allElements[i].name == "sp_description")
		{
			var ocomments = allElements[i].value;
			if ( ocomments.length <= 0 )
			{
				errors += "-> Your Specials Description is a mandatory field, please enter your Specials Description\n";
			}	
		}
		
		//CHECK PRICE IS NOT NULL OR IS NUMERIC
		//else if (allElements[i].type=="text" && allElements[i].name == "sp_price") 
		//{
		//	var oSwitchCou = allElements[i].value;	
		//	if (oSwitchCou.length <= 0)
		//	{
		//		errors += "-> Your Specials Price is a mandatory field, please enter your Specials Price\n";
		//	}		
		//	else if (isNaN(oSwitchCou))
		//	{
		//		errors += "-> Your Specials Price is a numeric field, please enter your Specials Price\n";
		//	}			
		//}
		
		//CHECK PRICE IS NOT NULL OR IS NUMERIC
		//else if (allElements[i].type=="text" && allElements[i].name == "sp_cents") 
		//{
		//	var oSwitchCou = allElements[i].value;	
		//	if (oSwitchCou.length <= 0)
		//	{
		//		errors += "-> Your Specials Price Cents is a mandatory field, please enter your Specials Price Cents\n";
		//	}		
		//	else if (isNaN(oSwitchCou))
		//	{
		//		errors += "-> Your Specials Price Cents is a numeric field, please enter your Specials Price Cents\n";
		//	}			
		//}
		
		//CHECK DROPDOWN TITLE LIST
		//else if (allElements[i].name == "brandlogo")
		//	{
		//		var otitle = allElements[i].value.checked;
		//			if  (otitle.checked == 'checked')
		//				{		
		//					if (allElements[i].name == "brand")
		//					{
		//						var otitle = allElements[i].value;
		//						if  ( ( otitle.length <= 0 ) || (allElements[i].selectedIndex == 0) )
		//						{
		//							errors += "-> A brand logo is a Mandatory field, please select your Title\n";
		//						}
		//					}
		//				}
		//		}

		
		//CHECK FIRSTNAME NOT EMPTY
		if (allElements[i].name == "fullname")
		{
			var ocomments = allElements[i].value;
			if ( ocomments.length <= 0 ) {errors += "-> Your full name is a mandatory field, please enter your first / full name\n"; document.form1.fullname.focus();}	
		}
		
		//CHECK LASTNAME NOT EMPTY
		if (allElements[i].name == "lastname")
		{
			var ocomments = allElements[i].value;
			if ( ocomments.length <= 0 ) {errors += "-> Your Last name is a mandatory field, please enter\n";}	
		}		
		
		//CHECK EMAIL ADDRESS NOT EMPTY AND VALID
		if (allElements[i].type == "text" && allElements[i].name == "email")
		{
			var oEmail = allElements[i].value;
			var chkDot = true;
			var result = false;
			var ndxAt = ndxDot =  0;
			var ndxAt = ndxDot =  0;

			if (oEmail.length <= 0 )
			{
				errors += "-> Your Email is a mandatory field, please enter your email\n"; document.form1.email.focus();
			}
			else //not empty start email address validation
			{
				ndxAt  = oEmail.indexOf("@");
				ndxDot = oEmail.indexOf(".");
				ndxDot2 = oEmail.lastIndexOf(".");
									
				var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
				
			        if (oEmail.match(illegalChars)) { 
			                errors += "Your email contains illegal characters\n";
			        }
				else if ( (ndxDot < 0) ) //check for a '.' sign
				{
					errors += "->Your email lacks '.'\n\tThe format is 'you@domain.com'";
				}
				else if ( (ndxAt < 0) ) //check for an '@' sign
				{
					errors += "->Your email lacks an '@'\n\tThe format is 'you@domain.com'";
				}
				else if (ndxDot2 - 3 <= ndxAt)
				{
					errors += "->You may be missing Your email's domain name\n\tThe format is 'you@domain.com'";
				}
			}	
		}
		
		//CHECK CONTACT DIAL CODE NUMBER NOT EMPTY
		else if (allElements[i].type=="text" && allElements[i].name == "contact-area1")
		{
			var oFullName = allElements[i].value;
			if ( oFullName.length <= 0 ){errors += "-> International code is a mandatory field, please enter code\n";}
		}
		
		//CHECK CONTACT DIAL CODE NUMBER NOT EMPTY
		else if (allElements[i].type=="text" && allElements[i].name == "contact-area2")
		{
			var oFullName = allElements[i].value;
			if ( oFullName.length <= 0 ){errors += "-> Local dialing code is a mandatory field, please enter code\n";}			
		}		
		
		//CHECK CONTACT NUMBER1 NOT EMPTY
		else if (allElements[i].type=="text" && allElements[i].name == "contact-number")
		{
			var oFullName = allElements[i].value;
			if ( oFullName.length <= 0 ){errors += "-> Contact number is a mandatory field, please enter number\n";}			
		}
		
		//CHECK COMMMENTS NOT EMPTY
		else if (allElements[i].type=="textarea" && allElements[i].name == "comments")
		{
			var oFullName = allElements[i].value;
			if ( oFullName.length <= 0 ){errors += "-> Comments is a mandatory field, please enter your comment\n";}			
		}
		
		//CHECK EMAILCODE NOT EMPTY
		if (allElements[i].name == "code")
		{
			var ocomments = allElements[i].value;
			if ( ocomments.length <= 0 ) {errors += "-> Please enter the image verification code\n"; document.form1.code.focus();}	
		}
		
	}
	if (coCount == 2) 
	{
			
		errors += "-> Please fill in the neccesary country and area code in the Contact Number\n";
	}
	
	if(errors)
	{
		alert("The following errors were found\n" + errors);
		errors = "";
		returnVal = false;
	}
	else
	{
		returnVal = true;
	}
	return returnVal; 
}

