function resizeWin()
{
if (document.all) {
        winHeight=document.all['bodyArea'].offsetHeight;
        winWidth=document.all['bodyArea'].offsetWidth;
}
// add 30 to the width for a border
// add 60 to the height to account for a border + the titlebar
window.resizeTo(winWidth+30,winHeight+80);
//alert("width="+winWidth+" height="+winHeight);
//window.resizeTo(winWidth+30,800);

//centre the window
if (window.moveTo) window.moveTo((screen.availWidth-winWidth)/2,(screen.availHeight-winHeight)/2);
}



//   Usage : call function using a URL, window width, height and Name..
//	Example : open_url('http://myurl.com',100,100,'MyPoPuP');

var Winpop;
var msg;
function open_url(url,swidth,sheight,wname) {
      LeftPosition=(screen.width)?(screen.width-swidth)/2:100;
      TopPosition=(screen.height)?(screen.height-sheight)/2:100;
      //var sb = (s == "true")? "1":"0";
      //alert(sb);
      if ((!Winpop)||(Winpop.closed)) {
         Winpop = window.open(url,wname,'scrollbars=0,menu=0,height='+sheight+',width='+swidth+',left='+LeftPosition+',top='+TopPosition);
         Winpop.focus();
      }else {
      	 Winpop.close();	
         Winpop = window.open(url,wname,'scrollbars=0,menu=0,height='+sheight+',width='+swidth+',left='+LeftPosition+',top='+TopPosition);
         //Winpop.location.href = url;
         Winpop.focus();
      }
}

function  phone_check(code, phone)
{
    if ((phone.value.length>0) && (code.value.length==0))
    {
        alert("telefon kod numarasını girmelisiniz!");
        code.focus();
        code.select();
        return(false);
    }
    else if (((phone.value.length>0) || (code.value.length>0)) && ((code.value.length<3) || (!checkNumber(code.value))))
    {
        alert("telefon kod numarasını doğru girmelisiniz!");
        code.focus();
        code.select();
        return(false);
    }
    else if ((phone.value.length==0) && (code.value.length>0))
    {
        alert("telefon numarasını girmelisiniz!");
        phone.focus();
        phone.select();
        return(false);
    }
    else if (((phone.value.length>0) || (code.value.length>0)) && ((phone.value.length<7) || (!checkNumberGTZero(phone.value))))
    {
        alert("telefon numarasını doğru girmelisiniz!");
        phone.focus();
        phone.select();
        return(false);
    }

    return(true);
}
function  phone_checkStr(phone)
{
    if ((phone.length==0))
    {
        alert("telefon numarasını girmelisiniz!");
        return(false);
    }
    else if ((phone.length>0) && (!checkNumberGTZero(phone) || (phone.length!=10) ) )
    {
        alert("Lütfen telefon numarasını başında 0 olmadan 10 rakam olacak şekilde giriniz.");
        return(false);
    }

    return(true);
}
function radioCheckValue(radio,val)
{
 if (radio.value!=null) {
   if (radio.value==val) return true;
 }
 else {
 for (counter = 0; counter < radio.length; counter++)
 {
	 if ((radio[counter].checked) && (radio[counter].value==val)) {
		 return true;
     }
 }
 }
 return false;
}

function radioIsEmpty(radio)
{
	 for (counter = 0; counter < radio.length; counter++)
	 {
		 if (radio[counter].checked) {
			 return false;
		     }
	 }
 	return true;
 }

function  email_check(stremail)
{
   if (stremail.indexOf("@") < 1)
       return(0)
   else if (stremail.indexOf(".")==0)
       return(0)
   else if (stremail.indexOf("..")>=0)
       return(0)
   else if (stremail.indexOf(".@")>=0)
       return(0)
   else if (stremail.indexOf("@.")>=0)
       return(0)
   else if (stremail.indexOf(".", stremail.indexOf("@")+2)<0)
       return(0)
   else if (stremail.lastIndexOf(".")== (stremail.length-1))
       return(0)
   else if ((stremail.indexOf(" ")>0) && (stremail.indexOf(" ")<stremail.length-1))
       return(0)
   else
       return(1);
}



function checkNumberGTZero(n)
{
    if (!checkNumber(n)) return false;

    var c, ok = false;
	for(i = 0;!ok && i < n.length; i++)
	{
		c = n.charAt(i);
		if (c!= '0') ok = true;
	}
	return ok;
}

function checkEmail(e)
{
	if (checkEmpty(e)) return false;

	var i = e.indexOf('@');
	if (i < 1) return false;

	i = e.indexOf('.', i + 1);
	if (i == -1) return false;

	return true;
}

function checkEmpty(s)
{
	var c, ok = true;
	for(i = 0; ok && i < s.length; i++)
	{
		c = s.charAt(i);
		if (c!= ' ') ok = false;
	}

	return ok;
}

function checkBlank(s)
{
	var c, ok = false;
	for(i = 0; !ok && i < s.length; i++)
	{
		c = s.charAt(i);
		if (c== ' ') ok = true;
	}

	return ok;
}

function checkNumber(n)
{
	var c, ok = true;
	for(i = 0; ok && i < n.length; i++)
	{
		c = n.charAt(i);
		if (c < '0' || c > '9') ok = false;
	}

	return ok;
}

function checkDouble(d)
{
	var c, ok = true, decimal = false;
	for(i = 0; ok && i < d.length; i++)
	{
		c = d.charAt(i);
		if ((c == '.' || c == ',') &&!decimal) decimal = true;
		else if (c < '0' || c > '9') ok = false;
	}

	return ok;
}

function DaysOfMonth(m, y)
{
	if (m == 4 || m==6 || m==9 || m==11) d=30;
	else if (m!= 2) d=31;
	else if ((y%100) &&!(y%4)) d=29;
	else d = 28;

	return d;
}

function checkDate(g,a,y)
{
	var ret = true;

	if (!checkNumber(g)) return false;
	if (!checkNumber(a)) return false;
	if (!checkNumber(y)) return false;

	if ( 1*y < 1900 || 1*y > 2050) ret = false;
	else
	if (1*a < 1 || 1*a > 12) ret = false;
	else
	{
		var dc = DaysOfMonth(a, y);

		if (1*g < 1 || 1*g > dc) ret = false;
	}

	return ret;
}

function dateCompare(g1, a1, y1, g2, a2, y2)
{
	if (1 * y1 < 1 * y2) return 1;
	if (1 * y1 == 1 * y2 && 1 *a1 < 1 *a2) return 1;
	if (1 * y1 == 1 * y2 && 1 * a1 == 1 * a2 && 1 * g1 < 1 * g2) return 1;

	if (1 * y1 > 1 * y2) return -1;
	if (1 * y1 == 1 * y2 && 1 * a1 > 1 * a2) return -1;
	if (1 * y1 == 1 * y2 && 1 * a1 == 1 * a2 && 1 * g1 > 1 * g2) return -1;

	return 0;
}


function NumberToStr(number, precision)
{
	if (!number)
		return "0";

	var prefix = "";
	if (number < 0)
	{
		prefix = "-";
		number = -1 * number;
	}

	var n = 1;
	for (i = 1; i <= precision; i++)
		n = 10 * n;

	var m
	m	= Math.round(number * n);
	s	= m.toString();
	while (s.length < precision)
		s = '0' + s;

	sd = "";
	if (precision > 0)
	{
		sd	=s.substring(s.length - precision, s.length);
		s	=s.substring(0, s.length - precision) ;
	}
	if (sd!= "") sd = "." + sd;

	while (s.length > 0)
	{
		n = s.length;
		if (n > 3) n = 3;
		sd	= s.substring(s.length - n, s.length) + sd;
		s	= s.substring(0, s.length - n);
		if (s!= "") sd = "." + sd;
	}

	if (sd.substring(0, 1) == ".") sd = "0" + sd;
	return prefix + sd;
}

function NumberToStrWithZero(number, precision)
{
	if (!number)
		return "";

	var prefix = "";
	if (number < 0)
	{
		prefix = "-";
		number = -1 * number;
	}

	var n = 1;
	for (i = 1; i <= precision; i++)
		n = 10 * n;

	var m
	m	= Math.round(number * n);
	s	= m.toString();
	while (s.length < precision)
		s = '0' + s;

	sd = "";
	if (precision > 0)
	{
		sd	=s.substring(s.length - precision, s.length);
		s	=s.substring(0, s.length - precision) ;
	}
	if (sd!= "") sd = "." + sd;

	while (s.length > 0)
	{
		n = s.length;
		if (n > 3) n = 3;
		sd	= s.substring(s.length - n, s.length) + sd;
		s	= s.substring(0, s.length - n);
		if (s!= "") sd = "." + sd;
	}

	if (sd.substring(0, 1) == ".") sd = "0" + sd;
	return prefix + sd;
}

function RNumber(number)
{
	return number.replace(".", ",");
}
function removeitem(qstr, item)
{
   var i;

   if (qstr.length>0) {
        i=qstr.indexOf(item);
        while (i>-1) {
              qstr = qstr.substring(0,i)+qstr.substring(i+1,qstr.length);
              i=qstr.indexOf(item,i+1);
        }
        //alert(rqstr);
        return(qstr);
    }
    else
      return("");

}
// ilk karakteri büyük harf yapıyor, input adını ver.

function firstCharToUpper(temp)
{
  tempstring = stringToLowerStr(trimSpacesStr(temp.value));
  tempstr = tempstring.substring(0,1);

  
  
  for (var i = 1; i < tempstring.length; i++){      
    var ch = tempstring.substring(i, i + 1);      
    if((ch == "İ") || (ch == "I")) {
     	if(ch == "İ")ch = "i";
     	if(ch == "I")ch = "ı";
    }else{
    	ch =  ch.toLowerCase();
    }
    tempstr = tempstr + ch;
  }
  
  tempstring = tempstr;
  if(tempstring.substring(0,1) == 'i')
    temp.value = 'İ' + tempstring.substring(1, tempstring.length);
  else
    temp.value = tempstring.substring(0,1).toUpperCase() + tempstring.substring(1, tempstring.length);

  
} 

// bütün karakterleri büyük harfe çeviriyor.

function stringToUpper(temp)
{
  tempstring = temp.value;
  //temp.value = tempstring.toUpperCase();
  tempstr="";
  
   for (var i = 0; i < tempstring.length; i++){      
   var ch = tempstring.substring(i, i + 1);      
   if(ch == "i") {
     ch = "İ";
   }else{
	ch =  ch.toUpperCase();
   }
   tempstr = tempstr + ch; 
   }
   
   temp.value = tempstr;
  

} 


// parameter olarak string alıyor bütün karakterleri büyük harfe çeviriyor.

function stringToUpperStr(temp)
{
  tempstring = temp;
  tempstr="";
  
   for (var i = 0; i < tempstring.length; i++){      
   var ch = tempstring.substring(i, i + 1);      
   if(ch == "i") {
     ch = "İ";
   }else{
	ch =  ch.toUpperCase();
   }
   tempstr = tempstr + ch; 
   }
   
  return tempstr;
  

} 

// bütün karakterleri küçük harfe çeviriyor.

function stringToLower(temp)
{
  tempstring = temp.value;
  //temp.value = tempstring.toLowerCase();
  tempstr="";
  
   for (var i = 0; i < tempstring.length; i++){      
   var ch = tempstring.substring(i, i + 1);      
   if(ch == "i") {
     ch = "İ";
   }else{
	ch =  ch.toLowerCase();
   }
   tempstr = tempstr + ch; 
   }
   
   temp.value = tempstr;
  

} 


// parameter olarak string alıyor bütün karakterleri küçük harfe çeviriyor.

function stringToLowerStr(temp)
{
  tempstring = temp;
  tempstr="";
  
   for (var i = 0; i < tempstring.length; i++){      
   var ch = tempstring.substring(i, i + 1);      
   if(ch == "i") {
     ch = "İ";
   }else{
	ch =  ch.toLowerCase();
   }
   tempstr = tempstr + ch; 
   }
   
  return tempstr;
  

} 
//trims leading and trailing spaces
function trimSpaces(temp)
{
  //trailing
  while(''+temp.value.charAt(temp.value.length-1)==' ')
  temp.value=temp.value.substring(0,temp.value.length-1);
 
  //leading
  while(''+temp.value.charAt(0)==' ')
   temp.value=temp.value.substring(1,temp.value.length);
}
//trims leading and trailing spaces
function trimSpacesStr(temp)
{
  tempstr=temp;	
  //trailing
  while(''+tempstr.charAt(tempstr.length-1)==' ')
  tempstr=tempstr.substring(0,tempstr.length-1);
 
  //leading
  while(''+tempstr.charAt(0)==' ')
   tempstr=tempstr.substring(1,tempstr.length);
   
  return tempstr; 
}
function geturlparam( name )
{  
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
var regexS = "[\\?&]"+name+"=([^&#]*)";  
var regex = new RegExp( regexS );  
var results = regex.exec( window.location.href );  
if( results == null )    return "";  
else    return results[1];
}
function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}
function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}
