// xin's

function toggle(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		if (document.getElementById(id).style.display == 'block') {
			document.getElementById(id).style.display = 'none';
		} else {
			document.getElementById(id).style.display = 'block';
		}
	}
	else 
	{
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}



// christina's 

function countMsg(theForm) {
    textMsg = theForm.note;
    textCount = textMsg.value.length;
    if (textCount > 300)  {
        textMsg.value = textMsg.value.substring(0,300);
        textCount = 300;
    }
    theForm.remLen.value = textCount;
}


function countReason(theForm) {
    textMsg = theForm.reason;
    textCount = textMsg.value.length;
    if (textCount > 150)  {
        textMsg.value = textMsg.value.substring(0,150);
        textCount = 150;
    }
    theForm.remLen.value = textCount;
}


function countContactUsMessage(theForm) {
    textMsg = theForm.message;
    textCount = textMsg.value.length;
    if (textCount > 500)  {
        textMsg.value = textMsg.value.substring(0,500);
        textCount = 500;
    }
    theForm.remLen.value = textCount;
}

function countTellAFriendMessage(theForm) {
    textMsg = theForm.message;
    textCount = textMsg.value.length;
    if (textCount > 500)  {
        textMsg.value = textMsg.value.substring(0,500);
        textCount = 500;
    }
    theForm.remLen.value = textCount;
}

function countTellYourFriendMessage(theForm) {
    textMsg = theForm.message;
    textCount = textMsg.value.length;
    if (textCount > 500)  {
        textMsg.value = textMsg.value.substring(0,500);
        textCount = 500;
    }
    theForm.remLen.value = textCount;
}

function countChitChatMsg(theForm) {
    textMsg = theForm.comments;
    textCount = textMsg.value.length;
    if (textCount > 500)  {
        textMsg.value = textMsg.value.substring(0,500);
        textCount = 500;
    }
    theForm.remLen.value = textCount;
}

function toggleButton (button) {
  if (typeof button.disabled != "undefined") {
  	button.disabled = !button.disabled;
   } else if (button.clicked) {
    button.clicked = false;
    button.value = button.oldValue;
  }
}


function MyOpenWindow_TermsAgreement() {
  var MyURL = 'tumpang_TermsAgreement.php';
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=850,height=500,scrollbars=yes';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function MyOpenWindow_PrivacyPolicy() {
  var MyURL = 'tumpang_PrivacyPolicy.php';
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=850,height=500,scrollbars=yes';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function MyOpenWindow_ProductListingPolicy() {
  var MyURL = 'tumpang_ProductListingPolicy.php';
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=850,height=500,scrollbars=yes';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function MyOpenWindow_IntellectualPropertyPolicy() {
  var MyURL = 'tumpang_IntellectualPropertyPolicy.php';
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=850,height=500,scrollbars=yes';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function MyOpenWindow_Copyright() {
  var MyURL = 'tumpang_Copyright.php';
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=850,height=500,scrollbars=yes';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function MyOpenWindow_message(id) {
  var MyURL = 'message.php?id=' + id;
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=630,height=420,scrollbars=yes';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function MyOpenWindow_message_group(id) {
  var MyURL = 'message_group.php?id=' + id;
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=630,height=420,scrollbars=yes';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function MyOpenWindow_message_tumpangItem(id) {
  var MyURL = 'message_tumpangItem.php?id=' + id;
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=630,height=420,scrollbars=yes';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function MyOpenWindow_message_comment(id) {
  var MyURL = 'message_comment.php?id=' + id;
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=630,height=420,scrollbars=yes';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function MyOpenWindow_message_groupComment(id) {
  var MyURL = 'message_groupComment.php?id=' + id;
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=630,height=420,scrollbars=yes';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function MyOpenWindow_message_groupActivities(id, activities) {
  var MyURL = 'message_groupActivities.php?id=' + id + '&activities=' + activities;
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=630,height=420,scrollbars=yes';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function MyOpenWindow_message_fromTumpang(id, activities) {
  var MyURL = 'message_fromTumpang.php?id=' + id;
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=630,height=420,scrollbars=yes';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function MyOpenWindow_message_watchListComment(id) {
  var MyURL = 'message_watchList.php?id=' + id + '&act=comment';
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=630,height=420,scrollbars=yes';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function MyOpenWindow_message_watchListTumpang(id) {
  var MyURL = 'message_watchList.php?id=' + id + '&act=tumpang';
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=630,height=420,scrollbars=yes';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function MyOpenWindow_message_watchListWithdrawn(id) {
  var MyURL = 'message_watchList.php?id=' + id + '&act=withdrawn';
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=630,height=420,scrollbars=yes';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function MyOpenWindow_group_forum(memberID, groupID) {
  var MyURL = 'group_chat.php?m=' + memberID + '&g=' + groupID;
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=630,height=500,scrollbars=yes';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function MyOpenWindow_sentMessage(id) {
  var MyURL = 'sentMessage.php?id=' + id;
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=630,height=500,scrollbars=yes';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function MyOpenWindow_tutorial(tutorialFile) {
  var MyURL = tutorialFile;
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=830,height=505,scrollbars=no';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function MyOpenWindow_5reasons(tutorialFile) {
  var MyURL = tutorialFile;
  var MyWindowName = 'name_that_you_can_use_in_link_targets';
  var MyWindowOptions = 'width=600,height=620,scrollbars=yes';
  window.open(MyURL, MyWindowName, MyWindowOptions);
}

function countEventToints(theForm) {
    var textMsg3 = theForm.passengerSeat2.value;
    var output = textMsg3 * 20;
    theForm.toints2.value = output; 
}


function countToints(theForm) {
	var get_currency = theForm.get_currency.value;
    var textMsg1 = theForm.listPrice_dollar.value;
    var textMsg2 = theForm.tumpangPrice_dollar.value;
    var textMsg3 = theForm.passengerSeat.value;
    var max_num = Math.max(textMsg1, textMsg2);
    var at_least_one = ((textMsg1 - textMsg2) * textMsg3);


    
    if (max_num > textMsg1) {    	
    	alert("tumpang Price - The tumpang Price cannot exceeds the Retail Price.");
    	return false;
    } else {		
		if (textMsg2 == textMsg1) {
    	alert("tumpang Price - The tumpang price cannot be the same as the retail price. Please enter a valid tumpang price.");
    	return false;
    	} else {
    		if ((textMsg1.length >= 1) && (textMsg2.length >= 1) && (textMsg3.length >= 1)) {
    			var output = r2(((textMsg1 - textMsg2) * textMsg3) / get_currency);

    			var output1 = Math.ceil(output);
    				//alert ("output = " + output);
    				//alert ("output1 = " + output1);
    			var outputgap = (output - output1);
    				//alert ("output gap = " + outputgap);
    			
				if (outputgap == 0) {
					output = output1;
					//alert("aaa");
					//alert ("aaa = " + output);
					theForm.toints.value = output;
				} else { 
					output = output1;
					//alert("bbb");
					//alert ("bbb = " + output);
					theForm.toints.value = output;
				}    			
    			
    		}
    		
    		if ((textMsg1.length >= 1) && (textMsg2.length >= 1) && (textMsg3.length >= 1) &&(output < 1)) {
    			theForm.toints.value = "-";
    			alert("Please enter a valid price. The total savings for this item must be 1 or more.");
    			return false;
    		}
    	}
   	}
}


function r2(n) { 
  ans = (Math.round(n * 100))/100 + "" 
  dot = ans.indexOf(".",0) 
  if (dot == -1) {ans = ans + ".00"} 
  else if (dot == ans.length - 2) {ans = ans + "0"} 
  return ans 
} 


function checkCategory() {
     if (document.selection.category.value == "Others")
	 	document.selection.category_option.disabled = false;
     else 
		document.selection.category_option.disabled = true;
		
}


function checkGroupCategory() {
     if (document.selection.group_category.value == "Others")
	 	document.selection.group_category_option.disabled = false;
     else 
		document.selection.group_category_option.disabled = true;
		
}

function countGroupForumMsg(theForm) {
    textMsg = theForm.comments;
    textCount = textMsg.value.length;
    if (textCount > 500)  {
        textMsg.value = textMsg.value.substring(0,500);
        textCount = 500;
    }
    theForm.remLen.value = textCount;
}

function countMsg_Moderator(theForm) {
    textMsg = theForm.note;
    textCount = textMsg.value.length;
    if (textCount > 500)  {
        textMsg.value = textMsg.value.substring(0,500);
        textCount = 500;
    }
    theForm.remLen.value = textCount;
}
		
function countMsg_Member(theForm) {
    textMsg = theForm.note;
    textCount = textMsg.value.length;
    if (textCount > 500)  {
        textMsg.value = textMsg.value.substring(0,500);
        textCount = 500;
    }
    theForm.remLen.value = textCount;
}

function countTumpangNoteMsg(theForm) {
    textMsg = theForm.tumpangNote;
    textCount = textMsg.value.length;
    if (textCount > 500)  {
        textMsg.value = textMsg.value.substring(0,500);
        textCount = 500;
    }
    theForm.remLen.value = textCount;
}

function countPMMessage(theForm) {
    textMsg = theForm.message;
    textCount = textMsg.value.length;
    if (textCount > 120)  {
        textMsg.value = textMsg.value.substring(0,120);
        textCount = 120;
    }
    theForm.remLen.value = textCount;
}

function countcontactMsg(theForm) {
    textMsg = theForm.contact;
    textCount = textMsg.value.length;
    if (textCount > 500)  {
        textMsg.value = textMsg.value.substring(0,500);
        textCount = 500;
    }
    theForm.remLen.value = textCount;
}

 function emailThisPage(){
  var target = document.location;
  var win = window.open('sendmail.php?sendurl=' + target,
                        'notice',
                        'width=600,height=450,location=no,toolbar=no,status=no,resizable=no,scrollbars=yes');
  win.focus();
 }


 function addToFavorite(title){
  window.external.AddFavorite(document.location,title)
 }
 

function fnCheckAll(obj) { 
	if (obj.checked == true) {  	
            if (arrCheckBoxID != null) {
                for (var i = 0; i < arrCheckBoxID.length; i++)
                   document.getElementById(arrCheckBoxID[i]).checked = true;
            }
        }
       else
       {
            if (arrCheckBoxID != null)
            {
                for (var i = 0; i < arrCheckBoxID.length; i++)
                   document.getElementById(arrCheckBoxID[i]).checked = false;
            }
       }
}


function fnCheckAll_watchList(obj) { 
	if (obj.checked == true) {  	
            if (arrCheckBoxID != null) {
                for (var i = 0; i < arrCheckBoxID.length; i++)
                   document.getElementById(arrCheckBoxID[i]).checked = true;
            }
        }
       else
       {
            if (arrCheckBoxID != null)
            {
                for (var i = 0; i < arrCheckBoxID.length; i++)
                   document.getElementById(arrCheckBoxID[i]).checked = false;
            }
       }
}


function gotoLink(form) {
	var OptionIndex=form.ListBoxURL.selectedIndex;
	parent.location = form.ListBoxURL.options[OptionIndex].value;
}


function countBuyToints(theForm) {
    var textMsg1 = theForm.quantity.value;
    
    if (textMsg1 == null) {    	
    	alert("Please enter toints.");
    	return false;
    } else {		
		var output = r2(textMsg1 * 0.01);
		theForm.amount2.value = output;
	
    }
}
			
			
function checkBuyToints() {
    if (document.buyToints.quantity.value.length == 0) {
	 	alert("Please enter toints. Only allows number.");
	 	document.buyToints.quantity.focus();
	 	return false;
	 }		
    if (document.buyToints.quantity.value.length >= 6) {
	 	alert("Only allows up to maximum 5 integer.");
	 	document.buyToints.quantity.focus();
	 	return false;
	 }
    if (document.buyToints.quantity.value == 0) {
	 	alert("You have to buy at least minimum 1 toint.");
	 	document.buyToints.quantity.focus();
	 	return false;
	 }	 	 
}


function validateTointsQuantity(field) {
    var valid="0123456789"
    var ok = "yes";
    var temp;
    for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	
	if (field.value == 0) {
		ok = "no1";
	}		
       
	if (ok == "no") {
		alert("Invalid entry! Only allows number (0-9).");
		field.focus();
		field.select();
    }    
}

function check_iWantToBuy() {
    if (document.buy.iWantToBuy_item.value.length == 0) {
	 	alert("Please enter item you want to buy.");
	 	document.buy.iWantToBuy_item.focus();
	 	return false;
	 }		 
}

function validate_iWantToBuy(field) {
    var valid="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ";
    var ok = "yes";
    var temp;
    for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	
	if (field.value == 0) {
		ok = "no1";
	}		
       
	if (ok == "no") {
		alert("Only allows enter 1 item.");
		field.focus();
		field.select();
    }    
}
//  End -->