/*
 * Webiness - Core JS File
 *
 */

/* Flash Loader */
function popUp(URL) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=760,height=480');");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

var newWin;

/* Popup Window Functions     *************/

var newWin;

function tmt_winOpen(u,id,f,df){
	if(eval(id)==null||eval(id+".closed")){
	eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
	else if(df){eval(id+".focus()");}
	else{eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
}

/* Contact Form Validation    *************/

function checkForm() {
		var f = document.forms[0];
		var msg = "Please fill in the following fields:\n";
		var error_count = 0;
		if( f.subject.selectedIndex == 0 ) {
				msg += " - Subject\n";
				error_count++;
		}
		if( trim(f.name.value) == '' ) {
				msg += " - Your name\n";
				error_count++;
		}
		if( trim(f.CUSTOM_1.value) == '' ) {
				msg += " - Your company name\n";
				error_count++;
		}
		if( trim(f.email.value) == '' ) {
				msg += " - Your email address\n";
				error_count++;
		}
		if( trim(f.CUSTOM_2.value) == '' ) {
				msg += " - Your phone number\n";
				error_count++;
		}
		if( trim(f.msg.value) == '' ) {
				msg += " - A message\n";
				error_count++;
		}
		if( error_count ) {
				alert(msg);
				return false;
		}
		return true;
}

function trim(str) {
   return str.replace(/^\s*|\s*$/g,"");
}

/******* Form Code *******/

if( document.addEventListener ) document.addEventListener( 'DOMContentLoaded', cmxform, false );

function cmxform(){
  // Hide forms
  $( 'form.cmxform' ).hide().end();
  
  // Processing
  $( 'form.cmxform' ).find( 'li/label' ).not( '.nocmx' ).each( function( i ){
    var labelContent = this.innerHTML;
    var labelWidth = document.defaultView.getComputedStyle( this, '' ).getPropertyValue( 'width' );
    var labelSpan = document.createElement( 'span' );
        labelSpan.style.display = 'block';
        labelSpan.style.width = labelWidth;
        labelSpan.innerHTML = labelContent;
    this.style.display = '-moz-inline-box';
    this.innerHTML = null;
    this.appendChild( labelSpan );
  } ).end();
  
  // Show forms
  $( 'form.cmxform' ).show().end();
}
