// JavaScript Document

var newwindow;
function pop(url)
{
	newwindow=window.open(url,'name','height=400,width=400');
}

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_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_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_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];}
}

function show_tab(t)
{
	
	 //alert (t);
 curr_tab = document.getElementById('tab' + t);
 
 //curr_tab.blur(); 

 var tobj=document.getElementById("tabs")
 tobj_lis=tobj.getElementsByTagName("li")
 //alert (tobj_lis.length); 
 
 for(i=1; i<=5; i++)
 {
  document.getElementById('tab' + i).className = "hide-tab";
  if(tobj_lis[i-1]) tobj_lis[i-1].className="";
 }
 
 curr_tab.className="show-tab";
 tobj_lis[t-1].className="current";
}
function updatePrice(frm,obj)
{
	// ----------for multi option any operation
	
	p =	document.getElementById("baseprice").value;
	//document.getElementById("disp_price").innerHTML = p;
	document.getElementById("disp_price2").innerHTML = p;
	actual_price = p.substr(p.indexOf("$")+1, p.length);

	var price = parseFloat(actual_price);
	var pricevalAr = new Array();
	var direction = "add";
	
	for(i=0; i< frm.elements.length; i++)
	{
		e = frm.elements[i];
		if (e.type == "radio")
		{
			if(e.checked)
			{
				priceval = frm.elements[i].value;
				if(priceval.indexOf("(+$") > -1) {
					pricevalAr = priceval.split("(+$");
					direction = "add";
				} else if(priceval.indexOf("(+") > -1) {
					pricevalAr = priceval.split("(+");
					direction = "add";
				} else if(priceval.indexOf("(-") > -1) {
					pricevalAr = priceval.split("(-");
					direction = "sub";
				}else if(priceval.indexOf("(-$") > -1) {
					pricevalAr = priceval.split("(-$");
					direction = "sub";
				}else {pricevalAr = "";}
				

				if(pricevalAr.length > 1)
				{
					priceval = pricevalAr[1].split(")");
					priceval = parseFloat(priceval[0]);
				}
				else
				{	priceval = 0;}
				
				
					

				if(direction == "add")
					price = price + priceval
				else if(direction == "sub")
					price = price - priceval
			}
		}

	}//for ends

	/* if(optRealtimeDis != ''){
		price = price - parseFloat(optRealtimeDis)
	} */

	//alert (price);
	//alert (optRealtimeDis);
	//document.getElementById("disp_price").innerHTML = "$" + toDollarsAndCents(price);
	document.getElementById("disp_price2").innerHTML = "$" + toDollarsAndCents(price);
}

function updatePriceSelectBox(frm,obj)
{
	// ----------for multi option any operation
	
	p =	document.getElementById("baseprice").value;
	//document.getElementById("disp_price").innerHTML = p;
	document.getElementById("disp_price2").innerHTML = p;
	actual_price = p.substr(p.indexOf("$")+1, p.length);

	var price = parseFloat(actual_price);
	var pricevalAr = new Array();
	var direction = "add";
	
	for(i=0; i< frm.elements.length; i++)
	{
		e = frm.elements[i];
        
		if (e.type == "select-one")
		{

				priceval = frm.elements[i].value;
				if(priceval.indexOf("(+$") > -1) {
					pricevalAr = priceval.split("(+$");
					direction = "add";
				} else if(priceval.indexOf("(+") > -1) {
					pricevalAr = priceval.split("(+");
					direction = "add";
				} else if(priceval.indexOf("(-") > -1) {
					pricevalAr = priceval.split("(-");
					direction = "sub";
				}else if(priceval.indexOf("(-$") > -1) {
					pricevalAr = priceval.split("(-$");
					direction = "sub";
				}else {pricevalAr = "";}
				

				if(pricevalAr.length > 1)
				{
					priceval = pricevalAr[1].split(")");
					priceval = parseFloat(priceval[0]);
				}
				else
				{	priceval = 0;}
				
				
					

				if(direction == "add")
					price = price + priceval
				else if(direction == "sub")
					price = price - priceval

		}

	}//for ends

	/* if(optRealtimeDis != ''){
		price = price - parseFloat(optRealtimeDis)
	} */

	//alert (price);
	//alert (optRealtimeDis);
	//document.getElementById("disp_price").innerHTML = "$" + toDollarsAndCents(price);
	document.getElementById("disp_price2").innerHTML = "$" + toDollarsAndCents(price);
}

function toDollarsAndCents(n) {
  var s = "" + Math.round(n * 100) / 100
  var i = s.indexOf('.')
  if (i < 0) return s + ".00"
  var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
  if (i + 2 == s.length) t += "0"
  return t
}

function show_tab(t)
{
	
	 //alert (t);
 curr_tab = document.getElementById('tab' + t);
 
 //curr_tab.blur(); 

 var tobj=document.getElementById("tabs")
 tobj_lis=tobj.getElementsByTagName("li")
 //alert (tobj_lis.length); 
 
 for(i=1; i<=5; i++)
 {
  document.getElementById('tab' + i).className = "hide-tab";
  if(tobj_lis[i-1]) tobj_lis[i-1].className="";
 }
 
 curr_tab.className="show-tab";
 tobj_lis[t-1].className="current";
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Please type a valid e-mail address.")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please enter a valid e-mail address.")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please enter a valid e-mail address.")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please enter a valid e-mail address.")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please enter a valid e-mail address.")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please enter a valid e-mail address.")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please enter a valid e-mail address.")
		    return false
		 }

 		 return true					
	}

function validateForm(quote)
{
var emailID=document.forms.quote.email

if(document.forms.quote.fullName.value=="")
{
alert("Please enter your full name.");
document.forms.quote.fullName.focus();
return false;
}

if(document.forms.quote.phoneNum.value=="")
{
alert("Please enter your phone number.");
document.forms.quote.phoneNum.focus();
return false;
}

if(emailID.value=="")
{
alert("Please enter your email address.");
document.forms.quote.email.focus();
return false;
}

if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}

if(document.forms.quote.security_code.value=="")
{
alert("Please enter the security code.");
document.forms.quote.security_code.focus();
return false;
}

}


function updateCartPrice(price, what){
	var baseP;
	var cartPrice;
	if(document.getElementById("total-cart-value")){
		if(document.getElementById("total-cart-value").innerHTML!=""){
			baseP =	document.getElementById("total-cart-value").innerHTML;		
		}else if(document.getElementById("disp_price2")){
				if(document.getElementById("disp_price2").innerHTML!=""){
						baseP =	document.getElementById("disp_price2").innerHTML;		
				}
		}else{
			baseP =	document.getElementById("baseprice").value;	
		}
	}
	
	actual_price = baseP.substr(baseP.indexOf("$")+1, baseP.length);
	if(what==true){
		cartPrice = parseInt(actual_price) + parseInt(price);
		}else{
			cartPrice = parseInt(actual_price) - parseInt(price);
			}
	
	document.getElementById("total-cart-value").innerHTML = "$" + toDollarsAndCents(cartPrice);
	if(document.getElementById("disp_price2")){
		document.getElementById("disp_price2").innerHTML = "$" + toDollarsAndCents(cartPrice);
	}
}

try {
	document.onkeydown = checkKeycode();
} catch(e) {
	//*** IGNORE IE6 ERROR
}
function checkKeycode(e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
if(keycode==17){alert("This published designs/content is the intellectual property of Surveillance-Video and protected by International copyright law.");}

}
