function confirmSubmit(){
	if (confirm("Are you sure you wish to continue?"))
		return true;
	else
		return false;
}

function confirmDelete(warning){
	if (confirm(warning + " will be removed. Are you sure you wish to continue?"))
		return true;
	else
		return false;
}

function CheckAllBoxes(theform) {
	for(var i = 0; i < theform.length; i++){
    	var e = theform.elements[i];
    	
		if( e.type == "checkbox"){
			e.checked = true;
		}
	}
}

function UnCheckAllBoxes(theform) {
	for (var i = 0; i < theform.length; i++){
		var e = theform.elements[i];
		
		if( e.type == "checkbox"){
			e.checked = false;
		}
	}
}

function open_win(loc)
{
	new_window=window.open(loc,"new_window","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=600,height=559,top=100,left=100'")
}

function chg_row_color(cc,col){
	cc.oldcol=cc.style.backgroundColor; 
	cc.style.backgroundColor=col; 
	cc.onmouseout=function(){ this.style.backgroundColor=this.oldcol; }
}

//function chk_row_color(cc,col){ 
//	cc.oldcol=cc.style.backgroundColor;
//	if (cc.checked==true){ 
//		cc.style.backgroundColor=col;
//	}
//	else{
//		cc.onmouseout=function(){ this.style.backgroundColor=this.oldcol; }
//	}
//}

function chk_row_color(chg){ 
	P1=chg.parentNode; 
	P2=P1.parentNode; 
	if (chg.checked==true){ 
	  P2.style.backgroundColor='#EEEEEE'; 
	} 
	else {
	  P2.style.backgroundColor=''; 
	}
}

function chk_all_row_color() {
	for(var i = 0; i < document.form.length; i++){
    	var e = document.form.elements[i];
    	
		if( e.type == "checkbox"){
			if(e.checked){
				P1=e.parentNode;
				P2=P1.parentNode;
				P2.style.backgroundColor='#EEEEEE';
			}
		}
	}
}

function show_popup(text, w, h){
	var p=window.createPopup()
	var pbody=p.document.body
	
	posx = event.clientX
	posy = event.clientY
	
	pbody.style.backgroundColor="#FFFFE8"
	pbody.style.border="solid black 1px"
	pbody.style.fontFamily="Tahoma"
	pbody.style.fontSize="11px"
	
	pbody.innerHTML = text;
	p.show(posx, posy, w, h, document.body);
	
}

function close_popup(){
	p=window.createPopup();
	p.show(1, 1, 1, 1, '');
	p.hide;
}

function clearownership() {
 	document.getElementById("ownership").value = "";
}
  
function addownership() {
	if (document.getElementById("publisher").value == ""){
		alert('Please select a publisher!');
		return false;
	} if (document.getElementById("percentage").value == ""){
		document.getElementById("percentage").value = 0;
	}	if (document.getElementById("uploadFee").value == ""){
		document.getElementById("uploadFee").value = '0.00';
	}	if (document.getElementById("uploadAdvance").value == ""){
		document.getElementById("uploadAdvance").value = '0.00';
	} if (document.getElementById("uploadFulfillment").value == ""){
		document.getElementById("uploadFulfillment").value = 0;
	}
	
	var ownership = document.getElementById("ownership").value.split("\n");
	var len = ownership.length;
	var publisher_percent = 0;
	
	for (i=0; i<len; i++){
		info = ownership[i].split('|');
		var publisher = info[0];
		
		if (publisher == document.getElementById("publisher").value){
			alert(document.getElementById("publisher").value + ' was in the list!');
			return false;
		}
		
		publisher_percent += parseFloat(info[1]);
		var check_percent = publisher_percent + parseFloat(document.getElementById("percentage").value);
		
		if (check_percent > 100){
			alert('Publishers ownership exceeded 100% !');
			return false;
		}
	}
	
	var uploadFee = parseFloat(document.getElementById("uploadFee").value) * parseFloat(document.getElementById("percentage").value)/100;
	
  var a = document.getElementById("ownership").value;
  var b = document.getElementById("publisher").value + "|" 
				  + document.getElementById("percentage").value + "|" 
				  + uploadFee + "|" 
				  + document.getElementById("uploadAdvance").value + "|" 
				  + document.getElementById("uploadFulfillment").value + "\n";
		
  document.getElementById("ownership").value = a + b;
  
  return true;
}

function clear_content() {
 	document.getElementById("ContentDescBox").value = "";
}
  
function insert_content() {
	if (document.getElementById("CpId").value == ""){
		alert('Please select a content provider!');
		return false;
	}
	if (document.getElementById("ServiceId").value == ""){
		alert('Please select a service!');
		return false;
	}
	if (document.getElementById("ContentType").value == ""){
		alert('Please select a content type!');
		return false;
	}
	if (document.getElementById("CostPerTran").value == ""){
		alert('Please enter cost per tran!');
		return false;
	}
	if (document.getElementById("ContentDesc").value == ""){
		alert('Please enter a content description!');
		return false;
	}
	
	var ContentDescArray = document.getElementById("ContentDescBox").value.split("\n");
	var len = ContentDescArray.length;
	
	var current_box = document.getElementById("ContentDescBox").value;
  var append_box = document.getElementById("CpId").value + "-" 
  				+ document.getElementById("ServiceId").value+ "-" 
				  + document.getElementById("ContentType").value + "-" 
				  + document.getElementById("CostPerTran").value + "-" 
				  + document.getElementById("ContentDesc").value + "\n";
	
	for (i=0; i<len; i++){
		curr = ContentDescArray[i];
		if (curr == append_box){
			alert('This record was already in the list!');
			return false;
		}
	}
	
	document.getElementById("ContentDescBox").value = current_box + append_box;
	
  return true;
}

function magic(id){
	var thing = document.getElementById(id).style.display;
	
	if(thing == 'none'){
		show(id);
	}
	else{
		hide(id);
	}
}

function hide(id){
	document.getElementById(id).style.display = 'none';
}
function show(id){
	document.getElementById(id).style.display = '';
}

function fixH() 
{ 
	if (!(document.getElementById('leftNav')) ) 
	{return false;} 
	else 
	{
		var lh=document.getElementById('leftNav').offsetHeight; 
		var ch=document.getElementById('centerContent').offsetHeight;
		document.getElementById('leftNav').style.height=(ch>lh)? ch+"px" : lh+"px"; 
		document.getElementById('unhideBtn').style.height=(ch>lh)? ch+"px" : lh+"px"; 
		document.getElementById('hideBtn').style.height=(ch>lh)? ch+"px" : lh+"px"; 
	}
}

function highlight(field) {
 	document.getElementById(field).focus();
 	document.getElementById(field).select();
}

function cal_checkbox(theform, date){
	var dateArray = date.split("-");
	
	var type = dateArray[0];
	var date = dateArray[1];
	
	if (type == 'A'){
		for(var i = 2; i < theform.length; i++){
	    	var e = theform.elements[i];
	    
			if( e.type == "checkbox"){
				if(document.getElementById('all').checked == true){
					e.checked = true;
				}
				else{
					e.checked = false;
				}
			}
		}
	}
	else if(type == 'm'){
		for (var i=1; i<=31; i++){
			for (var j=0; j<=6; j++){
				var select_item = date + '-' + i + '-' + j;
				if (document.getElementById(select_item)){
					e = document.getElementById(select_item);
					e.checked = e.checked == true ? false : true;
				}
			}
		}
	}
	else if(type == 'w'){
		date = date++;
		for (var m=1; m<=12; m++){
			for (var i=1; i<=31; i++){
				var select_item = m + '-' + i + '-' + date;
					if (document.getElementById(select_item)){
						e = document.getElementById(select_item);
						e.checked = e.checked == true ? false : true;
					}
			}
		}
	}
	
}
