/**
 * @author Chris
 */
// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
function pageWidth() {return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;}
function pageHeight() {return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;}
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;}
function posRight() {return posLeft()+pageWidth();}
function posBottom() {return posTop()+pageHeight();}

//get absolute position of object
function getAbsX( oElement )
{
    var iReturnValue = 0;
    while( oElement != null ) {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

function getAbsY( oElement )
{
    var iReturnValue = 0;
    while( oElement != null ) {
        iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}
    
function fitObjectHeight(targetObjId, vertObjectIds)
{
  var iVertPad = 0;
  var targetObj = document.getElementById(targetObjId);
  var vertObject, marginTop, marginBottom;
  
  for (var i = 0; i < vertObjectIds.length; i++) 
  {
    vertObject = document.getElementById(vertObjectIds[i]);
    iVertPad = iVertPad + vertObject.offsetHeight;
    if (document.all) // IE
    {
      marginTop = vertObject.currentStyle.marginTop;
      marginBottom = vertObject.currentStyle.marginBottom;
    }
    else
    {
      marginTop = document.defaultView.getComputedStyle(vertObject, '').getPropertyValue('margin-top');
      marginBottom = document.defaultView.getComputedStyle(vertObject, '').getPropertyValue('margin-bottom');
    }
    if (!isNaN(parseInt(marginTop))) {
      iVertPad = iVertPad + parseInt(marginTop);
      //alert('marginTop:'+ vertObject.id +':'+marginTop);
    }
    if (!isNaN(parseInt(marginBottom))) 
    {
      iVertPad = iVertPad + parseInt(marginBottom);
      //alert('marginBottom:'+ vertObject.id +':'+marginBottom);
    }
    //alert(vertObjectIds[i] +":"+ vertObject.offsetHeight);
  }
  var iObjNewHeight = (pageHeight() - getAbsY(targetObj) - iVertPad - 8) + "px";
  //alert(iObjNewHeight);
  targetObj.style.height = iObjNewHeight;
}

function ShowObject(ObjID, Display)
{
  var myObj = document.getElementById(ObjID);
  myObj.style.display = Display;
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

/*
 * Store functions
*/

function calctot()
{	
		if (document.order_form.SEROD_no.value){
			SEROD = document.order_form.SEROD_no.value*59;
		}
		if (document.order_form.MEROD_no.value){
			MEROD = document.order_form.MEROD_no.value*59;
		}
		if (document.order_form.FEROD_no.value){
			FEROD = document.order_form.FEROD_no.value*59;
		}
		if (document.order_form.FFEROD_no.value){
			FFEROD = document.order_form.FFEROD_no.value*54;
		}
		if (document.order_form.SHAM_no.value){
			SHAM  = document.order_form.SHAM_no.value*85;
		}
		if (document.order_form.COND_no.value){
			 COND = document.order_form.COND_no.value*85;
		}
		if (document.order_form.PCBW_no.value){
			PCBW = document.order_form.PCBW_no.value*65;
		}
		if (document.order_form.BL_no.value){
			BL = document.order_form.BL_no.value*76;
		}
		if (document.order_form.SC_no.value){
			SC = document.order_form.SC_no.value*68;
		}
		if (document.order_form.PBCMT_no.value){
			PBCMT = document.order_form.PBCMT_no.value*40;
		}
		if (document.order_form.BSBW_no.value){
			BSBW = document.order_form.BSBW_no.value*70;
		}
		if (document.order_form.BBL_no.value){
			BBL = document.order_form.BBL_no.value*70;
		}
		if (document.order_form.BBC_no.value){
			BBC = document.order_form.BBC_no.value*70;
		}
		if (document.order_form.BW_no.value){
			BW = document.order_form.BW_no.value*70;
		}
		if (document.order_form.TBT_no.value){
			TBT = document.order_form.TBT_no.value*38;
		}
		if (document.order_form.TBB_no.value){
			TBB = document.order_form.TBB_no.value*54;
		}
			
		var Total = (BSBW + BBL + BBC + BW + SEROD + MEROD + FEROD + FFEROD + SHAM + COND + PCBW + BL + SC + PBCMT + TBB + TBT);
		
		if ($('#courierchkbx').attr('checked')){
      		DelvTot	= 70;
		}else/*
 if($('#postOfficeChkbx').attr('checked'))
*/
{
			DelvTot	= 35;
		}
		if (DelvTot == 0){
			document.order_form.Delv_no.value	= 'Free';		
		}else{
			document.order_form.Delv_no.value = 'R '+DelvTot;
		}
		
		Total += DelvTot;
		
		document.order_form.Total_no.value = 'R '+Total.toFixed(2);


}
 
function agreed(){
	if($('input[name=orderButton]').attr('disabled')){
		$('input[name=orderButton]').removeAttr('disabled');
	}else{
		$('input[name=orderButton]').attr('disabled', true);
	}	
}
 
function copyPhysAddy()
{
	document.order_form.order_PosAddy.value = document.order_form.order_PhyAddy.value;

}

function change_ref_head(selectedOption){
	newText = '';
	switch(selectedOption){
		case 'Advert':
			newText = 'Please specify which Publication...';
		break;
		case 'Agent':
			newText = 'Please specify Agent Name...';;
		break;
		case 'Brochure':
			newText = 'Please specify which Brochure...';
		break;
		case 'Exhibition':
			newText = 'Please specify which Exhibition...';
		break;
		case 'Website':
			newText = 'Please specify Website address...';
		break;			
		case 'Other':
			newText = 'Please provide details...';
		break;
	}

	document.getElementById('ref_head').innerHTML = newText;

}
					