function validate(f){
var v,i,e
for(i=0;e=f[i++];)
  if(v=window[e.getAttribute('valid')]){   
   if(!v(e.value))
    {    
    alert(e.getAttribute('alert'));e.focus();return 1}
    }
}

function niepuste(x){return x>''}
function ismail(e){return (/^[\w\.-]{2,}@[\w\.-]+\.[a-z]{2,5}$/i.test(e))||(e=='')}
function noempymail(e){return (/^[\w\.-]{2,}@[\w\.-]+\.[a-z]{2,5}$/i.test(e))>''}
function isnumopt(x){return x==~~x}
function isnum(x){return x==parseInt(x)}
function iscnum(x){return (/[\d]/.test(x))>''}
function istel(e){return (/\+[0-9]{11,18}/.test(e))>''}

function submitForm(id){
  if(!validate(document.getElementById(id).elements)) document.getElementById(id).submit();
}

function mail(a,b,desc){
  if(desc.length==0)desc=a+'@'+b
  document.write('<a href="mailto:'+a+'@'+b+'" >'+desc+'</a>')
}
function search(msg){
if(document.getElementById('searchText').value.length<4 )
{
alert(msg);
return false;
}
else if(document.getElementById('searchText').value=='search'){
document.getElementById('searchText').value='';
document.getElementById('searchText').focus();
return false;
}
else
{
document.getElementById('forms').submit();
}

}
function show_quote_form() {
			// Apply the HTML markup into body tag
			$('body').append('<div id="jquery-overlay"></div><div id="get_a_quote"><div id="quote_form"><h1>Get a Quote</h1><div id="close_quote">close</div><form method="post" id="quoteform" action="/quote_message/send"><div class="left_col"><table><tr><td width="80">Name: </td><td><input type="text" value="" valid="niepuste" alert="Name required" name="name"/></td></tr><tr><td>Email: </td><td><input type="text" value="" valid="noempymail" alert="Email required" name="email"/></td></tr><tr><td>Phone: </td><td><input type="text" value="" valid="niepuste" alert="Phone required" name="phone"/></td></tr><tr><td>Message: </td><td><textarea name="message" valid="niepuste" alert="Message required"></textarea></td></tr><tr><td>&nbsp;</td><td>How did you get to know DMCS?</td></tr><tr><td>&nbsp;</td><td ><select name="from_know" valid="niepuste" alert="How did you get to know DMCS? required"><option value="" >Please select</option><option value="Search engine" >Search engine</option><option value="Word of mouth" >Word of mouth</option><option value="Press advertising" >Press advertising</option><option value="Showroom" >Showroom</option><option value="Advertising Letter" >Advertising Letter</option><option value="Other" >Other</option></select></td></tr></table></div><div class="right_col"><table><tr><td><input type="checkbox" value="Construction services" class="cb" name="title[]"/>Construction services</td></tr><tr><td><input type="checkbox" class="cb" value="Window Products" name="title[]"/>Window Products</td></tr><tr><td><input class="cb" type="checkbox" value="Door Products" name="title[]"/>Door Products</td></tr><tr><td><input type="checkbox" class="cb" value="Bespoke Solutions" name="title[]"/>Bespoke Solutions</td></tr></table><input type="submit" onclick="submitForm(\'quoteform\');return false;" value="Send inquiry" class="grey_button" /></div></form></div></div>');	
			// Get page sizes
			var arrPageSizes = getPageSize();
			// Style overlay and show it
			$('#jquery-overlay').css({
				backgroundColor:	'#000',
				opacity:			0.8,
				width:				arrPageSizes[0],
				height:				arrPageSizes[1]
			}).fadeIn();
			// Get page scroll
			var arrPageScroll = getPageScroll();
			// Calculate top and left offset for the jquery-lightbox div object and show it
			
			// Assigning click events in elements to close overlay
			
			$('#close_quote').click(function() {
											
				$('#get_a_quote').remove();
				$('#jquery-overlay').fadeOut(function() { $('#jquery-overlay').remove(); });
				// Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
				$('embed, object, select').css({ 'visibility' : 'visible' });								
			});
			
			// Assign the _finish function to lightbox-loading-link and lightbox-secNav-btnClose objects
			
			// If window was resized, calculate the new overlay dimensions
			$(window).resize(function() {
				// Get page sizes
				var arrPageSizes = getPageSize();
				// Style overlay and show it
				$('#jquery-overlay').css({
					width:		arrPageSizes[0],
					height:		arrPageSizes[1]
				});		
			});
		}
		
		function getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};
		
		function getPageScroll() {
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		};
