// GoLive! Mobile 
// Architect Mobi Client Script
// Warren E. Gutierrez / Rainier Lee
// May 24, 2007 13:00 GMT +8 Bulacan, Philippines

function MobiCompat(_mtype, _carrier, _maker, _device) {
	
	var url = "http://instaconnect.golivemobile.com/include/dsttest.php?c=mCompat&mtype="+_mtype+"&carrier="+_carrier+"&maker="+_maker+"&device="+_device;
	var headTag = document.getElementsByTagName("head").item(0);
	var scriptTag = document.createElement("script");
	
	scriptTag.src = url;
	headTag.appendChild( scriptTag );   
	
}

function MobiBuy(_msisdn, _pin, _pid) {

	var url = "http://instaconnect.golivemobile.com/include/dsttest.php?c=mBuy&pincode="+_pin+"&msisdn="+_msisdn+"&product="+_pid;
	var headTag = document.getElementsByTagName("head").item(0);
	var scriptTag = document.createElement("script");
	
	scriptTag.src = url;
	headTag.appendChild( scriptTag );   
}

function MobiBuyDigi(_msisdn, _email, _pin, _pid) {

	var url = "http://instaconnect.golivemobile.com/include/dsttest.php?c=mBuyD&email="+_email+"&pincode="+_pin+"&msisdn="+_msisdn+"&product="+_pid;
	var headTag = document.getElementsByTagName("head").item(0);
	var scriptTag = document.createElement("script");
	
	scriptTag.src = url;
	headTag.appendChild( scriptTag );   
}

function MobiCheckout(_carrier, _msisdn, _prodid) {

	var url = "http://instaconnect.golivemobile.com/include/dsttest.php?c=mCout&carrier="+_carrier+"&msisdn="+_msisdn+"&productid="+_prodid;
	var headTag = document.getElementsByTagName("head").item(0);
	var scriptTag = document.createElement("script");
	
	scriptTag.src = url;
	headTag.appendChild( scriptTag );     

}

function MobiCheckoutDigi(_carrier, _msisdn, _prodid) {

	var url = "http://instaconnect.golivemobile.com/include/dsttest.php?c=mCoutD&carrier="+_carrier+"&msisdn="+_msisdn+"&productid="+_prodid;
	var headTag = document.getElementsByTagName("head").item(0);
	var scriptTag = document.createElement("script");
	
	scriptTag.src = url;
	headTag.appendChild( scriptTag );     

}

function MobiCart( _prodid ) {

	var url = "http://instaconnect.golivemobile.com/include/dsttest.php?c=mCart&productid="+_prodid;
	prodid = _prodid;
	
	var headTag = document.getElementsByTagName("head").item(0);
	var scriptTag = document.createElement("script");
	
	scriptTag.src = url;
	headTag.appendChild( scriptTag );  

}

function MobiCartDigi( _prodid ) {

	var url = "http://instaconnect.golivemobile.com/include/dsttest.php?c=mCartD&productid="+_prodid;
	prodid = _prodid;
	
	var headTag = document.getElementsByTagName("head").item(0);
	var scriptTag = document.createElement("script");
	
	scriptTag.src = url;
	headTag.appendChild( scriptTag );  

}

//**************  test  ************************//

function MobiCarttest( _prodid ) {
	var url = "http://instaconnect.golivemobile.com/include/mobitest/dsttest.php?c=mCart&productid="+_prodid;
	prodid = _prodid;
	var headTag = document.getElementsByTagName("head").item(0);
	var scriptTag = document.createElement("script");
	
	scriptTag.src = url;
	headTag.appendChild( scriptTag );  
}

function MobiCheckouttest(_carrier, _msisdn, _prodid) {
	var _cc = document.getElementById("countrycode").value;
	// _msisdn = _cc +_msisdn;

	_carrier = (document.frmMobiCart.countrydrp.options[document.frmMobiCart.countrydrp.selectedIndex].value==1)?_carrier:'';
	if(document.frmMobiCart.carrier.options[document.frmMobiCart.carrier.selectedIndex].value==''){ 
		alert("Please select carrier.");
	}else{
		var url = "http://instaconnect.golivemobile.com/include/mobitest/dsttest.php?c=mCout&carrier="+_carrier+"&msisdn="+_msisdn+"&productid="+_prodid+"&cc="+_cc;
		var headTag = document.getElementsByTagName("head").item(0);
		var scriptTag = document.createElement("script");
		
		scriptTag.src = url;
		headTag.appendChild( scriptTag );     
	}
}

function MobiBuytest(_msisdn, _pin, _pid) {
	var _cc = document.getElementById("cc").value;
	_msisdn = _cc +_msisdn;
	var url = "http://instaconnect.golivemobile.com/include/mobitest/dsttest.php?c=mBuy&pincode="+_pin+"&msisdn="+_msisdn+"&product="+_pid+"&cc="+_cc;
	var headTag = document.getElementsByTagName("head").item(0);
	var scriptTag = document.createElement("script");
	
	scriptTag.src = url;
	headTag.appendChild( scriptTag );   
}


//**************  test  ************************//
function handleResults( resultsObj ) {
	/*  transfer this to /js/default.js individual storefront
	try {
		document.getElementById('divmenu').setAttribute('style', 'display:none');	
		document.getElementById('divheader').setAttribute('style', 'display:none');
		document.getElementById('divmain').setAttribute('style', 'display:none');
	} catch (e) {}
	*/
	_html = replaceMe(decodeURIComponent(resultsObj.ResultSet.html),"+"," ");
	_rec = replaceMe(decodeURIComponent(resultsObj.ResultSet.rec),"+"," ");	
	
	orig_content = _html;
	
	if(_rec == 1) {
		showBox(_html);
	} else {
		_error = replaceMe(decodeURIComponent(resultsObj.ResultSet.error),"+"," ");
		alert(_error);		
	}
	
}
	
function replaceMe(sString, repWhat, repWith) {
	repWhatCount = repWhat.length;
	hit=0;

	for(ctr = 0; ctr < (sString.length); ctr++) {
		if(sString.substring(ctr,(ctr+repWhatCount)) == repWhat)
			hit++;	
	}

	for(ctr = 0; ctr < hit; ctr++)
		sString = sString.replace(repWhat,repWith);
		return sString;
	}	