/**
 * Client Side Functions Library for iGate
 * @access global
 * @author YP. Ajie (ajie@ageedev.com)
 * @abstract Handle AJAX Style operation.
 * @since 11/05/2006
 */

var imgs = new Image;
var img_ok = new Image;
var img_notok = new Image;
var resultBuffer = '';
var timerID = 0;

imgs.src = "/admin/_templates/default/images/progress.gif";
img_ok.src = "/admin/_templates/default/images/icons/ok.png";
img_notok.src = "/admin/_templates/default/images/icons/notok.png";

function getHTTPObject() {
				var http_object;
					/*@cc_on
					@if (@_jscript_version >= 5)
						try {
							http_object = new ActiveXObject("Msxml2.XMLHTTP");
						}
						catch (e) {
							try {
								http_object = new ActiveXObject("Microsoft.XMLHTTP");
							}
							catch (E) {
								http_object = false;
							}
						}
					@else
						xmlhttp = http_object;
					@end @*/

				if (!http_object && typeof XMLHttpRequest != 'undefined') {
					try {http_object = new XMLHttpRequest();}
					catch (e) {http_object = false;}
				}

	return http_object;
}

function startProgress(strMessage,btn,divcontainer){
	document.getElementById(divcontainer).innerHTML=' ';
	document.getElementById(divcontainer).style.display='';
	//document.getElementById(btn).disabled = true;
	document.getElementById(divcontainer).innerHTML = "<img id='progressrotator' src='/admin/_templates/default/images/progress.gif' align=absmiddle>&nbsp;&nbsp;" + strMessage + "...";
}

//EXPERIMENTAL
function playVid(){
	
  soundManager.createVideo({
    id:'photos3Demo',
    url:'http://freshly-ground.com/data/video/Yahoo! Photos 3 UI.MP4'
  });
  soundManager.play('photos3Demo');
	
}


function playSound(soundfile,soundID){
	var mySound = soundManager.createSound({
    id: soundID,
    url: soundfile
  });
  mySound.play();

}


function resetProgress(strMessage,btn,divcontainer,warning){
	document.getElementById(divcontainer).style.display='';
	document.getElementById(btn).disabled = false;
	if(warning==1){
		document.getElementById(divcontainer).innerHTML = "<img id='progressrotator' src='/admin/_templates/default/images/icons/icon_error.gif' align=absmiddle>&nbsp;&nbsp;" + strMessage + "...";
	}else{
		document.getElementById(divcontainer).innerHTML = "<img id='progressrotator' src='/admin/_templates/default/images/icons/icon_info.gif' align=absmiddle>&nbsp;&nbsp;" + strMessage + "...";
	}
	delayedMessageOut(divcontainer);
}

function delayedMessageOut(divcontainer){
	setTimeout("messageOut('" + divcontainer + "')", 4000);
}

function messageOut(divcontainer){
	document.getElementById(divcontainer).innerHTML='';
	document.getElementById(divcontainer).style.display='none';

}



function Get_Cookie(name) {
   var start = document.cookie.indexOf(name+"=");
   var len = start+name.length+1;
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
   if (start == -1) return null;
   var end = document.cookie.indexOf(";",len);
   if (end == -1) end = document.cookie.length;
   return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
    var cookieString = name + "=" +escape(value) +
       ( (expires) ? ";expires=" + expires.toGMTString() : "") +
       ( (path) ? ";path=" + path : "") +
       ( (domain) ? ";domain=" + domain : "") +
       ( (secure) ? ";secure" : "");
    document.cookie = cookieString;
}

function Delete_Cookie(name,path,domain) {
   if (Get_Cookie(name)) document.cookie = name + "=" +
      ( (path) ? ";path=" + path : "") +
      ( (domain) ? ";domain=" + domain : "") +
      ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}


var Common = {
	
	
	searchDistributor:function(){
		var prov = document.getElementById('dealer_prov').value;
		var city = document.getElementById('dealer_city').value;
		document.location = "/index.php?page=distributor&p="+prov+"&c="+city;
		
	},
	
	elementSetError:function(elementArray){
		
		document.getElementById("idElement").setAttribute("class", "className");
		
	},
	
	updateCityListByProvince:function(provID,targetEl){
					
					
					var conn = new Ext.data.Connection();
					conn.request({
					    url: '/_engine/AGAjaxConnector.php',
					    method: 'GET',
					    params: {cmd: 'Common.ajax_getAllCityByProvince', provID:provID},
					    success: function(responseObject) {
							results = responseObject.responseText;
							var arrayResult = results.split("@SPRTOR@");
						
							var defValue = arrayResult[0].split("@FSPRTOR@");
					
							var targetSel = document.getElementById(targetEl);
							
							for(i=0;i < 40;i++){
									targetSel.options[0] = null;
							}
	
							for(i=0;i < 40;i++){
									targetSel.options[0] = null;
							}
							
							targetSel.options[0] = new Option('All city', '-1', false, false);
	
							elCount = 1;
							for(j=0;j < arrayResult.length-1;j++){
								if(arrayResult[j] !=''){
									var comp = arrayResult[j].split("@FSPRTOR@");
									targetSel.options[elCount] = new Option(comp[0], comp[1], false, false);
									elCount++;
								}
							}
	
							//set active selection
							for(i=0;i < arrayResult.length-1;i++){
								var comp = arrayResult[i].split("@FSPRTOR@");
								if(parseInt(comp[1]) == parseInt(0)){
									targetSel.selectedIndex = i;
								}
							}
							
							
					    },
					     failure: function() {
					         Ext.Msg.alert('Status', 'Connection failed. Please try again later');
					     }
					});
					
					
					
				}
	
}

function searchfocus(){
	if(document.getElementById('s').value == 'Search') {
		document.getElementById('s').value = '';
	}	
}

function searchblur(){
	if(document.getElementById('s').value == '') {
		document.getElementById('s').value = 'Search';
	}
}





