if( document.captureEvents && Event.KEYUP ) {
  document.captureEvents( Event.KEYUP );
}
document.onkeyup = check_key;

function check_key(e) {
  if( !e ) {
    if( window.event ) {
      e = window.event;
    } else {
      return;
    }
  }
  if( typeof( e.keyCode ) == 'number'  ) {
    e = e.keyCode;
  } else if( typeof( e.which ) == 'number' ) {
    e = e.which;
  } else if( typeof( e.charCode ) == 'number'  ) {
    e = e.charCode;
  } else {
    return;
  }
 closeView(document.getElementById('newdiv'));
}



function posLeft() 
{
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
} 

function posTop() 
{
	return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
} 

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;
		}

		return [pageWidth,pageHeight];
	}

function getElementHeight(Elem) {
	/*if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	} else {*/
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (elem.style.pixelHeight) { 
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	//} 
}


function imageView(obj)
{
	if (document.getElementById("newdiv"))
	{
		return;
	}
	var dim = getPageSize();
	dim[1] = getElementHeight("container");
	var d = document.createElement('DIV');
	
	document.body.appendChild(d);
	d.style.height=dim[1]+"px";
	d.id = "newdiv";
	d.style.position = "absolute";
	d.style.top = "0";
	d.style.left = "0";
	var di = document.createElement('DIV');
	var w =100;
	var h = 100;
	di.id="innerDiv";

	var i = document.createElement("IMG");
	var imgPreload = new Image();
	imgPreload.onload=function(){
		i.src = obj.rel;
		w = imgPreload.width;
		h = imgPreload.height;
		di.style.position= "absolute"; 
		di.style.background="#FFFFFF"; 
		di.style.padding ="5px"; 
		di.style.width = w+"px"; 
		di.style.height =(h+40)+"px";
		var ww;
		var wh;
		if (typeof window.innerWidth != 'undefined')
		 {
			  ww = window.innerWidth,
			  wh = window.innerHeight
		 }
		else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
		 {
			   ww = document.documentElement.clientWidth,
			   wh = document.documentElement.clientHeight
		 }
		else
		 {
			   ww = document.getElementsByTagName('body')[0].clientWidth,
			   wh = document.getElementsByTagName('body')[0].clientHeight
		 }
		di.style.top = (wh/2 - h/2)+posTop()+"px";
		di.style.left = (ww/2 - w/2)+"px";
		di.style.width = w+"px"; 
		di.style.height =(h+80)+"px";
		di.style.top = (wh/2 - h/2)+posTop() +'px';
		di.style.left = (ww/2 - w/2)+'px';	
	}
	imgPreload.src = obj.rel;
	i.src = obj.rel;
	
	di.appendChild(i);
	var d1 = document.createElement("DIV");
	d1.id = "holder";
	di.appendChild(d1);
	d1.innerHTML  = document.getElementById("div"+obj.name).innerHTML;
	d1 = document.createElement("DIV");
	di.appendChild(d1);
	var b = document.createElement("BUTTON");
	b.className = "buy_btn";
	b.appendChild( document.createTextNode('Select template'));
	b.onclick = function()
	{
		closeView(d);
		document.location = "packages.php?template_id="+obj.name;
	}
	d1.appendChild(b);
	b = document.createElement("BUTTON");
	b.className = "close_btn";
	b.appendChild( document.createTextNode('Close'));
	b.onclick = function()
	{
		closeView(d);
	}
	d1.appendChild(b);
	d.appendChild(di);	
	
	return false;
}

function imageView2(obj)
{
	if (document.getElementById("newdiv"))
	{
		return;
	}
	var dim = getPageSize();
	var d = document.createElement('DIV');
	
	document.body.appendChild(d);
	d.style.height=dim[1]+"px";
	d.id = "newdiv";
	d.style.position = "absolute";
	d.style.top = "0";
	d.style.left = "0";
	var di = document.createElement('DIV');
	var w =100;
	var h = 100;
	di.id="innerDiv";

	var i = document.createElement("IMG");
	var imgPreload = new Image();
	imgPreload.onload=function(){
		i.src = obj.rel;
		w = imgPreload.width;
		h = imgPreload.height;
		di.style.position= "absolute"; 
		di.style.background="#FFFFFF"; 
		di.style.padding ="5px"; 
		di.style.width = w+"px"; 
		di.style.height =(h+40)+"px";
		var ww;
		var wh;
		if (typeof window.innerWidth != 'undefined')
		 {
			  ww = window.innerWidth,
			  wh = window.innerHeight
		 }
		else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
		 {
			   ww = document.documentElement.clientWidth,
			   wh = document.documentElement.clientHeight
		 }
		else
		 {
			   ww = document.getElementsByTagName('body')[0].clientWidth,
			   wh = document.getElementsByTagName('body')[0].clientHeight
		 }
		di.style.top = (wh/2 - h/2)+posTop()+"px";
		di.style.left = (ww/2 - w/2)+"px";
		di.style.width = w+"px"; 
		di.style.height =(h+80)+"px";
		di.style.top = (wh/2 - h/2)+posTop() +'px';
		di.style.left = (ww/2 - w/2)+'px';	
	}
	imgPreload.src = obj.rel;
	i.src = obj.rel;
	
	di.appendChild(i);
	var d1 = document.createElement("DIV");
	d1.id = "holder";
	di.appendChild(d1);
	d1.innerHTML  = document.getElementById("div"+obj.name).innerHTML;
	d1 = document.createElement("DIV");
	di.appendChild(d1);
	var b = document.createElement("BUTTON");
	b.className = "close_btn";
	b.appendChild( document.createTextNode('Close'));
	b.onclick = function()
	{
		closeView(d);
	}
	d1.appendChild(b);
	d.appendChild(di);	
	
	return false;
}

function imageView_W(obj)
{
	if (document.getElementById("newdiv"))
	{
		return;
	}
	var dim = getPageSize();
	var d = document.createElement('DIV');
	
	document.body.appendChild(d);
	d.style.height=dim[1]+"px";
	d.id = "newdiv";
	d.style.position = "absolute";
	d.style.top = "0";
	d.style.left = "0";
	var di = document.createElement('DIV');
	var w =100;
	var h = 100;
	di.id="innerDiv";
	di.style.position = "absolute";

	var i = document.createElement("IMG");
	i.style.display = "none";
	var imgPreload = new Image();
	imgPreload.onload=function(){
		i.src = obj.rel;
		w = imgPreload.width;
		h = imgPreload.height;
		di.style.position= "absolute"; 
		di.style.background="#FFFFFF"; 
		di.style.padding ="5px"; 
		di.style.width = w+"px"; 
		di.style.minHeight =(h+40)+"px";
		var ww;
		var wh;
		if (typeof window.innerWidth != 'undefined')
		 {
			  ww = window.innerWidth,
			  wh = window.innerHeight
		 }
		else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
		 {
			   ww = document.documentElement.clientWidth,
			   wh = document.documentElement.clientHeight
		 }
		else
		 {
			   ww = document.getElementsByTagName('body')[0].clientWidth,
			   wh = document.getElementsByTagName('body')[0].clientHeight
		 }
		di.style.top = (wh/2 - h/2)+posTop()+"px";
		di.style.left = (ww/2 - w/2)+"px";
		di.style.width = w+"px"; 
		di.style.minHeight =(h+80)+"px";
		di.style.top = (wh/2 - h/2)+posTop() +'px';
		di.style.left = (ww/2 - w/2)+'px';	
	}
	imgPreload.src = obj.rel;
	i.src = obj.rel;
	
	di.appendChild(i);
	
	var d1 = document.createElement("DIV");
	d1.id = "holder";
	di.appendChild(d1);
	d1.innerHTML  = document.getElementById("div"+obj.name).innerHTML;
	d1 = document.createElement("DIV");
	di.appendChild(d1);
	var b = document.createElement("BUTTON");
	b.className = "close_btn";
	b.appendChild( document.createTextNode('Close'));
	b.onclick = function()
	{
		closeView(d);
	}
	i.style.display = "block";
	d1.appendChild(b);
	d.appendChild(di);	
	
	return false;
}

function closeView(obj)
{
	if(obj)
		obj.parentNode.removeChild(obj);
}

function radio_button()
{
  if (document.getElementById("templateid").value=="")
  {
    alert("Select a template");
    return false;
  }
  else
  {
  if (document.pack_form.checkbox.checked==true)
  {
    if (document.pack_form.radio[0].checked == true)
      document.pack_form.action='{LINK1}';
    if (document.pack_form.radio[1].checked == true)
      document.pack_form.action='{LINK2}';
    return true;
  }
  else
  {
    alert ("Please accept our Terms and Conditions");
    return false;
   }
   }  
}

var pr1= 0;
var pr2 = 0;
var tid = 0;

function set_text(a,p1,p2)
{
	pr1= p1;
	pr2 = p2;
	tid = a;
	document.pack_form.templateid.value = tid;
 /* document.pack_form.price1.value=p1;
  document.pack_form.price2.value=p2;
  document.pack_form.templateid.value = a;
  document.pack_form.price_tf.value=p1;
  document.pack_form.tempcheck.checked=false;
  document.pack_form.selected.value="selected";
  return true;*/
}

function change_price(pp, pt)
{
  if (document.getElementById("tempcheck").checked == true)
  {
	document.getElementById("price").value = pt+pp;
	document.getElementById("on2").value = "Exclusive: yes";
  }
  else
  {
	document.getElementById("price").value = pp;
	document.getElementById("on2").value = "Exclusive: no";
  }
}

function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}


// closing divs
function setting_tabs(id)
{
	var tabs=new Array("descholder","empty");
	
	for(i=0;i<tabs.length;i++)
	{
		if(tabs[i]!=id)
		{
			document.getElementById(tabs[i]).style.display="none";
		}
		else {
			document.getElementById(tabs[i]).style.display="block";
		}
	}
return;
}

function leg(id)
{
	var tabs=new Array("cont_1","cont_2","cont_3");
	
	for(i=0;i<tabs.length;i++)
	{
		if(tabs[i]!=id)
		{
			document.getElementById(tabs[i]).style.display="none";
		}
		else {
			document.getElementById(tabs[i]).style.display="block";
		}
	}
return;
}

// quote selects populate
function quotes() {

   var ServiceList = document.quote.service;
   
   // Clear out the list of teams
   ClearOptions(document.quote.subs);
   
   if (ServiceList[ServiceList.selectedIndex].value == "1") {
      AddToOptionList(document.quote.subs, "1", "Please select service above");
      (document.quote.subs.disabled=true);
   }
   
   if (ServiceList[ServiceList.selectedIndex].value == "2") {
      AddToOptionList(document.quote.subs, "1", "Please select ...");
      AddToOptionList(document.quote.subs, "2", "Custom Website design");
      AddToOptionList(document.quote.subs, "3", "E-commerce development");
      AddToOptionList(document.quote.subs, "4", "Corporate website development");
      AddToOptionList(document.quote.subs, "5", "CodeExperts Off the shelf templates");
      AddToOptionList(document.quote.subs, "6", "Flash templates");
      AddToOptionList(document.quote.subs, "7", "Website redesign");
      AddToOptionList(document.quote.subs, "8", "Logo design &amp; Banner design");
      (document.quote.subs.disabled=false);
      document.quote.serv.value = ServiceList[ServiceList.selectedIndex].label;
   }

   if (ServiceList[ServiceList.selectedIndex].value == "3") {
      AddToOptionList(document.quote.subs, "1", "Please select ...");
      AddToOptionList(document.quote.subs, "2", "Pro File Uploader");
      AddToOptionList(document.quote.subs, "3", "Custom email Form");
      AddToOptionList(document.quote.subs, "4", "Custom contact forms");
      AddToOptionList(document.quote.subs, "5", "Ebay Custom template listing");
      AddToOptionList(document.quote.subs, "6", "API integration");
      AddToOptionList(document.quote.subs, "7", "Database design and development");
      AddToOptionList(document.quote.subs, "8", "Web application development");
      (document.quote.subs.disabled=false);
      document.quote.serv.value = ServiceList[ServiceList.selectedIndex].label;
   }

   if (ServiceList[ServiceList.selectedIndex].value == "4") {
      AddToOptionList(document.quote.subs, "1", "Please select ...");
      AddToOptionList(document.quote.subs, "2", "OS Commerce");
      AddToOptionList(document.quote.subs, "3", "Zen Cart");
      AddToOptionList(document.quote.subs, "4", "Custom Shopping Cart");
      AddToOptionList(document.quote.subs, "5", "Addons &amp; Forum integration");
      AddToOptionList(document.quote.subs, "6", "PayPal Integration");
      AddToOptionList(document.quote.subs, "7", "SecPay Integration");
      AddToOptionList(document.quote.subs, "8", "WHMCS Skinning");
      (document.quote.subs.disabled=false);
      document.quote.serv.value = ServiceList[ServiceList.selectedIndex].label;
   }
}

function quotes_sub()
{
  var ServiceList = document.quote.subs;
  if (ServiceList[ServiceList.selectedIndex].value > "1")
  {
    document.quote.sserv.value = ServiceList[ServiceList.selectedIndex].text;
    document.quote.sssel.value = ServiceList[ServiceList.selectedIndex].value;
  }
}

function subs_dis(val)
{
  var ServiceList = document.quote.service;
  //var val= document.quote.sssel.value;
  if ((ServiceList[ServiceList.selectedIndex].value != "1")&&(ServiceList[ServiceList.selectedIndex].value != ""))
    {
      (document.quote.subs.options[ val].selected = true);
      //(document.quote.subs.disabled=false);
      
    }
  //else
    //(document.quote.subs.options[1].selected = true);
}

function ClearOptions(OptionList) {

   // Always clear an option list from the last entry to the first
   for (x = OptionList.length; x >= 0; x = x - 1) {
      OptionList[x] = null;
   }
}


function AddToOptionList(OptionList, OptionValue, OptionText) {
   // Add option to the bottom of the list
   OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}
// end quote selects populate

// iFrame scrolling
var timer_id;
function scroll_div(d,s) {
 if (timer_id) clearTimeout(timer_id);
if (d<0)
 document.getElementById("templatelist").scrollLeft -= s;
 else
 document.getElementById("templatelist").scrollLeft += s;
    timer_id = setTimeout("scroll_div("+d+","+s+")", 5);
  
}

function stopScroll() { if (timer_id) clearTimeout(timer_id); }

/* template page package filter */

function uncheckall()
{
	if (document.getElementById("all").checked == true)
	{
		document.getElementById("all").checked = false;
	}
}
function select_all()
{
	t = document.getElementById("catfilter").getElementsByTagName("input");
	for (i=0; i<t.length; i++)
	{
		t[i].checked = true;
	}
}

function deselect_all()
{
	t = document.getElementById("catfilter").getElementsByTagName("input");
	for (i=0; i<t.length; i++)
	{
		t[i].checked = false;
	}
}

function changeall(obj)
{
	if (obj.checked == true)
	{
		select_all();
	}
	else
	{
		deselect_all();
	}
}

/*function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return false")*/


function show_login()
{
	if (document.getElementById("newdiv"))
	{
		return;
	}
	var dim = getPageSize();
	var d = document.createElement('DIV');
	
	document.body.appendChild(d);
	d.style.height=dim[1]+"px";
	d.id = "newdiv";
	d.style.position = "absolute";
	d.style.top = "0";
	d.style.left = "0";
	
	var dl = document.getElementById("loginbox").cloneNode(true);
	dl.style.display =  "block";
	var w = 470;
	var h = 213;
	var ww;
	var wh;
	
	if (typeof window.innerWidth != 'undefined')
	 {
		  ww = window.innerWidth,
		  wh = window.innerHeight
	 }
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
	 {
		   ww = document.documentElement.clientWidth,
		   wh = document.documentElement.clientHeight
	 }
	else
	 {
		   ww = document.getElementsByTagName('body')[0].clientWidth,
		   wh = document.getElementsByTagName('body')[0].clientHeight
	 }
	dl.style.top = (wh/2 - h/2)+posTop()+"px";
	dl.style.left = (ww/2 - w/2)+"px";
	
	d.appendChild(dl);	
}

function hide_login()
{
	var d = document.getElementById("newdiv");
	d.parentNode.removeChild(d);
}
