// JavaScript Document
/* -----------------------------------------------
  Image Preloader - v.1.1
  (c) 2007 http://www.haan.net
  You may use this script but please leave the credits on top intact.
  Please inform us of any improvements made.
  When useful, we will add your credits.
------------------------------------------------ */
function preload(pics) {
 	var brochure = new Array();
 	//var dir = './images/navigation/' // path to images
 	for (i=0;i<pics.length;i++) {
  		brochure[i] = new Image();
  		brochure[i].src = pics[i]; // change file extension, if necessary.
 		// uncomment next line for testing; click OK to continue loop and cancel to break
 		//if(i==0)
		//	if(!confirm(brochure[i].src)) break;
 	}
}

// call the function with the list of images (unique part of names)
// Multiple onload function created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
/*function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
*/
/*
addLoadEvent(function() {
	hideIt();loadGoogleMap();
	chkSlideShow();
	galPreload();
	
});
*/
//-------------------------------------------------


/*window.onload = function(){
// this is main fucntion to call on page load
init_table_list ('listing');
}*/


function init_table_list (tableid){

	var tb = document.getElementById(tableid);
	var tbid = tb.getElementsByTagName("tr");
	for (var i in tbid) {
		tbid[i].onmouseover = function() {highlight_on(this,'#EEF1FB')}
		tbid[i].onmouseout = function() {highlight_off(this,'')}
	}
/*
	var tbid = document.getElementById(tableid);	
	tbid.onmouseover = function() {
		//alert("mouse over");
		highlight_on(this,'#EEF1FB')
	}
	
	tbid.onmouseout = function() {
		//alert("mouse out");
		highlight_off(this,'')
	}
*/
}

function highlight_on (thisobj,color){
	thisobj.style.backgroundColor=color;
}

function highlight_off (thisobj,color){
	thisobj.style.backgroundColor=color;
}
/* show/hide element */
function show_element(elem_id, elem_show){
	elem_show  = typeof(elem_show)  != 'undefined' ? elem_show : true;
	var elem=document.getElementById(elem_id);
	if(elem_show==true)	elem.style.display='';
	else elem.style.display='none';
}

//-------------

/*show body content with javascript*/
function jsgo(URL){
	var iURL  = typeof(URL)  != 'undefined' ? URL  : window.location;
	window.location.href = iURL;
}

/*open popup window*/
function winPop(URL,name, w, h) {
  //set default to arg
  URL  = typeof(URL)  != 'undefined' ? URL  : "empty";
  name = typeof(name) != 'undefined' ? name : "WinPoP";
  w	   = typeof(w)    != 'undefined' ? w    : "350";
  h    = typeof(h)    != 'undefined' ? h    : "200";
  x	   = 0;
  y    = 0;
  if(screen){
 	y  = (screen.availHeight - h)/2;
	x  = (screen.availWidth - w)/2;
  }
  
  if(URL!="empty"){
    window.open(URL, name,"resizable=yes,scrollbars=yes,toolbar=no,status=no,height="+h+",width="+w+",top="+y+",left="+x);			
  }else{ alert("Error:: winPop() : Undefined URL ");}
}

/*Open new window for print coupon of company*/
function printCoupon(coupon_id,path){
	if(typeof(coupon_id)!='undefined'){
		var URL=path+"/coupon_print.php?cp_id="+coupon_id;
		winPop(URL,'PrintCoupon',350,150);
		return true;
	}else return false;
}

/*check input value is between the lenght or not
  return TRUE if value between in the lenght
  return FALSE if not in lenght
*/
function isBetween(num,min_val,max_val){
	if (min_val > num || max_val < num) {
		return false;  // not between
	}else return true; // between value
}

/*
  show element of form for company data field
*/
function selectCustComp(comp_checked){
	
	//comp_checked = true , selected on company
	document.getElementById('c_id').disabled			=!comp_checked;
	document.getElementById('us_company').disabled		=!comp_checked;
	document.getElementById('us_description').disabled	=!comp_checked;
	document.getElementById('us_sale').disabled			=!comp_checked;
	document.getElementById('us_website').disabled		=!comp_checked;
	document.getElementById('us_logo').disabled			=!comp_checked;
	

	show_element('frm_comp_cat',comp_checked);
	show_element('frm_comp_name',comp_checked);
	show_element('frm_comp_description',comp_checked);
	show_element('frm_comp_sale',comp_checked);
	show_element('frm_comp_website',comp_checked);
	show_element('frm_comp_logo',comp_checked);
	
	//default value
	if(comp_checked){ //selected on company
		var df_max=document.getElementById('df_max_c').value;
		var df_life=document.getElementById('df_life_c').value;
		var df_life_type=document.getElementById('df_life_type_c').value;
	}else{
		var df_max=document.getElementById('df_max_p').value;
		var df_life=document.getElementById('df_life_p').value;
		var df_life_type=document.getElementById('df_life_type_p').value;
	}

	document.getElementById('us_max_items').value=df_max;
	document.getElementById('us_life_item').value=df_life;
	var sel=0;
	switch(df_life_type){
		case 'day':   sel=0; break;
		case 'month': sel=1; break;
		case 'year':  sel=2; break;
	}
	document.getElementById('us_life_type').options[sel].selected=true;
}

/*check both password*/
function check_both_password(pw1,pw2,target){
	if(pw1!="" && pw2!=""){	
		var txt="<font color='red'>Passwoerter stimmen nicht ueberein.</font>";
		if( pw1!=pw2 )	document.getElementById(target).innerHTML=txt;	
		else document.getElementById(target).innerHTML="";	
	}else document.getElementById(target).innerHTML="";	
}

/* print mailto link*/
var user;
var domain;
var suffix;
function jemail(user, domain, suffix){
document.write('<a href="' + 'mailto:' + user + '@' + domain + '.' + suffix + '">' + user + '@' + domain + '.' + suffix +"<\/a>");
}


/* ---> Begin
 This script and many more are available free online at
 The JavaScript Source!! http://javascript.internet.com
 Created by: Abraham Joffe :: http://www.abrahamjoffe.com.au/ */
 
/***** CUSTOMIZE THESE VARIABLES *****/


var maxWidth=200;// width to resize large images to
var maxHeight=200;// height to resize large images to
var fileTypes=["gif","jpg","jpeg"];// valid file types
var outImage="previewField";// the id of the preview image tag
var defaultPic="spacing.gif";// what to display when the image is not valid
/***** DO NOT EDIT BELOW *****/

function preview(what,maxW,maxH,maxSize,allowedType){
  maxW 		  = typeof(maxW) 		!= 'undefined' ? maxW  		 : maxWidth;
  maxH 		  = typeof(maxH) 		!= 'undefined' ? maxH  		 : maxHeight;
  maxSize 	  = typeof(maxSize)    	!= 'undefined' ? maxSize     : 0;
  allowedType = typeof(allowedType) != 'undefined' ? allowedType : fileTypes;

  var source=what.value;
  var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
  for (var i=0; i<fileTypes.length; i++) if (fileTypes[i]==ext) break;
  globalPic=new Image();
  if (i<fileTypes.length){
	  globalPic.src=source;
	  alert("img siz:"+ globalPic.fileSize);
	  jsGetFileSize(what);
  }else {
    //globalPic.src=defaultPic;
    alert("THAT IS NOT A VALID IMAGE\nPlease load an image with an extention of one of the following:\n\n"+fileTypes.join(", "));
  }
  setTimeout("applyChanges()",10);
  
}
var globalPic;
function applyChanges(){
	//alert("applychange()"+globalPic.width);
  var field	=document.getElementById(outImage);
  var x		=parseInt(globalPic.width);
  var y		=parseInt(globalPic.height);
  if (x>maxWidth) {   y*=maxWidth/x;   x=maxWidth;  }
  if (y>maxHeight) {  x*=maxHeight/y;  y=maxHeight; }
  field.style.display=(x<1 || y<1)?"none":"";
  field.src=globalPic.src;
  field.width=x;
  field.height=y;
}

function jsGetFileSize(elem){
var oas = new ActiveXObject("Scripting.FileSystemObject");
var d = elem.value;
var e = oas.getFile(d);
var f = e.size;
alert(f + " bytes");
}
function jsEmail(prefix,domain,style_class){
	document.write('<a '+style_class+' href="mailto:' + prefix + '@' + domain + '">');
	document.write(prefix + '@' + domain + '<\/a>');
}
// End -->
