//--------------------------------------------------------------------------------------------------------- Your Custom JS Functions Here -------
function HelloWorld()
{
     alert('hello world!');
}
function nav()
{
     var nav = document.getElementById("menu"); 
     var lis = nav.getElementsByTagName("li"); 
     for (var i=0;i<lis.length;i++){ 
          var links = lis[i].firstChild; 
          var href = links.getAttribute("href"); 
          if(href!=null)
          {
                var current_href = window.location.href;
                var h=href.split("/");
                var c=current_href.split("/");
                href=h[h.length-1];
                current_href=c[c.length-1];
                if (current_href.toLowerCase() == href.toLowerCase() ){ 
                      if(href.toLowerCase()!="faq.htm")
                      lis[i].className="current";
                } 
           }
     } 
 }


/** 
Cookie class 
*/ 
function Cookie(){ 
/** 
@desc set Cookie 
@return void 
*/ 
this.setCookie=function(name, value, hours){ 
var expire = ""; 
if(hours != null){ 
expire = new Date((new Date()).getTime() + hours * 3600000); 
expire = "; expires=" + expire.toGMTString(); 
} 
document.cookie = escape(name) + "=" + escape(value) + expire; 
} 
 
/** 
@desc get Cookie 
@return String 
*/ 
this.getCookie=function(name){ 
var cookieValue = ""; 
var search = escape(name) + "="; 
if(document.cookie.length > 0){  
offset = document.cookie.indexOf(search); 
if (offset != -1){  
offset += search.length; 
end = document.cookie.indexOf(";", offset); 
if (end == -1) end = document.cookie.length; 
cookieValue = unescape(document.cookie.substring(offset, end)) 
} 
} 
return cookieValue; 
} 
} 
function Car(name){ 
 

 
this.carName = name; 
this.expire = 24*30;//(30days) 
this.carDatas = new Array();
this.numbers = true; 
this.total =0;
this.cookie = new Cookie(); 
this.typeObj=function(name,value){
this.name =name; 
this.value=value; 
} 
this.proObj=function(name,price,amount){
this.name =name; 
this.price=price;
this.amount=amount; 
} 
 
//##private function########################################################## 
// 
//getTypePoint(typeName);
//getProPoint(typeName,proName);
//saveCookie()
// 
//######################################################################## 
 
/** 
@desc 
@return int 
*/ 
this.getTypePoint=function(typeName){ 
var isok=false; 
var i=0; 
for(;i<this.carDatas.length;i++){ 
if(this.carDatas[i].name==typeName){ 
isok=true;
break; 
} 
} 
if(isok)return i; 
else return -1; 
} 
 
/** 
@desc 
@return int 
*/ 
this.getProPoint=function(typeId,proName){ 
var isok=false; 
var j = 0; 
var tempProObj=this.carDatas[typeId].value; 
for(;j<tempProObj.length;j++){ 
if(tempProObj[j].name==proName){ 
isok=true; 
break; 
} 
} 
if(isok)return j; 
else return -1; 
} 

this.replacementOfDangerousSymbols = function(str){
var pattern = /\:/ig;
str = str.toString().replace(pattern, "__COLON__");
pattern = /\|/ig;
str = str.toString().replace(pattern, "__VLINE__");
pattern = /\#/ig;
str =str.toString().replace(pattern, "__POUND__");
pattern = /\,/ig;
str = str.toString().replace(pattern, "__COMMA__");
return str;
}

this.restoreSymbols=function(str){
var pattern = /\_\_COLON\_\_/ig;
str = str.toString().replace(pattern, ":");
pattern = /\_\_VLINE\_\_/ig;
str = str.toString().replace(pattern, "|");
pattern = /\_\_POUND\_\_/ig;
str = str.toString().replace(pattern, "#");
pattern = /\_\_COMMA\_\_/ig;
str = str.toString().replace(pattern, ",");
return str;
}
 
/** 
@desc cookie
@return void 
*/ 
this.saveCookie=function(){ 
var outStr=''; 
for( i=0; i<this.carDatas.length; i++ ){ 
var typeName =this.carDatas[i].name; 
typeName = this.replacementOfDangerousSymbols(typeName);
var typeValue=this.carDatas[i].value; 
var proOutStr=''; 
for( j=0; j<typeValue.length; j++ )
{
var proName = this.replacementOfDangerousSymbols(typeValue[j].name) ;
var proPrice = this.replacementOfDangerousSymbols(typeValue[j].price);
var proAmount = this.replacementOfDangerousSymbols(typeValue[j].amount);
if ( j==0 )proOutStr = proName + ':' + proPrice + ':' + proAmount; 
else proOutStr += '|' + proName + ':' + proPrice + ':' + proAmount; 
} 
if ( i==0 )outStr = typeName + '#' + proOutStr; 
else outStr += ',' + typeName + '#' + proOutStr; 
} 
this.cookie.setCookie(this.carName,outStr,this.expire);
} 
 
if(this.cookie.getCookie(name)==''){ 
this.cookie.setCookie(name,'',this.expire); 
}else{ 
var cookie = this.cookie.getCookie(name);
var tempTypes=cookie.split(','); 
for(i=0;i<tempTypes.length;i++){ 
var tempTypeObj=tempTypes[i].split('#'); 
var type_pro=new Array(); 
if(tempTypeObj[1]){ 
var tempProObj=tempTypeObj[1].split('|'); 
for(j=0;j<tempProObj.length;j++){ 
var proDesc=tempProObj[j].split(':'); 
type_pro.push(new this.proObj(this.restoreSymbols(proDesc[0]),this.restoreSymbols(proDesc[1]),this.restoreSymbols(proDesc[2]))); 
} 
} 
this.carDatas.push(new this.typeObj(this.restoreSymbols(tempTypeObj[0]),type_pro)); 
} 
} 
//##public funtion######################################################### 
// 
//addType(typeName);//add a sprot
//addPro(typeName,proName,price,amount);//add a product
//editPro(typeName,proName,price,amount);//update product
//delPro(typeName,proName);//delete a product
//delType(typeName);//delete a sport
//delCar();//clear cart data
// 
//getCar();//get cart data
//getType();//get all sprots
//getPro(typeName);//get all products
//getProPrice(typeName,proName);//get product price
//    getProAmount(typeName,proName);       //get product amount 
//
//######################################################################## 
 
/** 
@desc 
@return bool 
*/ 
this.addType=function(typeName){ 
if(this.getTypePoint(typeName)!=-1)return false;
this.carDatas.push(new this.typeObj(typeName,new Array()));
this.saveCookie();
return true; 
} 
 
/** 
@desc add product to cart
@return bool 
*/ 
this.addPro=function(typeName,proName,price,amount){ 
var typePoint=this.getTypePoint(typeName);if ( typePoint ==-1 ){this.addType(typeName); typePoint=this.getTypePoint(typeName);}
var proPoint =this.getProPoint(typePoint,proName);
if ( proPoint != -1 ) 
{
if(this.numbers)
{
this.carDatas[typePoint].value[proPoint].price = parseInt(this.carDatas[typePoint].value[proPoint].price) + parseInt(price);
this.carDatas[typePoint].value[proPoint].amount = parseInt(this.carDatas[typePoint].value[proPoint].amount) + parseInt(amount);
}
else
return false;
}
else
this.carDatas[typePoint].value.push(new this.proObj(proName,price,amount));
this.saveCookie();
return true; 
} 
 
/** 
@desc update product.
@return bool 
*/ 
this.editPro=function(typeName,proName,price,amount){ 
var typePoint=this.getTypePoint(typeName);if ( typePoint == -1 ) return false;
var proPoint =this.getProPoint(typePoint,proName);if ( proPoint == -1 ) return false;
if(amount >= 1)
    return this.editProIndex(typePoint, proPoint, price, amount);
else
    return this.delProIndex(typePoint, proPoint);
} 

this.editProIndex=function(typePoint, proPoint, price, amount){
this.carDatas[typePoint].value[proPoint].price=price;
this.carDatas[typePoint].value[proPoint].amount=amount;
this.saveCookie();
return true; 
}

 
/** 
@desc delete product.
@return bool 
*/ 
this.delPro=function(typeName,proName){ 
var typePoint=this.getTypePoint(typeName);if ( typePoint == -1 ) return false;
var proPoint =this.getProPoint(typePoint,proName);if ( proPoint == -1 ) return false;
return this.delProIndex(typePoint, proPoint);
} 

this.delProIndex=function(typePoint, proPoint){
var pros=this.carDatas[typePoint].value.length; 
this.carDatas[typePoint].value[proPoint] = this.carDatas[typePoint].value[pros-1];
this.carDatas[typePoint].value.pop(); 
this.saveCookie();
return true; 
}
 
/** 
@desc delete sports
@return bool 
*/ 
this.delType=function(typeName){ 
var typePoint=this.getTypePoint(typeName);if ( typePoint == -1 ) return false;
return this.delTypeIndex(typePoint);
} 

this.delTypeIndex=function(typePoint){
var types=this.carDatas.length; 
this.carDatas[typePoint] = this.carDatas[types-1];
this.carDatas.pop(); 
this.saveCookie();
return true; 
}
 
/** 
@desc clear cart
@return void 
*/ 
this.delCar=function(){ 
this.cookie.setCookie(this.carName,'',0); 
this.carDatas=new Array(); 
this.saveCookie();
} 
 
/** 
@desc get cart data
@return Array 
*/ 
this.getCar=function(){ 
return this.carDatas; 
} 
 
/** 
@desc get sprot list
@return Array 
*/ 
this.getType=function(){ 
var returnarr=new Array(); 
for ( i=0; i<this.carDatas.length; i++)returnarr.push(this.carDatas[i].name); 
return returnarr; 
} 
 
/** 
@desc get product list
@return Array 
*/ 
this.getPro=function(typeName){ 
var typePoint=this.getTypePoint(typeName);if ( typePoint == -1 ) return false;
return this.carDatas[typePoint].value; 
} 
 
/** 
@desc get product price
@return String 
*/ 
this.getProPrice=function(typeName,proName){ 
var typePoint=this.getTypePoint(typeName);if ( typePoint == -1 ) return false;
var proPoint =this.getProPoint(typePoint,proName);if ( proPoint == -1 ) return false;
return this.carDatas[typePoint].value[proPoint].price; 
} 

/** 
@desc get product amount
@return String 
*/ 
this.getProAmount=function(typeName,proName){
var typePoint=this.getTypePoint(typeName);if ( typePoint == -1 ) return false;
var proPoint =this.getProPoint(typePoint,proName);if ( proPoint == -1 ) return false;
return this.carDatas[typePoint].value[proPoint].amount; 
}


this.showCart=function(obj, btnID){
  var total= 0;
  var html = "<table cellpadding='5' cellspacing='0' width='100%' border='0'>";
  html += "<tr style='background:#0697DA;color:#fff;'><td width='40%'>ALL-SPORTS PACKAGES: NAME & ITEM CODE</td><td>QTY</td><td>PRICE</td><td>DELETE</td></tr>";
  for( i=0; i<this.carDatas.length; i++ ){ 
  var typeValue=this.carDatas[i].value; 
  for( j=0; j<typeValue.length; j++ )
  {
    html += "<tr>";
    html += "<td><div style='margin-right:150px'>" + typeValue[j].name + "</div></td>";
    html += "<td><input type='text' id='amount_" + i + "|" + j + "' value='" + typeValue[j].amount + "' size='3'>&nbsp;&nbsp;<input onclick='updatePro(this, \"" + obj + "\", \"" + btnID + "\")' type='button' id='update_" + i + "|" + j + "|" + typeValue[j].amount + "|" + typeValue[j].price + "' value='Update' class='buttonNormal'></td>";
    html += "<td style='color:#fe2221'>$" + typeValue[j].price + "</td>";
    html += "<td><input type='button' id='delete_" + i + "|" + j + "' value='Delete' onclick='deletePro(this, \"" + obj + "\", \"" + btnID + "\")' class='buttonNormal'></td>"
    html += "</tr>";
    html += "<tr><td colspan='4'><div style='border-top:1px DASHED #cccccc;height:1px'>&nbsp;</div></td></tr>";
    total += parseInt(typeValue[j].price);
  } 
  }
  html += "</table>";
  document.getElementById(obj).innerHTML = "<div style='float:right;font-weight:bold;font-size:14px;padding:5px 0px;'>Your Shopping Cart <font color='#fe2221'>$" + total + "</font></div><div class='clear'></div>" + html;
  this.total = total;
  if(total == 0)
  {
    document.getElementById(btnID).style.display = "none";
    document.getElementById(obj).innerHTML = "<center>No items in your shopping cart.</center><br><br>";
  }
}

this.addData=function(typeName, name, price){
    this.addPro(typeName, name.replace(/\_\_QUOT\_\_/ig, "'"), price, "1");
    alert("Item has been added to cart!");
    this.redirct();
}

this.redirct = function(){
  //window.location="/cartlist.aspx";
}
}

var cart= new Car("BAS");

function updatePro(obj, containerID, btnID){
    var proInfo = obj.id.split('_')[1].split('|');
    var typePoint = proInfo[0];
    var proPoint = proInfo[1];
    var oldAmount = proInfo[2];
    var price = proInfo[3];
    var newAmount = document.getElementById("amount_" + typePoint+ "|" + proPoint).value;
    if(newAmount == "")
    {
        alert("Quantity can not be blank.");
        document.getElementById("amount_" + typePoint+ "|" + proPoint).focus();
        return false;
    }
    if(isNaN(newAmount))
    {
       alert("Quantity must be number.");
       document.getElementById("amount_" + typePoint+ "|" + proPoint).select();
       return;
    }
    if(parseInt(oldAmount) == newAmount)return;
    if(newAmount == "" || newAmount < 1)cart.delProIndex(typePoint, proPoint);
    else cart.editProIndex(typePoint, proPoint, price/oldAmount*newAmount, newAmount);
    cart.showCart(containerID, btnID);
}

function isdigit(s)
{
    var r,re;
    re = /\d*/i;
    r = s.match(re);
    return (r==s)?1:0;
}



function deletePro(obj, containerID, btnID){
    var bln = confirm('Are you sure you want to delete this record.');  
    if(bln == false) return;    
    var proInfo = obj.id.split('_')[1].split('|');
    var typePoint = proInfo[0];
    var proPoint = proInfo[1];
    cart.delProIndex(typePoint, proPoint);
    cart.showCart(containerID, btnID);
}

function playMedia(files,texts,height,width,type,control,title) {
  if(type == "video")
    embedSource(files,texts,height,width,control);
else
    embedSource_Audio(files,height,width,control,title);
}


function embedSource(files,texts,height,width,control)
{
    var html = "<embed src='/media/play.swf' allowFullScreen='true' autoPlay='true' FlashVars='vcastr_file=";
        html += files+ "&vcastr_title=" + texts + "&IsAutoPlay=1' menu='true' quality='high' width='";
        html += width + "' height='" + height + "' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
        document.getElementById(control).innerHTML = html;
}

function embedSource_Audio(files,height,width,control,title)
{
    var top = (parseInt(height) - 100)/2;
    var left = (parseInt(width) - 300)/2;
    title = "<font style='color:#2F5EC0;font-weight:bold;font-size:16px'>Audio:&nbsp;" + title + "&nbsp;Information</b>";
    var html = "<div style='position:absolute;top:15px;left:15px'>" + title + "</div><div id='S_div' style='position:absolute;top:" + top + "px;left:" + left + "px'><object id='MediaPlayer1' width='300' height='100' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'";
    html += " codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112'";
    html += "align='baseline' border='0' standby='Loading Microsoft Windows Media Player components...' ";
    html += "type='application/x-oleobject'>";
    html += "<param name='URL' value='" + files + "'>"
    html += "<param name='autoStart' value='true'>";
    html += "<param name='invokeURLs' value='false'>";
    html += "<param name='playCount' value='100'>";
    html += "<param name='defaultFrame' value='datawindow'>";
    html += "<embed src='" + files + "' align='baseline' border='0' width='300' height='100'";
    html += " type='application/x-mplayer2'  pluginspage='' name='MediaPlayer1' showcontrols='1' showpositioncontrols='0'";
    html += " showaudiocontrols='1' showtracker='1' showdisplay='0' showstatusbar='1' autosize='0'	showgotobar='0'";
    html += " showcaptioning='0' autostart='1' autorewind='0' animationatstart='0' transparentatstart='0' allowscan='1'";
    html += " enablecontextmenu='1' clicktoplay='0' defaultframe='datawindow' invokeurls='0'></embed></object></div>";
    document.getElementById(control).innerHTML = html;
}

function GetBrowser()
{
   var agt=navigator.userAgent.toLowerCase();
   if( ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)) )
       return "IE";
   else if( ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
         && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
         && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)) )
       return "Netscape";
   else
       return "unknown";
}

function openWindow(url, width, height)
{
var  top=(window.screen.height-height)/2;
var  left=(window.screen.width-width)/2;
window.open (url, "newwindow", "height=" + height + ", width=" + width + ", top=" + top + ", left=" + left + ", toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no") 
}
























