function cs(e, eventTarget, eventArgument)
{
	if (e.keyCode == 13 || e.which == 13)
	{		
		return doPB(e, eventTarget, eventArgument)
	}
	return false;
}

function doPB(e, eventTarget, eventArgument)
{
		if (e.preventDefault) e.preventDefault();
		if (e.stopPropagation) e.stopPropagation();
		//if (e.preventBubble) e.preventBubble();
		e.cancelBubble = true;
		e.returnValue = false;
		if (typeof(__doPostBack) == 'function'){
			__doPostBack(eventTarget, eventArgument);
		}
		else {
		var theform = document.forms[0];
		theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
		theform.__EVENTARGUMENT.value = eventArgument;
		theform.submit();
		}
		return false;
}

function swImage(url) {
	NewWindow(url,'',500,500,1,1,100,100);	
}

function swPopup(url) {
	NewWindow(url,'',440,300,1,1,100,100);
}

function NewWindow(url, title, w, h, winResize, winScroll, winLeftPos, winTopPos) {
	if(title == null) title = '';
	if(w == null) w = '600';
	if(h == null) h = '500';
	if(winResize == null) bResize = 'yes';
	if(winScroll == null) bScroll = 'yes';
	if(winLeftPos == null) winLeftPos = (screen.width-w)/2;
	if(winTopPos  == null) winTopPos  = (screen.height-h)/2;	
	settings = 'width='+w+',height='+h+',top='+winTopPos+',left='+winLeftPos+',scrollbars='+winScroll+',resizable='+winResize+',location=no,directories=no,status=no,menubar=no,toolbar=no';
	win = window.open(url, title, settings)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function cvIsNumeric(source, arguments) {
		arguments.IsValid = (parseInt(arguments.Value) > 0)?true:false;
}
 
function swDisplay(elemId,imgId,bShowElem) { 
	var o = document.getElementById(elemId);	
 	if(o == null || o == null) return false; 	
 	if(bShowElem != null) { 	
  		o.style.display=(bShowElem)?"block":"none";
 	}
 	else { 	
 		o.style.display=(o.style.display=="none")?"block":"none";
 	} 	
 	if(imgId != null) { 	 	
 		var oimg = document.getElementById(imgId);
 		if(oimg != null || oimg != null){
 			var s=(o.style.display=="none")?"add.gif":"sub.gif";
  			setTimeout("document.getElementById('"+imgId+"').src='../images/"+s+"'", 10);  			
  		}
 	}
} 

function showCCDetails(obj) {
    if(obj == null) return false;
    var cctype = obj.options[obj.selectedIndex].value;
    var _UK0 = document.getElementById("_UK0");
    var _UK1 = document.getElementById("_UK1");
    if(_UK0 != null && _UK1 != null){
      if (cctype == 8 || cctype == 9) {
	_UK0.style.display = "block";
	_UK1.style.display = "block";
      }
      else {
	_UK0.style.display = "none";
	_UK1.style.display = "none";		
      }
    }
}

/* valdate credit card number */
function cvIsCardNum(source, arguments) {

	var s = arguments.Value
	var v = "0123456789";
	var w = "";

	for (var i=0; i < s.length; i++) {
		x = s.charAt(i);
		if (v.indexOf(x,0) != -1)
		w += x;
	}
		
	var j = w.length / 2;	
	if (j < 6.5 || j > 8 || j == 7) {
		arguments.IsValid = false;
		return arguments.IsValid;
	}

	var k = Math.floor(j);
	var m = Math.ceil(j) - k;
	var c = 0;
	
	for (var i=0; i<k; i++) {
		a = w.charAt(i*2+m) * 2;
		c += a > 9 ? Math.floor(a/10 + a%10) : a;
	}
	
	for (var i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
	
	arguments.IsValid = (c%10 == 0);
	return arguments.IsValid;
}

//add option to ddl
function addOption(ddl,text,value) {
	var op = document.createElement("OPTION");
	op.text = text;
	op.value = value;
	ddl.options.add(op);
}

//UserAccount.ascx, ViewCart.ascx
function setStateLayout(cid,selValue) {
	if(selValue == null) selValue = '';
	uid = uid.split(":").join("_");
	uid = uid.split("$").join("_"); //.NET 2.0
	var c, c1, c1d, c2, szipreq;
	if(cid=='b' || cid=='s'){
		c = document.getElementById(uid+'_'+cid+'country');
		c1 = document.getElementById(uid+'_'+cid+'state');		
		c2 = document.getElementById(uid+'_'+cid+'state_textbox');	
		c1d = c1;		
	}
	else {
		c = document.getElementById(uid+'_ddlCountry');
		c1 = document.getElementById(uid+'_ddlState');
		c1d = document.getElementById(uid+'_stateRow');
	}	
	zipreq = document.getElementById(cid + 'zipreq');	
	
	if(c == null || c1 == null) return;
	if(typeof(arrCCL) == "undefined") { //no countries with states
		c1d.style.display="none";
		c1.options.selectedIndex=0;						
		if(c2 != null){
		  c2.style.display="block";		 
		  if(zipreq != null){zipreq.style.display=c1.style.display;}
		}
		return;
	}
	var ccode = c.options[c.selectedIndex].value;
	var i;
	for(i=0; i<arrCCL.length; i++)
	{
		if(ccode == arrCCL[i])
		{			
			var arr;
			try { arr = eval('arr'+ccode) } catch (e) {};
			if(arr == null) return;
			for(i=c1.length-1; i>=0; i--){c1.options[i] = null;}
			for(i=0; i<=arr.length-2; i+=2){
				addOption(c1,arr[i+1],arr[i]);				
			}
			for(i=0; i<c1.length; i++){
			  if(c1.options[i].value == selValue){
			    c1.selectedIndex = i;
			    break;			    
			  }
			}
			c1d.style.display="";
			if(c2 != null){
			  c2.style.display="none";
			  if(zipreq != null){zipreq.style.display=c1.style.display;}
			}
			return;
		}
		else {
			c1d.style.display="none";
			c1.options.selectedIndex=0;						
			if(c2 != null){
			  c2.style.display="block";
			  if(zipreq != null){zipreq.style.display=c1.style.display;}
			}
		}	
	}
}



//Set tab to intially be selected when page loads:
//[which tab (1=first tab), ID of tab content to display (or "" if no corresponding tab content)]:
var initialtab=[1, "sc1"]

//Turn menu into single level image tabs (completely hides 2nd level)?
var turntosingle=0 //0 for no (default), 1 for yes

//Disable hyperlinks in 1st level tab images?
var disabletablinks=0 //0 for no (default), 1 for yes


////////Stop editting////////////////

var previoustab=""

if (turntosingle==1)
document.write('<style type="text/css">\n#tabcontentcontainer{display: none;}\n</style>')

function expandcontent(cid, aobject){
if (disabletablinks==1)
aobject.onclick=new Function("return false")
if (document.getElementById && turntosingle==0){
highlighttab(aobject);
if (previoustab!="")
document.getElementById(previoustab).style.display="none";
if (document.getElementById(cid)!=null){
  document.getElementById(cid).style.display="block";
previoustab=cid;
}
}
}

function highlighttab(aobject){
if (typeof tabobjlinks=="undefined")
collectddtabs()
for (i=0; i<tabobjlinks.length; i++)
tabobjlinks[i].className=""
aobject.className="current"
}

function collectddtabs(){
var tabobj=document.getElementById("ddtabs");
if(tabobj == null) return -1;
tabobjlinks=tabobj.getElementsByTagName("A");
}

function do_onload(){
if (collectddtabs() == -1) return;
expandcontent(initialtab[1], tabobjlinks[initialtab[0]-1])
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload
