$(document).ready(function () {
	$('ul.sf-menu').superfish();
	$(".expand").click(function(){
		$(this).next(".collapse").toggle("slow");
	});
	$("#contactLink").click(function(){
			if ($("#contactForm").is(":hidden")){
				$("#contactForm").slideDown("slow");
			}
			else{
				$("#contactForm").slideUp("slow");
			}
	});
});
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
function getContent() {
  var content_param = gup( 'content' );
  var source = "landing.html";
  if(content_param !== null && content_param.length > 0) {
    source = content_param;
  }
  return source;
}
iframe_url = getContent();

//Contents for menu 1
var menu1=new Array()
menu1[0]='<a href="wholesale_voip.html">Overview</a>'
menu1[1]='<a href="TIII_Overview.html">Titanium III</a>'
menu1[2]='<a href="voip-origination.html">Origination</a>'
///menu1[2]='<a href="orig_US48_dids.html"> - Local DIDs</a>'
///menu1[3]='<a href="orig_8xx_dids.html"> - 8XX DIDs</a>'
///menu1[4]='<a href="orig_t38.html"> - T.38</a>'
menu1[3]='<a href="voip-termination.html">Termination</a>'
menu1[4]='<a href="E911.html">E911</a>'
///menu1[6]='<a href="term_domestic.html"> - Domestic</a>'
//menu1[7]='<a href="term_international.html"> - International</a>'
///menu1[8]='<a href="term_t38.html"> - Rate Decks</a>'
//menu1[9]='<a href="term_dialer.html"> - Dialer</a>'
menu1[5]='<a href="additionalservices.html">Additional Services</a>'
///menu1[11]='<a href="add_411.html"> - 411</a>'
///menu1[12]='<a href="add_911.html"> - 911</a>'
///menu1[13]='<a href="add_cnam.html"> - CNAM Services</a>'
///menu1[14]='<a href="wholesale-signup.html">Wholesale INQUIRY</a>'
//Contents for menu 2, and so on
var menu2=new Array()
menu2[0]='<a href="network.html">Our Network</a>'
menu2[1]='<a href="coverage.asp">Available Numbers</a>'
menu2[2]='<a href="TIII_Overview.html">Titanium III</a>'
//menu2[3]='<a href="lnp.html">Online LNP</a>'

var menu3=new Array()
menu3[0]='<a href="about.html">About Us</a>'
menu3[1]='<a href="http://www.youtube.com/user/VoipInnovations" target="_blank">Videos</a>'
menu3[2]='<a href="testimonials.html">Testimonials</a>'
menu3[3]='<a href="careers.html">Careers</a>'
menu3[4]='<a href="downloads.html">Downloads</a>'
menu3[5]='<a href="http://voipinnovations.wordpress.com/" target="_blank">News & Events</a>'
menu3[6]='<a href="http://voipinnovations.wordpress.com/" target="_blank">Blog</a>'


var menu4=new Array()
//menu4[0]='<a href="index_kb.html?content=http://support.voipinnovations.com">Trouble Tickets</a>'
//menu4[0]='<a href="http://support.voipinnovations.com" target="_blank">Trouble Tickets</a>'
//menu4[2]='<a href="voiptest.html">VoIP Test</a>'
//menu4[3]='<a href="speedtest.html">Speed Test</a>'

var menu5=new Array()
menu5[0]='<a href="contact.html">Contact Us</a>'
menu5[1]='<a href="wholesale-signup.html">Inquiry Form</a>'
menu5[2]='<a href="carrier_relations.html">Carrier Relations</a>'

var menu6=new Array()
menu6[0]='<a href="carriers.html">Carriers</a>'
menu6[1]='<a href="ITSPs.html">ITSPs</a>'
menu6[2]='<a href="callcenters.html">Call Centers</a>'
menu6[3]='<a href="callingcards.html">Calling Cards</a>'
menu6[4]='<a href="enterprise.html">Enterprise/SMB</a>'

var menu7=new Array()
menu7[0]='<a href="TIII_Overview.html">Overview</a>'
menu7[1]='<a href="TIII_DIDs.html">DIDs</a>'
menu7[2]='<a href="TIII_LNP.html">LNP</a>'
menu7[3]='<a href="TIII_API.html">API</a>'
menu7[4]='<a href="TIII_Billing.html">Billing</a>'
menu7[5]='<a href="TIII_Management.html">Management</a>'
menu7[6]='<a href="TIII_Mobile.html">Smartphone App</a>'
menu7[7]='<a href="TIII_Screenshots.html">Screenshots</a>'

var menuwidth='300px' //default menu width
var menubgcolor='#b2b2b2' //menu bgcolor
var disappeardelay=250 //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

/////No further editting needed

//no idea why these need to be checked but not riskin the delete
var isIE4=document.all
var ns6=document.getElementById&&!document.all

if (isIE4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (isIE4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top="-500px"
if (menuwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=isIE4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=isIE4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=isIE4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function populatemenu(what){
if (isIE4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (isIE4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (isIE4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (isIE4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (isIE4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (isIE4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu


<!--
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) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
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_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];}
}
//-->

var TimerID = 0;
function Revolver(index){
	if(TimerID != 0){
		clearTimeout(TimerID);
	}

	var imgArray = new Array(5);
	var imgUrl = new Array(5);

	imgArray[0] = "images/ad_tier_x.jpg";
	imgArray[1] = "images/ad_per_port.jpg";
	imgArray[2] = "images/d_term.jpg";
	imgArray[3] = "images/ad_it_expo.jpg";
	imgArray[4] = "images/titanium_new_web_banner.jpg";
	
	imgUrl[0] = "";
	imgUrl[1] = "";
	imgUrl[2] = "";
	imgUrl[3] = "";
	imgUrl[4] = "https://www.loginto.us/Voip";

	var imgDiv = document.getElementById("lr_ad");
	
	var adHTML = "<img style='height:17.95em; width:13.063em;' src = \""+ imgArray[index] +"\"  border = \"0\" />";
	if (imgUrl[index] != "")
		adHTML = "<a href='" + imgUrl[index] + "' target='_new'>" + adHTML + "</a>";

	imgDiv.innerHTML = adHTML;
	index = (index+1)%imgArray.length;
	var st = "Revolver(" + index + ")";
	TimerID = setTimeout(st, 7500);
}

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function validate_email() {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	return reg.test($('#email').val().trim());
}

function validate_phone() {
	var reg = /^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$/;
	return reg.test($('#phone').val().trim());
}

function validate_form() {
	if( $('#company').val().trim().length == 0 ) {
		alert("Error: Please enter your company name");
		$('#company').focus();
		return false;
	}
	if( $('#first_name').val().trim().length == 0 ) {
		alert("Error: Please enter your first name");
		$('#first_name').focus();
		return false;
	}
	if( $('#last_name').val().trim().length == 0 ) {
		alert("Error: Please enter your last name");
		$('#last_name').focus();
		return false;
	}
	if( !validate_email() && !validate_phone() ) {
		alert("Error: Please enter a valid email and/or phone so that we may contact you");
		$('#email').focus();
		return false;
	}
	return true;
}

function submit_form_ajax_old() {
	if (!validate_form())
		return false;	
	//form is valid, make ajax post
	$.ajax({
	  type: 'POST',
	  url: 'inquiryemail.asp',
	  dataType: 'text',
	  async: false,
	  contentType: 'application/x-www-form-urlencoded; charset=utf-8',
	  data: $("#inquiry").serialize(),
	  success: function(msg) {
		$('#company').val('');
		$('#first_name').val('');
		$('#last_name').val('');
		$('#email').val('');
		$('#phone').val('');
		$('#URL').val('');
		$('#comments').val('');
		alert(msg);
	  },
	  error: function(XMLHttpRequest, textStatus, errorThrown) {
	  	alert('Error submitting inquiry. Please try again.');
	  }
	});
}
function submit_form_ajax() {
	if (!validate_form())
		return false;
	//form is valid, make ajax post
	$.ajax({
	  type: 'POST',
	  target: '_blank',
	  url: 'emailcaptchapopup.asp',
	  dataType: 'text',
	  async: false,
	  contentType: 'application/x-www-form-urlencoded; charset=utf-8',
	  data: $("#inquiry").serialize() + '&load=True',
	  success: function(msg) {
		var w = 330;
		var h = 200;
		var left = (screen.width/2)-(w/2);
		var top = (screen.height/2)-(h/2);
		myWindow=window.open('','','location=no,directories=no,status=no,copyhistory=no,menubar=no,toolbar=no,resizable=yes,width='+w+',height='+h+',top='+top+',left='+left);
		if (myWindow == null)
			alert('You must allow pop-ups from this site to send a service inquiry.');
		myWindow.document.write("<p>" + msg + "</p>");
		myWindow.focus();
		$("#contactForm").slideUp("slow");
	  },
	  error: function(XMLHttpRequest, textStatus, errorThrown) {
		alert('Error submitting inquiry. Please try again.');
	  }
	});
}
