
function popup(theURL,winName,width,height) {
	var winWidth = width;
	var winHeight = height;
	var windowName = winName;
	var posLeft = (screen.width - winWidth) / 2;
	var posTop = 200;
	features = 'height=' + winHeight + ',width=' + winWidth + ',top=' + posTop + ',left=' + posLeft + ',scrollbars=yes, resizable=yes';
	newWin = window.open(theURL,windowName,features);
}

function returnObject(arg, formObj) {
	var myObj = null;
	if (formObj != null) {
		myObj = formObj.elements[arg];
	} else if (typeof arg == 'string') {
		myObj = document.getElementById(arg);
	} else if (typeof arg == 'object') {
		myObj = arg;
	}

	return myObj;
}

// simple function to show a container
function show(arg) {
	var myObj = returnObject(arg);
	if (myObj != null) {
		myObj.style.display = "block";
	}
}

// simple function to hide a container
function hide(arg) {
	var myObj = returnObject(arg);
	if (myObj != null) {
		myObj.style.display = "none";
	}
}

//hide Multiple hideM(field1,field2,...)
function hideM() {
	for (var i = 0; i < arguments.length; i++) {
		hide(arguments[i]);
	}
}
//show Multiple showM(field1,field2,...)
function showM() {
	for (var i = 0; i < arguments.length; i++) {
		show(arguments[i]);
	}
}

function clearInputsWithValue(form, myValue, inputType) {
	// if inputType is not specified, then use 'input' as default
	var type = (inputType == null) ? 'input' : inputType;

	var formObj = returnObject(form);

	var inputs = formObj.getElementsByTagName(type);

	// lets remove the specified value from our input values
	for ( i = 0; i < inputs.length; i++ ) {
		if(inputs[i].value.toLowerCase() == myValue) {
			inputs[i].value = '';
		}
	}
}

function scrollToTop() {
	if (document.body.scrollTop) {
		document.body.scrollTop = 0;
	} else if(document.body.scrollTo) {
		document.body.scrollTo(0,0);
	} else {
		location.href = "#top";
	}
}

//Delay function after a few seconds delay("alert('sample!')",1000);
function delay(functionToCall,delayMill){
	if(functionToCall && delayMill != null){
		window.setTimeout(functionToCall,delayMill);
	}
}


/*var imgOn = new Image();
	imgOn.src="images/side-menu-arrow3.png"
var imgOff = new Image();
	imgOff.src="images/side-menu-arrow.png"
*/
function showHide(arg,imgId) {
// alert("welcome");
  var myObj = returnObject(arg);
  var myImg = document.getElementById(imgId);
  var ID = arg +'style';

  var myStyle = document.getElementById(ID);

  if (myObj != null) {
	  if(myObj.style.display == "" && myObj.style.display != "none") {
		  myObj.style.display="none";
		  if(myImg != null){
			myImg.src = imgOff.src;
		  }
	  } else if(myObj.style.display && myObj.style.display != "none") {
		  myObj.style.display="none";
		  if(myImg != null){
			myImg.src = imgOff.src;
		  }
	  } else {
		  myObj.style.display="block";
		//   myStyle.className = "dir-here";
		//   alert(myStyle.className);
		  if(myImg != null){
			myImg.src = imgOn.src;
		  }
	  }
   }
}


function showHide_new(arg,imgId) {
  var myObj = returnObject(arg);
  var myImg = document.getElementById(imgId);
  var IDs = arg +'-img';
  var myStyle = document.getElementById(IDs);
  if (myObj != null) {
	  if(myObj.style.display == "" && myObj.style.display != "none") {
		  myObj.style.display="none";
		  if(myImg != null){
			myImg.src = imgOff.src;
		  }
	  } else if(myObj.style.display && myObj.style.display != "none") {
		  myObj.style.display="none";
		  if(myImg != null){
			myImg.src = imgOff.src;
		  }
	  } else {
		  myObj.style.display="block";
		   myStyle.className = "dir-here";
		  if(myImg != null){
			myImg.src = imgOn.src;
		  }
	  }
   }
}

function showHide_new1(arg,imgId) {
//	alert("welcome");
  var myObj = returnObject(arg);
  var myImg = document.getElementById(imgId);
  var IDs = arg +'-img2';
  var myStyle = document.getElementById(IDs);
  if(myStyle != null){
	myStyle.className = "dir-here";
  }
}


/* This function is used for hide and show of sections
var temp = "";
var plusImg = new Image();
	plusImg.src="images/plus.gif"
var minusImg = new Image();
	minusImg.src="images/minus.gif"

function hideLevel( _levelId, _imgId ) {
	var thisLevel = document.getElementById( _levelId );
	var thisImg = document.getElementById( _imgId );
	if(thisLevel != null)
		thisLevel.style.display = "none";
	if(thisImg != null)
		thisImg.src = plusImg.src;
}

function showLevel( _levelId, _imgId ) {
	var thisLevel = document.getElementById( _levelId );
	var thisImg = document.getElementById( _imgId );
	if (thisLevel != null && thisLevel.style.display == "none") {
		thisLevel.style.display = "block";
		thisImg.src = minusImg.src;
	}
	else {
		hideLevel( _levelId, _imgId);
	}
}
*/


$(document).ready(function(){
	// validate signup form on keyup and submit
	$("#startForm").validate({
		errorContainer: $("#msgs-error"),

		rules: {
			bus_name: "required",
			bus_type: "required",
			f_name: "required",
			l_name: "required",
			phone: {
				required: true,
				minlength: 13
			},
			email: {
				required: true,
				email: true
			}
		}
			
	});

	// Set the width via CSS.
	$('select#select-field').ieSelectWidth
	({
		width: 108,
		containerClassName : 'select-container',
		overlayClassName : 'select-overlay'
	});
});


//Function to Hide and Show the hero section
function hideHeroes(){
	$(".heroes").hide();
}
function showHero(divId){
	hideHeroes();
	show(divId);
}

//Delay function after a few seconds delay("alert('sample!')",1000);
function delay(functionToCall,delayMill){
	if(functionToCall && delayMill != null){
		window.setTimeout(functionToCall,delayMill);
	}
}

//Ajax function that post to a controller and update the html section on the page
function loadPage(divId,urlPage){
	$().ready(function() {
		$.ajax({
			type: "POST",
			url: urlPage,
			cache: false,
			success: function(html){
			$(divId).html(html);
			}
		});
	});
}

function setCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function deleteCookie(name) {
    setCookie(name,"",-1);
}
