var global_url = window.location.protocol+'//'+window.location.host;

function pgRedirect(page){
	window.location = page;
}

function formSendOpt(url, formName, params, loader, status) {
	
	var pars=$('#'+formName).serialize();	
	
	if(loader!=undefined){ 
		$('#'+loader).ajaxStart(function(){
				$(this).show();
		}).ajaxComplete(function(){
				$(this).hide();
		});
	}
	$.ajax({
		type: "POST",
		url:url,
		dataType: 'html',
		data: pars,
		success: function (data){
			sp= data.split('~');
			if(sp[0]==1){
				window.location=sp[1];
			}else{
				$('#'+status).html(sp[1]);	
			}	
		}
	});
}
	

function formSend(url, formName, params, loader, status) {
	
	var pars=$('#'+formName).serialize();
	if(loader!=undefined){ 
		$('#'+loader).ajaxStart(function(){
				$(this).show();
		}).ajaxComplete(function(){
				$(this).hide();
		});
	}
	$.ajax({
		type: "POST",
		url:url,
		dataType: 'html',
		data: pars,
		success: function (data){
			if(typeof(data.error) != 'undefined') {
				if(data.error != '')
					alert(data.error);
			} else {
					$('#'+status).html(data);	
			}
		}
	});
} 

function formSendChange(url, formName, params, loader, status, statusForm) {
	var pars=$('#'+formName).serialize();
	if(loader!='undefined'){ 
		$('#'+loader).ajaxStart(function(){
				$(this).show();
		}).ajaxComplete(function(){
				$(this).hide();
		});
	}
	
	$.ajax({
		type: "POST",
		url:url,
		dataType: 'html',
		data: pars,
		success: function (data){
			var sp=data.split('~');
			if(sp[0]==0){
				$('#'+status).html(sp[1]);	
			}
			if(sp[0]==1){
				$('#'+statusForm).html(sp[1]) ;
			}
			if(sp[0]==2){
				window.location=sp[1];
			}
			if(sp[0]==3){
				$('#'+status).html(sp[1]);	
				$('#'+formName).reset();
					
			}
			
		}
	});
	
	
} 

function getMePost(url, content, params) {	 
	$('#'+content).fadeTo("fast", 0);
	$.ajax({
		type: "POST",
		url:url,
		dataType: 'html',
		data: params,
		success: function (data){
			if(typeof(data.error) != 'undefined') {
				if(data.error != '')
					alert(data.error);
			} else {
				
				$('#'+content).html(data);
				$('#'+content).fadeTo("fast", 1);
			}
		}
	});
}

function openWin(name,wid,hei,sbar,title){

	xx=screen.availWidth/2-wid/2;
	yy=screen.availHeight/2-hei/2;
	str="left=" + Math.round(xx) + ",top=" + Math.round(yy);
	window.open(name,title,'width='+wid+',height='+hei+',toolbar=no,scrollbars='+sbar+',resizable='+sbar+','+str);

}

function confirm_delete(loc){ 
	
	if (confirm("Are you sure you want to delete!")){ 
			self.location=loc; 
	} //end of if
} //end of function
 

function loginFormSend(url, formName, params, loader, status) {
	var pars=$(formName).serialize();	
	if(loader!=undefined){ 
		$('#'+loader).ajaxStart(function(){
				$(this).show();
		}).ajaxComplete(function(){
				$(this).hide();
		});
	}
	$.ajax({
		type: "POST",
		url:url,
		dataType: 'html',
		data: params,
		postBody:pars,
		success: function (data){
			if(typeof(data.error) != 'undefined') {
				if(data.error != '')
					alert(data.error);
			} else {
				sp= data.split('~');
				if(sp[0]==1){
					if(sp[1]!=""){
					window.location=sp[1];
					}
				}else{
					$('#'+status).html(sp[1]);	
				}
			}
		}
	});
} 


var flag = new Array();	
function getEffect(con){
	if(flag[con]=='undefined' || flag[con]==true){
		$('#'+con).slideDown('slow');
		flag[con]=false;
	}else{
		$('#'+con).slideUp('slow');
		flag[con]=true;
	}			
}
			
function ShowEffect(element, sto){
      $('#'+element).fadeTo("fast", sto);
}
function HideEffect(element, sto){
    	$('#'+element).fadeTo("fast", sto);
}





function clearTextBlur(id, values){
	
	if(!$('#'+id).val()){
		$('#'+id).val(values);
	} 
}
function clearTextFocus(id, values){
	
	
	if($('#'+id).val()==values) {
		$('#'+id).val('');
		//$(id).style.color = '#018bb0';
	}
	
}
function slider(url, content, params, loader){
	HideEffect(content, '0');
	if(loader!=undefined){ 
		$(loader).ajaxStart(function(){
				$(this).show();
		}).ajaxComplete(function(){
				$(this).hide();
		});
	}
	$.ajax({
		type: "POST",
		url:url,
		dataType: 'html',
		data: params,
		success: function (data){
			if(typeof(data.error) != 'undefined') {
				if(data.error != '')
					alert(data.error);
			} else {
				$('#'+content).html(data);
				ShowEffect(content,'1');
				
			}
		}
	});	
}
function checkrequired(which) {
	var pass=true;
	if (document.images) {
		for (i=0;i<which.length;i++) {
			var tempobj=which.elements[i];
			if (tempobj.name.substring(0,8)=="required") {
				if (tempobj.defaultValue==tempobj.value) tempobj.value = ""
				if (((tempobj.type=="text"||tempobj.type=="textarea")&&
				tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
				tempobj.selectedIndex==0)) {
					pass=false;
					break;
				}
			}
		}
	}
	if (!pass) {
		shortFieldName=tempobj.name.substring(8,30).toUpperCase();
		alert("Error: Please Fill the requirement");
		return false;
	} else {
		return true;
	}
}
